martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

Support for AppCompat preferences #24

Closed alexandrucene closed 4 years ago

alexandrucene commented 8 years ago

Hello,

I am using com.android.support:preference-v7:23.4.0 to implement the preferences screen in my app. Even if I'll set the min SDK to 11, I'll get an error when trying to use your Color Picker: com.rarepebble.colorpicker.ColorPreference cannot be cast to android.support.v7.preference.Preference

Is there anything I can do to use it in my app?

Thanks!

martin-stone commented 8 years ago

You can re-compile the source yourself, after changing the import of the DialogPreference to use one from the support library. You should only need to change the import here, I think:

https://github.com/martin-stone/hsv-alpha-color-picker-android/blob/e327611fa208eefe4a2c76f127190f0d8816d363/colorpicker/src/main/java/com/rarepebble/colorpicker/ColorPreference.java#L24

alexandrucene commented 8 years ago

Thank you for the fast response. Is there any chance this would be included in a future update?

martin-stone commented 8 years ago

I wasn't planning to. I don't use the support preference in the app I wrote it for.

alexandrucene commented 8 years ago

I would love if this would be supported in the future!

martin-stone commented 8 years ago

What min SDK are you using? And what preference features do you need that aren't available using the standard android.preference.Preference etc.? I'm not aware of a reason to use the support preferences these days.

alexandrucene commented 8 years ago

In my case, the app has a min SDK of 9. I can make also 11, but the problem is another. I have an AppCompatActivity in which I load a PreferenceFragmentCompat, so that the theme of the settings will be material design.

In this scenario, I cannot use a normal Preference.

martin-stone commented 8 years ago

I am also using the support library activities, but I'm successfully using an ordinary PreferenceFragment and ordinary Preference and it is Material-styled and working fine. Maybe you're trying to use getSupportFragmentManager() instead of getFragmentManager() in your activity.

alexandrucene commented 8 years ago

Thanks Martin, I will try your suggestion to see if it's working.

kustra commented 7 years ago

In my case, it was easier porting this library for the Support Library PreferenceFragmentCompat than trying to switch my existing preferences screen to the ordinary PreferencesFragment. The change is not as trivial as just switching out imports, but not too hard either. Created a PR for it: #35

ligi commented 5 years ago

PreferenceFragment is deprecated: https://developer.android.com/reference/android/preference/PreferenceFragment

Also when using a MaterialComponents theme to use MaterialComponents from support library 28 you will run into problems with PreferenceFragment (perhaps the reason why they deprecated it with SDK level 28)

would really love to see @kustra 's PR to be merged

Khantahr commented 5 years ago

As @ligi said, PreferenceFragment has been depreciated. I love this library, but unless it's ported to use the AndroidX preferences, it's unusable.

martin-stone commented 5 years ago

I'm planning to have a look at this soon.

martin-stone commented 5 years ago

I have now published version 3.0.0 to jcenter and this switches over completely to using the support library preferences. Please try this out and let me know how it goes. Source changes are currently on a feature branch, and 2.4.2 will remain the official version until you guys report that 3.0.0 is working as you expect.

Note that the support preferences require extra code in your app to show the color picker dialog. See the branch readme or demo app for detals.

martin-stone commented 4 years ago

Now merged to master.