From 33a061ddccd105c69a14e6b516dbee53fcdb8989 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 16:21:17 -0500 Subject: [PATCH] Migrate more Activity theming ThemeManager --- .../common/preferences/QKPreference.java | 2 +- .../java/com/moez/QKSMS/ui/ThemeManager.java | 16 ++-------- .../com/moez/QKSMS/ui/base/QKActivity.java | 30 +++++++++++-------- .../ui/messagelist/MessageListViewHolder.java | 2 +- .../com/moez/QKSMS/ui/view/AvatarView.java | 2 +- .../com/moez/QKSMS/ui/view/ComposeView.java | 2 +- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java index 7e788ab3..8a92aeea 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java @@ -90,7 +90,7 @@ public enum QKPreference { QK_COMPOSE("pref_key_quickcompose", false), // LiveViews - ACTIVE_THEME("pref_key_active_theme"); + ACTIVE_COLOR("pref_key_active_theme"); private String mKey; private Object mDefaultValue; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java index fa262add..c1de8a4a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -353,18 +353,12 @@ public class ThemeManager { mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_light_text_primary); mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_light_text_secondary); mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent); - /*if (mActivity != null) { - mActivity.getToolbar().setPopupTheme(R.style.PopupThemeLight); - }*/ break; case GREY: case BLACK: mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_dark_text_primary); mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_dark_text_secondary); mRippleBackground = mResources.getDrawable(R.drawable.button_background_transparent_light); - /*if (mActivity != null) { - mActivity.getToolbar().setPopupTheme(R.style.PopupTheme); - }*/ break; } @@ -377,11 +371,7 @@ public class ThemeManager { setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); setBubbleStyleNew(mPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true)); - /*if (mActivity != null) { - // 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); - }*/ + LiveViewManager.refreshViews(QKPreference.THEME); } public static void setIcon(final QKActivity context) { @@ -649,7 +639,7 @@ public class ThemeManager { mWindow.setNavigationBarColor(ColorUtils.darken(color1)); } - LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); + LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR); }); colorAnimation.addListener(new AnimatorListenerAdapter() { @Override @@ -689,7 +679,7 @@ public class ThemeManager { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } - LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); + LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR); } private static boolean isColorDarkEnough(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java index 7b80536b..be2eeeda 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java @@ -73,10 +73,25 @@ public abstract class QKActivity extends AppCompatActivity { setSupportActionBar(mToolbar); } - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { + LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> { 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); } @@ -102,10 +117,10 @@ public abstract class QKActivity extends AppCompatActivity { public void colorMenuIcons(Menu menu, int color) { // Toolbar navigation icon - Drawable navigationIcon = getToolbar().getNavigationIcon(); + Drawable navigationIcon = mToolbar.getNavigationIcon(); if (navigationIcon != null) { navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); - getToolbar().setNavigationIcon(navigationIcon); + mToolbar.setNavigationIcon(navigationIcon); } // 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() { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListViewHolder.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListViewHolder.java index 2de9dd22..a8d14dfc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListViewHolder.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListViewHolder.java @@ -94,7 +94,7 @@ public class MessageListViewHolder extends ClickyViewHolder impleme } protected void setLiveViewCallback(LiveView liveViewCallback) { - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, liveViewCallback); + LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, liveViewCallback); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AvatarView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AvatarView.java index 8b79b5c0..ead8d0ac 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AvatarView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AvatarView.java @@ -91,7 +91,7 @@ public class AvatarView extends ImageView implements View.OnClickListener { setOnClickListener(this); - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { + LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> { mPaint.setColor(ThemeManager.getTextOnColorPrimary()); mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/ComposeView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/ComposeView.java index 36e621c2..c1881f57 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/ComposeView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/ComposeView.java @@ -181,7 +181,7 @@ public class ComposeView extends LinearLayout implements View.OnClickListener { mCancel.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); mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP);