Code Monkey home page Code Monkey logo

android-support-preference's Introduction

Material Preference

Material theme for preference widgets.

Backporting dat material look and functionality.

Available from API 14. Connecting AndroidX Preference to AppCompat.

For older version see the 2.x branch.

Table of contents

dependencies {
    implementation("net.xpece.android:support-preference:3.0.0")
}

repositories {
    mavenCentral()
}

Compatibility

Version 3.x.x requires AndroidX.

How to get color picker preference too?

dependencies {
    implementation("net.xpece.android:support-preference-color:3.0.0")
}

How to get custom Material popup menu and spinner?

dependencies {
    implementation("net.xpece.android:support-spinner:3.0.0")
}

Android version 4.4.

Showcasing simple menu/dialog, custom title and summary text appearance and color picker.

Simple menu  Simple dialog with long items  ColorPreference and custom text color  Overview 1  EditTextPreference  MultiSelectListPreference  PreferenceScreen  Overview 2  RingtonePreference  SeekBarDialogPreference  ListPreference  Disabled preferences 

Support preference

  • Preference
  • CheckBoxPreference
  • SwitchPreference
    • Using SwitchCompat available from API 7
  • DialogPreference
    • Uses AppCompat AlertDialog Material theme
  • EditTextPreference
  • ListPreference
    • Optionally can display as a simple menu or simple dialog.
    • Subclasses support custom adapter.
  • DropDownPreference
  • MultiSelectListPreference
    • Available since API 7
  • SeekBarDialogPreference extends DialogPreference
    • Made public
  • SeekBarPreference
  • RingtonePreference
    • Coerced Ringtone Picker Activity from AOSP
  • XpPreferenceFragment
    • Handles proper Preference inflation and DialogPreference dialogs
  • SharedPreferencesCompat
    • getStringSet and putStringSet methods allow persisting string sets even before API 11
  • XpPreferenceManager
    • setDefaultValues method takes into account preference classes in custom packages
  • XpPreferenceHelpers
    • Tinted icons and text appearance support for preferences outside of this library
  • ColorPreference

Support spinner

Spinner, popup menu and adapters behaving according to Material Design specs. Read https://www.google.com/design/spec/components/menus.html#menus-behavior.

  • XpAppCompatSpinner
    • Spinner variant that uses simple menu or simple dialog.
  • XpListPopupWindow
    • Popup window that supports minimum distance from edges, multiple size measuring modes, ListView padding etc.
  • CheckedTypedItemAdapter<T>
    • ListAdapter plus SpinnerAdapter that highlights one item.
    • Open methods for converting T to CharSequence.
    • Allows different string representations for selected spinner item and drop down menu.

Features on top of AndroidX Preference

  • Using AppCompat features.
  • Material preference item layouts out of the box.
  • Icon and dialog icon tinting and padding.
  • EditTextPreference understands EditText XML attributes.
    • Use EditTextPreference.setOnCreateEditTextListener(OnCreateEditTextListener) to setup your input field.
  • Several preference widgets not publicly available in AndroidX or SDK.
    • RingtonePreference, SeekBarPreference, SeekBarDialogPreference, MultiSelectListPreference
  • Subscreen navigation implementation.
  • ListPreference can optionally show as a simple menu in a popup instead of a dialog.
  • ColorPreference
  • Preference long click listeners.
  • Title/summary text color and text appearance defined in Java or XML.

Basic setup

Your preference fragment needs to extend XpPreferenceFragment.

Setup your preference items in the following method:

public void onCreatePreferences2(final Bundle savedInstanceState, final String rootKey) {
    addPreferencesFromResource(R.xml.my_preferences);
}

Your settings activity theme needs to specify the following values:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Used to theme preference list and items. -->
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.Asp.Material</item>
    <!-- Default icon tint for preferences. -->
    <item name="asp_preferenceIconTint">?colorAccent</item>
    <item name="asp_preferenceDialogIconTint">?asp_preferenceIconTint</item>
</style>

Recommended tint colors are ?colorAccent or ?colorControlNormal.

Styling alertDialogTheme is recommended for a proper color theme. See the sample project.

Dividers

AndroidX Preference provides a divider implementation out of the box. If you want to customize how this divider looks you can call setDivider(...) and setDividerHeight(...). The divider will be drawn just between items and at the bottom of the list. It will not be drawn before the end of category.

If you want more control over where the dividers are drawn, disable the default implementation and enable the one from this library:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getListView().addItemDecoration(
            new PreferenceDividerDecoration(getStyledContext())
                    .drawBottom(true));
    setDivider(null);
}

Ringtone picker

RingtonePicker will show only system ringtones/notification sounds by default. If you want to include sounds from the external storage your app needs to request android.permission.READ_EXTERNAL_STORAGE permission in its manifest. Don't forget to check this runtime permission before opening ringtone picker on API 23.

ListPreference custom adapter

If you subclass ListPreference you can supply your own SpinnerAdapter which may or may not use getEntries() as its data set. Here follow the methods you need to override:

  • SpinnerAdapter buildSimpleMenuAdapter(Context) - Used in simple menus.
  • SpinnerAdapter buildSimpleDialogAdapter(Context) - Used in simple dialogs.
  • Override the following methods if your SpinnerAdapter does not use getEntries() as data set:
    • CharSequence[] getEntries() - Item captions.
    • CharSequence[] getEntryValues() - Persisted item values.

