Migrate more Activity theming ThemeManager

This commit is contained in:
Moez Bhatti
2016-01-03 16:21:17 -05:00
parent 87e910a892
commit 33a061ddcc
6 changed files with 25 additions and 29 deletions
@@ -90,7 +90,7 @@ public enum QKPreference {
QK_COMPOSE("pref_key_quickcompose", false), QK_COMPOSE("pref_key_quickcompose", false),
// LiveViews // LiveViews
ACTIVE_THEME("pref_key_active_theme"); ACTIVE_COLOR("pref_key_active_theme");
private String mKey; private String mKey;
private Object mDefaultValue; private Object mDefaultValue;
@@ -353,18 +353,12 @@ public class ThemeManager {
mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_light_text_primary); mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_light_text_primary);
mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_light_text_secondary); mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_light_text_secondary);
mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent); mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent);
/*if (mActivity != null) {
mActivity.getToolbar().setPopupTheme(R.style.PopupThemeLight);
}*/
break; break;
case GREY: case GREY:
case BLACK: case BLACK:
mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_dark_text_primary); mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_dark_text_primary);
mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_dark_text_secondary); mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_dark_text_secondary);
mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent_light); mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent_light);
/*if (mActivity != null) {
mActivity.getToolbar().setPopupTheme(R.style.PopupTheme);
}*/
break; break;
} }
@@ -377,11 +371,7 @@ public class ThemeManager {
setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false));
setBubbleStyleNew(mPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true)); setBubbleStyleNew(mPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true));
/*if (mActivity != null) { LiveViewManager.refreshViews(QKPreference.THEME);
// We need to set this here because the title bar is initialized before the ThemeManager,
// so it's not using the correct color yet
((QKTextView) mActivity.findViewById(R.id.toolbar_title)).setTextColor(mTextOnColorPrimary);
}*/
} }
public static void setIcon(final QKActivity context) { public static void setIcon(final QKActivity context) {
@@ -649,7 +639,7 @@ public class ThemeManager {
mWindow.setNavigationBarColor(ColorUtils.darken(color1)); mWindow.setNavigationBarColor(ColorUtils.darken(color1));
} }
LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR);
}); });
colorAnimation.addListener(new AnimatorListenerAdapter() { colorAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
@@ -689,7 +679,7 @@ public class ThemeManager {
mWindow.setNavigationBarColor(ColorUtils.darken(color)); mWindow.setNavigationBarColor(ColorUtils.darken(color));
} }
LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR);
} }
private static boolean isColorDarkEnough(int color) { private static boolean isColorDarkEnough(int color) {
@@ -73,10 +73,25 @@ public abstract class QKActivity extends AppCompatActivity {
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
} }
LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> {
mToolbar.setBackgroundColor(ThemeManager.getColor()); mToolbar.setBackgroundColor(ThemeManager.getColor());
}); });
LiveViewManager.registerView(QKPreference.THEME, this, key -> {
switch (ThemeManager.getTheme()) {
case WHITE:
case OFFWHITE:
mToolbar.setPopupTheme(R.style.PopupThemeLight);
break;
case GREY:
case BLACK:
mToolbar.setPopupTheme(R.style.PopupTheme);
break;
}
((QKTextView) findViewById(R.id.toolbar_title)).setTextColor(ThemeManager.getTextOnColorPrimary());
});
ThemeManager.themeActivity(this); ThemeManager.themeActivity(this);
} }
@@ -102,10 +117,10 @@ public abstract class QKActivity extends AppCompatActivity {
public void colorMenuIcons(Menu menu, int color) { public void colorMenuIcons(Menu menu, int color) {
// Toolbar navigation icon // Toolbar navigation icon
Drawable navigationIcon = getToolbar().getNavigationIcon(); Drawable navigationIcon = mToolbar.getNavigationIcon();
if (navigationIcon != null) { if (navigationIcon != null) {
navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
getToolbar().setNavigationIcon(navigationIcon); mToolbar.setNavigationIcon(navigationIcon);
} }
// Overflow icon // Overflow icon
@@ -217,15 +232,6 @@ public abstract class QKActivity extends AppCompatActivity {
} }
} }
/**
* Returns the Toolbar for this activity.
*
* @return
*/
public Toolbar getToolbar() {
return mToolbar;
}
public boolean isScreenOn() { public boolean isScreenOn() {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
@@ -94,7 +94,7 @@ public class MessageListViewHolder extends ClickyViewHolder<MessageItem> impleme
} }
protected void setLiveViewCallback(LiveView liveViewCallback) { protected void setLiveViewCallback(LiveView liveViewCallback) {
LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, liveViewCallback); LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, liveViewCallback);
} }
@Override @Override
@@ -91,7 +91,7 @@ public class AvatarView extends ImageView implements View.OnClickListener {
setOnClickListener(this); setOnClickListener(this);
LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> {
mPaint.setColor(ThemeManager.getTextOnColorPrimary()); mPaint.setColor(ThemeManager.getTextOnColorPrimary());
mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP);
@@ -181,7 +181,7 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
mCancel.setOnClickListener(this); mCancel.setOnClickListener(this);
mDelay.setOnClickListener(this); mDelay.setOnClickListener(this);
LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> {
mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP);
mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP);
mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP);