From e943e69e0d3b2034c21ecb7f2399f6c2a4dd2ea9 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 12:17:59 -0500 Subject: [PATCH] Theme Toolbar from activity --- .../java/com/moez/QKSMS/common/LiveViewManager.java | 2 +- .../main/java/com/moez/QKSMS/ui/ThemeManager.java | 12 ++---------- .../main/java/com/moez/QKSMS/ui/base/QKActivity.java | 5 +++++ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java index 26194b3e..19be390b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -29,7 +29,7 @@ import java.util.WeakHashMap; public abstract class LiveViewManager { private static final String TAG = "ThemedViewManager"; - private static HashMap> sViews = new HashMap<>(); + private static final HashMap> sViews = new HashMap<>(); /** * Initialize preferences and register a listener for changes 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 5747341d..fa262add 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -11,7 +11,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Resources; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.preference.PreferenceManager; @@ -261,7 +260,6 @@ public class ThemeManager { */ public static void themeActivity(QKActivity activity) { - activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mColor)); mWindow = activity.getWindow(); mStatusTintEnabled = mPrefs.getBoolean(SettingsFragment.STATUS_TINT, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; @@ -644,16 +642,14 @@ public class ThemeManager { colorAnimation.addUpdateListener(animation -> { int color1 = (Integer) animation.getAnimatedValue(); - if (activity.getSupportActionBar() != null) { - activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color1)); - } - if (mStatusTintEnabled) { mWindow.setStatusBarColor(ColorUtils.darken(color1)); } if (mNavigationTintEnabled) { mWindow.setNavigationBarColor(ColorUtils.darken(color1)); } + + LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); }); colorAnimation.addListener(new AnimatorListenerAdapter() { @Override @@ -686,10 +682,6 @@ public class ThemeManager { public static void setActiveColor(QKActivity activity, int color) { mActiveColor = color; - if (activity.getSupportActionBar() != null) { - activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color)); - } - if (mStatusTintEnabled) { mWindow.setStatusBarColor(ColorUtils.darken(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 d1cdd1eb..ba94c9d9 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 @@ -23,6 +23,7 @@ import android.widget.Toast; import com.android.volley.RequestQueue; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.view.QKTextView; @@ -72,6 +73,10 @@ public abstract class QKActivity extends ActionBarActivity { setSupportActionBar(mToolbar); } + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + mToolbar.setBackgroundColor(ThemeManager.getColor()); + }); + ThemeManager.themeActivity(this); }