Simple menu and Simple dialog

Simple menu is described in Material Design specs.

If you want to show your ListPreference in a popup instead of a dialog use this configuration:

<ListPreference
    style="@style/Preference.Material.DialogPreference.ListPreference.SimpleMenu"/>

Above code will ensure that:

  • If all items fit on one line a popup window is shown.
  • Otherwise a simple dialog is shown.
  • Popup window width will round up to nearest multiply of 56dp on phones and 64dp on tablets.

These are the attributes and values for manual setup:

Attribute Values Description
app:asp_menuMode dialog Default behavior. Alert dialog with radio buttons and optional window title.
simple_menu Menu is shown in a popup window. Selected option is highlighted. Less disruptive than dialog.
simple_dialog Menu is shown in a dialog with no other controls. Selected option is highlighted.
simple_adaptive Menu is shown in a popup window if it contains single line items only . Otherwise simple dialog is shown.
app:asp_simpleMenuWidthUnit 0dp Default behavior. Popup window width is determined by the width of its content.
*X*dp Popup width is determined by the width of its content and rounded up to the nearest multiply of Xdp.
app:asp_simpleMenuWidthMode match_constraint Popup width will stretch to match underlying ListPreference width.
wrap_content Default behavior. Popup window width is determined by the width of its content.
wrap_content_unit Popup width is determined by the width of its content and rounded up to the nearest multiply of Xdp.
app:asp_simpleMenuMaxWidth fit_anchor Default behavior. Popup width can stretch up to width of the underlying ListPreference.
fit_screen Popup width can stretch up to width of the screen.
app:asp_simpleMenuMaxItemCount -1 Default behavior. Popup will show as many items as fit on the screen.
X Popup will show at most X items.

Material Spinner

New XpAppCompatSpinner widget is built according to Material Design specs.

Menus are positioned over their emitting elements such that the currently selected menu item appears on top of the emitting element.

Example setup:

<net.xpece.android.support.widget.XpAppCompatSpinner
    style="@style/Widget.Material.Spinner.Underlined"
    android:theme="ThemeOverlay.Material.Spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/my_entries"
    app:asp_spinnerMode="dialog|dropdown|adaptive"/>

The above setup will ensure the following:

  • Popup ListView will have top and bottom padding.
    • Theme overlay applied via android:theme directly limits its effects on this widget.
    • Is not supported by AppCompat or platform popup windows.
  • Spinner will have proper space around its caret before API 23.
    • If using style="@style/Widget.Material.Spinner" or style="@style/Widget.Material.Spinner.Underlined".

If you need to alter entries programmatically create by CheckedItemAdapter.newInstance(Context, CharSequence[], int) or supply your own adapter (responsible for its own styling) to XpAppCompatSpinner.setAdapter(SpinnerAdapter).

Attribute Values Description
app:asp_spinnerMode dropdown Menu is shown in a popup window. Selected option is highlighted. Less disruptive.
dialog Menu is shown in a dialog with no other controls. Selected option is highlighted.
adaptive Default behavior. Menu is shown in a popup window if it contains only single line items. Otherwise simple dialog is shown.
app:asp_simpleMenuWidthUnit 0dp Default behavior. Popup window width is determined by the width of its content.
*X*dp Popup width is determined by the width of its content and rounded up to the nearest multiply of Xdp.
app:asp_simpleMenuWidthMode match_constraint Popup width will stretch to match underlying anchor width.
wrap_content Default behavior. Popup window width is determined by the width of its content.
wrap_content_unit Popup width is determined by the width of its content and rounded up to the nearest multiply of Xdp.
app:asp_simpleMenuMaxWidth fit_anchor Popup width can stretch up to width of the underlying anchor.
fit_screen Default behavior. Popup width can stretch up to width of the screen.
app:asp_simpleMenuMaxItemCount -1 Default behavior. Popup will show as many items as fit on the screen.
X Popup will show at most X items.

Color preference

<ColorPreference
    android:defaultValue="?colorPrimary"
    android:entries="@array/colors_material_names"
    android:entryValues="@array/colors_material"
    android:key="notif_color"
    android:title="Notification color"/>

<array name="colors_material">
     <item>@color/material_red_500</item>
     <item>@color/material_light_blue_500</item>
     <item>@color/material_light_green_500</item>
     <item>@color/material_orange_500</item>
</array>

<string-array name="colors_material_names">
    <item>Red</item>
    <item>Light Blue</item>
    <item>Light Green</item>
    <item>Orange</item>
</string-array>

Attributes include:

Attribute Values Description
android:entryValues Array of colors Specifies an array of colors to display.
android:entries Array of text Specifies textual description of each color.
app:asp_columnCount Integer Specifies the number of columns in the color picker. Use an integer resource which will allow you to specify greater number on tablets. Default is 4.
-1 Number of columns will be computed automatically to fill space available in window.
app:asp_swatchSize small Default option. Swatches will be 48dp in width and height plus 4dp margin on each side.
large Swatches will be 64dp in width and height plus 8dp margin on each side.

Finally you need to make your preference fragment fire up the color picker dialog when the preference is clicked and optionally update summary when a color is chosen. Please review sample SettingsActivity.java and SettingsFragment.java respectively.

If you need to change the default style either use style attribute or override it in your theme:

<item name="colorPreferenceStyle">@style/Preference.Material.DialogPreference.ColorPreference</item>

The color is stored internally as a 32-bit integer.

Subscreen navigation

Possible solution is implemented in PreferenceScreenNavigationStrategy.ReplaceFragment class. This class will help you replace the whole preference fragment with a new instance with specified root preference. It is using fragment transactions and back stack allowing for transition animations and saved states.

This class also supports Up button navigation which synthesizes preference screen stack on-the-fly. Please see the sample project for details.

Known issues with support library

You may have experienced unexpected background color which manifests as holo blue on Android 4 and grey on Android 5. This is caused by PreferenceFragment's RecyclerView grabbing focus on fragment start. We can disable this behavior while still being able to navigate between individual preferences with a D-pad.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final RecyclerView listView = getListView();

    // We don't want this. The children are still focusable.
    listView.setFocusable(false);
}

Icon tinting

All preferences:

  • app:asp_tint
  • app:asp_tintMode
  • app:asp_tintEnabled

All dialog preferences:

  • app:asp_dialogTint
  • app:asp_dialogTintMode
  • app:asp_dialogTintEnabled

Icon padding

Application icons (48dp x 48dp) require no extra padding. For smaller icons extra padding of 4dp on each side is needed. Achieve this by using app:asp_iconPaddingEnabled and app:asp_dialogIconPaddingEnabled attributes. Icon padding is enabled by default.

Handling PreferenceScreen icons

As PreferenceScreen class is final and hardwired into preference system I was unable to automate icon tinting and padding. However you are able to do this yourself:

Preference subs = findPreference("subscreen");
PreferenceIconHelper subsHelper = new PreferenceIconHelper(subs);
subsHelper.setIconPaddingEnabled(true); // Call this BEFORE setIcon!
subsHelper.setIcon(R.drawable.some_icon);
subsHelper.setTintList(AppCompatResources.getColorStateList(subs.getContext(), R.color.accent));
subsHelper.setIconTintEnabled(true);
/* or */
PreferenceIconHelper.setup(subs /* preference */,
    R.drawable.some_icon /* icon */,
    R.color.accent /* tint */,
    true /* padding */);

You can use this class even on preference classes from androidx.preference package in case you're not using XpPreferenceFragment.

Proguard

Proguard rules are bundled with the library.

Changelog

See CHANGELOG.md.

Some devices require special care and specific errors may occur inside this library. You are encouraged to opt-in to notifications about these internal errors so this library and relay them to the Issues section.

Here's an example how to get error reports to Crashlytics:

class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Setup Crashlytics, do whatever else you need...

        XpSupportPreferencePlugins.registerErrorInterceptor(new ErrorInterceptor() {
            @Override
            public void onError(@NonNull Throwable t, @Nullable String message) {
                Timber.w(t, message);
                if (message != null) Crashlytics.log(message);
                Crashlytics.logException(t);
            }
        });
    }
}

Only register the listener once per app process!

When reporting your findings here make sure to strip any user or sensitive data.

What's needed:

  • Android version
  • Device manufacturer and model
  • Stacktrace with line numbers preserved
  • Android support library version
  • xpece-android-support-preference library version

Thanks for making this library better!

Credit

Most of this library is straight up pillaged latest SDK mixed with heavy reliance on AndroidX AppCompat and Preference. Kudos to people who create and maintain these!

android-support-preference's People

Contributors

consp1racy avatar kennygoers avatar mygod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

android-support-preference's Issues

build error with support library version of 23.2.0

If version 23.2.0 of support libraries are used then I get some errors like:
Error:(2) Attribute "preferenceStyle" has already been defined
Error:(2) Attribute "checkBoxPreferenceStyle" has already been defined
Error:(2) Attribute "dialogPreferenceStyle" has already been defined
Error:(2) Attribute "editTextPreferenceStyle" has already been defined
Error:(2) Attribute "ringtonePreferenceStyle" has already been defined
Error:(2) Attribute "switchPreferenceStyle" has already been defined
Error:(2) Attribute "seekBarPreferenceStyle" has already been defined
Error:(2) Attribute "preferenceScreenStyle" has already been defined
Error:(2) Attribute "preferenceFragmentListStyle" has already been defined

Would it be resolved if you updated your library with these support libraries? If so, can you please do that?

Wildcard support libs dependency

I just added library to project and app crash when starting. After I deleted dependence - the app works again!

dependencies {
    compile 'net.xpece.android:support-preference:1.0.3'
}
09-17 18:38:17.207 19437-19437/proviser.legalapps.com.proviser E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: proviser.legalapps.com.proviser, PID: 19437
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{proviser.legalapps.com.proviser/proviser.legalapps.com.proviser.ClassicMenuActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class android.support.design.widget.FloatingActionButton
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                     at android.os.Looper.loop(Looper.java:193)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5333)
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                                     at dalvik.system.NativeStart.main(Native Method)
                                                                                  Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class android.support.design.widget.FloatingActionButton
                                                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                                     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                                                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                     at proviser.legalapps.com.proviser.ClassicMenuActivity.onCreate(ClassicMenuActivity.java:148)
                                                                                     at android.app.Activity.performCreate(Activity.java:5343)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                     at android.os.Looper.loop(Looper.java:193) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                                     at dalvik.system.NativeStart.main(Native Method) 
                                                                                  Caused by: java.lang.reflect.InvocationTargetException
                                                                                     at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                     at proviser.legalapps.com.proviser.ClassicMenuActivity.onCreate(ClassicMenuActivity.java:148) 
                                                                                     at android.app.Activity.performCreate(Activity.java:5343) 
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331) 
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                     at android.os.Looper.loop(Looper.java:193) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                                     at dalvik.system.NativeStart.main(Native Method) 
                                                                                  Caused by: java.lang.NoSuchMethodError: android.support.v7.widget.AppCompatImageHelper.<init>
                                                                                     at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:170)
                                                                                     at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:147)
                                                                                     at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
                                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                     at proviser.legalapps.com.proviser.ClassicMenuActivity.onCreate(ClassicMenuActivity.java:148) 
                                                                                     at android.app.Activity.performCreate(Activity.java:5343) 
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331) 
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                     at android.os.Looper.loop(Looper.java:193) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                                     at dalvik.system.NativeStart.main(Native Method) 

question: Audio (music) picker preference

Is it possible to have a preference that works similar to the Ringtone preference but shows all the Audio files that is on the device (with some kind of structure, like Artists in ascending order or something)? When the item is clicked the sound should be played.
This can be achieved with using a picker Intent but I have a lot of issues that 3rd party apps return URIs in various formats so I'd like to have something done natively.

How to build the library and sample?

I did
git clone
the project and then inside it I run
./gradlew clean build
which gives me a lot of errors (cannot find symbol, .. does not exist).
Can you provide build instructions?

Request: FolderChooserPreference

Hi there, I have a feature request for your library, i.e. FolderChooserPreference. This preference makes developers able to ask the user to choose the save path. Also, disable the choose button if the path is not writable and don't forget to add back button for the dialog.

Thanks in advance.

Preference widget for numbers

I know this library doesn't have a number picker, then which is the suggested widget for inputting numbers?
Just use EditTextPrefence?
(sorry if this is a silly question :)

SeekBarPreference

Thanks so much for this library!!!!
I´m using the SeekBarPreference in my app
I had to change onStopTrackingTouch if mPreferredMin isn´t 0, but maybe i was using it wrong

@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
    mTrackingTouch = false;
    if (seekBar.getProgress() + **mPreferredMin**  != mProgress)
    {
        syncProgress(seekBar);
    }
    if (mOnSeekBarChangeListener != null)
    {
        mOnSeekBarChangeListener.onStopTrackingTouch(seekBar);
    }
}

java.lang.IllegalStateException: No cursor that can return names

Can you please take a look at this? I'm using RingtonePreference and I get this crash from time to time.
I can't reproduce it on my own. Using 0.8.0, but I got this with 0.6.2 as well.

Fatal Exception: java.lang.IllegalStateException: No cursor that can return names
       at net.xpece.android.support.preference.SortCursor.getColumnNames(SortCursor.java:253)
       at android.database.AbstractCursor.getColumnIndex(AbstractCursor.java:283)
       at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:300)
       at android.support.v4.widget.CursorAdapter.init$f13d381(CursorAdapter.java:174)
       at android.support.v4.widget.CursorAdapter.(CursorAdapter.java)
       at android.support.v4.widget.ResourceCursorAdapter.(ResourceCursorAdapter.java)
       at android.support.v4.widget.SimpleCursorAdapter.(SimpleCursorAdapter.java)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.onPrepareDialogBuilder(XpRingtonePreferenceDialogFragment.java:195)
       at android.support.v7.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:151)
       at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
       at android.os.Handler.handleCallback(Handler.java:615)
       at android.os.Handler.dispatchMessage(Handler.java:92)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4867)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
       at dalvik.system.NativeStart.main(NativeStart.java)

Simple menu is not animated correctly

When the user clicks on a ListPreference with the menu mode set to simple menu, it shows with an alpha animation which differs from the framework animation (kind of zoom/scale).

Crashes with the native Switch on specific devices

Hi, I'm getting crashes from an user of my app when using SwitchPreference with the native switch on specific devices, the crash is from a Verizon Ellipsis 10 tablet with API 22, but others may be affected as well.

Here's a full stack trace.

I investigated it and I've found out that for some reason the attribute mShowText in android.widget.Switch is set to true, and that leads to a crash at the beginning of the method makeLayout.

One possible fix would be to set android:switchTextOn and android:switchTextOff to an empty string in the xml resource, but the developer must be aware of it and it's quite ugly.

Another possible fix is to update the method syncSwitchView and call switchView.setShowText(false) for the native one, but I don't know if the crash happens after or before binding the view so it may not work.

