MultipleChoicePreference to set colored navigation bar for each activity individually.

This commit is contained in:
Karim Abou Zeid 2015-04-18 17:03:11 +02:00
commit 2d08e5c5d1
12 changed files with 161 additions and 132 deletions

View file

@ -8,8 +8,13 @@ public class UIPreferenceChangedEvent {
public static final int ALBUM_OVERVIEW_PALETTE_CHANGED = 1;
public static final int COLORED_NAVIGATION_BAR_ARTIST_CHANGED = 2;
public static final int COLORED_NAVIGATION_BAR_ALBUM_CHANGED = 3;
public static final int PLAYBACK_CONTROLLER_CARD_CHANGED = 4;
public static final int TOOLBAR_TRANSPARENT_CHANGED = 5;
public static final int COLORED_NAVIGATION_BAR_PLAYLIST_CHANGED = 4;
public static final int COLORED_NAVIGATION_BAR_TAG_EDITOR_CHANGED = 5;
public static final int COLORED_NAVIGATION_BAR_CURRENT_PLAYING_CHANGED = 6;
public static final int COLORED_NAVIGATION_BAR_CHANGED = 10;
public static final int COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED = 7;
public static final int PLAYBACK_CONTROLLER_CARD_CHANGED = 8;
public static final int TOOLBAR_TRANSPARENT_CHANGED = 9;
private final int action;
private final Object value;

View file

@ -58,6 +58,7 @@ import com.koushikdutta.ion.Ion;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MainActivity extends AbsFabActivity
@ -99,7 +100,7 @@ public class MainActivity extends AbsFabActivity
@Override
protected boolean shouldColorNavBar() {
return false;
return PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled();
}
private void setUpViewPager() {
@ -355,6 +356,16 @@ public class MainActivity extends AbsFabActivity
case UIPreferenceChangedEvent.TOOLBAR_TRANSPARENT_CHANGED:
setToolBarTransparent((boolean) event.getValue());
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
setShouldColorNavBar((boolean) event.getValue());
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_CHANGED:
try {
setShouldColorNavBar(((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS));
} catch (NullPointerException ignored) {
setShouldColorNavBar(false);
}
break;
}
}

View file

@ -81,7 +81,7 @@ public class PlaylistDetailActivity extends AbsFabActivity {
@Override
protected boolean shouldColorNavBar() {
return true;
return PreferenceUtils.getInstance(this).coloredNavigationBarPlaylistEnabled();
}
private void getIntentExtras() {

View file

@ -21,6 +21,9 @@ import com.kabouzeid.gramophone.prefs.ColorChooserPreference;
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.PreferenceUtils;
import com.kabouzeid.gramophone.util.Util;
import java.util.Set;
public class SettingsActivity extends AbsBaseActivity implements ColorChooserDialog.ColorCallback {
public static final String TAG = SettingsActivity.class.getSimpleName();
@ -29,7 +32,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
@Override
protected void onCreate(Bundle savedInstanceState) {
setStatusBarTranslucent(false);
setStatusBarTranslucent(!Util.hasLollipopSDK());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
@ -48,7 +51,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
@Override
protected boolean shouldColorNavBar() {
return true;
return PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled();
}
@Override
@ -134,22 +137,6 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}
});
findPreference("colored_navigation_bar_artist").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ARTIST_CHANGED, o));
return true;
}
});
findPreference("colored_navigation_bar_album").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_ALBUM_CHANGED, o));
return true;
}
});
findPreference("playback_controller_card").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
@ -158,6 +145,14 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}
});
findPreference("colored_navigation_bar").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_CHANGED, o));
return true;
}
});
equalizer = findPreference("equalizer");
resolveEqualizer();
equalizer.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@ -201,6 +196,23 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}
}
@Override
protected void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
super.onUIPreferenceChangedEvent(event);
switch (event.getAction()) {
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
setShouldColorNavBar((boolean) event.getValue());
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_CHANGED:
try {
setShouldColorNavBar(((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS));
} catch (NullPointerException ignored) {
setShouldColorNavBar(false);
}
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {

View file

@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
@ -20,13 +21,13 @@ import com.readystatesoftware.systembartint.SystemBarTintManager;
/**
* READ!
*
* <p/>
* Instructions:
*
* <p/>
* KitKat or Lollipop solid statusBar with the right color (primaryDark):
* - shouldColorStatusBar return true OR return false and call setStatusBarColor() in the activity with a custom color
* - setStatusBarTranslucent(!Util.hasLollipopSDK())
*
* <p/>
* KitKat or Lollipop translucent statusBar (not the color is too dark on Lollipop and KitKat only does fading but MUCH better performance the setStatusBarColor in onScrollCallback)
* - shouldColorStatusBar return false DO NOT return true and do not call setStatusBarColor() in this case at all here
* - setStatusBarTranslucent(true)
@ -49,13 +50,8 @@ public abstract class ThemeBaseActivity extends ActionBarActivity implements Kab
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTheme() {
// Apply colors to system UI if necessary
final int primaryDark = PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker();
if (Util.hasLollipopSDK()) {
if (shouldColorNavBar())
getWindow().setNavigationBarColor(primaryDark);
}
if (shouldColorStatusBar()) setStatusBarColor(primaryDark, false);
setShouldColorNavBar(shouldColorNavBar());
setShouldColorStatusBar(shouldColorStatusBar());
// Persist current values so the Activity knows if they change
// mLastDarkTheme = PreferenceUtils.getInstance(this).getGeneralTheme() == 1;
@ -110,4 +106,31 @@ public abstract class ThemeBaseActivity extends ActionBarActivity implements Kab
tintManager.setStatusBarTintColor(color);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setShouldColorNavBar(boolean shouldColorNavBar) {
if (Util.hasLollipopSDK()) {
if (shouldColorNavBar) {
final int primaryDark = PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker();
getWindow().setNavigationBarColor(primaryDark);
} else {
getWindow().setNavigationBarColor(Color.BLACK);
}
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setShouldColorStatusBar(boolean shouldColorStatusBar) {
if (shouldColorStatusBar) {
final int primaryDark = PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker();
setStatusBarColor(primaryDark, false);
} else {
if (Util.hasLollipopSDK()) {
getWindow().setStatusBarColor(Util.resolveColor(this, android.R.attr.statusBarColor));
} else {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(false);
}
}
}
}

View file

@ -199,12 +199,13 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
protected abstract void save();
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void restoreStandardColors() {
final int vibrantColor = PreferenceUtils.getInstance(this).getThemeColorPrimary();
paletteColorPrimary = vibrantColor;
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
setStatusBarColor(ColorChooserDialog.shiftColorDown(vibrantColor), false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(this).coloredNavigationBarTagEditorEnabled())
getWindow().setNavigationBarColor(vibrantColor);
}
@ -256,7 +257,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
int primaryDark = ColorChooserDialog.shiftColorDown(paletteColorPrimary);
setStatusBarColor(primaryDark, false);
if (Util.hasLollipopSDK())
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(this).coloredNavigationBarTagEditorEnabled())
getWindow().setNavigationBarColor(primaryDark);
}
@ -295,7 +296,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
paletteColorPrimary = vibrantColor;
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
setStatusBarColor(ColorChooserDialog.shiftColorDown(vibrantColor), false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
if (Util.hasLollipopSDK() && PreferenceUtils.getInstance(AbsTagEditorActivity.this).coloredNavigationBarTagEditorEnabled())
getWindow().setNavigationBarColor(vibrantColor);
}
});

View file

@ -23,9 +23,13 @@ public final class PreferenceUtils {
public static final String ONLY_ON_WIFI = "auto_download_artist_images";
// public static final String DOWNLOAD_MISSING_ARTIST_IMAGES = "auto_download_artist_images";
public static final String COLORED_ALBUM_FOOTERS = "colored_album_footers";
public static final String COLORED_NAVIGATION_BAR = "colored_navigation_bar";
public static final String COLORED_NAVIGATION_BAR_ALBUM = "colored_navigation_bar_album";
public static final String COLORED_NAVIGATION_BAR_ARTIST = "colored_navigation_bar_artist";
public static final String COLORED_NAVIGATION_BAR_CURRENT_PLAYING = "colored_navigation_bar_current_playing_enabled";
public static final String COLORED_NAVIGATION_BAR_CURRENT_PLAYING = "colored_navigation_bar_current_playing";
public static final String COLORED_NAVIGATION_BAR_PLAYIST = "colored_navigation_bar_playlist";
public static final String COLORED_NAVIGATION_BAR_TAG_EDITOR = "colored_navigation_bar_tag_editor";
public static final String COLORED_NAVIGATION_BAR_OTHER_SCREENS = "colored_navigation_bar_other_screens";
public static final String PLAYBACK_CONTROLLER_BOX = "playback_controller_card";
public static final String TRANSPARENT_TOOLBAR = "transparent_toolbar";
public static final String ALBUM_GRID_COLUMNS = "album_grid_columns";
@ -81,30 +85,6 @@ public final class PreferenceUtils {
mPreferences.edit().putInt("accent_color", color).commit();
}
// public void setGeneralTheme(int appTheme) {
// int value = -1;
// switch (appTheme) {
// case R.style.Theme_MaterialMusic_Light:
// value = 0;
// break;
// case R.style.Theme_MaterialMusic:
// value = 1;
// break;
// }
// if (value != 0 && value != 1) {
// return;
// }
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putString(GENERAL_THEME, String.valueOf(value));
// editor.apply();
// }
//
// public void setDefaultStartPage(final int value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putString(DEFAULT_START_PAGE, String.valueOf(value));
// editor.apply();
// }
public final int getDefaultStartPage() {
return Integer.parseInt(mPreferences.getString(DEFAULT_START_PAGE, "-1"));
}
@ -119,92 +99,70 @@ public final class PreferenceUtils {
return mPreferences.getInt(LAST_START_PAGE, DEFAULT_PAGE);
}
public final boolean autoDownloadOnlyOnWifi() {
return mPreferences.getBoolean(ONLY_ON_WIFI, false);
}
// public void setAutoDownloadOnlyOnWifi(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(ONLY_ON_WIFI, value);
// editor.apply();
// public final boolean autoDownloadOnlyOnWifi() {
// return mPreferences.getBoolean(ONLY_ON_WIFI, false);
// }
public final boolean coloredAlbumFootersEnabled() {
return mPreferences.getBoolean(COLORED_ALBUM_FOOTERS, true);
}
// public void setColoredAlbumFootersEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_ALBUM_FOOTERS, value);
// editor.apply();
// }
public final boolean coloredNavigationBarAlbumEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_ALBUM, true);
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_ALBUM);
}
/*public void setColoredNavigationBarAlbumEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_NAVIGATION_BAR_ALBUM, value);
editor.apply();
}*/
public final boolean coloredNavigationBarArtistEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_ARTIST, true);
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_ARTIST);
}
// public void setColoredNavigationBarArtistEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_NAVIGATION_BAR_ARTIST, value);
// editor.apply();
// }
public final boolean coloredNavigationBarCurrentPlayingEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_CURRENT_PLAYING, true);
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_CURRENT_PLAYING);
}
// public void setColoredNavigationBarCurrentPlayingEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_NAVIGATION_BAR_CURRENT_PLAYING, value);
// editor.apply();
// }
public final boolean coloredNavigationBarPlaylistEnabled() {
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_PLAYIST);
}
public final boolean coloredNavigationBarTagEditorEnabled() {
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_TAG_EDITOR);
}
public final boolean coloredNavigationBarOtherScreensEnabled() {
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_OTHER_SCREENS);
}
private final boolean coloredNavigationBarFor(String key) {
try {
return mPreferences.getStringSet(COLORED_NAVIGATION_BAR, null).contains(key);
} catch (NullPointerException e) {
return false;
}
}
@SuppressLint("CommitPrefEdits")
private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) {
mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit();
}
public final boolean playbackControllerBoxEnabled() {
return mPreferences.getBoolean(PLAYBACK_CONTROLLER_BOX, false);
}
// public void setPlaybackControllerBoxEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(PLAYBACK_CONTROLLER_BOX, value);
// editor.apply();
// }
public final boolean transparentToolbar() {
return mPreferences.getBoolean(TRANSPARENT_TOOLBAR, false);
}
// public void setTransparentToolbar(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(TRANSPARENT_TOOLBAR, value);
// editor.apply();
// }
// public final boolean downloadMissingArtistImages() {
// return mPreferences.getBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, true);
// }
//
// public void setDownloadMissingArtistImages(final boolean value) {
// private void setSortOrder(final String key, final String value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, value);
// editor.putString(key, value);
// editor.apply();
// }
private void setSortOrder(final String key, final String value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(key, value);
editor.apply();
}
// public void setArtistSortOrder(final String value) {
// setSortOrder(ARTIST_SORT_ORDER, value);
// }

View file

@ -34,12 +34,12 @@ public class Util {
// return resId;
// }
// public static int resolveColor(Context context, int color) {
// TypedArray a = context.obtainStyledAttributes(new int[]{color});
// int resId = a.getColor(0, 0);
// a.recycle();
// return resId;
// }
public static int resolveColor(Context context, int color) {
TypedArray a = context.obtainStyledAttributes(new int[]{color});
int resId = a.getColor(0, 0);
a.recycle();
return resId;
}
// public static boolean isWindowTranslucent(Context context) {
// TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowTranslucentStatus});