mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Initialize ThemeManager on startup
This commit is contained in:
@@ -19,7 +19,6 @@ public class NightModeAutoReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
ThemeManager.loadThemeProperties(context);
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) {
|
if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) {
|
||||||
|
|||||||
@@ -243,7 +243,6 @@ public class ThemeManager {
|
|||||||
private static boolean mStatusTintEnabled = false;
|
private static boolean mStatusTintEnabled = false;
|
||||||
private static boolean mNavigationTintEnabled = false;
|
private static boolean mNavigationTintEnabled = false;
|
||||||
|
|
||||||
private static QKActivity mActivity;
|
|
||||||
private static Context mContext;
|
private static Context mContext;
|
||||||
private static Window mWindow;
|
private static Window mWindow;
|
||||||
|
|
||||||
@@ -252,37 +251,30 @@ public class ThemeManager {
|
|||||||
|
|
||||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
mResources = context.getResources();
|
mResources = context.getResources();
|
||||||
|
|
||||||
|
mColor = Integer.parseInt(mPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR));
|
||||||
|
mActiveColor = mColor;
|
||||||
|
|
||||||
|
initializeTheme(Theme.fromString(mPrefs.getString(SettingsFragment.BACKGROUND, "offwhite")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all theme properties. Should be called during onCreate
|
* Loads all theme properties. Should be called during onCreate
|
||||||
* of each activity that contains fragments that use ThemeManager
|
* of each activity that contains fragments that use ThemeManager
|
||||||
*/
|
*/
|
||||||
public static void loadThemeProperties(Context context) {
|
public static void themeActivity(QKActivity activity) {
|
||||||
|
|
||||||
mContext = context;
|
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mColor));
|
||||||
|
mWindow = activity.getWindow();
|
||||||
mColor = Integer.parseInt(mPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR));
|
|
||||||
mActiveColor = mColor;
|
|
||||||
|
|
||||||
if (context instanceof QKActivity) {
|
|
||||||
mActivity = (QKActivity) context;
|
|
||||||
mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mColor));
|
|
||||||
mWindow = mActivity.getWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeTheme(Theme.fromString(mPrefs.getString(SettingsFragment.BACKGROUND, "offwhite")));
|
|
||||||
|
|
||||||
mStatusTintEnabled = mPrefs.getBoolean(SettingsFragment.STATUS_TINT, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
mStatusTintEnabled = mPrefs.getBoolean(SettingsFragment.STATUS_TINT, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
mNavigationTintEnabled = mPrefs.getBoolean(SettingsFragment.NAVIGATION_TINT, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
mNavigationTintEnabled = mPrefs.getBoolean(SettingsFragment.NAVIGATION_TINT, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
|
||||||
if (mActivity != null && mStatusTintEnabled) {
|
if (mStatusTintEnabled) {
|
||||||
if (mStatusTintEnabled) {
|
mWindow.setStatusBarColor(ColorUtils.darken(mColor));
|
||||||
mWindow.setStatusBarColor(ColorUtils.darken(mColor));
|
}
|
||||||
}
|
if (mNavigationTintEnabled) {
|
||||||
if (mNavigationTintEnabled) {
|
mWindow.setNavigationBarColor(ColorUtils.darken(mColor));
|
||||||
mWindow.setNavigationBarColor(ColorUtils.darken(mColor));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -292,11 +284,11 @@ public class ThemeManager {
|
|||||||
initializeTheme(theme);
|
initializeTheme(theme);
|
||||||
int endColor = mBackgroundColor;
|
int endColor = mBackgroundColor;
|
||||||
|
|
||||||
if (mActivity instanceof MainActivity) {
|
if (mContext instanceof MainActivity) {
|
||||||
final View background = mActivity.findViewById(R.id.menu_frame).getRootView();
|
final View background = ((MainActivity) mContext).findViewById(R.id.menu_frame).getRootView();
|
||||||
final View menu = mActivity.findViewById(R.id.menu_frame);
|
final View menu = ((MainActivity) mContext).findViewById(R.id.menu_frame);
|
||||||
final View content = mActivity.findViewById(R.id.content_frame);
|
final View content = ((MainActivity) mContext).findViewById(R.id.content_frame);
|
||||||
final View fragment = ((MainActivity) mActivity).getContent().getView();
|
final View fragment = ((MainActivity) mContext).getContent().getView();
|
||||||
|
|
||||||
if (startColor != endColor) {
|
if (startColor != endColor) {
|
||||||
ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
|
ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
|
||||||
@@ -366,18 +358,18 @@ 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) {
|
/*if (mActivity != null) {
|
||||||
mActivity.getToolbar().setPopupTheme(R.style.PopupThemeLight);
|
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) {
|
/*if (mActivity != null) {
|
||||||
mActivity.getToolbar().setPopupTheme(R.style.PopupTheme);
|
mActivity.getToolbar().setPopupTheme(R.style.PopupTheme);
|
||||||
}
|
}*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,11 +382,11 @@ 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) {
|
/*if (mActivity != null) {
|
||||||
// We need to set this here because the title bar is initialized before the ThemeManager,
|
// We need to set this here because the title bar is initialized before the ThemeManager,
|
||||||
// so it's not using the correct color yet
|
// so it's not using the correct color yet
|
||||||
((QKTextView) mActivity.findViewById(R.id.toolbar_title)).setTextColor(mTextOnColorPrimary);
|
((QKTextView) mActivity.findViewById(R.id.toolbar_title)).setTextColor(mTextOnColorPrimary);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setIcon(final QKActivity context) {
|
public static void setIcon(final QKActivity context) {
|
||||||
@@ -575,7 +567,7 @@ public class ThemeManager {
|
|||||||
ColorPickerPalette palette = new ColorPickerPalette(context);
|
ColorPickerPalette palette = new ColorPickerPalette(context);
|
||||||
palette.setGravity(Gravity.CENTER);
|
palette.setGravity(Gravity.CENTER);
|
||||||
palette.init(getSwatch(swatchColour).length, 4, color -> {
|
palette.init(getSwatch(swatchColour).length, 4, color -> {
|
||||||
setColour(color);
|
setColour(context, color);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -624,7 +616,7 @@ public class ThemeManager {
|
|||||||
return String.format("#%08x", color).toUpperCase();
|
return String.format("#%08x", color).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setColour(int color) {
|
public static void setColour(QKActivity activity, int color) {
|
||||||
|
|
||||||
AnalyticsManager.getInstance().sendEvent(
|
AnalyticsManager.getInstance().sendEvent(
|
||||||
AnalyticsManager.CATEGORY_PREFERENCE_CHANGE,
|
AnalyticsManager.CATEGORY_PREFERENCE_CHANGE,
|
||||||
@@ -660,10 +652,8 @@ public class ThemeManager {
|
|||||||
colorAnimation.addUpdateListener(animation -> {
|
colorAnimation.addUpdateListener(animation -> {
|
||||||
int color1 = (Integer) animation.getAnimatedValue();
|
int color1 = (Integer) animation.getAnimatedValue();
|
||||||
|
|
||||||
if (mActivity != null) {
|
if (activity.getSupportActionBar() != null) {
|
||||||
if (mActivity.getSupportActionBar() != null) {
|
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color1));
|
||||||
mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStatusTintEnabled) {
|
if (mStatusTintEnabled) {
|
||||||
@@ -683,9 +673,9 @@ public class ThemeManager {
|
|||||||
colorAnimation.start();
|
colorAnimation.start();
|
||||||
|
|
||||||
|
|
||||||
if (mActivity != null && mActivity.findViewById(R.id.toolbar_title) != null) {
|
if (activity.findViewById(R.id.toolbar_title) != null) {
|
||||||
//final Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.title);
|
//final Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.title);
|
||||||
final QKTextView title = (QKTextView) mActivity.findViewById(R.id.toolbar_title);
|
final QKTextView title = (QKTextView) activity.findViewById(R.id.toolbar_title);
|
||||||
|
|
||||||
if (title.getCurrentTextColor() != mTextOnColorPrimary) {
|
if (title.getCurrentTextColor() != mTextOnColorPrimary) {
|
||||||
ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), title.getCurrentTextColor(), mTextOnColorPrimary);
|
ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), title.getCurrentTextColor(), mTextOnColorPrimary);
|
||||||
@@ -694,21 +684,20 @@ public class ThemeManager {
|
|||||||
titleColorAnimation.addUpdateListener(animation -> {
|
titleColorAnimation.addUpdateListener(animation -> {
|
||||||
int color1 = (Integer) animation.getAnimatedValue();
|
int color1 = (Integer) animation.getAnimatedValue();
|
||||||
title.setTextColor(color1);
|
title.setTextColor(color1);
|
||||||
mActivity.colorMenuIcons(mActivity.getMenu(), color1);
|
activity.colorMenuIcons(activity.getMenu(), color1);
|
||||||
});
|
});
|
||||||
titleColorAnimation.start();
|
titleColorAnimation.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setActiveColor(int color) {
|
public static void setActiveColor(QKActivity activity, int color) {
|
||||||
mActiveColor = color;
|
mActiveColor = color;
|
||||||
|
|
||||||
if (mActivity != null) {
|
if (activity.getSupportActionBar() != null) {
|
||||||
if (mActivity.getSupportActionBar() != null) {
|
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
|
||||||
mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStatusTintEnabled) {
|
if (mStatusTintEnabled) {
|
||||||
mWindow.setStatusBarColor(ColorUtils.darken(color));
|
mWindow.setStatusBarColor(ColorUtils.darken(color));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public abstract class QKActivity extends ActionBarActivity {
|
|||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeManager.loadThemeProperties(this);
|
ThemeManager.themeActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showBackButton(boolean show) {
|
protected void showBackButton(boolean show) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public abstract class QKPopupActivity extends QKActivity {
|
|||||||
setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true));
|
setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true));
|
||||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||||
setContentView(getLayoutResource());
|
setContentView(getLayoutResource());
|
||||||
ThemeManager.loadThemeProperties(this);
|
ThemeManager.themeActivity(this);
|
||||||
|
|
||||||
((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor());
|
((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor());
|
||||||
|
|
||||||
|
|||||||
@@ -762,7 +762,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
|||||||
mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeManager.setActiveColor(mConversationPrefs.getColor());
|
ThemeManager.setActiveColor(mContext, mConversationPrefs.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -787,13 +787,13 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeManager.setActiveColor(ThemeManager.getThemeColor());
|
ThemeManager.setActiveColor(mContext, ThemeManager.getThemeColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuChanging(float percentOpen) {
|
public void onMenuChanging(float percentOpen) {
|
||||||
if (mConversationPrefs != null) {
|
if (mConversationPrefs != null) {
|
||||||
ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate(
|
ThemeManager.setActiveColor(mContext, (int) mArgbEvaluator.evaluate(
|
||||||
percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor()));
|
percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class WelcomeActivity extends QKActivity implements ViewPager.OnPageChang
|
|||||||
});
|
});
|
||||||
colorAnimation.start();
|
colorAnimation.start();
|
||||||
|
|
||||||
ThemeManager.setColour(color);
|
ThemeManager.setColour(this, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColorBackground(int color) {
|
public void setColorBackground(int color) {
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ public class WidgetProvider extends AppWidgetProvider {
|
|||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||||
|
|
||||||
ThemeManager.loadThemeProperties(context);
|
|
||||||
|
|
||||||
for (int appWidgetId : appWidgetIds) {
|
for (int appWidgetId : appWidgetIds) {
|
||||||
updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId));
|
updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user