I also don't know why the SwitchPreference class from the support library included the switch text, since AFAIK it's never shown (it always uses the text from the preference, not the widget).

PreferenceScreenNavigationStrategy question

Hi,

I was using 0.6.2 and updated to 0.8.0 recently. Now I just noticed that I have an issue with preference navigation strategy.

I use the following:

private PreferenceScreenNavigationStrategy.ReplaceRoot mPreferenceScreenNavigation;

if (mPreferenceScreenNavigation == null) {
                    mPreferenceScreenNavigation = new PreferenceScreenNavigationStrategy.ReplaceRoot(this, this);
                    mPreferenceScreenNavigation.onCreatePreferences(paramBundle);
                }
@Override
    public boolean onPreferenceTreeClick(Preference preference) {
        if (preference instanceof PreferenceScreen) {
            PreferenceScreen preferenceScreen = (PreferenceScreen) preference;
            mPreferenceScreenNavigation.onPreferenceScreenClick(preferenceScreen);
            return true;
        }
        return super.onPreferenceTreeClick(preference);
    }

If I just simply click on a PreferenceScreen then it's all OK. But if I try to use

mPreferenceScreenNavigation.onPreferenceScreenClick(mPreference);

then I get NPE.

java.lang.NullPointerException
net.xpece.android.support.preference.PreferenceScreenNavigationStrategy$ReplaceRoot.navigateToPreferenceScreen(PreferenceScreenNavigationStrategy.java:193)
net.xpece.android.support.preference.PreferenceScreenNavigationStrategy$ReplaceRoot.onPreferenceScreenClick(PreferenceScreenNavigationStrategy.java:247)

It was working with 0.6.2. I don't really want to migrate to ReplaceFragment at this point in time.
Is there a way to make this work with 0.8.0?

Must Implement onWindowStartingSupportActionMode(Callback)

When extending from net.xpece.android.support.preference.AppCompatPreferenceActivity, the following error message is raised.

Error:(45, 8) error: SettingsActivity is not abstract and does not override abstract method onWindowStartingSupportActionMode(Callback) in AppCompatCallback

I was previously using 22.2.0 appcompat version but rolling back to 22.1.1, also didn't work. In the end needed to implement. (Your sample doesn't include this)

@Nullable
    @Override
    public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) {
        return null;
    }

Everything is working, fine.
Great lib, cheers for the effort put into it.

Preference items created at runtime losing style?

I'm creating preference items at runtime under some category of my PreferenceScreen this way:

Preference pref = new Preference(getActivity());
pref.setKey("key");
pref.setTitle("title");
pref.setSummary("summary");
prefCategory.addPreference(pref);

It works but the preference loses its default style, showing the title with a big font size for example.
A similar preference created in XML is displayed correctly.

Any ideas how can I get those runtime items displayed correctly?

RingtonePreference ActivityNotFoundException

Can you please take a look at this?

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.RINGTONE_PICKER (has extras) }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1817)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1632)
    at android.app.Activity.startActivityFromFragment(Activity.java:4630)
    at android.app.Fragment.startActivityForResult(Fragment.java:1114)
    at android.app.Fragment.startActivityForResult(Fragment.java:1098)
    at android.preference.RingtonePreference.onClick(RingtonePreference.java:168)
    at android.preference.Preference.performClick(Preference.java:1163)
    at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:269)
    at android.widget.AdapterView.performItemClick(AdapterView.java:339)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1544)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3721)
    at android.widget.AbsListView$3.run(AbsListView.java:5660)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6837)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

ListPreference problem with Tint color

Hi, I have a problem with list preference, I can't change the tint color.

ListPreference
screenshot at jun 16 19-08-35

Other preference seems to be fine

SeekBarPreference
image

SwitchPreference
image

I'm using version 8.1

I tried adding these but still no luck

app:asp_tint="@color/colorPrimary"
app:asp_tintMode="src_in"
app:asp_tintEnabled="true"
app:asp_dialogTint="@color/colorPrimary"
app:asp_dialogTintMode="src_in"
app:asp_dialogTintEnabled="true"

PreferenceFragment and AppCompat.

