MultipleChoicePreference to set colored navigation bar for each activity individually.
This commit is contained in:
parent
00b72b7a75
commit
2d08e5c5d1
12 changed files with 161 additions and 132 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class PlaylistDetailActivity extends AbsFabActivity {
|
|||
|
||||
@Override
|
||||
protected boolean shouldColorNavBar() {
|
||||
return true;
|
||||
return PreferenceUtils.getInstance(this).coloredNavigationBarPlaylistEnabled();
|
||||
}
|
||||
|
||||
private void getIntentExtras() {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue