MrBIMC / VintageChroma

A Beautiful and very advanced material color picker for Android(written in Java).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for preference-v7

JoseGD opened this issue · comments

(Related to issue #4)

Hi @MrBIMC any chance to bring support for preference-v7 for your color picker preference? (http://developer.android.com/intl/es/tools/support-library/features.html#v7-preference).

I give you more context: I'm using the very complete Android Support Preference library (https://github.com/consp1racy/android-support-preference), I think it's the only one bringing material design to preferences down to API 7. That library recently introduced a color picker, it's one taken from AOSP, very nice but with a limited set of colors.

This is not suitable for my apps where people have been using an old style color picker with more freedom to choose the exact hex color. So your picker seems a good candidate for me, but its preference is not based on preference-v7, so I can't use it alongside android-support-preference.

I will take a look at the code and see if I can tweak a bit your preference class to make it work with that library. I'll keep you posted.

Thank you

UPDATE:
I managed to get ChromaPreference working as a child of android.support.v7.preference.Preference, I haven't had luck with showing the dialog though. I'm afraid that the changes will affect many parts of your code.

hey, I hacked a bit and managed to make it work, but it isn't ideal.
View-Related stuff works perfectly (and now it requires v4 FragmentManager instead of v11 one).

But things are not so nice with preferences: I made ChromaPreferenceCompat that is using preference-v7, but there's no way for v7-prefs to get supportFragmentManager from inside of itself, thus you have to inject it programmatically. It's easy, but requires few additional lines of code:

https://github.com/MrBIMC/VintageChroma/blob/master/sample-api-v7/src/main/java/com/pavelsikun/vintagechroma/sample_api_v7/SettingsActivity.java

Please try it out and respond with your ideas and improvements, relating to this implementation. I was unable to get v8 and v7 emulators working, so, while theoretically everything is ok, I don't really know whether it works or no.

I'll do. Thanks!

It worked.

I made an improvement that applies to the particular case of my app's settings: the color preferences are grouped in a subscreen. Here it's convenient for the activity to implement the PreferenceFragmentCompat.OnPreferenceStartScreenCallback interface to handle the supportFragmentManager assignment, resulting in this code (called when a new subscreen is shown):

 @Override
   public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen preference) {
      if (preference.getKey().equals(Consts.COLORS_SUBSCREEN)) {
         for (int i = 0; i < preference.getPreferenceCount(); i++) {
            Preference p = preference.getPreference(i);
            if (p instanceof ChromaPreferenceCompat) {
               ((ChromaPreferenceCompat) p).setSupportFragmentManager(getSupportFragmentManager());
            }
         }
      }
      return true;
   }

I think it's cleaner but won't work for people having color preferences in the main settings screen.

Maybe it will be better to inherit ChromaPreferenceCompat from DialogPreference?
This is what android-support-preference (and I think other libraries too) are doing. See https://github.com/consp1racy/android-support-preference/blob/master/colorpicker/src/main/java/net/xpece/android/support/preference/ColorPreference.java
My guess is inheriting from DialogPreference could avoid the fragment manager problem.

DialogPreference requires rewriting of the whole Dialog-related part of the library(that touches both View and Preference). I will look into it, but that's a task of completely different scale.

I suspected that. Don't worry, thanks for your work

I guess I'll release new version as it is, since it works, v7-prefs aren't common anyway.

If you manage to make some better implementation, I will happily accept your pull requests.
If your stuff will require breakage of some APIs, please make it parallel and mark those classes with Compat postfix(like ChromaPreferenceCompat).

Ok, I'll see what to do. Thanks for your time