It`s possible extends from Fragment from support library? I'm using Navigation View on a project and all fragmens needs extending android.support.v4.app.Fragment

Unable to use the new Color Preference

Hi, I couldn't get the new Color preference working.

After including in my gradle file the compile 'net.xpece.android:support-preference-color:0.6.0' line, I get

Error:Failed to resolve: xpece-android-support-preference:support-preference:unspecified

Title/Subtitle tinting

Does the library support title and summary tinting as it support icon tinting?
In my app when i disable a dependency, the children's title color stays the same and only the icons change tint.

Scroll position when returning from subscreen

I don't know if this is intended or it's a bug:

I have a somewhat long list of preferences, and a pair of subscreen items that can be reached after scrolling the list a bit. I enter one of the subscreens and when I return the main settings list is reset to the top, losing the scroll position.

0.9.1 with ProGuard: InflateException

Tried to update to 0.9.1. It works fine with debug builds but once I generate a signed APK with ProGuard enabled I get the following error when I test the app. Can you please take a look at it? Is this something on my end or something with this release of the library? With 0.8.1 it is working fine with ProGuard as well.

Thanks!

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{.SettingsActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class ListPreference
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
       at android.app.ActivityThread.access$600(ActivityThread.java:138)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:213)
       at android.app.ActivityThread.main(ActivityThread.java:4787)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by android.view.InflateException: Binary XML file line #13: Error inflating class ListPreference
       at android.support.v7.preference.PreferenceInflater.createItem(PreferenceInflater.java:263)
       at android.support.v7.preference.PreferenceInflater.onCreateItem(PreferenceInflater.java:2281)
       at android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:359)
       at android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:361)
       at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:167)
       at android.support.v7.preference.PreferenceInflater.inflate$7af30e91(PreferenceInflater.java:117)
       at android.support.v7.preference.XpPreferenceManager.inflateFromResource$6154c3e6(XpPreferenceManager.java:72)

Uncaught exception using XpPreferenceFragment on Android 2.3.6. (4.1.2 and 5.1.1 ok)

Hi,

I have been trying to use XpPreferenceFragment with great success on newer Android phones with (Samsung GT-I9100) 4.1.2 and (HTC Desire HD CyanogenMod 12.1-UNOFFICIAL) 5.1.1.

But it fails with the most basic contrived preferences xml resources file when addPreferencesFromResource(R.id.settings) is called inside onCreatePreferences2 on an Android (Samsung GT-I8510T) 2.3.6 phone.

If I include the settings.xml listed below it fails with the exception also listed below. However if I omit the CheckBoxPreference tag in the settings.xml I can see "Hello World".

Could you please help?

In my build.gradle in Android Studio 2.0 I am using the following compile directives.

compile 'net.xpece.android:support-preference:0.7.0'
compile 'net.xpece.android:support-preference-color:0.7.0@aar'

Here are the contents of my SettingsFragment.java

package au.com.company.product.UI;
import android.os.Bundle;
import android.support.v7.preference.XpPreferenceFragment;
import au.com.company.product.R;
public class SettingsFragment extends XpPreferenceFragment {
    @Override
    public void onCreatePreferences2(final Bundle savedInstanceState, final String rootKey) {
        // Load the settings from an XML resource
        addPreferencesFromResource(R.xml.settings);
    }
}

Here are the contents of my settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:title="HelloWorld">
        <CheckBoxPreference
            android:key="some_check_box"
            android:title="This will fail to load"/>
    </PreferenceCategory>
</PreferenceScreen>

Here is the callstack of the exception thrown.

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         android.view.InflateException: Binary XML file line #18: Error inflating class <unknown>
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:518)
                                                                             at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
                                                                             at android.support.v7.preference.XpPreferenceGroupAdapter.onCreateViewHolder(XpPreferenceGroupAdapter.java:76)
                                                                             at android.support.v7.preference.XpPreferenceGroupAdapter.onCreateViewHolder(XpPreferenceGroupAdapter.java:16)
                                                                             at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
                                                                             at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
                                                                             at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
                                                                             at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
                                                                             at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
                                                                             at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
                                                                             at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
                                                                             at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
                                                                             at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
                                                                             at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
                                                                             at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
                                                                             at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
                                                                             at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                             at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1170)
                                                                             at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
                                                                             at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
                                                                             at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
                                                                             at android.view.View.layout(View.java:7228)
                                                                             at android.view.ViewRoot.performTraversals(ViewRoot.java:1148)
                                                                             at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                             at android.os.Looper.loop(Looper.java:130)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:3691)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:507)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
                                                                             at dalvik.system.NativeStart.main(Native Method)
                                                                          Caused by: java.lang.reflect.InvocationTargetException
                                                                            at java.lang.reflect.Constructor.con

Many Thanks

PreferenceFragment has incorrect margins

The Preference fragment doesn't have proper 16dp margins, they appear to be 8dp. Could be set in the activity but this would add white space to the edge. Not horrible, but repairable.

ListPreference MenuMode question

Hi,

Sorry for this, I'm sure that this is something on my end, but I just realized that none of my ListPreferences are working since migrating to 1.0.0 from 0.8.1. Now I'm on 1.0.2.

listPreference.buildSimpleDialogAdapter(getActivity());
listPreference.setMenuMode(ListPreference.MENU_MODE_SIMPLE_ADAPTIVE);

This works, but I want to stick to the normal Alert Dialog style. If I change the menu mode to dialog or simple dialog then nothing happens when I click on the preference.

This is how I use it in my preferences.xml

<ListPreference xmlns:app="http://schemas.android.com/apk/res-auto"
            android:icon="?attr/icSettingsProfile"
            android:key="settingsId"
            android:title="@string/settings_choose_profile"
            app:asp_iconPaddingEnabled="false" />

And this is the theme:

<style name="AppThemeSettingsDark" parent="AppThemeDark">
        <!-- Used to theme preference list and items. -->
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
        <item name="alertDialogTheme">@style/AppThemeDark.Dialog.Alert</item>
        <item name="dialogTheme">@style/AppThemeDark.Dialog</item>
        <item name="asp_preferenceIconTint">?colorAccent</item>
        <item name="asp_preferenceDialogIconTint">?asp_preferenceIconTint</item>
    </style>

 <style name="AppThemeDark.Dialog" parent="Theme.AppCompat.Dialog">
        <item name="colorPrimary">@color/dark_primary</item>
        <item name="colorPrimaryDark">@color/dark_primary_dark</item>
        <item name="colorAccent">@color/dark_primary_accent</item>
        <!--<item name="android:textColorHighlight">@color/secondary_text_default_material_dark</item>-->
    </style>

    <style name="AppThemeDark.Dialog.Alert" parent="Theme.AppCompat.Dialog.Alert">
        <item name="colorPrimary">@color/dark_primary</item>
        <item name="colorPrimaryDark">@color/dark_primary_dark</item>
        <item name="colorAccent">@color/dark_primary_accent</item>
        <!--<item name="android:textColorHighlight">@color/secondary_text_default_material_dark</item>-->
    </style>

Thanks!

preference save configuration bug.

on OnPreferenceChangeListener be called,

String value=PreferenceManager.getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), R.string.xxx);

the value is not the new.

private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@OverRide
public boolean onPreferenceChange(Preference preference, Object value) {

        if (preference.getKey().equals(preference.getContext().getString(R.string.preference_key_left_screen))) {
            Boolean stringValue = (Boolean)value;
            FlyLauncherProSetting.LEFT_SCRENN_ENABLE=stringValue;
        }

// call refresh the UI

        return true;
    }
};

Ringtone permissions

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liveultrahealthy.violet/com.liveultrahealthy.violet.ui.settings.SettingsActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/50 from pid=19062, uid=10187 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
       at android.os.Parcel.readException(Parcel.java:1546)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
       at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
       at android.content.ContentResolver.query(ContentResolver.java:513)
       at android.content.ContentResolver.query(ContentResolver.java:448)
       at com.lge.media.RingtoneManagerEx.getActualDefaultRingtoneUri(RingtoneManagerEx.java:244)
       at android.media.RingtoneEx.getTitle(RingtoneEx.java:177)
       at android.media.RingtoneEx.getTitle(RingtoneEx.java:145)
       at com.liveultrahealthy.violet.ui.settings.SettingsFragment$1.onPreferenceChange(SettingsFragment.java:65)
       at com.liveultrahealthy.violet.ui.settings.SettingsFragment.bindPreferenceSummaryToValue(SettingsFragment.java:80)
       at com.liveultrahealthy.violet.ui.settings.SettingsFragment.onCreatePreferences2(SettingsFragment.java:152)
       at android.support.v7.preference.XpPreferenceFragment.onCreatePreferences(XpPreferenceFragment.java:53)
       at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:216)
       at com.liveultrahealthy.violet.ui.settings.SettingsFragment.onCreate(SettingsFragment.java:102)
...

Device: LG H634
Android 5.1.1

PreferenceScreen (subscreen) support

Hi,

Thanks for a great library!

Do you have any plans to support subscreens with icon tinting and having the action bar show on the subscreen in the near future?

Pull all strings for RingtonePickerActivity from AOSP

From SDK:
ringtone_default, ringtone_silent, ringtone_picker_title

From android/platform/packages/providers/MediaProvider:
notification_sound_default, alarm_sound_default

Additional strings from SDK:
capital_on, capital_off

Request: SeekBarDialogPreference.setInfo(...) + realtime listener support

Hi @consp1racy, I want to introduce you a new attribute for SeekBarPreference. I have edited below picture from your screenshot. Look at the preferences. Each of them had a unit. For Media preference, the unit is % (percent), and for Vibration the unit is ms (milliseconds) which means the device will be vibrated for 200ms. I hope you can add this feature by adding the following attribute to the preference:

<SeekBarPreference
    android:key="vibrate_duration"
    app:asp_preferenceUnit="ms"
    ... />

Also, once user seek the bar, the value will be updated automatically.

unit pref


I have the second request for you, i.e. by adding app:asp_dialogContent="Some explanation." attribute to SeekBarDialogPreference. Adding this attribute makes a big difference between SeekBarPreference and SeekBarDialogPreference. Let's say that you have a SeekBarDialogPreference without any explanation about it. If that's so, why don't you just use SeekBarPreference which already had no explanation but a title? You can see the edited screenshot below:

<SeekBarDialogPreference
    android:key="custom_volume"
    app:asp_dialogContent="This is an explanation."
    ... />

dialog explanation pref

And the last request is, I want you to add setMin(int min) method and app:asp_min to this preference. We can define the minimum value for the SeekBar. For example:

<SeekBarPreference
    android:max="500"
    app:asp_min="20"
    app:asp_preferenceUnit="ms"
    ... />

The SeekBar had range value between 20 to 500 with unit in milliseconds.


Thanks in advance. I hope you accept this idea.

support-preference without support-spinner

Hi there,

Since there is a separate version for support-spinner only, would it be possible to have the support-preference without it?
I tried to exclude this module in my dependency list but then I get errors with missing parent themes.

Thanks

Customizing list preference

Hi @consp1racy, I want to customize items in a ListPreference one by one, to achieve something similar to this: http://stackoverflow.com/questions/34707077/android-listpreference-as-font-size-picker-or-accessing-individual-views-of-lis

Is that code appropriate for the ListPreference implementation of this library?

Also, if I use the SimpleMenu style, where should I look to get a similar list item customization? I'm pretty sure the adapter works differently with SimpleMenu

Set title and summary on multilines

Hi,

Please add a parameter to set both title and summary of a CheckBoxPreference on multilines because, for example, when I use a long title it get cut and hidden. I wrote a custom CheckBoxPreference based on yours:

    @Override
    public void onBindViewHolder(final PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        TextView mTitle = (TextView) holder.findViewById(android.R.id.title);
        mTitle.setSingleLine(false);

        View checkboxView = holder.findViewById(android.R.id.checkbox);
        if (checkboxView == null) {
            checkboxView = holder.findViewById(R.id.checkbox);
        }
        if (checkboxView instanceof Checkable) {
            ((Checkable) checkboxView).setChecked(mChecked);
        }

        syncSummaryView(holder);
    }

This is the custom onBindViewHolder method I'm using currently. Thank you for your work.

java.lang.ClassCastException: android.support.v4.widget.NestedScrollView cannot be cast to android.widget.ScrollView

I just received exception through Mint. It happened on samsung Galaxy Nexus running Android 4.1.1. Stack trace is as follows:

0 java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.shmoula.nxtwalch/net.xpece.android.support.app.RingtonePickerActivity}: java.lang.ClassCastException: android.support.v4.widget.NestedScrollView cannot be cast to android.widget.ScrollView 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074) 2 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099) 3 at android.app.ActivityThread.access$600(ActivityThread.java:145) 4 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 5 at android.os.Handler.dispatchMessage(Handler.java:119) 6 at android.os.Looper.loop(Looper.java:137) 7 at android.app.ActivityThread.main(ActivityThread.java:4873) 8 at java.lang.reflect.Method.invokeNative(Native Method) 9 at java.lang.reflect.Method.invoke(Method.java:528) 10 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 11 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12 at dalvik.system.NativeStart.main(Native Method) 13 Caused by: java.lang.ClassCastException: android.support.v4.widget.NestedScrollView cannot be cast to android.widget.ScrollView 14 at net.xpece.android.support.app.AlertController.setupContent(AlertController.java:545) 15 at net.xpece.android.support.app.AlertController.setupView(AlertController.java:431) 16 at net.xpece.android.support.app.AlertController.installContent(AlertController.java:240) 17 at net.xpece.android.support.app.AlertActivity.setupAlert(AlertActivity.java:90) 18 at net.xpece.android.support.app.RingtonePickerActivity.onCreate(RingtonePickerActivity.java:188)

java.lang.NullPointerException

I got a few crash reports like this, using 0.6.2 and 0.8.0. Can you please a take a look at it? Do you happen to have any idea how can I avoid it?

Fatal Exception: java.lang.NullPointerException
       at android.content.res.XmlBlock.nativeGetStyleAttribute(XmlBlock.java)
       at android.content.res.XmlBlock.access$1400(XmlBlock.java:34)
       at android.content.res.XmlBlock$Parser.getStyleAttribute(XmlBlock.java:440)
       at android.widget.TextView.(TextView.java:666)
       at android.widget.EditText.(EditText.java:65)
       at android.widget.EditText.(EditText.java:61)
       at android.support.v7.widget.AppCompatEditText.(AppCompatEditText.java:60)
       at android.support.v7.widget.AppCompatEditText.(AppCompatEditText.java:56)
       at net.xpece.android.support.preference.XpEditTextPreferenceDialogFragment.net.xpece.android.support.preference.EditTextPreference.createEditText(XpEditTextPreferenceDialogFragment.java:2067)
       at android.support.v7.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:143)
       at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5595)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)

AccessibilityManager causes CheckBoxPreference not checked

I don't know why you only put below code in SwitchPreference and CheckBoxPreference, while another preferences don't have it. Sometimes, accessibilityManager.isEnabled() returns false, and sometimes returns true. This makes SwitchPreference and CheckBoxPreference sometimes checked, and sometimes not checked. Can you explain the purpose of below code and fix this bug?

AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
    ...
}

PreferenceManager.setDefaultValues failing to find classes

I need to initialize the shared preferences from my prefs.xml file from an activity before the preference fragment is shown, but the call to setDefaultValues is failing with the following exception:

android.view.InflateException: Binary XML file line #36: Error inflating class (not found)ColorPreference

I assume this is happening because the PreferenceManager doesn't know about the correct package paths.

How would you recommend I solve this issue? Do I need to include the full class paths in the prefs.xml file?

implementing SeekBar listeners

Is it possible to implement SeekBarPreference onStartTrackingTouch and onStopTrackingTouch listeners?
If so, can someone provide a small sample code?

Ringtone Preference not working...

I tried in both my app and the sample application when cloning the current code base, the Ringtone picker crashes with: String resource ID #0x0 not found. This is on an 4.4 emulator. I'll see if I can contribute...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.