Coder Social home page Coder Social logo

ferrannp / material-preferences Goto Github PK

View Code? Open in Web Editor NEW
43.0 3.0 5.0 436 KB

Make easier to create a preference screen on pre-Lollipop devices looking exactly as if it was a Lollipop one.

License: MIT License

Java 100.00%
android material-preferences material-design

material-preferences's People

Contributors

ferrannp avatar wiyarmir 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

Watchers

 avatar  avatar  avatar

material-preferences's Issues

support v7 ActionBar API > 21

Hi, I'm using the Library but for Lollipop devices when I go to preferences, the application stops. Giving me an error.

void android.support.v7.app.ActionBar.setHomeButtonEnabled(boolean)

Toolbar theme

Hi, thaks for sharing this lib.

Can you change used Toolbar-Theme (in layout/mp_toolbar.xml) from android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
to something in styles.xml, so we can easily switch to Light ActionBar.

Thank you...

Android 2.3 support

I'm trying to make the sample work in Android 2.3 emulator (API 10):

diff --git a/sample/build.gradle b/sample/build.gradle
index ce4d69c..159b023 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -6,7 +6,7 @@ android {

     defaultConfig {
         applicationId "com.fnp.materialpreferences"
-        minSdkVersion 11
+        minSdkVersion 7
         targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
         versionCode Integer.parseInt(VERSION_CODE)
         versionName VERSION_NAME

This does not work:

I/ActivityManager(  802): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.fnp.materialpreferences/com.fnp.materialpreferencessample.SettingsActivity } from pid 894
I/ActivityManager(  802): Start proc com.fnp.materialpreferences for activity com.fnp.materialpreferences/com.fnp.materialpreferencessample.SettingsActivity: pid=2356 uid=10034 gids={}
W/dalvikvm( 2356): Unable to resolve superclass of Lcom/fnp/materialpreferences/PreferenceFragment; (211)
W/dalvikvm( 2356): Link of class 'Lcom/fnp/materialpreferences/PreferenceFragment;' failed
W/dalvikvm( 2356): Unable to resolve superclass of Lcom/fnp/materialpreferencessample/SettingsActivity$MyPreferenceFragment; (1782)
W/dalvikvm( 2356): Link of class 'Lcom/fnp/materialpreferencessample/SettingsActivity$MyPreferenceFragment;' failed
E/dalvikvm( 2356): Could not find class 'com.fnp.materialpreferencessample.SettingsActivity$MyPreferenceFragment', referenced from method com.fnp.materialpreferencessample.SettingsActivity.onCreate
W/dalvikvm( 2356): VFY: unable to resolve new-instance 1813 (Lcom/fnp/materialpreferencessample/SettingsActivity$MyPreferenceFragment;) in Lcom/fnp/materialpreferencessample/SettingsActivity;
D/dalvikvm( 2356): VFY: replacing opcode 0x22 at 0x0003
D/dalvikvm( 2356): VFY: dead code 0x0005-000b in Lcom/fnp/materialpreferencessample/SettingsActivity;.onCreate (Landroid/os/Bundle;)V
I/dalvikvm( 2356): Could not find method com.fnp.materialpreferences.PreferenceActivity.getFragmentManager, referenced from method com.fnp.materialpreferences.PreferenceActivity.onOptionsItemSelected
W/dalvikvm( 2356): VFY: unable to resolve virtual method 14839: Lcom/fnp/materialpreferences/PreferenceActivity;.getFragmentManager ()Landroid/app/FragmentManager;
D/dalvikvm( 2356): VFY: replacing opcode 0x6e at 0x0012
D/dalvikvm( 2356): VFY: dead code 0x0015-0022 in Lcom/fnp/materialpreferences/PreferenceActivity;.onOptionsItemSelected (Landroid/view/MenuItem;)Z
W/dalvikvm( 2356): Unable to resolve superclass of Lcom/fnp/materialpreferences/PreferenceFragment; (211)
W/dalvikvm( 2356): Link of class 'Lcom/fnp/materialpreferences/PreferenceFragment;' failed
W/dalvikvm( 2356): VFY: unable to find class referenced in signature (Lcom/fnp/materialpreferences/PreferenceFragment;)
I/dalvikvm( 2356): Could not find method com.fnp.materialpreferences.PreferenceActivity.getFragmentManager, referenced from method com.fnp.materialpreferences.PreferenceActivity.setPreferenceFragment
W/dalvikvm( 2356): VFY: unable to resolve virtual method 14839: Lcom/fnp/materialpreferences/PreferenceActivity;.getFragmentManager ()Landroid/app/FragmentManager;
D/dalvikvm( 2356): VFY: replacing opcode 0x6e at 0x0000
D/dalvikvm( 2356): VFY: dead code 0x0003-002e in Lcom/fnp/materialpreferences/PreferenceActivity;.setPreferenceFragment (Lcom/fnp/materialpreferences/PreferenceFragment;)V
I/dalvikvm( 2356): Could not find method android.view.Window.hasFeature, referenced from method android.support.v7.app.AppCompatDelegateImplV7.hasWindowFeature
W/dalvikvm( 2356): VFY: unable to resolve virtual method 14100: Landroid/view/Window;.hasFeature (I)Z
D/dalvikvm( 2356): VFY: replacing opcode 0x6e at 0x0009
D/dalvikvm( 2356): VFY: dead code 0x000c-000c in Landroid/support/v7/app/AppCompatDelegateImplV7;.hasWindowFeature (I)Z
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.dispatchGenericMotionEvent, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.dispatchGenericMotionEvent
W/dalvikvm( 2356): VFY: unable to resolve interface method 14072: Landroid/view/Window$Callback;.dispatchGenericMotionEvent (Landroid/view/MotionEvent;)Z
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.dispatchGenericMotionEvent (Landroid/view/MotionEvent;)Z
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.dispatchKeyShortcutEvent, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyShortcutEvent
W/dalvikvm( 2356): VFY: unable to resolve interface method 14074: Landroid/view/Window$Callback;.dispatchKeyShortcutEvent (Landroid/view/KeyEvent;)Z
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.dispatchKeyShortcutEvent (Landroid/view/KeyEvent;)Z
W/dalvikvm( 2356): VFY: unable to find class referenced in signature (Landroid/view/ActionMode;)
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.onActionModeFinished, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onActionModeFinished
W/dalvikvm( 2356): VFY: unable to resolve interface method 14078: Landroid/view/Window$Callback;.onActionModeFinished (Landroid/view/ActionMode;)V
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0005 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.onActionModeFinished (Landroid/view/ActionMode;)V
W/dalvikvm( 2356): VFY: unable to find class referenced in signature (Landroid/view/ActionMode;)
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.onActionModeStarted, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onActionModeStarted
W/dalvikvm( 2356): VFY: unable to resolve interface method 14079: Landroid/view/Window$Callback;.onActionModeStarted (Landroid/view/ActionMode;)V
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0005 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.onActionModeStarted (Landroid/view/ActionMode;)V
W/dalvikvm( 2356): VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
W/dalvikvm( 2356): VFY: unable to resolve interface method 14090: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.onSearchRequested (Landroid/view/SearchEvent;)Z
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
W/dalvikvm( 2356): VFY: unable to resolve interface method 14093: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;)Landroid/view/ActionMode;
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;)Landroid/view/ActionMode;
I/dalvikvm( 2356): Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
W/dalvikvm( 2356): VFY: unable to resolve interface method 14094: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm( 2356): VFY: replacing opcode 0x72 at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/view/WindowCallbackWrapper;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
I/dalvikvm( 2356): Could not find method android.view.ViewGroup.onHoverEvent, referenced from method android.support.v7.widget.Toolbar.onHoverEvent
W/dalvikvm( 2356): VFY: unable to resolve virtual method 13982: Landroid/view/ViewGroup;.onHoverEvent (Landroid/view/MotionEvent;)Z
D/dalvikvm( 2356): VFY: replacing opcode 0x6f at 0x0010
D/dalvikvm( 2356): VFY: dead code 0x0013-0019 in Landroid/support/v7/widget/Toolbar;.onHoverEvent (Landroid/view/MotionEvent;)Z
I/dalvikvm( 2356): Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
W/dalvikvm( 2356): VFY: unable to resolve virtual method 13991: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
D/dalvikvm( 2356): VFY: replacing opcode 0x6f at 0x0007
I/dalvikvm( 2356): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
W/dalvikvm( 2356): VFY: unable to resolve virtual method 411: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
D/dalvikvm( 2356): VFY: replacing opcode 0x6e at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/widget/TintTypedArray;.getChangingConfigurations ()I
I/dalvikvm( 2356): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
W/dalvikvm( 2356): VFY: unable to resolve virtual method 433: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm( 2356): VFY: replacing opcode 0x6e at 0x0002
D/dalvikvm( 2356): VFY: dead code 0x0005-0006 in Landroid/support/v7/internal/widget/TintTypedArray;.getType (I)I
D/AndroidRuntime( 2356): Shutting down VM
W/dalvikvm( 2356): threadid=1: thread exiting with uncaught exception (group=0xb6f7f4f0)
E/AndroidRuntime( 2356): FATAL EXCEPTION: main
E/AndroidRuntime( 2356): java.lang.NoClassDefFoundError: com.fnp.materialpreferencessample.SettingsActivity$MyPreferenceFragment
E/AndroidRuntime( 2356):    at com.fnp.materialpreferencessample.SettingsActivity.onCreate(SettingsActivity.java:11)
E/AndroidRuntime( 2356):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2356):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime( 2356):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 2356):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 2356):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 2356):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2356):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 2356):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 2356):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2356):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 2356):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2356):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 2356):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  802):   Force finishing activity com.fnp.materialpreferences/com.fnp.materialpreferencessample.SettingsActivity

