Witched to supportv7 prefs. Should fix a NPE when opening settings for some devices.

This commit is contained in:
Karim Abou Zeid 2016-02-03 20:10:16 +01:00
commit 9873f67139
9 changed files with 78 additions and 72 deletions

View file

@ -12,7 +12,6 @@ import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.TwoStatePreference;
import android.support.v7.widget.Toolbar;
@ -21,6 +20,9 @@ import android.view.View;
import com.afollestad.materialdialogs.color.ColorChooserDialog;
import com.kabouzeid.appthemehelper.ThemeStore;
import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEColorPreference;
import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat;
import com.kabouzeid.appthemehelper.util.ColorUtil;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
import com.kabouzeid.gramophone.util.NavigationUtil;
@ -84,7 +86,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
return super.onOptionsItemSelected(item);
}
public static class SettingsFragment extends PreferenceFragmentCompat {
public static class SettingsFragment extends ATEPreferenceFragmentCompat {
private static void setSummary(@NonNull Preference preference) {
setSummary(preference, PreferenceManager
@ -120,7 +122,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
getListView().setPadding(0, 0, 0, 0);
invalidateSettings();
}
@ -159,37 +161,37 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}
});
// ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
// final int primaryColor = ThemeStore.primaryColor(getActivity());
// primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor));
// primaryColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
// @Override
// public boolean onPreferenceClick(@NonNull Preference preference) {
// new ColorChooserDialog.Builder(((SettingsActivity) getActivity()), R.string.primary_color)
// .accentMode(false)
// .allowUserColorInput(true)
// .allowUserColorInputAlpha(false)
// .preselect(primaryColor)
// .show();
// return true;
// }
// });
//
// ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
// final int accentColor = ThemeStore.accentColor(getActivity());
// accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor));
// accentColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
// @Override
// public boolean onPreferenceClick(@NonNull Preference preference) {
// new ColorChooserDialog.Builder(((SettingsActivity) getActivity()), R.string.accent_color)
// .accentMode(true)
// .allowUserColorInput(true)
// .allowUserColorInputAlpha(false)
// .preselect(accentColor)
// .show();
// return true;
// }
// });
ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
final int primaryColor = ThemeStore.primaryColor(getActivity());
primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor));
primaryColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
new ColorChooserDialog.Builder(((SettingsActivity) getActivity()), R.string.primary_color)
.accentMode(false)
.allowUserColorInput(true)
.allowUserColorInputAlpha(false)
.preselect(primaryColor)
.show();
return true;
}
});
ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
final int accentColor = ThemeStore.accentColor(getActivity());
accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor));
accentColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
new ColorChooserDialog.Builder(((SettingsActivity) getActivity()), R.string.accent_color)
.accentMode(true)
.allowUserColorInput(true)
.allowUserColorInputAlpha(false)
.preselect(accentColor)
.show();
return true;
}
});
TwoStatePreference colorNavBar = (TwoStatePreference) findPreference("should_color_navigation_bar");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

View file

@ -27,6 +27,8 @@
<!-- necessary to find the overflow button later in the layout-->
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<style name="Theme.Phonograph.Base.Light" parent="Theme.AppCompat.Light.NoActionBar">
@ -55,6 +57,8 @@
<!-- necessary to find the overflow button later in the layout-->
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<style name="Theme.Phonograph.Base.Black" parent="@style/Theme.Phonograph.Base">

View file

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_audio">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_audio">
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="gapless_playback"
android:summary="@string/pref_summary_gapless_playback"
android:title="@string/pref_title_gapless_playback" />
<com.kabouzeid.appthemehelper.common.prefs.ATEPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreference
android:key="equalizer"
android:title="@string/equalizer" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,32 +1,32 @@
<android. xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_colors">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_colors">
<com.kabouzeid.appthemehelper.common.prefs.ATEColorPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEColorPreference
android:key="primary_color"
android:persistent="false"
android:summary="@string/primary_color_desc"
android:title="@string/primary_color" />
<com.kabouzeid.appthemehelper.common.prefs.ATEColorPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEColorPreference
android:key="accent_color"
android:persistent="false"
android:summary="@string/accent_color_desc"
android:title="@string/accent_color" />
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="true"
android:key="colored_notification"
android:summary="@string/pref_summary_colored_notification"
android:title="@string/pref_title_colored_notification" />
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="should_color_navigation_bar"
android:persistent="false"
android:summary="@string/pref_summary_colored_navigation_bar"
android:title="@string/pref_title_navigation_bar" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</android.>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,8 +1,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_general">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_general">
<com.kabouzeid.appthemehelper.common.prefs.ATEListPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="-1"
android:entries="@array/pref_start_page_list_titles"
android:entryValues="@array/pref_start_page_list_values"
@ -11,7 +11,7 @@
android:positiveButtonText="@null"
android:title="@string/pref_title_set_default_start_page" />
<com.kabouzeid.appthemehelper.common.prefs.ATEListPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="light"
android:entries="@array/pref_general_theme_list_titles"
android:entryValues="@array/pref_general_theme_list_values"
@ -20,6 +20,6 @@
android:positiveButtonText="@null"
android:title="@string/pref_title_general_theme" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_images">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_images">
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="ignore_media_store_artwork"
android:summary="@string/pref_summary_ignore_media_store_artwork"
android:title="@string/pref_title_ignore_media_store_artwork" />
<com.kabouzeid.appthemehelper.common.prefs.ATEListPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="only_wifi"
android:entries="@array/pref_auto_download_images_titles"
android:entryValues="@array/pref_auto_download_images_values"
@ -18,6 +18,6 @@
android:positiveButtonText="@null"
android:title="@string/pref_title_auto_download_artist_images" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,20 +1,20 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_lockscreen">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_lockscreen">
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="true"
android:key="album_art_on_lockscreen"
android:summary="@string/pref_summary_album_art_on_lockscreen"
android:title="@string/pref_title_album_art_on_lockscreen" />
<com.kabouzeid.appthemehelper.common.prefs.ATESwitchPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:dependency="album_art_on_lockscreen"
android:key="blurred_album_art"
android:summary="@string/pref_summary_blurred_album_art"
android:title="@string/pref_title_blurred_album_art" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory android:title="@string/pref_header_now_playing_screen">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_now_playing_screen">
<com.kabouzeid.appthemehelper.common.prefs.ATEListPreference
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
android:enabled="false"
android:key="now_playing_layout"
android:negativeButtonText="@null"
@ -11,6 +11,6 @@
android:summary="Coming soon"
android:title="@string/pref_title_now_playing_layout" />
</com.kabouzeid.appthemehelper.common.prefs.ATEPreferenceCategory>
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>