Loading QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package com.moez.QKSMS.common; import android.content.Context; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Typeface; import android.preference.PreferenceManager; import com.moez.QKSMS.R; import com.moez.QKSMS.ui.ThemeManager; Loading @@ -26,7 +27,7 @@ public class FontManager { public static final int TEXT_TYPE_DIALOG_BUTTON = 0x7; public static final int TEXT_TYPE_TOOLBAR = 0x8; public static int getFontFamily(Context context) { private static int getFontFamily(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return Integer.parseInt(prefs.getString(SettingsFragment.FONT_FAMILY, "0")); } Loading Loading @@ -115,7 +116,7 @@ public class FontManager { return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); } public static int getFontWeight(Context context, boolean heavy) { private static int getFontWeight(Context context, boolean heavy) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int fontWeight = Integer.parseInt(prefs.getString(SettingsFragment.FONT_WEIGHT, "0")); int fontFamily = getFontFamily(context); Loading @@ -133,4 +134,16 @@ public class FontManager { return TypefaceManager.TextWeight.BOLD; } } public static Typeface getFont(Context context, int type) { int fontFamily = getFontFamily(context); int fontWeight = getFontWeight(context, getIsFontHeavy(type)); return TypefaceManager.obtainTypeface(context, fontFamily, fontWeight); } public static Typeface getFont(Context context) { int fontFamily = getFontFamily(context); int fontWeight = getFontWeight(context, false); return TypefaceManager.obtainTypeface(context, fontFamily, fontWeight); } } QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +0 −18 Original line number Diff line number Diff line Loading @@ -57,24 +57,6 @@ public abstract class LiveViewManager { }); } /** * Convenience method for #registerView(QKPreference, ThemedView) to allow registering a single * ThemedView to listen for multiple preferences * * @param view The LiveView * @param parent The object to tie the lifecycle of the LiveView to. If we only reference * a LiveView anonymous inner class, then it'll be quickly garbage collected * and removed from the WeakHashMap. Instead, we should reference the parent * object (ie. The Activity, Fragment, View, etc...) that this LiveView is * concerned with. In most cases, it's acceptable to just pass in `this` * @param preferences The preferences to listen for */ public static void registerView(LiveView view, Object parent, QKPreference... preferences) { for (QKPreference preference : preferences) { registerView(preference, parent, view); } } /** * Register a view to be updated when a QKPreference is changed * We don't need to manually unregister the views because we're using weak sets Loading QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +7 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import com.android.ex.chips.BaseRecipientAdapter; import com.android.ex.chips.RecipientEditTextView; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; Loading Loading @@ -41,11 +40,13 @@ public class AutoCompleteContactView extends RecipientEditTextView { setAdapter(mAdapter); setOnItemClickListener(this); LiveViewManager.registerView(key -> { int fontFamily = FontManager.getFontFamily(mContext); int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); LiveViewManager.registerView(QKPreference.FONT_FAMILY, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_WEIGHT, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); Loading QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +7 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import android.util.AttributeSet; import android.util.TypedValue; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.ui.ThemeManager; Loading Loading @@ -50,11 +49,13 @@ public class QKEditText extends android.widget.EditText { private void init(Context context) { mContext = context; LiveViewManager.registerView(key -> { int fontFamily = FontManager.getFontFamily(mContext); int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); LiveViewManager.registerView(QKPreference.FONT_FAMILY, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_WEIGHT, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); Loading QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java +7 −2 Original line number Diff line number Diff line Loading @@ -29,10 +29,15 @@ public class QKSwitch extends SwitchCompat { private void init(Context context) { mRes = context.getResources(); LiveViewManager.registerView(key -> { LiveViewManager.registerView(QKPreference.THEME, this, key -> { DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); }, QKPreference.THEME, QKPreference.BACKGROUND); }); LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); }); } private ColorStateList getSwitchThumbColorStateList() { Loading Loading
QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package com.moez.QKSMS.common; import android.content.Context; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Typeface; import android.preference.PreferenceManager; import com.moez.QKSMS.R; import com.moez.QKSMS.ui.ThemeManager; Loading @@ -26,7 +27,7 @@ public class FontManager { public static final int TEXT_TYPE_DIALOG_BUTTON = 0x7; public static final int TEXT_TYPE_TOOLBAR = 0x8; public static int getFontFamily(Context context) { private static int getFontFamily(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return Integer.parseInt(prefs.getString(SettingsFragment.FONT_FAMILY, "0")); } Loading Loading @@ -115,7 +116,7 @@ public class FontManager { return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); } public static int getFontWeight(Context context, boolean heavy) { private static int getFontWeight(Context context, boolean heavy) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int fontWeight = Integer.parseInt(prefs.getString(SettingsFragment.FONT_WEIGHT, "0")); int fontFamily = getFontFamily(context); Loading @@ -133,4 +134,16 @@ public class FontManager { return TypefaceManager.TextWeight.BOLD; } } public static Typeface getFont(Context context, int type) { int fontFamily = getFontFamily(context); int fontWeight = getFontWeight(context, getIsFontHeavy(type)); return TypefaceManager.obtainTypeface(context, fontFamily, fontWeight); } public static Typeface getFont(Context context) { int fontFamily = getFontFamily(context); int fontWeight = getFontWeight(context, false); return TypefaceManager.obtainTypeface(context, fontFamily, fontWeight); } }
QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +0 −18 Original line number Diff line number Diff line Loading @@ -57,24 +57,6 @@ public abstract class LiveViewManager { }); } /** * Convenience method for #registerView(QKPreference, ThemedView) to allow registering a single * ThemedView to listen for multiple preferences * * @param view The LiveView * @param parent The object to tie the lifecycle of the LiveView to. If we only reference * a LiveView anonymous inner class, then it'll be quickly garbage collected * and removed from the WeakHashMap. Instead, we should reference the parent * object (ie. The Activity, Fragment, View, etc...) that this LiveView is * concerned with. In most cases, it's acceptable to just pass in `this` * @param preferences The preferences to listen for */ public static void registerView(LiveView view, Object parent, QKPreference... preferences) { for (QKPreference preference : preferences) { registerView(preference, parent, view); } } /** * Register a view to be updated when a QKPreference is changed * We don't need to manually unregister the views because we're using weak sets Loading
QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +7 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import com.android.ex.chips.BaseRecipientAdapter; import com.android.ex.chips.RecipientEditTextView; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; Loading Loading @@ -41,11 +40,13 @@ public class AutoCompleteContactView extends RecipientEditTextView { setAdapter(mAdapter); setOnItemClickListener(this); LiveViewManager.registerView(key -> { int fontFamily = FontManager.getFontFamily(mContext); int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); LiveViewManager.registerView(QKPreference.FONT_FAMILY, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_WEIGHT, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); Loading
QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +7 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import android.util.AttributeSet; import android.util.TypedValue; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.ui.ThemeManager; Loading Loading @@ -50,11 +49,13 @@ public class QKEditText extends android.widget.EditText { private void init(Context context) { mContext = context; LiveViewManager.registerView(key -> { int fontFamily = FontManager.getFontFamily(mContext); int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); LiveViewManager.registerView(QKPreference.FONT_FAMILY, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_WEIGHT, this, key -> { setTypeface(FontManager.getFont(mContext)); }); LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); Loading
QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java +7 −2 Original line number Diff line number Diff line Loading @@ -29,10 +29,15 @@ public class QKSwitch extends SwitchCompat { private void init(Context context) { mRes = context.getResources(); LiveViewManager.registerView(key -> { LiveViewManager.registerView(QKPreference.THEME, this, key -> { DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); }, QKPreference.THEME, QKPreference.BACKGROUND); }); LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); }); } private ColorStateList getSwitchThumbColorStateList() { Loading