The problem is that PreferenceFragment exists only for API 11+:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public abstract class PreferenceFragment extends android.preference.PreferenceFragment {
...

That's quite confusing because README states that library supports API 7. Are pre-Honecomb versions really supported or this is a typo?

Issues with Nested PreferenceScreen

The preferences styles and the tinting are ok, but there are two main problems:

Following this answer http://stackoverflow.com/a/29820402/2277631 with the new AppCompatPreferenceActivity.java does not seem to work in this case.

Summary is aligned exactly to the bounds of the title on RTL languages

Hi,
Thank you for this great work.
Please take a look at this screen shot and notice how the summary goes exactly with the title end and doesn't pass it
screenshot_2017-10-21-06-52-06

Can you test it against RTL language please and tell if it has the same issue or it just on my end.

Android version is 4.2.2

Thanks

No test suite

Some unit and/or instrument tests should be added.

For pre-LOLLIPOP android:widgetLayout is ignored

  <PreferenceScreen
        android:title="@string/phone_profiles_pref_category_gui"
        android:key="applicationInterfaceCategory"
        android:widgetLayout="@layout/start_activity_preference" >

or

<Preference
       android:key="prf_pref_writeSystemSettingsPermissions"
       android:title="@string/phone_profiles_pref_writeSystemSettingPermissions"
       android:summary="@string/phone_profiles_pref_writeSystemSettingPermissions_summary"
       android:widgetLayout="@layout/start_activity_preference" >

android:widgetLayout is ignored for pre-LOLLIPOP.

CheckBoxPreference & SwitchPreference have no animation on pre-Lollipop

As we can read in the README.txt, in order to create a Material looking SwitchPreference we actually use this trick:

<CheckBoxPreference
    android:key="some_key"
    android:title="Hooray!"
    android:widgetLayout="@layout/mp_preference_switch"/>

It works pretty good with just one drawback: There is no animation for pre-Lollipop devices (Switch switches instantly).

There is a post in StackOverflow about it: http://stackoverflow.com/questions/30336635/extending-preference-classes-in-android-lollipop-losing-animation

In the same way, this also happens with a pure CheckBoxPreference:

<CheckBoxPreference
    android:key="some_key"
    android:title="Hooray!" />

There is an opened and forgotten bug about it here: https://code.google.com/p/android/issues/detail?id=85392

Crashed on lollipop

im launching SettingsActivity from ActionBarActivity with intent like this :

Intent settings= new Intent(SampleActivity.this,SettingsActivity.class);
startActivity(settings);

Logcat:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ye.ok.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
at com.fnp.materialpreferences.PreferenceActivity.onCreate(PreferenceActivity.java:44)
at com.xorcom.amity.amityappdemo.SettingsActivity.onCreate(SettingsActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
... 10 more

Non-transparent shadow

Hi! Thanks for this nice lib! Shadow under the toolbar is not transparent. I have found a fix - in a file mp_activity_settings.xml you need to change this part

to this:

I used this snippet as a temporary solution in my code (SettingsActivity.onCreate):

FrameLayout layout = (FrameLayout) findViewById(R.id.content);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layout.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.toolbar);
layout.setLayoutParams(params);

findPreference() compatibility

Hi, You mentioned in the build.gradle file of the project, that the min SDK is 9, and looks like the findPreference() method here is only available for API >= 11. ...Is there a work-around for this ?

Custom shared preferences name is not supported

In my code in PreferenceFragment.onCreate():

    prefMng = getPreferenceManager();
    prefMng.setSharedPreferencesName("peferenceName");
    prefMng.setSharedPreferencesMode(Activity.MODE_PRIVATE);

This not working. Preference views are not set to values from shared preference "preferenceName".
But values in "preferenceName" are changed.

NPE when using a Theme that does not have ActionBar in API>=21

If the main theme does not use ActionBar (in order to use ToolBar from the new support library), the library won't attach it in Lollipop upwards, as is seen in the PreferenceActivity implementation.

This will crash a couple of lines later when doing getSupportActionBar().setHomeButtonEnabled(true);

Workaround: create a child theme from the main one with ActionBar enabled and plug it into the manifest declaration of the preferences activity.

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.