From 7104a676a8e09c4b8cc217bad539159b6dcb3c7e Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 20 Dec 2015 12:58:18 -0500 Subject: [PATCH 01/49] Added theme to conversation prefs --- .../moez/QKSMS/common/ConversationPrefsHelper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java index 0240e5e72..52d11e149 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java @@ -21,6 +21,11 @@ public ConversationPrefsHelper(Context context, long threadId) { mConversationPrefs = context.getSharedPreferences(CONVERSATIONS_FILE + threadId, Context.MODE_PRIVATE); } + public int getColor() { + //return getInt(SettingsFragment.THEME, 0xFF009688); + return 0xFFFF0000; + } + public boolean getNotificationsEnabled() { return getBoolean(SettingsFragment.NOTIFICATIONS, true); } @@ -65,6 +70,15 @@ public boolean getDimissedReadEnabled() { return getBoolean(SettingsFragment.DISMISSED_READ, false); } + public void putInt(String key, int value) { + mConversationPrefs.edit().putInt(key, value).apply(); + } + + public int getInt(String key, int defaultValue) { + int globalValue = mPrefs.getInt(key, defaultValue); + return mConversationPrefs.getInt(key, globalValue); + } + public void putString(String key, String value) { mConversationPrefs.edit().putString(key, value).apply(); } From 4192691cafdf99418eda03d675a7e04afd3c2a0d Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 20 Dec 2015 21:54:22 -0500 Subject: [PATCH 02/49] Add support for getting preference via enum --- .../common/preferences/QKPreference.java | 111 ++++++++++++++++++ .../common/preferences/QKPreferences.java | 38 ++++++ .../QKSMS/ui/settings/SettingsFragment.java | 4 - QKSMS/src/main/res/xml/settings_general.xml | 1 + 4 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java create mode 100644 QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java 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 new file mode 100644 index 000000000..5683bedce --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreference.java @@ -0,0 +1,111 @@ +package com.moez.QKSMS.common.preferences; + +import java.util.Arrays; +import java.util.HashSet; + +public enum QKPreference { + // Appearance + THEME("pref_key_theme", 0xFFFFF), + ICON("pref_key_icon"), + BACKGROUND("pref_key_background", "offwhite"), + + BUBBLES("pref_key_bubbles"), + BUBBLES_NEW("pref_key_new_bubbles", true), + BUBBLES_COLOR_SENT("pref_key_colour_sent", false), + BUBBLES_COLOR_RECEIVED("pref_key_colour_received", true), + + AUTO_NIGHT("pref_key_night_auto", false), + AUTO_NIGHT_DAY_START("pref_key_day_start", "6:00"), + AUTO_NIGHT_NIGHT_START("pref_key_night_start", "21:00"), + + TINTED_STATUS("pref_key_status_tint", true), + TINTED_NAV("pref_key_navigation_tint", false), + + FONT_FAMILY("pref_key_font_family", "0"), + FONT_SIZE("pref_key_font_size", "1"), + FONT_WEIGHT("pref_key_font_weight", "0"), + + AVATAR_CONVERSATIONS("pref_key_avatar_conversations", true), + AVATAR_SENT("pref_key_avatar_sent", false), + AVATAR_RECEIVED("pref_key_avatar_received", true), + + MESSAGE_COUNT("pref_key_message_count", false), + SLIDING_TAB("pref_key_sliding_tab", false), + TIMESTAMPS_24H("pref_key_24h", false), + + // General + DELAYED_MESSAGING("pref_key_delayed", false), + DELAYED_DURATION("pref_key_delay_duration", 3), + + DELIVERY_CONFIRMATIONS("pref_key_delivery", false), + DELIVERY_TOAST("pref_key_delivery_toast", true), + DELIVERY_VIBRATE("pref_key_delivery_vibrate", true), + + AUTO_EMOJI("pref_key_auto_emoji", false), + TEXT_FORMATTING("pref_key_markdown_enabled", false), + STRIP_UNICODE("pref_key_strip_unicode", false), + SPLIT_SMS("pref_key_split", false), + SPLIT_COUNTER("pref_key_split_counter", true), + + BLOCKED_CONVERSATIONS("pref_key_blocked_enabled", false), + BLOCKED_SENDERS("pref_key_blocked_senders", new HashSet()), + BLOCKED_FUTURE("pref_key_block_future", new HashSet()), + MOBILE_ONLY("pref_key_mobile_only", false), + ENTER_BUTTON("pref_key_enter_button", "0"), + STARRED_CONTACTS("pref_key_compose_favorites", true), + PROXIMITY_SENSOR("pref_key_prox_sensor_calling", false), + YAPPY_INTEGRATION("pref_key_endlessjabber", false), + QK_RESPONSES("pref_key_qk_responses", new HashSet<>(Arrays.asList(new String[]{ + "Okay", "Give me a moment", "On my way", "Thanks", "Sounds good", "What's up?", "Agreed", "No", + "Love you", "Sorry", "LOL", "That's okay"}))), + + // Notifications + NOTIFICATIONS("pref_key_notifications", true), + NOTIFICATIONS_LED("pref_key_led", true), + NOTIFICATIONS_LED_COLOR("pref_key_theme_led", "-48060"), + NOTIFICATIONS_WAKE("pref_key_wake", false), + NOTIFICATIONS_TICKER("pref_key_ticker", false), + NOTIFICATIONS_PRIVATE("pref_key_notification_private", false), + NOTIFICATIONS_VIBRATION("pref_key_vibration", true), + NOTIFICATIONS_SOUND("pref_key_ringtone", "content://settings/system/notification_sound"), + NOTIFICATIONS_CALL_BUTTON("pref_key_notification_call", false), + NOTIFICATIONS_MARK_READ("pref_key_dismiss_read", false), + + // MMS + GROUP_MESSAGING("pref_key_compose_group", true), + AUTOMATIC_DATA("pref_key_auto_data", true), + LONG_AS_MMS("", true), + LONG_AS_MMS_AFTER("", true), + MAX_MMS_SIZE("", true), + AUTO_CONFIGURE_MMS("", true), + MMSC("mmsc_url", true), + MMS_PORT("mms_port", true), + MMS_PROXY("mms_proxy", true), + + // QK Reply + QK_REPLY("pref_key_quickreply_enabled", true), + TAP_DISMISS("pref_key_quickreply_dismiss", true), + + // QK Compose + QK_COMPOSE("pref_key_quickcompose", false); + + private String mKey; + private Object mDefaultValue; + + QKPreference(String key) { + mKey = key; + } + + QKPreference(String key, Object defaultValue) { + mKey = key; + mDefaultValue = defaultValue; + } + + public String getKey() { + return mKey; + } + + public Object getDefaultValue() { + return mDefaultValue; + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java new file mode 100644 index 000000000..a7b89d6fc --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java @@ -0,0 +1,38 @@ +package com.moez.QKSMS.common.preferences; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +public class QKPreferences { + + private SharedPreferences mPrefs; + + public QKPreferences(Context context) { + mPrefs = PreferenceManager.getDefaultSharedPreferences(context); + } + + public boolean getBoolean(QKPreference preference) { + return mPrefs.getBoolean(preference.getKey(), (boolean) preference.getDefaultValue()); + } + + public void setBoolean(QKPreference preference, boolean newValue) { + mPrefs.edit().putBoolean(preference.getKey(), newValue).apply(); + } + + public int getInt(QKPreference preference) { + return mPrefs.getInt(preference.getKey(), (int) preference.getDefaultValue()); + } + + public void setInt(QKPreference preference, int newValue) { + mPrefs.edit().putInt(preference.getKey(), newValue).apply(); + } + + public String getString(QKPreference preference) { + return mPrefs.getString(preference.getKey(), (String) preference.getDefaultValue()); + } + + public void setString(QKPreference preference, String newValue) { + mPrefs.edit().putString(preference.getKey(), newValue).apply(); + } +} \ No newline at end of file diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 3bbb50a94..f5c2f2d80 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -139,10 +139,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O public static final String SIMPLE_PREFS = "pref_key_simple"; public static final String DONATE = "pref_key_donate"; public static final String DISMISSED_READ = "pref_key_dismiss_read"; - /** - * @deprecated - */ - public static final String APN_CHOOSER = "pref_key_apn_chooser"; public static final String MAX_MMS_ATTACHMENT_SIZE = "pref_mms_max_attachment_size"; public static final String QUICKREPLY = "pref_key_quickreply_enabled"; public static final String QUICKREPLY_TAP_DISMISS = "pref_key_quickreply_dismiss"; diff --git a/QKSMS/src/main/res/xml/settings_general.xml b/QKSMS/src/main/res/xml/settings_general.xml index 166af425b..8038ad446 100644 --- a/QKSMS/src/main/res/xml/settings_general.xml +++ b/QKSMS/src/main/res/xml/settings_general.xml @@ -80,6 +80,7 @@ android:widgetLayout="@layout/view_switch" /> Date: Wed, 23 Dec 2015 02:35:36 -0500 Subject: [PATCH 03/49] Remove code for secondary menu --- .../ui/view/slidingmenu/CustomViewBehind.java | 34 ------ .../ui/view/slidingmenu/SlidingMenu.java | 112 +----------------- 2 files changed, 3 insertions(+), 143 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java index 18ba322f0..8775f9e56 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java @@ -75,22 +75,6 @@ public View getContent() { return mContent; } - /** - * Sets the secondary (right) menu for use when setMode is called with SlidingMenu.LEFT_RIGHT. - * - * @param v the right menu - */ - public void setSecondaryContent(View v) { - if (mSecondaryContent != null) - removeView(mSecondaryContent); - mSecondaryContent = v; - addView(mSecondaryContent); - } - - public View getSecondaryContent() { - return mSecondaryContent; - } - public void setChildrenEnabled(boolean enabled) { mChildrenEnabled = enabled; } @@ -128,8 +112,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int height = b - t; mContent.layout(0, 0, width - mWidthOffset, height); - if (mSecondaryContent != null) - mSecondaryContent.layout(0, 0, width - mWidthOffset, height); } @Override @@ -140,8 +122,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width - mWidthOffset); final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height); mContent.measure(contentWidth, contentHeight); - if (mSecondaryContent != null) - mSecondaryContent.measure(contentWidth, contentHeight); } /** @@ -152,7 +132,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { private final Paint mFadePaint = new Paint(); private float mScrollScale; private Drawable mShadowDrawable; - private Drawable mSecondaryShadowDrawable; private int mShadowWidth; private float mFadeDegree; @@ -160,8 +139,6 @@ public void setMode(int mode) { if (mode == SlidingMenu.LEFT || mode == SlidingMenu.RIGHT) { if (mContent != null) mContent.setVisibility(View.VISIBLE); - if (mSecondaryContent != null) - mSecondaryContent.setVisibility(View.INVISIBLE); } mMode = mode; } @@ -183,11 +160,6 @@ public void setShadowDrawable(Drawable shadow) { invalidate(); } - public void setSecondaryShadowDrawable(Drawable shadow) { - mSecondaryShadowDrawable = shadow; - invalidate(); - } - public void setShadowWidth(int width) { mShadowWidth = width; invalidate(); @@ -225,7 +197,6 @@ public void scrollBehindTo(View content, int x, int y) { (x - getBehindWidth()) * mScrollScale), y); } else if (mMode == SlidingMenu.LEFT_RIGHT) { mContent.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE); - mSecondaryContent.setVisibility(x <= content.getLeft() ? View.INVISIBLE : View.VISIBLE); vis = x == 0 ? View.INVISIBLE : View.VISIBLE; if (x <= content.getLeft()) { scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y); @@ -355,11 +326,6 @@ public void drawShadow(View content, Canvas canvas) { } else if (mMode == SlidingMenu.RIGHT) { left = content.getRight(); } else if (mMode == SlidingMenu.LEFT_RIGHT) { - if (mSecondaryShadowDrawable != null) { - left = content.getRight(); - mSecondaryShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); - mSecondaryShadowDrawable.draw(canvas); - } left = content.getLeft() - mShadowWidth; } mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java index c3e523fc0..1d2695ef6 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java @@ -78,8 +78,6 @@ public class SlidingMenu extends RelativeLayout { private OnOpenListener mOpenListener; private OnOpenedListener mOpenedListener; - private OnOpenListener mSecondaryOpenListener; - private OnOpenedListener mSecondaryOpenedListener; private OnCloseListener mCloseListener; private OnClosedListener mClosedListener; @@ -223,7 +221,6 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { mViewAbove.setOnPageChangeListener(new OnPageChangeListener() { public static final int POSITION_OPEN = 0; public static final int POSITION_CLOSE = 1; - public static final int POSITION_SECONDARY_OPEN = 2; public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -238,10 +235,6 @@ public void onPageSelected(int position, boolean anim) { mCloseListener.onClose(); } else if (position == POSITION_CLOSE && mClosedListener != null) { mClosedListener.onClosed(); - } else if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenListener != null && anim) { - mSecondaryOpenListener.onOpen(); - } else if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenedListener != null) { - mSecondaryOpenedListener.onOpened(); } } }); @@ -411,35 +404,6 @@ public View getMenu() { return mViewBehind.getContent(); } - /** - * Set the secondary behind view (right menu) content from a layout resource. The resource will be inflated, adding all top-level views - * to the behind view. - * - * @param res the new content - */ - public void setSecondaryMenu(int res) { - setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null)); - } - - /** - * Set the secondary behind view (right menu) content to the given View. - * - * @param view The desired content to display. - */ - public void setSecondaryMenu(View v) { - mViewBehind.setSecondaryContent(v); - // mViewBehind.invalidate(); - } - - /** - * Retrieves the current secondary menu (right). - * - * @return the current menu - */ - public View getSecondaryMenu() { - return mViewBehind.getSecondaryContent(); - } - /** * Sets the sliding enabled. @@ -515,24 +479,6 @@ public void showMenu(boolean animate) { mViewAbove.setCurrentItem(0, animate); } - /** - * Opens the menu and shows the secondary menu view. Will default to the regular menu - * if there is only one. - */ - public void showSecondaryMenu() { - showSecondaryMenu(true); - } - - /** - * Opens the menu and shows the secondary (right) menu view. Will default to the regular menu - * if there is only one. - * - * @param animate true to animate the transition, false to ignore animation - */ - public void showSecondaryMenu(boolean animate) { - mViewAbove.setCurrentItem(2, animate); - } - /** * Closes the menu and shows the above view. */ @@ -578,15 +524,6 @@ public boolean isMenuShowing() { return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; } - /** - * Checks if is the behind view showing. - * - * @return Whether or not the behind view is showing - */ - public boolean isSecondaryMenuShowing() { - return mViewAbove.getCurrentItem() == 2; - } - /** * Gets the behind offset. * @@ -781,24 +718,6 @@ public void setShadowDrawable(Drawable d) { mViewBehind.setShadowDrawable(d); } - /** - * Sets the secondary (right) shadow drawable. - * - * @param resId the resource ID of the new shadow drawable - */ - public void setSecondaryShadowDrawable(int resId) { - setSecondaryShadowDrawable(ContextCompat.getDrawable(getContext(), resId)); - } - - /** - * Sets the secondary (right) shadow drawable. - * - * @param d the new shadow drawable - */ - public void setSecondaryShadowDrawable(Drawable d) { - mViewBehind.setSecondaryShadowDrawable(d); - } - /** * Sets the shadow width. * @@ -908,26 +827,6 @@ public void setOnOpenListener(OnOpenListener listener) { } - /** - * Sets the OnOpenListener for secondary menu {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the secondary SlidingMenu is opened - * - * @param listener the new OnOpenListener - */ - - public void setSecondaryOnOpenListener(OnOpenListener listener) { - mSecondaryOpenListener = listener; - } - - /** - * Sets the OnOpenedListener for the secondary menu. {@link OnOpenedListener#onOpened() OnOpenedListener.onOpened()} will be called after the secondary SlidingMenu is opened - * - * @param listener the new OnOpenedListener - */ - public void setSecondaryOnOpenedListener(OnOpenedListener listener) { - mSecondaryOpenedListener = listener; - mViewAbove.setOnOpenedListener(listener); - } - /** * Sets the OnCloseListener. {@link OnCloseListener#onClose() OnCloseListener.onClose()} will be called when any one of the SlidingMenu is closed * @@ -1041,14 +940,9 @@ public void manageLayers(float percentOpen) { final int layerType = layer ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE; if (layerType != getContent().getLayerType()) { - getHandler().post(new Runnable() { - public void run() { - getContent().setLayerType(layerType, null); - getMenu().setLayerType(layerType, null); - if (getSecondaryMenu() != null) { - getSecondaryMenu().setLayerType(layerType, null); - } - } + getHandler().post(() -> { + getContent().setLayerType(layerType, null); + getMenu().setLayerType(layerType, null); }); } } From 1f6d320b676c69b94ffc6bfd5545d7fcc7eab760 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Wed, 23 Dec 2015 05:21:06 -0500 Subject: [PATCH 04/49] Stripped out a lot of unneeded code from SlidingMenu --- .../java/com/moez/QKSMS/ui/MainActivity.java | 37 +- .../ui/view/slidingmenu/CustomViewAbove.java | 183 +----- .../ui/view/slidingmenu/CustomViewBehind.java | 287 +-------- .../ui/view/slidingmenu/SlidingMenu.java | 567 +----------------- QKSMS/src/main/res/values/attrs.xml | 28 - 5 files changed, 50 insertions(+), 1052 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index f103af369..c6f2081c8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -110,7 +110,15 @@ public void onCreate(Bundle savedInstanceState) { setTitle(R.string.title_conversation_list); mSlidingMenu = (SlidingMenu) findViewById(R.id.sliding_menu); - setupSlidingMenu(); + setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false)); + mSlidingMenu.setOnOpenListener(this); + mSlidingMenu.setOnCloseListener(this); + mSlidingMenu.setOnOpenedListener(this); + mSlidingMenu.setOnClosedListener(this); + mSlidingMenu.setContent(); + mSlidingMenu.setMenu(); + mSlidingMenu.showContent(false); + mSlidingMenu.showMenu(false); setupFragments(savedInstanceState); onNewIntent(getIntent()); @@ -219,30 +227,10 @@ private void launchWelcomeActivity() { startActivityForResult(welcomeIntent, WelcomeActivity.WELCOME_REQUEST_CODE); } - public SlidingMenu getSlidingMenu() { - return mSlidingMenu; - } - public void showMenu() { mSlidingMenu.showMenu(); } - private void setupSlidingMenu() { - setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false)); - mSlidingMenu.setBehindScrollScale(0.5f); - mSlidingMenu.setFadeDegree(0.5f); - mSlidingMenu.setOnOpenListener(this); - mSlidingMenu.setOnCloseListener(this); - mSlidingMenu.setOnOpenedListener(this); - mSlidingMenu.setOnClosedListener(this); - mSlidingMenu.setShadowDrawable(R.drawable.shadow_slidingmenu); - mSlidingMenu.setShadowWidthRes(R.dimen.shadow_width); - mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); - mSlidingMenu.setContent(R.layout.content_frame); - mSlidingMenu.setMenu(R.layout.menu_frame); - mSlidingMenu.showMenu(false); - } - /** * Configured the sliding menu view to peek the content or not. * @@ -250,11 +238,8 @@ private void setupSlidingMenu() { */ public void setSlidingTabEnabled(boolean slidingTabEnabled) { if (slidingTabEnabled) { - mSlidingMenu.setShadowDrawable(R.drawable.shadow_slidingmenu); - mSlidingMenu.setShadowWidth(Units.dpToPx(this, 8)); mSlidingMenu.setBehindOffset(Units.dpToPx(this, 48)); } else { - mSlidingMenu.setShadowWidth(0); mSlidingMenu.setBehindOffset(0); } } @@ -275,10 +260,6 @@ public boolean onPrepareOptionsMenu(Menu menu) { return super.onPrepareOptionsMenu(menu); } - public Fragment getConversationList() { - return mConversationList; - } - public Fragment getContent() { return (Fragment) mContent; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java index 82b2a8829..66ef5beed 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java @@ -2,12 +2,10 @@ import android.content.Context; import android.graphics.Canvas; -import android.graphics.Rect; import android.os.Build; import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.VelocityTrackerCompat; -import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewConfigurationCompat; import android.util.AttributeSet; import android.util.FloatMath; @@ -23,9 +21,6 @@ import android.view.animation.Interpolator; import android.widget.Scroller; -import java.util.ArrayList; -import java.util.List; - public class CustomViewAbove extends ViewGroup { private static final String TAG = "CustomViewAbove"; @@ -36,13 +31,7 @@ public class CustomViewAbove extends ViewGroup { private static final int MAX_SETTLE_DURATION = 350; // ms private static final int MIN_DISTANCE_FOR_FLING = 25; // dips - private static final Interpolator sInterpolator = new Interpolator() { - // See [1] for explanation for the 0.63 * t. - // http://www.wolframalpha.com/input/?i=graph+1%2B%28t-1%29%5E5%2C+1%2B%28t*0.63-1%29%5E5+from+t+%3D+0+to+1 - public float getInterpolation(float t) { - return (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f; - } - }; + private static final Interpolator sInterpolator = t -> (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f; private View mContent; @@ -82,21 +71,13 @@ public float getInterpolation(float t) { private int mFlingDistance; private CustomViewBehind mViewBehind; - // private int mMode; - private boolean mEnabled = true; private OnPageChangeListener mOnPageChangeListener; private OnPageChangeListener mInternalPageChangeListener; - // private OnCloseListener mCloseListener; - // private OnOpenListener mOpenListener; private SlidingMenu.OnClosedListener mClosedListener; private SlidingMenu.OnOpenedListener mOpenedListener; - private List mIgnoredViews = new ArrayList<>(); - - // private int mScrollState = SCROLL_STATE_IDLE; - /** * Callback interface for responding to changing state of the selected page. */ @@ -111,7 +92,7 @@ public interface OnPageChangeListener { * @param positionOffset Value from [0, 1) indicating the offset from the page at position. * @param positionOffsetPixels Value in pixels indicating the offset from position. */ - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); + void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); /** * This method will be invoked when a new page becomes selected. Animation is not @@ -119,7 +100,7 @@ public interface OnPageChangeListener { * * @param position Position index of the new selected page. */ - public void onPageSelected(int position, boolean anim); + void onPageSelected(int position, boolean anim); } @@ -138,10 +119,6 @@ public void onPageSelected(int position, boolean anim) { // This space for rent } - public void onPageScrollStateChanged(int state) { - // This space for rent - } - } public CustomViewAbove(Context context) { @@ -227,8 +204,7 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int setCurrentItemInternal(item, smoothScroll, always, velocity, false); } - void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity, - boolean notify) { + void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity, boolean notify) { if (!always && mCurItem == item) { setScrollingCacheEnabled(false); @@ -275,15 +251,6 @@ public void setOnPageChangeListener(OnPageChangeListener listener) { mOnPageChangeListener = listener; } - /* - public void setOnOpenListener(OnOpenListener l) { - mOpenListener = l; - } - - public void setOnCloseListener(OnCloseListener l) { - mCloseListener = l; - } - */ public void setOnOpenedListener(SlidingMenu.OnOpenedListener l) { mOpenedListener = l; } @@ -304,20 +271,6 @@ OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener return oldListener; } - public void addIgnoredView(View v) { - if (!mIgnoredViews.contains(v)) { - mIgnoredViews.add(v); - } - } - - public void removeIgnoredView(View v) { - mIgnoredViews.remove(v); - } - - public void clearIgnoredViews() { - mIgnoredViews.clear(); - } - // We want the duration of the page snap animation to be influenced by the distance that // the screen has to travel, however, we don't want this duration to be effected in a // purely linear fashion. Instead, we use this method to moderate the effect that the distance @@ -325,7 +278,7 @@ public void clearIgnoredViews() { float distanceInfluenceForSnapDuration(float f) { f -= 0.5f; // center the values about 0. f *= 0.3f * Math.PI / 2.0f; - return (float) FloatMath.sin(f); + return FloatMath.sin(f); } public int getDestScrollX(int page) { @@ -347,23 +300,10 @@ private int getRightBound() { return mViewBehind.getAbsRightBound(mContent); } - public int getContentLeft() { - return mContent.getLeft() + mContent.getPaddingLeft(); - } - public boolean isMenuOpen() { return mCurItem == 0 || mCurItem == 2; } - private boolean isInIgnoredView(MotionEvent ev) { - Rect rect = new Rect(); - for (View v : mIgnoredViews) { - v.getHitRect(rect); - if (rect.contains((int) ev.getX(), (int) ev.getY())) return true; - } - return false; - } - public int getBehindWidth() { if (mViewBehind == null) { return 0; @@ -372,35 +312,6 @@ public int getBehindWidth() { } } - public int getChildWidth(int i) { - switch (i) { - case 0: - return getBehindWidth(); - case 1: - return mContent.getWidth(); - default: - return 0; - } - } - - public boolean isSlidingEnabled() { - return mEnabled; - } - - public void setSlidingEnabled(boolean b) { - mEnabled = b; - } - - /** - * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. - * - * @param x the number of pixels to scroll by on the X axis - * @param y the number of pixels to scroll by on the Y axis - */ - void smoothScrollTo(int x, int y) { - smoothScrollTo(x, y, 0); - } - /** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * @@ -444,8 +355,6 @@ void smoothScrollTo(int x, int y, int velocity) { if (velocity > 0) { duration = 4 * Math.round(1000 * Math.abs(distance / velocity)); } else { - final float pageDelta = (float) Math.abs(dx) / width; - duration = (int) ((pageDelta + 1) * 100); duration = MAX_SETTLE_DURATION; } duration = Math.min(duration, MAX_SETTLE_DURATION); @@ -487,8 +396,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { // Make sure scroll position is set correctly. if (w != oldw) { // [ChrisJ] - This fixes the onConfiguration change for orientation issue.. - // maybe worth having a look why the recomputeScroll pos is screwing - // up? + // maybe worth having a look why the recomputeScroll pos is screwing up? completeScroll(); scrollTo(getDestScrollX(mCurItem), getScrollY()); } @@ -501,13 +409,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { mContent.layout(0, 0, width, height); } - public void setAboveOffset(int i) { - // RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mContent.getLayoutParams()); - // params.setMargins(i, params.topMargin, params.rightMargin, params.bottomMargin); - mContent.setPadding(i, mContent.getPaddingTop(), - mContent.getPaddingRight(), mContent.getPaddingBottom()); - } - @Override public void computeScroll() { @@ -587,35 +488,12 @@ private void completeScroll() { mScrolling = false; } - protected int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN; - - public void setTouchMode(int i) { - mTouchMode = i; - } - - public int getTouchMode() { - return mTouchMode; - } - private boolean thisTouchAllowed(MotionEvent ev) { - int x = (int) (ev.getX() + mScrollX); - if (isMenuOpen()) { - return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x); - } else { - switch (mTouchMode) { - case SlidingMenu.TOUCHMODE_FULLSCREEN: - return !isInIgnoredView(ev); - case SlidingMenu.TOUCHMODE_NONE: - return false; - case SlidingMenu.TOUCHMODE_MARGIN: - return mViewBehind.marginTouchAllowed(mContent, x); - } - } - return false; + return !isMenuOpen(); } private boolean thisSlideAllowed(float dx) { - boolean allowed = false; + boolean allowed; if (isMenuOpen()) { allowed = mViewBehind.menuOpenSlideAllowed(dx); } else { @@ -641,9 +519,6 @@ private int getPointerIndex(MotionEvent ev, int id) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!mEnabled) - return false; - final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (DEBUG) @@ -695,15 +570,9 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { @Override public boolean onTouchEvent(MotionEvent ev) { - if (!mEnabled) - return false; - if (!mIsBeingDragged && !thisTouchAllowed(ev)) return false; - // if (!mIsBeingDragged && !mQuickReturn) - // return false; - final int action = ev.getAction(); if (mVelocityTracker == null) { @@ -841,7 +710,7 @@ private int determineTargetPage(float pageOffset, int velocity, int deltaX) { targetPage += 1; } } else { - targetPage = (int) Math.round(mCurItem + pageOffset); + targetPage = Math.round(mCurItem + pageOffset); } return targetPage; } @@ -855,8 +724,6 @@ protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); // Draw the margin drawable if needed. mViewBehind.drawShadow(mContent, canvas); - mViewBehind.drawFade(mContent, canvas, getPercentOpen()); - mViewBehind.drawSelector(mContent, canvas, getPercentOpen()); } // variables for drawing @@ -910,38 +777,6 @@ private void setScrollingCacheEnabled(boolean enabled) { } } - /** - * Tests scrollability within child views of v given a delta of dx. - * - * @param v View to test for horizontal scrollability - * @param checkV Whether the view v passed should itself be checked for scrollability (true), - * or just its children (false). - * @param dx Delta scrolled in pixels - * @param x X coordinate of the active touch point - * @param y Y coordinate of the active touch point - * @return true if child views of v can be scrolled by delta of dx. - */ - protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { - if (v instanceof ViewGroup) { - final ViewGroup group = (ViewGroup) v; - final int scrollX = v.getScrollX(); - final int scrollY = v.getScrollY(); - final int count = group.getChildCount(); - // Count backwards - let topmost views consume scroll distance first. - for (int i = count - 1; i >= 0; i--) { - final View child = group.getChildAt(i); - if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && - y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && - canScroll(child, true, dx, x + scrollX - child.getLeft(), - y + scrollY - child.getTop())) { - return true; - } - } - } - - return checkV && ViewCompat.canScrollHorizontally(v, -dx); - } - @Override public boolean dispatchKeyEvent(KeyEvent event) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java index 8775f9e56..8e260044b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java @@ -1,32 +1,19 @@ package com.moez.QKSMS.ui.view.slidingmenu; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.util.AttributeSet; -import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import com.moez.QKSMS.R; +import com.moez.QKSMS.common.utils.Units; public class CustomViewBehind extends ViewGroup { - private static final String TAG = "CustomViewBehind"; - private static final int MARGIN_THRESHOLD = 48; // dips - private int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN; - - private CustomViewAbove mViewAbove; - private View mContent; - private View mSecondaryContent; - private int mMarginThreshold; private int mWidthOffset; - private SlidingMenu.CanvasTransformer mTransformer; private boolean mChildrenEnabled; public CustomViewBehind(Context context) { @@ -35,16 +22,7 @@ public CustomViewBehind(Context context) { public CustomViewBehind(Context context, AttributeSet attrs) { super(context, attrs); - mMarginThreshold = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, - MARGIN_THRESHOLD, getResources().getDisplayMetrics()); - } - - public void setCustomViewAbove(CustomViewAbove customViewAbove) { - mViewAbove = customViewAbove; - } - - public void setCanvasTransformer(SlidingMenu.CanvasTransformer t) { - mTransformer = t; + mShadowWidth = Units.dpToPx(getContext(), 8); } public void setWidthOffset(int i) { @@ -52,21 +30,14 @@ public void setWidthOffset(int i) { requestLayout(); } - public void setMarginThreshold(int marginThreshold) { - mMarginThreshold = marginThreshold; - } - - public int getMarginThreshold() { - return mMarginThreshold; - } - public int getBehindWidth() { return mContent.getWidth(); } public void setContent(View v) { - if (mContent != null) + if (mContent != null) { removeView(mContent); + } mContent = v; addView(mContent); } @@ -82,8 +53,6 @@ public void setChildrenEnabled(boolean enabled) { @Override public void scrollTo(int x, int y) { super.scrollTo(x, y); - if (mTransformer != null) - invalidate(); } @Override @@ -98,13 +67,7 @@ public boolean onTouchEvent(MotionEvent e) { @Override protected void dispatchDraw(Canvas canvas) { - if (mTransformer != null) { - canvas.save(); - mTransformer.transformCanvas(canvas, mViewAbove.getPercentOpen()); - super.dispatchDraw(canvas); - canvas.restore(); - } else - super.dispatchDraw(canvas); + super.dispatchDraw(canvas); } @Override @@ -124,63 +87,23 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mContent.measure(contentWidth, contentHeight); } - /** - * Determines the location of the menu(s): left only, right only, or on both left and right. - */ - private int mMode; - private boolean mFadeEnabled; - private final Paint mFadePaint = new Paint(); private float mScrollScale; private Drawable mShadowDrawable; private int mShadowWidth; - private float mFadeDegree; - - public void setMode(int mode) { - if (mode == SlidingMenu.LEFT || mode == SlidingMenu.RIGHT) { - if (mContent != null) - mContent.setVisibility(View.VISIBLE); - } - mMode = mode; - } - - public int getMode() { - return mMode; - } public void setScrollScale(float scrollScale) { mScrollScale = scrollScale; } - public float getScrollScale() { - return mScrollScale; - } - public void setShadowDrawable(Drawable shadow) { mShadowDrawable = shadow; invalidate(); } - public void setShadowWidth(int width) { - mShadowWidth = width; - invalidate(); - } - - public void setFadeEnabled(boolean b) { - mFadeEnabled = b; - } - - public void setFadeDegree(float degree) { - if (degree > 1.0f || degree < 0.0f) - throw new IllegalStateException("The BehindFadeDegree must be between 0.0f and 1.0f"); - mFadeDegree = degree; - } - public int getMenuPage(int page) { page = (page > 1) ? 2 : ((page < 1) ? 0 : page); - if (mMode == SlidingMenu.LEFT && page > 1) { + if (page > 1) { return 0; - } else if (mMode == SlidingMenu.RIGHT && page < 1) { - return 2; } else { return page; } @@ -188,96 +111,27 @@ public int getMenuPage(int page) { public void scrollBehindTo(View content, int x, int y) { int vis = View.VISIBLE; - if (mMode == SlidingMenu.LEFT) { - if (x >= content.getLeft()) vis = View.INVISIBLE; - scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y); - } else if (mMode == SlidingMenu.RIGHT) { - if (x <= content.getLeft()) vis = View.INVISIBLE; - scrollTo((int) (getBehindWidth() - getWidth() + - (x - getBehindWidth()) * mScrollScale), y); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - mContent.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE); - vis = x == 0 ? View.INVISIBLE : View.VISIBLE; - if (x <= content.getLeft()) { - scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y); - } else { - scrollTo((int) (getBehindWidth() - getWidth() + - (x - getBehindWidth()) * mScrollScale), y); - } - } + if (x >= content.getLeft()) vis = View.INVISIBLE; + scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y); setVisibility(vis); } public int getMenuLeft(View content, int page) { - if (mMode == SlidingMenu.LEFT) { - switch (page) { - case 0: - return content.getLeft() - getBehindWidth(); - case 2: - return content.getLeft(); - } - } else if (mMode == SlidingMenu.RIGHT) { - switch (page) { - case 0: - return content.getLeft(); - case 2: - return content.getLeft() + getBehindWidth(); - } - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - switch (page) { - case 0: - return content.getLeft() - getBehindWidth(); - case 2: - return content.getLeft() + getBehindWidth(); - } + switch (page) { + case 0: + return content.getLeft() - getBehindWidth(); + case 2: + return content.getLeft(); } return content.getLeft(); } public int getAbsLeftBound(View content) { - if (mMode == SlidingMenu.LEFT || mMode == SlidingMenu.LEFT_RIGHT) { - return content.getLeft() - getBehindWidth(); - } else if (mMode == SlidingMenu.RIGHT) { - return content.getLeft(); - } - return 0; + return content.getLeft() - getBehindWidth(); } public int getAbsRightBound(View content) { - if (mMode == SlidingMenu.LEFT) { - return content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) { - return content.getLeft() + getBehindWidth(); - } - return 0; - } - - public boolean marginTouchAllowed(View content, int x) { - int left = content.getLeft(); - int right = content.getRight(); - if (mMode == SlidingMenu.LEFT) { - return (x >= left && x <= mMarginThreshold + left); - } else if (mMode == SlidingMenu.RIGHT) { - return (x <= right && x >= right - mMarginThreshold); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return (x >= left && x <= mMarginThreshold + left) || - (x <= right && x >= right - mMarginThreshold); - } - return false; - } - - public void setTouchMode(int i) { - mTouchMode = i; - } - - public boolean menuOpenTouchAllowed(View content, int currPage, float x) { - switch (mTouchMode) { - case SlidingMenu.TOUCHMODE_FULLSCREEN: - return true; - case SlidingMenu.TOUCHMODE_MARGIN: - return menuTouchInQuickReturn(content, currPage, x); - } - return false; + return content.getLeft(); } /** @@ -288,125 +142,22 @@ public boolean menuOpenTouchAllowed(View content, int currPage, float x) { * @param x the position of the touch */ public boolean menuTouchInQuickReturn(View content, int currPage, float x) { - if (mMode == SlidingMenu.LEFT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 0)) { - return x >= content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 2)) { - return x <= content.getRight(); - } - return false; + return x >= content.getLeft(); } public boolean menuClosedSlideAllowed(float dx) { - if (mMode == SlidingMenu.LEFT) { - return dx > 0; - } else if (mMode == SlidingMenu.RIGHT) { - return dx < 0; - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return true; - } - return false; + return dx > 0; } public boolean menuOpenSlideAllowed(float dx) { - if (mMode == SlidingMenu.LEFT) { - return dx < 0; - } else if (mMode == SlidingMenu.RIGHT) { - return dx > 0; - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return true; - } - return false; + return dx < 0; } public void drawShadow(View content, Canvas canvas) { if (mShadowDrawable == null || mShadowWidth <= 0) return; - int left = 0; - if (mMode == SlidingMenu.LEFT) { - left = content.getLeft() - mShadowWidth; - } else if (mMode == SlidingMenu.RIGHT) { - left = content.getRight(); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - left = content.getLeft() - mShadowWidth; - } + int left = content.getLeft() - mShadowWidth; mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); mShadowDrawable.draw(canvas); } - public void drawFade(View content, Canvas canvas, float openPercent) { - if (!mFadeEnabled) return; - final int alpha = (int) (mFadeDegree * 255 * Math.abs(1 - openPercent)); - mFadePaint.setColor(Color.argb(alpha, 0, 0, 0)); - int left = 0; - int right = 0; - if (mMode == SlidingMenu.LEFT) { - left = content.getLeft() - getBehindWidth(); - right = content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT) { - left = content.getRight(); - right = content.getRight() + getBehindWidth(); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - left = content.getLeft() - getBehindWidth(); - right = content.getLeft(); - canvas.drawRect(left, 0, right, getHeight(), mFadePaint); - left = content.getRight(); - right = content.getRight() + getBehindWidth(); - } - canvas.drawRect(left, 0, right, getHeight(), mFadePaint); - } - - private boolean mSelectorEnabled = true; - private Bitmap mSelectorDrawable; - private View mSelectedView; - - public void drawSelector(View content, Canvas canvas, float openPercent) { - if (!mSelectorEnabled) return; - if (mSelectorDrawable != null && mSelectedView != null) { - String tag = (String) mSelectedView.getTag(R.id.selected_view); - if (tag.equals(TAG + "SelectedView")) { - canvas.save(); - int left, right, offset; - offset = (int) (mSelectorDrawable.getWidth() * openPercent); - if (mMode == SlidingMenu.LEFT) { - right = content.getLeft(); - left = right - offset; - canvas.clipRect(left, 0, right, getHeight()); - canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null); - } else if (mMode == SlidingMenu.RIGHT) { - left = content.getRight(); - right = left + offset; - canvas.clipRect(left, 0, right, getHeight()); - canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null); - } - canvas.restore(); - } - } - } - - public void setSelectorEnabled(boolean b) { - mSelectorEnabled = b; - } - - public void setSelectedView(View v) { - if (mSelectedView != null) { - mSelectedView.setTag(R.id.selected_view, null); - mSelectedView = null; - } - if (v != null && v.getParent() != null) { - mSelectedView = v; - mSelectedView.setTag(R.id.selected_view, TAG + "SelectedView"); - invalidate(); - } - } - - private int getSelectorTop() { - int y = mSelectedView.getTop(); - y += (mSelectedView.getHeight() - mSelectorDrawable.getHeight()) / 2; - return y; - } - - public void setSelectorBitmap(Bitmap b) { - mSelectorDrawable = b; - refreshDrawableState(); - } - } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java index 1d2695ef6..eb4a8230d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java @@ -1,79 +1,29 @@ package com.moez.QKSMS.ui.view.slidingmenu; import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.app.Activity; import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Point; import android.graphics.Rect; -import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.support.v4.content.ContextCompat; import android.util.AttributeSet; -import android.view.Display; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.FrameLayout; import android.widget.RelativeLayout; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener; -import java.lang.reflect.Method; - /** * Stripped down version of Jeremy Feinstein's SlidingMenu library */ public class SlidingMenu extends RelativeLayout { - private static final String TAG = "SlidingMenu"; - public static final int SLIDING_WINDOW = 0; - public static final int SLIDING_CONTENT = 1; private boolean mActionbarOverlay = false; - /** - * Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe - * gesture on the screen's margin - */ - public static final int TOUCHMODE_MARGIN = 0; - - /** - * Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe - * gesture anywhere on the screen - */ - public static final int TOUCHMODE_FULLSCREEN = 1; - - /** - * Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe - * gesture - */ - public static final int TOUCHMODE_NONE = 2; - - /** - * Constant value for use with setMode(). Puts the menu to the left of the content. - */ - public static final int LEFT = 0; - - /** - * Constant value for use with setMode(). Puts the menu to the right of the content. - */ - public static final int RIGHT = 1; - - /** - * Constant value for use with setMode(). Puts menus to the left and right of the content. - */ - public static final int LEFT_RIGHT = 2; - private CustomViewAbove mViewAbove; - private CustomViewBehind mViewBehind; private OnOpenListener mOpenListener; @@ -95,7 +45,7 @@ public interface OnOpenListener { /** * On open. */ - public void onOpen(); + void onOpen(); } /** @@ -114,7 +64,7 @@ public interface OnOpenedListener { /** * On opened. */ - public void onOpened(); + void onOpened(); } /** @@ -133,7 +83,7 @@ public interface OnCloseListener { /** * On close. */ - public void onClose(); + void onClose(); } /** @@ -152,21 +102,7 @@ public interface OnClosedListener { /** * On closed. */ - public void onClosed(); - } - - /** - * The Interface CanvasTransformer. - */ - public interface CanvasTransformer { - - /** - * Transform canvas. - * - * @param canvas the canvas - * @param percentOpen the percent open - */ - public void transformCanvas(Canvas canvas, float percentOpen); + void onClosed(); } /** @@ -178,17 +114,6 @@ public SlidingMenu(Context context) { this(context, null); } - /** - * Instantiates a new SlidingMenu and attach to Activity. - * - * @param activity the activity to attach slidingmenu - * @param slideStyle the slidingmenu style - */ - public SlidingMenu(Activity activity, int slideStyle) { - this(activity, null); - this.attachToActivity(activity, slideStyle); - } - /** * Instantiates a new SlidingMenu. * @@ -215,15 +140,14 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mViewAbove = new CustomViewAbove(context); addView(mViewAbove, aboveParams); - // register the CustomViewBehind with the CustomViewAbove + mViewBehind.setScrollScale(0.5f); + mViewBehind.setShadowDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shadow_slidingmenu)); mViewAbove.setCustomViewBehind(mViewBehind); - mViewBehind.setCustomViewAbove(mViewAbove); mViewAbove.setOnPageChangeListener(new OnPageChangeListener() { public static final int POSITION_OPEN = 0; public static final int POSITION_CLOSE = 1; - public void onPageScrolled(int position, float positionOffset, - int positionOffsetPixels) { + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } public void onPageSelected(int position, boolean anim) { @@ -239,112 +163,6 @@ public void onPageSelected(int position, boolean anim) { } }); - // now style everything! - TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu); - // set the above and behind views if defined in xml - int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT); - setMode(mode); - int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1); - if (viewAbove != -1) { - setContent(viewAbove); - } else { - setContent(new FrameLayout(context)); - } - int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1); - if (viewBehind != -1) { - setMenu(viewBehind); - } else { - setMenu(new FrameLayout(context)); - } - int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN); - setTouchModeAbove(touchModeAbove); - int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN); - setTouchModeBehind(touchModeBehind); - - int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1); - int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1); - if (offsetBehind != -1 && widthBehind != -1) - throw new IllegalStateException("Cannot set both behindOffset and behindWidth for a SlidingMenu"); - else if (offsetBehind != -1) - setBehindOffset(offsetBehind); - else if (widthBehind != -1) - setBehindWidth(widthBehind); - else - setBehindOffset(0); - float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f); - setBehindScrollScale(scrollOffsetBehind); - int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1); - if (shadowRes != -1) { - setShadowDrawable(shadowRes); - } - int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0); - setShadowWidth(shadowWidth); - boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true); - setFadeEnabled(fadeEnabled); - float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f); - setFadeDegree(fadeDeg); - boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false); - setSelectorEnabled(selectorEnabled); - int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, -1); - if (selectorRes != -1) - setSelectorDrawable(selectorRes); - ta.recycle(); - } - - /** - * Attaches the SlidingMenu to an entire Activity - * - * @param activity the Activity - * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW - */ - public void attachToActivity(Activity activity, int slideStyle) { - attachToActivity(activity, slideStyle, false); - } - - /** - * Attaches the SlidingMenu to an entire Activity - * - * @param activity the Activity - * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW - * @param actionbarOverlay whether or not the ActionBar is overlaid - */ - public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) { - if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT) - throw new IllegalArgumentException("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT"); - - if (getParent() != null) - throw new IllegalStateException("This SlidingMenu appears to already be attached"); - - // get the window background - TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowBackground}); - int background = a.getResourceId(0, 0); - a.recycle(); - - switch (slideStyle) { - case SLIDING_WINDOW: - mActionbarOverlay = false; - ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); - ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); - // save ActionBar themes that have transparent assets - decorChild.setBackgroundResource(background); - decor.removeView(decorChild); - decor.addView(this); - setContent(decorChild); - break; - case SLIDING_CONTENT: - mActionbarOverlay = actionbarOverlay; - // take the above view out of - ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content); - contentParent.addView(LayoutInflater.from(getContext()).inflate(R.layout.toolbar, contentParent, false)); - View content = contentParent.getChildAt(0); - contentParent.removeView(content); - contentParent.addView(this); - setContent(content); - // save people from having transparent backgrounds - if (content.getBackground() == null) - content.setBackgroundResource(background); - break; - } } /** @@ -353,18 +171,8 @@ public void attachToActivity(Activity activity, int slideStyle, boolean actionba * * @param res the new content */ - public void setContent(int res) { - setContent(LayoutInflater.from(getContext()).inflate(res, null)); - } - - /** - * Set the above view content to the given View. - * - * @param view The desired content to display. - */ - public void setContent(View view) { - mViewAbove.setContent(view); - showContent(); + public void setContent() { + mViewAbove.setContent(LayoutInflater.from(getContext()).inflate(R.layout.content_frame, null)); } /** @@ -382,17 +190,8 @@ public View getContent() { * * @param res the new content */ - public void setMenu(int res) { - setMenu(LayoutInflater.from(getContext()).inflate(res, null)); - } - - /** - * Set the behind view (menu) content to the given View. - * - * @param view The desired content to display. - */ - public void setMenu(View v) { - mViewBehind.setContent(v); + public void setMenu() { + mViewBehind.setContent(LayoutInflater.from(getContext()).inflate(R.layout.menu_frame, null)); } /** @@ -404,65 +203,6 @@ public View getMenu() { return mViewBehind.getContent(); } - - /** - * Sets the sliding enabled. - * - * @param b true to enable sliding, false to disable it. - */ - public void setSlidingEnabled(boolean b) { - mViewAbove.setSlidingEnabled(b); - } - - /** - * Checks if is sliding enabled. - * - * @return true, if is sliding enabled - */ - public boolean isSlidingEnabled() { - return mViewAbove.isSlidingEnabled(); - } - - /** - * Sets which side the SlidingMenu should appear on. - * - * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT - */ - public void setMode(int mode) { - if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) { - throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT"); - } - mViewBehind.setMode(mode); - } - - /** - * Returns the current side that the SlidingMenu is on. - * - * @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT - */ - public int getMode() { - return mViewBehind.getMode(); - } - - /** - * Sets whether or not the SlidingMenu is in static mode (i.e. nothing is moving and everything is showing) - * - * @param b true to set static mode, false to disable static mode. - */ - public void setStatic(boolean b) { - if (b) { - setSlidingEnabled(false); - mViewAbove.setCustomViewBehind(null); - mViewAbove.setCurrentItem(1); - // mViewBehind.setCurrentItem(0); - } else { - mViewAbove.setCurrentItem(1); - // mViewBehind.setCurrentItem(1); - mViewAbove.setCustomViewBehind(mViewBehind); - setSlidingEnabled(true); - } - } - /** * Opens the menu and shows the menu view. */ @@ -476,7 +216,7 @@ public void showMenu() { * @param animate true to animate the transition, false to ignore animation */ public void showMenu(boolean animate) { - mViewAbove.setCurrentItem(0, animate); + mViewAbove.setCurrentItem(0, animate, true); } /** @@ -524,15 +264,6 @@ public boolean isMenuShowing() { return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; } - /** - * Gets the behind offset. - * - * @return The margin on the right of the screen that the behind view scrolls to - */ - public int getBehindOffset() { - return ((LayoutParams) mViewBehind.getLayoutParams()).rightMargin; - } - /** * Sets the behind offset. * @@ -547,282 +278,12 @@ public void setBehindOffset(int i) { mViewBehind.setWidthOffset(i); } - /** - * Sets the behind offset. - * - * @param resID The dimension resource id to be set as the behind offset. - * The menu, when open, will leave this width margin on the right of the screen. - */ - public void setBehindOffsetRes(int resID) { - int i = (int) getContext().getResources().getDimension(resID); - setBehindOffset(i); - } - - /** - * Sets the above offset. - * - * @param i the new above offset, in pixels - */ - public void setAboveOffset(int i) { - mViewAbove.setAboveOffset(i); - } - - /** - * Sets the above offset. - * - * @param resID The dimension resource id to be set as the above offset. - */ - public void setAboveOffsetRes(int resID) { - int i = (int) getContext().getResources().getDimension(resID); - setAboveOffset(i); - } - - /** - * Sets the behind width. - * - * @param i The width the Sliding Menu will open to, in pixels - */ - @SuppressWarnings("deprecation") - public void setBehindWidth(int i) { - int width; - Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) - .getDefaultDisplay(); - try { - Class cls = Display.class; - Class[] parameterTypes = {Point.class}; - Point parameter = new Point(); - Method method = cls.getMethod("getSize", parameterTypes); - method.invoke(display, parameter); - width = parameter.x; - } catch (Exception e) { - width = display.getWidth(); - } - setBehindOffset(width - i); - } - - /** - * Sets the behind width. - * - * @param res The dimension resource id to be set as the behind width offset. - * The menu, when open, will open this wide. - */ - public void setBehindWidthRes(int res) { - int i = (int) getContext().getResources().getDimension(res); - setBehindWidth(i); - } - - /** - * Gets the behind scroll scale. - * - * @return The scale of the parallax scroll - */ - public float getBehindScrollScale() { - return mViewBehind.getScrollScale(); - } - - /** - * Gets the touch mode margin threshold - * - * @return the touch mode margin threshold - */ - public int getTouchmodeMarginThreshold() { - return mViewBehind.getMarginThreshold(); - } - - /** - * Set the touch mode margin threshold - * - * @param touchmodeMarginThreshold - */ - public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) { - mViewBehind.setMarginThreshold(touchmodeMarginThreshold); - } - - /** - * Sets the behind scroll scale. - * - * @param f The scale of the parallax scroll (i.e. 1.0f scrolls 1 pixel for every - * 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels) - */ - public void setBehindScrollScale(float f) { - if (f < 0 && f > 1) - throw new IllegalStateException("ScrollScale must be between 0 and 1"); - mViewBehind.setScrollScale(f); - } - - /** - * Sets the behind canvas transformer. - * - * @param t the new behind canvas transformer - */ - public void setBehindCanvasTransformer(CanvasTransformer t) { - mViewBehind.setCanvasTransformer(t); - } - - /** - * Gets the touch mode above. - * - * @return the touch mode above - */ - public int getTouchModeAbove() { - return mViewAbove.getTouchMode(); - } - - /** - * Controls whether the SlidingMenu can be opened with a swipe gesture. - * Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN}, - * or {@link #TOUCHMODE_NONE TOUCHMODE_NONE} - * - * @param i the new touch mode - */ - public void setTouchModeAbove(int i) { - if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN - && i != TOUCHMODE_NONE) { - throw new IllegalStateException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); - } - mViewAbove.setTouchMode(i); - } - - /** - * Controls whether the SlidingMenu can be opened with a swipe gesture. - * Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN}, - * or {@link #TOUCHMODE_NONE TOUCHMODE_NONE} - * - * @param i the new touch mode - */ - public void setTouchModeBehind(int i) { - if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN - && i != TOUCHMODE_NONE) { - throw new IllegalStateException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); - } - mViewBehind.setTouchMode(i); - } - - /** - * Sets the shadow drawable. - * - * @param resId the resource ID of the new shadow drawable - */ - public void setShadowDrawable(int resId) { - setShadowDrawable(ContextCompat.getDrawable(getContext(), resId)); - } - - /** - * Sets the shadow drawable. - * - * @param d the new shadow drawable - */ - public void setShadowDrawable(Drawable d) { - mViewBehind.setShadowDrawable(d); - } - - /** - * Sets the shadow width. - * - * @param resId The dimension resource id to be set as the shadow width. - */ - public void setShadowWidthRes(int resId) { - setShadowWidth((int) getResources().getDimension(resId)); - } - - /** - * Sets the shadow width. - * - * @param pixels the new shadow width, in pixels - */ - public void setShadowWidth(int pixels) { - mViewBehind.setShadowWidth(pixels); - } - - /** - * Enables or disables the SlidingMenu's fade in and out - * - * @param b true to enable fade, false to disable it - */ - public void setFadeEnabled(boolean b) { - mViewBehind.setFadeEnabled(b); - } - - /** - * Sets how much the SlidingMenu fades in and out. Fade must be enabled, see - * {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)} - * - * @param f the new fade degree, between 0.0f and 1.0f - */ - public void setFadeDegree(float f) { - mViewBehind.setFadeDegree(f); - } - - /** - * Enables or disables whether the selector is drawn - * - * @param b true to draw the selector, false to not draw the selector - */ - public void setSelectorEnabled(boolean b) { - mViewBehind.setSelectorEnabled(true); - } - - /** - * Sets the selected view. The selector will be drawn here - * - * @param v the new selected view - */ - public void setSelectedView(View v) { - mViewBehind.setSelectedView(v); - } - - /** - * Sets the selector drawable. - * - * @param res a resource ID for the selector drawable - */ - public void setSelectorDrawable(int res) { - mViewBehind.setSelectorBitmap(BitmapFactory.decodeResource(getResources(), res)); - } - - /** - * Sets the selector drawable. - * - * @param b the new selector bitmap - */ - public void setSelectorBitmap(Bitmap b) { - mViewBehind.setSelectorBitmap(b); - } - - /** - * Add a View ignored by the Touch Down event when mode is Fullscreen - * - * @param v a view to be ignored - */ - public void addIgnoredView(View v) { - mViewAbove.addIgnoredView(v); - } - - /** - * Remove a View ignored by the Touch Down event when mode is Fullscreen - * - * @param v a view not wanted to be ignored anymore - */ - public void removeIgnoredView(View v) { - mViewAbove.removeIgnoredView(v); - } - - /** - * Clear the list of Views ignored by the Touch Down event when mode is Fullscreen - */ - public void clearIgnoredViews() { - mViewAbove.clearIgnoredViews(); - } - /** * Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened * * @param listener the new OnOpenListener */ public void setOnOpenListener(OnOpenListener listener) { - //mViewAbove.setOnOpenListener(listener); mOpenListener = listener; } @@ -833,7 +294,6 @@ public void setOnOpenListener(OnOpenListener listener) { * @param listener the new setOnCloseListener */ public void setOnCloseListener(OnCloseListener listener) { - //mViewAbove.setOnCloseListener(listener); mCloseListener = listener; } @@ -932,7 +392,6 @@ protected boolean fitSystemWindows(Rect insets) { return true; } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void manageLayers(float percentOpen) { if (Build.VERSION.SDK_INT < 11) return; diff --git a/QKSMS/src/main/res/values/attrs.xml b/QKSMS/src/main/res/values/attrs.xml index 5af737fdb..5a63fd086 100644 --- a/QKSMS/src/main/res/values/attrs.xml +++ b/QKSMS/src/main/res/values/attrs.xml @@ -66,32 +66,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From cdd964c5d3e2e1065baf6e24a18fed20cdb0d8dd Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 13:56:40 -0500 Subject: [PATCH 05/49] Add ability to listen for updates to content fragment position --- .../com/moez/QKSMS/ui/ContentFragment.java | 8 + .../java/com/moez/QKSMS/ui/MainActivity.java | 14 +- .../QKSMS/ui/compose/ComposeFragment.java | 5 + .../ui/messagelist/MessageListFragment.java | 5 + .../moez/QKSMS/ui/search/SearchFragment.java | 5 + .../QKSMS/ui/settings/SettingsFragment.java | 5 + .../ui/view/slidingmenu/CustomViewAbove.java | 60 ++++---- .../ui/view/slidingmenu/CustomViewBehind.java | 11 +- .../ui/view/slidingmenu/SlidingMenu.java | 139 ++---------------- 9 files changed, 84 insertions(+), 168 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java index 3ca7aef1a..64ff6b9fa 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java @@ -32,6 +32,14 @@ public interface ContentFragment { */ void onContentClosed(); + /** + * Called multiple times as the content is opening or closing. Allows it to receive updates + * of the position. Currently used to animate to the new theme color + * + * @param percentOpen + */ + void onMenuChanging(float percentOpen); + /** * Allows the MainActivity to delegate setting of the Toolbar title and menu */ diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index c6f2081c8..6af99a338 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -60,8 +60,8 @@ import java.net.URLDecoder; import java.util.Collection; -public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListener, SlidingMenu.OnCloseListener, - SlidingMenu.OnOpenedListener, SlidingMenu.OnClosedListener, LiveView { + +public class MainActivity extends QKActivity implements LiveView, SlidingMenu.SlidingMenuListener { private final String TAG = "MainActivity"; @@ -111,10 +111,7 @@ public void onCreate(Bundle savedInstanceState) { mSlidingMenu = (SlidingMenu) findViewById(R.id.sliding_menu); setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false)); - mSlidingMenu.setOnOpenListener(this); - mSlidingMenu.setOnCloseListener(this); - mSlidingMenu.setOnOpenedListener(this); - mSlidingMenu.setOnClosedListener(this); + mSlidingMenu.setListener(this); mSlidingMenu.setContent(); mSlidingMenu.setMenu(); mSlidingMenu.showContent(false); @@ -604,6 +601,11 @@ public void onClosed() { if (mContent != null) mContent.onContentOpened(); } + @Override + public void onChanging(float percentOpen) { + if (mContent != null) mContent.onMenuChanging(percentOpen); + } + /** * Build and show the proper delete thread dialog. The UI is slightly different * depending on whether there are locked messages in the thread(s) and whether we're diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java index 5b5673148..527e1ec68 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java @@ -168,6 +168,11 @@ public void onContentClosing() { } } + @Override + public void onMenuChanging(float percentOpen) { + + } + @Override public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { inflater.inflate(R.menu.compose, menu); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 6b128d151..99f501cf7 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -773,6 +773,11 @@ public void onContentClosed() { } } + @Override + public void onMenuChanging(float percentOpen) { + Log.d(TAG, "onChanging: " + percentOpen); + } + @Override public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { inflater.inflate(R.menu.conversation, menu); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java index b9ef8fefa..12ebac04a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java @@ -135,6 +135,11 @@ public void onContentOpened() { KeyboardUtils.showAndFocus(mContext, mQuery); } + @Override + public void onMenuChanging(float percentOpen) { + + } + @Override public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { inflater.inflate(R.menu.search, menu); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 5d444a649..ea1fc0eb1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -725,6 +725,11 @@ public void onContentClosed() { } + @Override + public void onMenuChanging(float percentOpen) { + + } + @Override public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { if (mContext == null) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java index 66ef5beed..bec8be984 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java @@ -2,7 +2,6 @@ import android.content.Context; import android.graphics.Canvas; -import android.os.Build; import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.VelocityTrackerCompat; @@ -75,8 +74,7 @@ public class CustomViewAbove extends ViewGroup { private OnPageChangeListener mOnPageChangeListener; private OnPageChangeListener mInternalPageChangeListener; - private SlidingMenu.OnClosedListener mClosedListener; - private SlidingMenu.OnOpenedListener mOpenedListener; + private SlidingMenu.SlidingMenuListener mListener; /** * Callback interface for responding to changing state of the selected page. @@ -211,11 +209,11 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int if (notify) { // Notify the listeners here, because the client has switched content. if (isMenuOpen()) { - if (mOpenedListener != null) - mOpenedListener.onOpened(); + if (mListener != null) + mListener.onOpened(); } else { - if (mClosedListener != null) - mClosedListener.onClosed(); + if (mListener != null) + mListener.onClosed(); } } @@ -251,12 +249,8 @@ public void setOnPageChangeListener(OnPageChangeListener listener) { mOnPageChangeListener = listener; } - public void setOnOpenedListener(SlidingMenu.OnOpenedListener l) { - mOpenedListener = l; - } - - public void setOnClosedListener(SlidingMenu.OnClosedListener l) { - mClosedListener = l; + public void setListener(SlidingMenu.SlidingMenuListener listener) { + mListener = listener; } /** @@ -332,11 +326,11 @@ void smoothScrollTo(int x, int y, int velocity) { if (dx == 0 && dy == 0) { completeScroll(); if (isMenuOpen()) { - if (mOpenedListener != null) - mOpenedListener.onOpened(); + if (mListener != null) + mListener.onOpened(); } else { - if (mClosedListener != null) - mClosedListener.onClosed(); + if (mListener != null) + mListener.onClosed(); } return; } @@ -478,11 +472,11 @@ private void completeScroll() { scrollTo(x, y); } if (isMenuOpen()) { - if (mOpenedListener != null) - mOpenedListener.onOpened(); + if (mListener != null) + mListener.onOpened(); } else { - if (mClosedListener != null) - mClosedListener.onClosed(); + if (mListener != null) + mListener.onClosed(); } } mScrolling = false; @@ -545,7 +539,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { if (thisTouchAllowed(ev)) { mIsBeingDragged = false; mIsUnableToDrag = false; - if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) { mQuickReturn = true; } } else { @@ -641,7 +635,7 @@ public boolean onTouchEvent(MotionEvent ev) { } mActivePointerId = INVALID_POINTER; endDrag(); - } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) { // close the menu setCurrentItem(1); endDrag(); @@ -696,9 +690,13 @@ private void determineDrag(MotionEvent ev) { @Override public void scrollTo(int x, int y) { super.scrollTo(x, y); + float percentOpen = getPercentOpen(); mScrollX = x; mViewBehind.scrollBehindTo(mContent, x, y); - ((SlidingMenu) getParent()).manageLayers(getPercentOpen()); + ((SlidingMenu) getParent()).manageLayers(percentOpen); + if (mListener != null) { + mListener.onChanging(percentOpen); + } } private int determineTargetPage(float pageOffset, int velocity, int deltaX) { @@ -803,14 +801,12 @@ public boolean executeKeyEvent(KeyEvent event) { handled = arrowScroll(FOCUS_RIGHT); break; case KeyEvent.KEYCODE_TAB: - if (Build.VERSION.SDK_INT >= 11) { - // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD - // before Android 3.0. Ignore the tab key on those devices. - if (KeyEventCompat.hasNoModifiers(event)) { - handled = arrowScroll(FOCUS_FORWARD); - } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { - handled = arrowScroll(FOCUS_BACKWARD); - } + // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD + // before Android 3.0. Ignore the tab key on those devices. + if (KeyEventCompat.hasNoModifiers(event)) { + handled = arrowScroll(FOCUS_FORWARD); + } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { + handled = arrowScroll(FOCUS_BACKWARD); } break; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java index 8e260044b..05a3c2f12 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java @@ -16,6 +16,10 @@ public class CustomViewBehind extends ViewGroup { private int mWidthOffset; private boolean mChildrenEnabled; + private float mScrollScale; + private Drawable mShadowDrawable; + private int mShadowWidth; + public CustomViewBehind(Context context) { this(context, null); } @@ -87,10 +91,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mContent.measure(contentWidth, contentHeight); } - private float mScrollScale; - private Drawable mShadowDrawable; - private int mShadowWidth; - public void setScrollScale(float scrollScale) { mScrollScale = scrollScale; } @@ -138,10 +138,9 @@ public int getAbsRightBound(View content) { * Returns whether x is on a menu. * * @param content content - * @param currPage current page * @param x the position of the touch */ - public boolean menuTouchInQuickReturn(View content, int currPage, float x) { + public boolean menuTouchInQuickReturn(View content, float x) { return x >= content.getLeft(); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java index eb4a8230d..c6d025f93 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java @@ -12,7 +12,6 @@ import android.view.View; import android.widget.RelativeLayout; import com.moez.QKSMS.R; -import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener; /** @@ -26,83 +25,18 @@ public class SlidingMenu extends RelativeLayout { private CustomViewAbove mViewAbove; private CustomViewBehind mViewBehind; - private OnOpenListener mOpenListener; - private OnOpenedListener mOpenedListener; - private OnCloseListener mCloseListener; - private OnClosedListener mClosedListener; + private SlidingMenuListener mListener; - /** - * The listener interface for receiving onOpen events. - * The class that is interested in processing a onOpen - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's addOnOpenListener method. When - * the onOpen event occurs, that object's appropriate - * method is invoked - */ - public interface OnOpenListener { - - /** - * On open. - */ + public interface SlidingMenuListener { void onOpen(); - } - /** - * The listener interface for receiving onOpened events. - * The class that is interested in processing a onOpened - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's addOnOpenedListener method. When - * the onOpened event occurs, that object's appropriate - * method is invoked. - * - * @see OnOpenedEvent - */ - public interface OnOpenedListener { - - /** - * On opened. - */ void onOpened(); - } - /** - * The listener interface for receiving onClose events. - * The class that is interested in processing a onClose - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's addOnCloseListener method. When - * the onClose event occurs, that object's appropriate - * method is invoked. - * - * @see OnCloseEvent - */ - public interface OnCloseListener { - - /** - * On close. - */ void onClose(); - } - /** - * The listener interface for receiving onClosed events. - * The class that is interested in processing a onClosed - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's addOnClosedListener method. When - * the onClosed event occurs, that object's appropriate - * method is invoked. - * - * @see OnClosedEvent - */ - public interface OnClosedListener { - - /** - * On closed. - */ void onClosed(); + + void onChanging(float percentOpen); } /** @@ -151,14 +85,14 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse } public void onPageSelected(int position, boolean anim) { - if (position == POSITION_OPEN && mOpenListener != null && anim) { - mOpenListener.onOpen(); - } else if (position == POSITION_OPEN && mOpenedListener != null) { - mOpenedListener.onOpened(); - } else if (position == POSITION_CLOSE && mCloseListener != null && anim) { - mCloseListener.onClose(); - } else if (position == POSITION_CLOSE && mClosedListener != null) { - mClosedListener.onClosed(); + if (position == POSITION_OPEN && mListener != null && anim) { + mListener.onOpen(); + } else if (position == POSITION_OPEN && mListener != null) { + mListener.onOpened(); + } else if (position == POSITION_CLOSE && mListener != null && anim) { + mListener.onClose(); + } else if (position == POSITION_CLOSE && mListener != null) { + mListener.onClosed(); } } }); @@ -168,8 +102,6 @@ public void onPageSelected(int position, boolean anim) { /** * Set the above view content from a layout resource. The resource will be inflated, adding all top-level views * to the above view. - * - * @param res the new content */ public void setContent() { mViewAbove.setContent(LayoutInflater.from(getContext()).inflate(R.layout.content_frame, null)); @@ -187,8 +119,6 @@ public View getContent() { /** * Set the behind view (menu) content from a layout resource. The resource will be inflated, adding all top-level views * to the behind view. - * - * @param res the new content */ public void setMenu() { mViewBehind.setContent(LayoutInflater.from(getContext()).inflate(R.layout.menu_frame, null)); @@ -270,51 +200,12 @@ public boolean isMenuShowing() { * @param i The margin, in pixels, on the right of the screen that the behind view scrolls to. */ public void setBehindOffset(int i) { - // RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()); - // int bottom = params.bottomMargin; - // int top = params.topMargin; - // int left = params.leftMargin; - // params.setMargins(left, top, i, bottom); mViewBehind.setWidthOffset(i); } - /** - * Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened - * - * @param listener the new OnOpenListener - */ - public void setOnOpenListener(OnOpenListener listener) { - mOpenListener = listener; - } - - - /** - * Sets the OnCloseListener. {@link OnCloseListener#onClose() OnCloseListener.onClose()} will be called when any one of the SlidingMenu is closed - * - * @param listener the new setOnCloseListener - */ - public void setOnCloseListener(OnCloseListener listener) { - mCloseListener = listener; - } - - /** - * Sets the OnOpenedListener. {@link OnOpenedListener#onOpened() OnOpenedListener.onOpened()} will be called after the SlidingMenu is opened - * - * @param listener the new OnOpenedListener - */ - public void setOnOpenedListener(OnOpenedListener listener) { - mOpenedListener = listener; - mViewAbove.setOnOpenedListener(listener); - } - - /** - * Sets the OnClosedListener. {@link OnClosedListener#onClosed() OnClosedListener.onClosed()} will be called after the SlidingMenu is closed - * - * @param listener the new OnClosedListener - */ - public void setOnClosedListener(OnClosedListener listener) { - mClosedListener = listener; - mViewAbove.setOnClosedListener(listener); + public void setListener(SlidingMenuListener listener) { + mListener = listener; + mViewAbove.setListener(listener); } public static class SavedState extends BaseSavedState { From a2f75190c5dbe85b65ca656f95012cc1a0a02ea7 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 14:42:06 -0500 Subject: [PATCH 06/49] Use the changing position to animate the toolbar color --- .../com/moez/QKSMS/common/ConversationPrefsHelper.java | 2 +- .../moez/QKSMS/ui/messagelist/MessageListFragment.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java index 52d11e149..733e63fe1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/ConversationPrefsHelper.java @@ -23,7 +23,7 @@ public ConversationPrefsHelper(Context context, long threadId) { public int getColor() { //return getInt(SettingsFragment.THEME, 0xFF009688); - return 0xFFFF0000; + return 0xff26a69a; } public boolean getNotificationsEnabled() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 99f501cf7..1645948bb 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -1,5 +1,6 @@ package com.moez.QKSMS.ui.messagelist; +import android.animation.ArgbEvaluator; import android.app.Activity; import android.app.AlertDialog; import android.app.LoaderManager; @@ -69,6 +70,7 @@ import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.MainActivity; +import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKContentFragment; import com.moez.QKSMS.ui.base.RecyclerCursorAdapter; import com.moez.QKSMS.ui.delivery.DeliveryReportHelper; @@ -154,6 +156,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private boolean mIsSmsEnabled; private Cursor mCursor; + private ArgbEvaluator mArgbEvaluator; private MessageListAdapter mAdapter; private SmoothLinearLayoutManager mLayoutManager; private MessageListRecyclerView mRecyclerView; @@ -166,6 +169,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private AsyncDialog mAsyncDialog; private ComposeView mComposeView; private SharedPreferences mPrefs; + private ConversationPrefsHelper mConversationPrefs; private ConversationDetailsDialog mConversationDetailsDialog; private int mSavedScrollPosition = -1; // we save the ListView's scroll position in onPause(), @@ -207,7 +211,9 @@ public void onCreate(Bundle savedInstanceState) { mShowImmediate = savedInstanceState.getBoolean(ARG_SHOW_IMMEDIATE, false); } + mArgbEvaluator = new ArgbEvaluator(); mPrefs = mContext.getPrefs(); + mConversationPrefs = new ConversationPrefsHelper(mContext, mThreadId); mIsSmsEnabled = MmsConfig.isSmsEnabled(mContext); mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager()); setHasOptionsMenu(true); @@ -775,7 +781,8 @@ public void onContentClosed() { @Override public void onMenuChanging(float percentOpen) { - Log.d(TAG, "onChanging: " + percentOpen); + mContext.getToolbar().setBackgroundColor((int) mArgbEvaluator.evaluate( + percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getColor())); } @Override From 535a21a1ea4a692e2e4b537134b90bbbe572b31d Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 16:34:00 -0500 Subject: [PATCH 07/49] Remove SharedPreferences object from MessageListFragment --- .../common/preferences/QKPreferences.java | 38 ------------------- .../com/moez/QKSMS/ui/base/QKActivity.java | 25 ++++++++++++ .../ui/messagelist/MessageListFragment.java | 7 ++-- 3 files changed, 28 insertions(+), 42 deletions(-) delete mode 100644 QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java b/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java deleted file mode 100644 index a7b89d6fc..000000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/preferences/QKPreferences.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.moez.QKSMS.common.preferences; - -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; - -public class QKPreferences { - - private SharedPreferences mPrefs; - - public QKPreferences(Context context) { - mPrefs = PreferenceManager.getDefaultSharedPreferences(context); - } - - public boolean getBoolean(QKPreference preference) { - return mPrefs.getBoolean(preference.getKey(), (boolean) preference.getDefaultValue()); - } - - public void setBoolean(QKPreference preference, boolean newValue) { - mPrefs.edit().putBoolean(preference.getKey(), newValue).apply(); - } - - public int getInt(QKPreference preference) { - return mPrefs.getInt(preference.getKey(), (int) preference.getDefaultValue()); - } - - public void setInt(QKPreference preference, int newValue) { - mPrefs.edit().putInt(preference.getKey(), newValue).apply(); - } - - public String getString(QKPreference preference) { - return mPrefs.getString(preference.getKey(), (String) preference.getDefaultValue()); - } - - public void setString(QKPreference preference, String newValue) { - mPrefs.edit().putString(preference.getKey(), newValue).apply(); - } -} \ No newline at end of file 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 33405c68a..c85c31af2 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 com.android.volley.RequestQueue; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.view.QKTextView; @@ -236,4 +237,28 @@ public void makeToast(@StringRes int message) { public RequestQueue getRequestQueue() { return ((QKSMSApp) getApplication()).getRequestQueue(); } + + public boolean getBoolean(QKPreference preference) { + return getPrefs().getBoolean(preference.getKey(), (boolean) preference.getDefaultValue()); + } + + public void setBoolean(QKPreference preference, boolean newValue) { + getPrefs().edit().putBoolean(preference.getKey(), newValue).apply(); + } + + public int getInt(QKPreference preference) { + return getPrefs().getInt(preference.getKey(), (int) preference.getDefaultValue()); + } + + public void setInt(QKPreference preference, int newValue) { + getPrefs().edit().putInt(preference.getKey(), newValue).apply(); + } + + public String getString(QKPreference preference) { + return getPrefs().getString(preference.getKey(), (String) preference.getDefaultValue()); + } + + public void setString(QKPreference preference, String newValue) { + getPrefs().edit().putString(preference.getKey(), newValue).apply(); + } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 1645948bb..7a025e244 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -56,6 +56,7 @@ import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.conversationdetails.ConversationDetailsDialog; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.DrmUtils; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; @@ -168,7 +169,6 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private SensorManager mSensorManager; private AsyncDialog mAsyncDialog; private ComposeView mComposeView; - private SharedPreferences mPrefs; private ConversationPrefsHelper mConversationPrefs; private ConversationDetailsDialog mConversationDetailsDialog; @@ -212,7 +212,6 @@ public void onCreate(Bundle savedInstanceState) { } mArgbEvaluator = new ArgbEvaluator(); - mPrefs = mContext.getPrefs(); mConversationPrefs = new ConversationPrefsHelper(mContext, mThreadId); mIsSmsEnabled = MmsConfig.isSmsEnabled(mContext); mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager()); @@ -221,7 +220,7 @@ public void onCreate(Bundle savedInstanceState) { mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); - if (mPrefs.getBoolean(SettingsFragment.PROXIMITY_CALLING, false)) { + if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } @@ -751,7 +750,7 @@ public void onContentOpened() { super.onContentOpened(); mOpened = true; // The fragment has finished animating in - if (mPrefs != null && mPrefs.getBoolean(SettingsFragment.PROXIMITY_CALLING, false)) { + if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } } From 0b8dbebac5017b88413a5c379c75d36d9acc0bf5 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 16:52:12 -0500 Subject: [PATCH 08/49] Tint status bar with new color --- .../moez/QKSMS/common/utils/ColorUtils.java | 9 +++-- .../java/com/moez/QKSMS/ui/ThemeManager.java | 37 ++++++++++++------- .../ui/messagelist/MessageListFragment.java | 7 ++-- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/ColorUtils.java b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/ColorUtils.java index 54cbe02ac..5e19f0f9c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/utils/ColorUtils.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/utils/ColorUtils.java @@ -34,9 +34,10 @@ public static int lighten(int color) { } public static int darken(int color) { - return Color.argb(Color.alpha(color), - (int) (Color.red(color) * 0.7), - (int) (Color.green(color) * 0.7), - (int) (Color.blue(color) * 0.7)); + float[] hsv = new float[3]; + Color.colorToHSV(color, hsv); + hsv[2] *= 0.75f; + color = Color.HSVToColor(hsv); + return color; } } 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 a2f2e30f8..53ace59d8 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.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Resources; -import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; @@ -25,6 +24,7 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.AnalyticsManager; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.receiver.IconColorReceiver; import com.moez.QKSMS.ui.base.QKActivity; @@ -71,6 +71,7 @@ public static Theme fromString(String color) { } private static int sColor; + private static int sActiveColor; private static int sBackgroundColor; private static Theme sTheme; @@ -256,6 +257,7 @@ public static void loadThemeProperties(Context context) { mContext = context; sColor = Integer.parseInt(sPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR)); + sActiveColor = sColor; if (context instanceof QKActivity) { mActivity = (QKActivity) context; @@ -270,10 +272,10 @@ public static void loadThemeProperties(Context context) { if (mActivity != null && sStatusTintEnabled) { if (sStatusTintEnabled) { - mWindow.setStatusBarColor(darkenColor(sColor)); + mWindow.setStatusBarColor(ColorUtils.darken(sColor)); } if (sNavigationTintEnabled) { - mWindow.setNavigationBarColor(darkenColor(sColor)); + mWindow.setNavigationBarColor(ColorUtils.darken(sColor)); } } @@ -586,7 +588,7 @@ public static void setStatusBarTintEnabled(boolean enabled) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.addUpdateListener(animation -> { - mWindow.setStatusBarColor(darkenColor((Integer) animation.getAnimatedValue())); + mWindow.setStatusBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); }); colorAnimation.start(); } @@ -602,7 +604,7 @@ public static void setNavigationBarTintEnabled(boolean enabled) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.addUpdateListener(animation -> { - mWindow.setNavigationBarColor(darkenColor((Integer) animation.getAnimatedValue())); + mWindow.setNavigationBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); }); colorAnimation.start(); } @@ -622,6 +624,7 @@ public static void setColour(int color) { int colourFrom = sColor; sColor = color; + sActiveColor = color; sPrefs.edit().putString(SettingsFragment.THEME, "" + color).apply(); @@ -654,10 +657,10 @@ public static void setColour(int color) { } if (sStatusTintEnabled) { - mWindow.setStatusBarColor(darkenColor(color1)); + mWindow.setStatusBarColor(ColorUtils.darken(color1)); } if (sNavigationTintEnabled) { - mWindow.setNavigationBarColor(darkenColor(color1)); + mWindow.setNavigationBarColor(ColorUtils.darken(color1)); } }); colorAnimation.addListener(new AnimatorListenerAdapter() { @@ -688,12 +691,20 @@ public void onAnimationEnd(Animator animation) { } } - private static int darkenColor(int color) { - float[] hsv = new float[3]; - Color.colorToHSV(color, hsv); - hsv[2] *= 0.75f; - color = Color.HSVToColor(hsv); - return color; + public static void setActiveColor(int color) { + sActiveColor = color; + + if (mActivity != null) { + if (mActivity.getSupportActionBar() != null) { + mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color)); + } + } + if (sStatusTintEnabled) { + mWindow.setStatusBarColor(ColorUtils.darken(color)); + } + if (sNavigationTintEnabled) { + mWindow.setNavigationBarColor(ColorUtils.darken(color)); + } } private static boolean isColorDarkEnough(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 7a025e244..8fdc2a102 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -14,7 +14,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.Loader; -import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.database.sqlite.SqliteWrapper; @@ -780,8 +779,10 @@ public void onContentClosed() { @Override public void onMenuChanging(float percentOpen) { - mContext.getToolbar().setBackgroundColor((int) mArgbEvaluator.evaluate( - percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getColor())); + if (mConversationPrefs != null) { + ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( + percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getColor())); + } } @Override From f76f0863f8032ce96d67a1b6cc20207c81441f17 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 17:40:09 -0500 Subject: [PATCH 09/49] Live tinting of message bubbles --- .../common/preferences/QKPreference.java | 5 +++- .../java/com/moez/QKSMS/ui/ThemeManager.java | 16 +++++++++--- .../ui/messagelist/MessageListAdapter.java | 17 +++++++------ .../ui/messagelist/MessageListViewHolder.java | 25 ++++++++++++++++++- 4 files changed, 50 insertions(+), 13 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 5683bedce..7e788ab30 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 @@ -87,7 +87,10 @@ public enum QKPreference { TAP_DISMISS("pref_key_quickreply_dismiss", true), // QK Compose - QK_COMPOSE("pref_key_quickcompose", false); + QK_COMPOSE("pref_key_quickcompose", false), + + // LiveViews + ACTIVE_THEME("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 53ace59d8..e44a3763c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -36,6 +36,8 @@ import java.util.Set; +import static com.moez.QKSMS.common.preferences.QKPreference.ACTIVE_THEME; + public class ThemeManager { private final static String TAG = "ThemeManager"; @@ -81,9 +83,11 @@ public static Theme fromString(String color) { private static int sTextOnBackgroundSecondary; private static int sSentBubbleRes; private static int sSentBubbleAltRes; + private static boolean sSentBubbleColored; private static int sSentBubbleColor; private static int sReceivedBubbleRes; private static int sReceivedBubbleAltRes; + private static boolean sReceivedBubbleColored; private static int sReceivedBubbleColor; private static Drawable sRippleBackground; @@ -473,7 +477,7 @@ public static int getSentBubbleAltRes() { } public static int getSentBubbleColor() { - return sSentBubbleColor; + return sSentBubbleColored ? sActiveColor : getNeutralBubbleColor(); } public static int getReceivedBubbleRes() { @@ -485,7 +489,7 @@ public static int getReceivedBubbleAltRes() { } public static int getReceivedBubbleColor() { - return sReceivedBubbleColor; + return sReceivedBubbleColored ? sActiveColor : getNeutralBubbleColor(); } public static void setBubbleStyleNew(boolean styleNew) { @@ -496,11 +500,11 @@ public static void setBubbleStyleNew(boolean styleNew) { } public static void setSentBubbleColored(boolean colored) { - sSentBubbleColor = colored ? sColor : getNeutralBubbleColor(); + sSentBubbleColored = colored; } public static void setReceivedBubbleColored(boolean colored) { - sReceivedBubbleColor = colored ? sColor : getNeutralBubbleColor(); + sReceivedBubbleColored = colored; } public static int getNeutralBubbleColor() { @@ -705,6 +709,10 @@ public static void setActiveColor(int color) { if (sNavigationTintEnabled) { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } + + for (LiveView view : LiveViewManager.getViews(ACTIVE_THEME.getKey())) { + view.refresh(); + } } private static boolean isColorDarkEnough(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java index 45196a640..9820e8cde 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java @@ -130,7 +130,7 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { if (sent) { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getSentBubbleColor() != ThemeManager.getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); @@ -145,7 +145,7 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { } } else { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getReceivedBubbleColor() != ThemeManager.getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); @@ -306,11 +306,14 @@ private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ? ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes())); - if (messageItem.isMe()) { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - } else { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - } + holder.setLiveViewCallback(() -> { + if (messageItem.isMe()) { + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + } else { + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + } + }); + holder.refresh(); if (messageItem.isMe() && !mPrefs.getBoolean(SettingsFragment.HIDE_AVATAR_SENT, true)) { holder.mAvatarView.setVisibility(showAvatar ? View.VISIBLE : View.GONE); 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 12664ce9f..bacaf5ed7 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 @@ -9,8 +9,11 @@ import android.widget.ImageView; import android.widget.LinearLayout; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.google.ItemLoadedCallback; import com.moez.QKSMS.common.google.ThumbnailManager; +import com.moez.QKSMS.common.preferences.QKPreference; +import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.interfaces.SlideViewInterface; import com.moez.QKSMS.ui.base.ClickyViewHolder; import com.moez.QKSMS.ui.base.QKActivity; @@ -20,9 +23,13 @@ import java.util.Map; -public class MessageListViewHolder extends ClickyViewHolder implements SlideViewInterface { +public class MessageListViewHolder extends ClickyViewHolder implements SlideViewInterface, LiveView { private final String TAG = "MessageListViewHolder"; + protected interface LiveViewCallback { + void onRefresh(); + } + // Views protected View mRoot; protected QKTextView mBodyTextView; @@ -44,6 +51,8 @@ public class MessageListViewHolder extends ClickyViewHolder impleme protected ImageLoadedCallback mImageLoadedCallback; protected Presenter mPresenter; + protected LiveViewCallback mLiveViewCallback; + public MessageListViewHolder(QKActivity context, View view) { super(context, view); @@ -56,6 +65,9 @@ public MessageListViewHolder(QKActivity context, View view) { mAvatarView = (AvatarView) view.findViewById(R.id.avatar); mMessageBlock = (LinearLayout) view.findViewById(R.id.message_block); mSpace = view.findViewById(R.id.space); + + LiveViewManager.registerView(this); + LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); } protected void showMmsView(boolean visible) { @@ -90,6 +102,10 @@ protected void inflateDownloadControls() { } } + protected void setLiveViewCallback(LiveViewCallback liveViewCallback) { + mLiveViewCallback = liveViewCallback; + } + @Override public void setImage(String name, Bitmap bitmap) { showMmsView(true); @@ -209,6 +225,13 @@ public void setVisibility(boolean visible) { } + @Override + public void refresh() { + if (mLiveViewCallback != null) { + mLiveViewCallback.onRefresh(); + } + } + static protected class ImageLoadedCallback implements ItemLoadedCallback { private long mMessageId; private final MessageListViewHolder mListItem; From d3d336a4535a9424853fd5a50104d2e7fb2f945a Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 17:45:22 -0500 Subject: [PATCH 10/49] Update avatars with active theme --- QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java | 4 ++++ .../src/main/java/com/moez/QKSMS/ui/view/AvatarView.java | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) 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 e44a3763c..f55850fc1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -535,6 +535,10 @@ public static int getColor() { return sColor; } + public static int getActiveColor() { + return sActiveColor; + } + public static Theme getTheme() { return sTheme; } 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 b49749981..9523e4758 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 @@ -25,11 +25,11 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ImageUtils; import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; public class AvatarView extends ImageView implements View.OnClickListener, LiveView { private final String TAG = "AvatarView"; @@ -95,7 +95,7 @@ public AvatarView(Context context, AttributeSet attrs, int defStyle) { // Register this view for live updates. LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); + LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); } } @@ -261,7 +261,7 @@ private void setImageWhenReady() { getBackground().setColorFilter(0x00000000, PorterDuff.Mode.SRC_ATOP); } else { super.setImageDrawable(TextUtils.isEmpty(mInitial) ? mDefaultDrawable : null); - getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); } } } @@ -285,7 +285,7 @@ public void refresh() { if (getBackground() == null) { setBackgroundResource(R.drawable.circle); } - getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); } private class QueryHandler extends AsyncQueryHandler { From 7127333fa83e853475951107645f85a14e372522 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 18:14:46 -0500 Subject: [PATCH 11/49] LiveView tinting on ComposeButton --- .../src/main/java/com/moez/QKSMS/ui/view/ComposeView.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 2d5bde535..2578456e2 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 @@ -36,6 +36,8 @@ import android.widget.LinearLayout; import android.widget.Toast; import com.github.lzyzsd.circleprogress.DonutProgress; +import com.moez.QKSMS.common.preferences.*; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.mmssms.Transaction; import com.moez.QKSMS.mmssms.Utils; import com.moez.QKSMS.R; @@ -182,7 +184,7 @@ public void onFinishInflate() { mDelay.setOnClickListener(this); LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); + LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); refresh(); @@ -950,10 +952,10 @@ public void run() { @Override public void refresh() { - mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mButtonBackground.setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); + mAttachmentPanel.setBackgroundColor(ThemeManager.getActiveColor()); mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); updateDelayButton(); From 1d001d3b5e2f2a7a02651ecf47a653de5c598f46 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 18:32:23 -0500 Subject: [PATCH 12/49] Fix tinting in onResume --- QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 6af99a338..1359c4e1c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -386,7 +386,6 @@ protected void onStart() { @Override protected void onResume() { super.onResume(); - ThemeManager.loadThemeProperties(this); if (!mSlidingMenu.isMenuShowing()) { mContent.onContentOpened(); From e7641bc0121db38df2ba8639733dd537098d124d Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 19:04:57 -0500 Subject: [PATCH 13/49] Added additional option to conversation preferences for theme --- .../ConversationNotificationSettingsDialog.java | 11 ++++++++--- QKSMS/src/main/res/values/strings.xml | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java index e1266fd28..03602f50c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java @@ -15,12 +15,12 @@ import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; -import com.moez.QKSMS.ui.view.QKSwitchPreference; import com.moez.QKSMS.ui.view.QKPreference; import com.moez.QKSMS.ui.view.QKRingtonePreference; +import com.moez.QKSMS.ui.view.QKSwitchPreference; +import com.moez.QKSMS.ui.view.QKTextView; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch; -import com.moez.QKSMS.ui.view.QKTextView; public class ConversationNotificationSettingsDialog extends QKDialog implements Preference.OnPreferenceClickListener { private final String TAG = "ConversationNotificationSettingsDialog"; @@ -87,6 +87,9 @@ public void onColorSelected(int color) { LinearLayout list = new LinearLayout(getActivity()); list.setOrientation(LinearLayout.VERTICAL); + list.addView(new QKPreference(getActivity(), this, SettingsFragment.THEME, + R.string.pref_theme, 0).getView()); + list.addView(new QKSwitchPreference(getActivity(), this, SettingsFragment.NOTIFICATION_LED, mConversationPrefs.getConversationPrefs(), mConversationPrefs.getNotificationLedEnabled(), R.string.pref_led, 0).getView()); @@ -114,7 +117,9 @@ public void onColorSelected(int color) { } public boolean onPreferenceClick(Preference preference) { - if (preference.getKey().equals(SettingsFragment.NOTIFICATION_LED_COLOR)) { + if (preference.getKey().equals(SettingsFragment.THEME)) { + mContext.makeToast(R.string.test); + } else if (preference.getKey().equals(SettingsFragment.NOTIFICATION_LED_COLOR)) { mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker"); return true; } else if (preference.getKey().equals(SettingsFragment.NOTIFICATION_TONE)) { diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index d2ada51a0..1c50db8a9 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -646,7 +646,7 @@ Messages (%s new) Notifications Notifications off - Notification settings + Conversation settings View details Mark read Mark unread From ebc5762200eb13ad16bd1dcc7714af14b4c4270a Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 23:22:54 -0500 Subject: [PATCH 14/49] Better constructor for MessageListFragment --- .../java/com/moez/QKSMS/ui/MainActivity.java | 12 ++---------- .../ui/messagelist/MessageListFragment.java | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 1359c4e1c..2612051a4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -158,7 +158,7 @@ private void setupFragments(Bundle savedInstanceState) { case TYPE_CONVERSATION: Bundle args = new Bundle(); args.putLong(MessageListFragment.ARG_THREAD_ID, mThreadId); - mContent = MessageListFragment.getInstance(args); + mContent = MessageListFragment.getInstance(mThreadId, 0, null, false); break; case TYPE_SETTINGS: mContent = SettingsFragment.newInstance(R.xml.settings_simple); @@ -535,15 +535,7 @@ public void setConversation(long threadId, long rowId, String pattern) { } public void setConversation(long threadId, long rowId, String pattern, boolean animate) { - - // Build the arguments for this conversation - Bundle args = new Bundle(); - args.putLong(MessageListFragment.ARG_THREAD_ID, threadId); - args.putLong(MessageListFragment.ARG_ROW_ID, rowId); - args.putString(MessageListFragment.ARG_HIGHLIGHT, pattern); - args.putBoolean(MessageListFragment.ARG_SHOW_IMMEDIATE, !animate); - - MessageListFragment fragment = MessageListFragment.getInstance(args); + MessageListFragment fragment = MessageListFragment.getInstance(threadId, rowId, pattern, !animate); // Save the thread ID here and switch the content mThreadId = threadId; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 8fdc2a102..4e48bf0f5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -190,15 +190,24 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private String mHighlight; private boolean mShowImmediate; - public static MessageListFragment getInstance(Bundle args) { - MessageListFragment fragment = new MessageListFragment(); + public static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) { + + Bundle args = new Bundle(); + args.putLong(ARG_THREAD_ID, threadId); + args.putLong(ARG_ROW_ID, rowId); + args.putString(ARG_HIGHLIGHT, highlight); + args.putBoolean(ARG_SHOW_IMMEDIATE, showImmediate); - // Update the fragment with the new arguments. + MessageListFragment fragment = new MessageListFragment(); fragment.updateArguments(args); return fragment; } + public MessageListFragment() { + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -323,7 +332,7 @@ public long getThreadId() { /** * To be called when the user opens a conversation. Initializes the Conversation objects, sets * up the draft, and marks the conversation as read. - *

+ *

* Note: This will have no effect if the context has not been initialized yet. */ private void onOpenConversation() { @@ -672,7 +681,7 @@ public void onActivityResult(int requestCode, int resultCode, final Intent data) /** * Should only be called for failed messages. Deletes the message, placing the text from the * message back in the edit box to be updated and then sent. - *

+ *

* Assumes that cursor points to the correct MessageItem. * * @param msgItem From 249c986136bd030e743b5edcc45fcb0cb463fb66 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 23:42:57 -0500 Subject: [PATCH 15/49] No need for returning color and activeColor independently --- .../src/main/java/com/moez/QKSMS/ui/ThemeManager.java | 11 +++++------ .../QKSMS/ui/messagelist/MessageListFragment.java | 2 +- .../main/java/com/moez/QKSMS/ui/view/AvatarView.java | 4 ++-- .../main/java/com/moez/QKSMS/ui/view/ComposeView.java | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) 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 f55850fc1..cd252f0fe 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -24,6 +24,7 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.AnalyticsManager; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.receiver.IconColorReceiver; @@ -36,8 +37,6 @@ import java.util.Set; -import static com.moez.QKSMS.common.preferences.QKPreference.ACTIVE_THEME; - public class ThemeManager { private final static String TAG = "ThemeManager"; @@ -532,11 +531,11 @@ public static Drawable getRippleBackground() { } public static int getColor() { - return sColor; + return sActiveColor; } - public static int getActiveColor() { - return sActiveColor; + public static int getThemeColor() { + return sColor; } public static Theme getTheme() { @@ -714,7 +713,7 @@ public static void setActiveColor(int color) { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } - for (LiveView view : LiveViewManager.getViews(ACTIVE_THEME.getKey())) { + for (LiveView view : LiveViewManager.getViews(QKPreference.ACTIVE_THEME.getKey())) { view.refresh(); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 4e48bf0f5..eb387428f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -790,7 +790,7 @@ public void onContentClosed() { public void onMenuChanging(float percentOpen) { if (mConversationPrefs != null) { ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( - percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getColor())); + percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor())); } } 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 9523e4758..7e5486bb1 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 @@ -261,7 +261,7 @@ private void setImageWhenReady() { getBackground().setColorFilter(0x00000000, PorterDuff.Mode.SRC_ATOP); } else { super.setImageDrawable(TextUtils.isEmpty(mInitial) ? mDefaultDrawable : null); - getBackground().setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); } } } @@ -285,7 +285,7 @@ public void refresh() { if (getBackground() == null) { setBackgroundResource(R.drawable.circle); } - getBackground().setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); } private class QueryHandler extends AsyncQueryHandler { 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 2578456e2..2e1ee6405 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 @@ -36,7 +36,6 @@ import android.widget.LinearLayout; import android.widget.Toast; import com.github.lzyzsd.circleprogress.DonutProgress; -import com.moez.QKSMS.common.preferences.*; import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.mmssms.Transaction; import com.moez.QKSMS.mmssms.Utils; @@ -952,10 +951,10 @@ public void run() { @Override public void refresh() { - mButtonBackground.setColorFilter(ThemeManager.getActiveColor(), PorterDuff.Mode.SRC_ATOP); + mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mAttachmentPanel.setBackgroundColor(ThemeManager.getActiveColor()); + mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); updateDelayButton(); From 6b7d7a56cd8d2c2515aecabf4ae5bb3168a2e2a0 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 23:46:50 -0500 Subject: [PATCH 16/49] Make sure final color is met regardless of frames --- .../com/moez/QKSMS/ui/messagelist/MessageListFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index eb387428f..2bf8667a1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -761,6 +761,8 @@ public void onContentOpened() { if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } + + ThemeManager.setActiveColor(mConversationPrefs.getColor()); } @Override @@ -784,6 +786,8 @@ public void onContentClosed() { mComposeView.saveDraft(); } } + + ThemeManager.setActiveColor(ThemeManager.getThemeColor()); } @Override From 2f4e3b5525ce51b170790b12fbe3d83d205649b7 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 25 Dec 2015 14:23:14 -0500 Subject: [PATCH 17/49] ThemeManager singleton --- .../com/moez/QKSMS/common/FontManager.java | 20 +- .../com/moez/QKSMS/common/ListviewHelper.java | 6 +- .../com/moez/QKSMS/data/ContactHelper.java | 2 +- .../QKSMS/receiver/NightModeAutoReceiver.java | 6 +- .../receiver/WearableIntentReceiver.java | 2 +- .../transaction/NotificationManager.java | 2 +- .../java/com/moez/QKSMS/ui/MainActivity.java | 6 +- .../java/com/moez/QKSMS/ui/ThemeManager.java | 312 +++++++++--------- .../com/moez/QKSMS/ui/base/QKActivity.java | 4 +- .../moez/QKSMS/ui/base/QKContentFragment.java | 2 +- .../com/moez/QKSMS/ui/base/QKFragment.java | 2 +- .../moez/QKSMS/ui/base/QKPopupActivity.java | 4 +- .../ConversationListAdapter.java | 18 +- .../ConversationListFragment.java | 16 +- .../ConversationListViewHolder.java | 2 +- .../ui/dialog/BubblePreferenceDialog.java | 76 ++--- .../QKSMS/ui/dialog/DefaultSmsHelper.java | 2 +- .../com/moez/QKSMS/ui/dialog/QKDialog.java | 6 +- .../ui/dialog/mms/MMSDialogFragment.java | 6 +- .../ui/messagelist/MessageListAdapter.java | 22 +- .../ui/messagelist/MessageListFragment.java | 8 +- .../QKSMS/ui/settings/SettingsFragment.java | 18 +- .../ui/view/AutoCompleteContactView.java | 4 +- .../com/moez/QKSMS/ui/view/AvatarView.java | 8 +- .../com/moez/QKSMS/ui/view/ComposeView.java | 24 +- .../com/moez/QKSMS/ui/view/QKEditText.java | 4 +- .../com/moez/QKSMS/ui/view/QKImageView.java | 2 +- .../java/com/moez/QKSMS/ui/view/QKSwitch.java | 16 +- .../com/moez/QKSMS/ui/view/QKTextView.java | 12 +- .../QKSMS/ui/view/StarredContactsView.java | 10 +- .../QKSMS/ui/welcome/WelcomeActivity.java | 8 +- .../ui/welcome/WelcomeNightFragment.java | 10 +- .../ui/welcome/WelcomeThemeFragment.java | 4 +- .../moez/QKSMS/ui/widget/WidgetProvider.java | 8 +- .../moez/QKSMS/ui/widget/WidgetService.java | 16 +- 35 files changed, 340 insertions(+), 328 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java index 8c8c1fd51..b0ecccad7 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java @@ -89,26 +89,26 @@ public static ColorStateList getTextColor(Context context, int type) { // Colors and font weight switch (type) { case FontManager.TEXT_TYPE_PRIMARY: - boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.GREY || - ThemeManager.getTheme() == ThemeManager.Theme.BLACK; + boolean isNight = ThemeManager.getInstance().getTheme() == ThemeManager.Theme.GREY || + ThemeManager.getInstance().getTheme() == ThemeManager.Theme.BLACK; int id = isNight ? R.color.text_primary_dark : R.color.text_primary_light; return context.getResources().getColorStateList(id); case FontManager.TEXT_TYPE_SECONDARY: - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_TERTIARY: - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_CATEGORY: - return ColorStateList.valueOf(ThemeManager.getColor()); + return ColorStateList.valueOf(ThemeManager.getInstance().getColor()); case FontManager.TEXT_TYPE_DIALOG_TITLE: - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); case FontManager.TEXT_TYPE_DIALOG_MESSAGE: - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_DIALOG_BUTTON: - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); case FontManager.TEXT_TYPE_TOOLBAR: - return ColorStateList.valueOf(ThemeManager.getTextOnColorPrimary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnColorPrimary()); } - return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); } public static int getFontWeight(Context context, boolean heavy) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java index 1e6146976..bb196dd6c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java @@ -20,9 +20,9 @@ public static void applyCustomScrollbar(Context context, ListView listView) { try { Drawable drawable = ContextCompat.getDrawable(context, R.drawable.scrollbar); drawable.setColorFilter(Color.argb(64, - Color.red(ThemeManager.getTextOnBackgroundSecondary()), - Color.green(ThemeManager.getTextOnBackgroundSecondary()), - Color.blue(ThemeManager.getTextOnBackgroundSecondary())), + Color.red(ThemeManager.getInstance().getTextOnBackgroundSecondary()), + Color.green(ThemeManager.getInstance().getTextOnBackgroundSecondary()), + Color.blue(ThemeManager.getInstance().getTextOnBackgroundSecondary())), PorterDuff.Mode.SRC_ATOP); Field mScrollCacheField = View.class.getDeclaredField("mScrollCache"); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java index ea7fff1c4..9f279d729 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java @@ -197,7 +197,7 @@ public static Bitmap blankContact(Context context, String name) { int length = Units.dpToPx(context, 64); Bitmap bitmap = Bitmap.createBitmap(length, length, Bitmap.Config.ARGB_8888); - bitmap.eraseColor(ThemeManager.getColor()); + bitmap.eraseColor(ThemeManager.getInstance().getColor()); Canvas canvas = new Canvas(bitmap); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java index cfcb57589..351c468a8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java @@ -19,7 +19,7 @@ public class NightModeAutoReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - ThemeManager.loadThemeProperties(context); + ThemeManager.getInstance().loadThemeProperties(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) { @@ -42,11 +42,11 @@ public void onReceive(Context context, Intent intent) { (calendar.get(Calendar.HOUR_OF_DAY) == day.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) <= day.get(Calendar.MINUTE))) { Log.i(TAG, "Switching to night mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_GREY).apply(); - ThemeManager.setTheme(ThemeManager.Theme.GREY); + ThemeManager.getInstance().setTheme(ThemeManager.Theme.GREY); } else { Log.i(TAG, "Switching to day mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_OFFWHITE).apply(); - ThemeManager.setTheme(ThemeManager.Theme.OFFWHITE); + ThemeManager.getInstance().setTheme(ThemeManager.Theme.OFFWHITE); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java index f152b28ab..96f944796 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java @@ -56,7 +56,7 @@ public static WearableExtender getSingleConversationExtender(Context context, St background = Bitmap.createBitmap(640, 400, Bitmap.Config.ARGB_8888); // We can't use ThemeManager here because it might not be initialized - background.eraseColor(Integer.parseInt(prefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR))); + background.eraseColor(Integer.parseInt(prefs.getString(SettingsFragment.THEME, "" + ThemeManager.getInstance().DEFAULT_COLOR))); } wearableExtender.setBackground(background); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java index ee788e2b3..e11547884 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java @@ -680,7 +680,7 @@ public static void initQuickCompose(Context context, boolean override, boolean o .setContentIntent(composePI) .setSmallIcon(R.drawable.ic_compose) .setPriority(NotificationCompat.PRIORITY_MIN) - .setColor(ThemeManager.getColor()); + .setColor(ThemeManager.getInstance().getColor()); NotificationManager.notify(context, NOTIFICATION_ID_QUICKCOMPOSE, builder.build()); } else { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 2612051a4..0018d3e0f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -648,9 +648,9 @@ public void onClick(View v) { public void refresh() { // Update the background color. This code is important during the welcome screen setup, when the activity // in the ThemeManager isn't the MainActivity - findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); - findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); - findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); } public static class DeleteThreadListener implements DialogInterface.OnClickListener { 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 cd252f0fe..f995097c7 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -71,35 +71,6 @@ public static Theme fromString(String color) { } } - private static int sColor; - private static int sActiveColor; - private static int sBackgroundColor; - private static Theme sTheme; - - private static int sTextOnColorPrimary; - private static int sTextOnColorSecondary; - private static int sTextOnBackgroundPrimary; - private static int sTextOnBackgroundSecondary; - private static int sSentBubbleRes; - private static int sSentBubbleAltRes; - private static boolean sSentBubbleColored; - private static int sSentBubbleColor; - private static int sReceivedBubbleRes; - private static int sReceivedBubbleAltRes; - private static boolean sReceivedBubbleColored; - private static int sReceivedBubbleColor; - private static Drawable sRippleBackground; - - private static Resources sResources; - private static SharedPreferences sPrefs; - - private static boolean sStatusTintEnabled = false; - private static boolean sNavigationTintEnabled = false; - - private static QKActivity mActivity; - private static Context mContext; - private static Window mWindow; - // Colours copied from http://www.google.com/design/spec/style/color.html#color-ui-color-palette private static final int[][] COLOURS = {{ // Red @@ -249,45 +220,86 @@ public static Theme fromString(String color) { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }}; + private int mColor; + private int mActiveColor; + private int mBackgroundColor; + private Theme mTheme; + + private int mTextOnColorPrimary; + private int mTextOnColorSecondary; + private int mTextOnBackgroundPrimary; + private int mtextOnBackgroundSecondary; + private int mSentBubbleRes; + private int mSentBubbleAltRes; + private boolean mSentBubbleColored; + private int mReceivedBubbleRes; + private int mReceivedBubbleAltRes; + private boolean mReceivedBubbleColored; + private Drawable mRippleBackground; + + private Resources mResources; + private SharedPreferences mPrefs; + + private boolean mStatusTintEnabled = false; + private boolean mNavigationTintEnabled = false; + + private QKActivity mActivity; + private Context mContext; + private Window mWindow; + + private static ThemeManager sInstance; + + public static ThemeManager getInstance() { + if (sInstance == null) { + sInstance = new ThemeManager(); + } + + return sInstance; + } + + private ThemeManager() { + + } + /** * Loads all theme properties. Should be called during onCreate * of each activity that contains fragments that use ThemeManager */ - public static void loadThemeProperties(Context context) { - sPrefs = PreferenceManager.getDefaultSharedPreferences(context); - sResources = context.getResources(); + public void loadThemeProperties(Context context) { + mPrefs = PreferenceManager.getDefaultSharedPreferences(context); + mResources = context.getResources(); mContext = context; - sColor = Integer.parseInt(sPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR)); - sActiveColor = sColor; + mColor = Integer.parseInt(mPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.getInstance().DEFAULT_COLOR)); + mActiveColor = mColor; if (context instanceof QKActivity) { mActivity = (QKActivity) context; - mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(sColor)); + mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mColor)); mWindow = mActivity.getWindow(); } - initializeTheme(Theme.fromString(sPrefs.getString(SettingsFragment.BACKGROUND, "offwhite"))); + initializeTheme(Theme.fromString(mPrefs.getString(SettingsFragment.BACKGROUND, "offwhite"))); - sStatusTintEnabled = sPrefs.getBoolean(SettingsFragment.STATUS_TINT, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; - sNavigationTintEnabled = sPrefs.getBoolean(SettingsFragment.NAVIGATION_TINT, false) && 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; - if (mActivity != null && sStatusTintEnabled) { - if (sStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(sColor)); + if (mActivity != null && mStatusTintEnabled) { + if (mStatusTintEnabled) { + mWindow.setStatusBarColor(ColorUtils.darken(mColor)); } - if (sNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(sColor)); + if (mNavigationTintEnabled) { + mWindow.setNavigationBarColor(ColorUtils.darken(mColor)); } } } - public static void setTheme(Theme theme) { - int startColor = sBackgroundColor; + public void setTheme(Theme theme) { + int startColor = mBackgroundColor; initializeTheme(theme); - int endColor = sBackgroundColor; + int endColor = mBackgroundColor; if (mActivity instanceof MainActivity) { final View background = mActivity.findViewById(R.id.menu_frame).getRootView(); @@ -331,70 +343,70 @@ public void onAnimationEnd(Animator animation) { } } - public static void initializeTheme(Theme theme) { - sTheme = theme; + public void initializeTheme(Theme theme) { + mTheme = theme; switch (theme) { case WHITE: - sBackgroundColor = sResources.getColor(R.color.white_pure); + mBackgroundColor = mResources.getColor(R.color.white_pure); if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? R.style.AppThemeWhite : R.style.AppThemeWhiteDialog); break; case OFFWHITE: - sBackgroundColor = sResources.getColor(R.color.grey_light_mega_ultra); + mBackgroundColor = mResources.getColor(R.color.grey_light_mega_ultra); if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? R.style.AppThemeLight : R.style.AppThemeLightDialog); break; case GREY: - sBackgroundColor = sResources.getColor(R.color.grey_material); + mBackgroundColor = mResources.getColor(R.color.grey_material); if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? R.style.AppThemeDark : R.style.AppThemeDarkDialog); break; case BLACK: - sBackgroundColor = sResources.getColor(R.color.black); + mBackgroundColor = mResources.getColor(R.color.black); if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? R.style.AppThemeDarkAmoled : R.style.AppThemeDarkAmoledDialog); break; } - switch (sTheme) { + switch (mTheme) { case WHITE: case OFFWHITE: - sTextOnBackgroundPrimary = sResources.getColor(R.color.theme_light_text_primary); - sTextOnBackgroundSecondary = sResources.getColor(R.color.theme_light_text_secondary); - sRippleBackground = sResources.getDrawable(R.drawable.button_background_transparent); + 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: - sTextOnBackgroundPrimary = sResources.getColor(R.color.theme_dark_text_primary); - sTextOnBackgroundSecondary = sResources.getColor(R.color.theme_dark_text_secondary); - sRippleBackground = sResources.getDrawable(R.drawable.button_background_transparent_light); + 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; } - sTextOnColorPrimary = sResources.getColor(isColorDarkEnough(sColor) ? + mTextOnColorPrimary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_primary : R.color.theme_light_text_primary); - sTextOnColorSecondary = sResources.getColor(isColorDarkEnough(sColor) ? + mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); - setSentBubbleColored(sPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); - setReceivedBubbleColored(sPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); - setBubbleStyleNew(sPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true)); + setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); + 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(sTextOnColorPrimary); + ((QKTextView) mActivity.findViewById(R.id.toolbar_title)).setTextColor(mTextOnColorPrimary); } } - public static void setIcon(final QKActivity context) { + public void setIcon(final QKActivity context) { new QKDialog() .setContext(context) .setTitle(R.string.update_icon_title) @@ -420,7 +432,7 @@ public static void setIcon(final QKActivity context) { // Save the enabled component so we can kill the app with this one when // it's all done. - if (getSwatchColour(sColor) == PALETTE[i]) { + if (getSwatchColour(mColor) == PALETTE[i]) { enabledComponent = componentClassName; } else { @@ -447,106 +459,106 @@ public static void setIcon(final QKActivity context) { .show(); } - public static int getBackgroundColor() { - return sBackgroundColor; + public int getBackgroundColor() { + return mBackgroundColor; } - public static int getTextOnColorPrimary() { - return sTextOnColorPrimary; + public int getTextOnColorPrimary() { + return mTextOnColorPrimary; } - public static int getTextOnColorSecondary() { - return sTextOnColorSecondary; + public int getTextOnColorSecondary() { + return mTextOnColorSecondary; } - public static int getTextOnBackgroundPrimary() { - return sTextOnBackgroundPrimary; + public int getTextOnBackgroundPrimary() { + return mTextOnBackgroundPrimary; } - public static int getTextOnBackgroundSecondary() { - return sTextOnBackgroundSecondary; + public int getTextOnBackgroundSecondary() { + return mtextOnBackgroundSecondary; } - public static int getSentBubbleRes() { - return sSentBubbleRes; + public int getSentBubbleRes() { + return mSentBubbleRes; } - public static int getSentBubbleAltRes() { - return sSentBubbleAltRes; + public int getSentBubbleAltRes() { + return mSentBubbleAltRes; } - public static int getSentBubbleColor() { - return sSentBubbleColored ? sActiveColor : getNeutralBubbleColor(); + public int getSentBubbleColor() { + return mSentBubbleColored ? mActiveColor : getNeutralBubbleColor(); } - public static int getReceivedBubbleRes() { - return sReceivedBubbleRes; + public int getReceivedBubbleRes() { + return mReceivedBubbleRes; } - public static int getReceivedBubbleAltRes() { - return sReceivedBubbleAltRes; + public int getReceivedBubbleAltRes() { + return mReceivedBubbleAltRes; } - public static int getReceivedBubbleColor() { - return sReceivedBubbleColored ? sActiveColor : getNeutralBubbleColor(); + public int getReceivedBubbleColor() { + return mReceivedBubbleColored ? mActiveColor : getNeutralBubbleColor(); } - public static void setBubbleStyleNew(boolean styleNew) { - sSentBubbleRes = styleNew ? R.drawable.message_sent_2 : R.drawable.message_sent; - sSentBubbleAltRes = styleNew ? R.drawable.message_sent_alt_2 : R.drawable.message_sent_alt; - sReceivedBubbleRes = styleNew ? R.drawable.message_received_2 : R.drawable.message_received; - sReceivedBubbleAltRes = styleNew ? R.drawable.message_received_alt_2 : R.drawable.message_received_alt; + public void setBubbleStyleNew(boolean styleNew) { + mSentBubbleRes = styleNew ? R.drawable.message_sent_2 : R.drawable.message_sent; + mSentBubbleAltRes = styleNew ? R.drawable.message_sent_alt_2 : R.drawable.message_sent_alt; + mReceivedBubbleRes = styleNew ? R.drawable.message_received_2 : R.drawable.message_received; + mReceivedBubbleAltRes = styleNew ? R.drawable.message_received_alt_2 : R.drawable.message_received_alt; } - public static void setSentBubbleColored(boolean colored) { - sSentBubbleColored = colored; + public void setSentBubbleColored(boolean colored) { + mSentBubbleColored = colored; } - public static void setReceivedBubbleColored(boolean colored) { - sReceivedBubbleColored = colored; + public void setReceivedBubbleColored(boolean colored) { + mReceivedBubbleColored = colored; } - public static int getNeutralBubbleColor() { - if (sTheme == null) { + public int getNeutralBubbleColor() { + if (mTheme == null) { return 0xeeeeee; } - switch (sTheme) { + switch (mTheme) { case WHITE: - return sResources.getColor(R.color.grey_light_mega_ultra); + return mResources.getColor(R.color.grey_light_mega_ultra); case OFFWHITE: - return sResources.getColor(R.color.white_pure); + return mResources.getColor(R.color.white_pure); case GREY: - return sResources.getColor(R.color.grey_dark); + return mResources.getColor(R.color.grey_dark); default: - return sResources.getColor(R.color.grey_material); + return mResources.getColor(R.color.grey_material); } } - public static Drawable getRippleBackground() { - return sRippleBackground; + public Drawable getRippleBackground() { + return mRippleBackground; } - public static int getColor() { - return sActiveColor; + public int getColor() { + return mActiveColor; } - public static int getThemeColor() { - return sColor; + public int getThemeColor() { + return mColor; } - public static Theme getTheme() { - return sTheme; + public Theme getTheme() { + return mTheme; } - public static boolean isNightMode() { - return sTheme == Theme.GREY || sTheme == Theme.BLACK; + public boolean isNightMode() { + return mTheme == Theme.GREY || mTheme == Theme.BLACK; } - public static void showColourSwatchesDialog(final QKActivity context) { + public void showColourSwatchesDialog(final QKActivity context) { final QKDialog dialog = new QKDialog(); ColorPickerPalette palette = new ColorPickerPalette(context); @@ -556,7 +568,7 @@ public static void showColourSwatchesDialog(final QKActivity context) { dialog.dismiss(); }); - palette.drawPalette(PALETTE, getSwatchColour(sColor)); + palette.drawPalette(PALETTE, getSwatchColour(mColor)); dialog.setContext(context) .setTitle(R.string.pref_theme) @@ -566,7 +578,7 @@ public static void showColourSwatchesDialog(final QKActivity context) { dialog.show(); } - private static void showColourPickerDialog(final QKActivity context, int swatchColour) { + private void showColourPickerDialog(final QKActivity context, int swatchColour) { final QKDialog dialog = new QKDialog(); ColorPickerPalette palette = new ColorPickerPalette(context); @@ -576,7 +588,7 @@ private static void showColourPickerDialog(final QKActivity context, int swatchC dialog.dismiss(); }); - palette.drawPalette(getSwatch(swatchColour), sColor); + palette.drawPalette(getSwatch(swatchColour), mColor); dialog.setContext(context) .setTitle(R.string.pref_theme) @@ -586,11 +598,11 @@ private static void showColourPickerDialog(final QKActivity context, int swatchC } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static void setStatusBarTintEnabled(boolean enabled) { - if (sStatusTintEnabled != enabled) { - sStatusTintEnabled = enabled; - int colorFrom = enabled ? sResources.getColor(R.color.black) : sColor; - int colorTo = enabled ? sColor : sResources.getColor(R.color.black); + public void setStatusBarTintEnabled(boolean enabled) { + if (mStatusTintEnabled != enabled) { + mStatusTintEnabled = enabled; + int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; + int colorTo = enabled ? mColor : mResources.getColor(R.color.black); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(TRANSITION_LENGTH); @@ -602,11 +614,11 @@ public static void setStatusBarTintEnabled(boolean enabled) { } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static void setNavigationBarTintEnabled(boolean enabled) { - if (sNavigationTintEnabled != enabled) { - sNavigationTintEnabled = enabled; - int colorFrom = enabled ? sResources.getColor(R.color.black) : sColor; - int colorTo = enabled ? sColor : sResources.getColor(R.color.black); + public void setNavigationBarTintEnabled(boolean enabled) { + if (mNavigationTintEnabled != enabled) { + mNavigationTintEnabled = enabled; + int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; + int colorTo = enabled ? mColor : mResources.getColor(R.color.black); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(TRANSITION_LENGTH); @@ -617,11 +629,11 @@ public static void setNavigationBarTintEnabled(boolean enabled) { } } - public static String getColorString(int color) { + public String getColorString(int color) { return String.format("#%08x", color).toUpperCase(); } - public static void setColour(int color) { + public void setColour(int color) { AnalyticsManager.getInstance().sendEvent( AnalyticsManager.CATEGORY_PREFERENCE_CHANGE, @@ -629,17 +641,17 @@ public static void setColour(int color) { getColorString(color) ); - int colourFrom = sColor; - sColor = color; - sActiveColor = color; + int colourFrom = mColor; + mColor = color; + mActiveColor = color; - sPrefs.edit().putString(SettingsFragment.THEME, "" + color).apply(); + mPrefs.edit().putString(SettingsFragment.THEME, "" + color).apply(); - setSentBubbleColored(sPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); - setReceivedBubbleColored(sPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); - sTextOnColorPrimary = sResources.getColor(isColorDarkEnough(sColor) ? + setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); + setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); + mTextOnColorPrimary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_primary : R.color.theme_light_text_primary); - sTextOnColorSecondary = sResources.getColor(isColorDarkEnough(sColor) ? + mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); // Some views are updated every frame of the animation; get these views here. We @@ -663,10 +675,10 @@ public static void setColour(int color) { } } - if (sStatusTintEnabled) { + if (mStatusTintEnabled) { mWindow.setStatusBarColor(ColorUtils.darken(color1)); } - if (sNavigationTintEnabled) { + if (mNavigationTintEnabled) { mWindow.setNavigationBarColor(ColorUtils.darken(color1)); } }); @@ -684,8 +696,8 @@ public void onAnimationEnd(Animator animation) { //final Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.title); final QKTextView title = (QKTextView) mActivity.findViewById(R.id.toolbar_title); - if (title.getCurrentTextColor() != ThemeManager.sTextOnColorPrimary) { - ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), title.getCurrentTextColor(), ThemeManager.sTextOnColorPrimary); + if (title.getCurrentTextColor() != mTextOnColorPrimary) { + ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), title.getCurrentTextColor(), mTextOnColorPrimary); titleColorAnimation.setDuration(TRANSITION_LENGTH); titleColorAnimation.setInterpolator(new DecelerateInterpolator()); titleColorAnimation.addUpdateListener(animation -> { @@ -698,18 +710,18 @@ public void onAnimationEnd(Animator animation) { } } - public static void setActiveColor(int color) { - sActiveColor = color; + public void setActiveColor(int color) { + mActiveColor = color; if (mActivity != null) { if (mActivity.getSupportActionBar() != null) { mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color)); } } - if (sStatusTintEnabled) { + if (mStatusTintEnabled) { mWindow.setStatusBarColor(ColorUtils.darken(color)); } - if (sNavigationTintEnabled) { + if (mNavigationTintEnabled) { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } @@ -718,7 +730,7 @@ public static void setActiveColor(int color) { } } - private static boolean isColorDarkEnough(int color) { + private boolean isColorDarkEnough(int color) { for (int i = 0; i < COLOURS.length; i++) { for (int j = 0; j < COLOURS[i].length; j++) { if (color == COLOURS[i][j]) { @@ -730,7 +742,7 @@ private static boolean isColorDarkEnough(int color) { return true; } - public static int getSwatchColour(int colour) { + public int getSwatchColour(int colour) { for (int i = 0; i < COLOURS.length; i++) { for (int j = 0; j < COLOURS[i].length; j++) { if (colour == COLOURS[i][j]) { @@ -742,7 +754,7 @@ public static int getSwatchColour(int colour) { return colour; } - private static int[] getSwatch(int colour) { + private int[] getSwatch(int colour) { for (int[] swatch : COLOURS) { for (int swatchColor : swatch) { if (colour == swatchColor) { 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 c85c31af2..6e9d4d8d1 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 @@ -72,7 +72,7 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } - ThemeManager.loadThemeProperties(this); + ThemeManager.getInstance().loadThemeProperties(this); } protected void showBackButton(boolean show) { @@ -173,7 +173,7 @@ public Menu getMenu() { public boolean onPrepareOptionsMenu(Menu menu) { // Save a reference to the menu so that we can quickly access menu icons later. mMenu = menu; - colorMenuIcons(mMenu, ThemeManager.getTextOnColorPrimary()); + colorMenuIcons(mMenu, ThemeManager.getInstance().getTextOnColorPrimary()); return true; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java index 2e45c8080..9391c990b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java @@ -102,7 +102,7 @@ public void onContentClosed() { public void refresh() { View view = getView(); if (view != null) { - view.setBackgroundColor(ThemeManager.getBackgroundColor()); + view.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java index e071a7428..17d5d6d7a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java @@ -37,7 +37,7 @@ public void onDestroy() { @Override public void refresh() { if (getView() != null) { - getView().setBackgroundColor(ThemeManager.getBackgroundColor()); + getView().setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index 68ba6544b..cd92d99d5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -29,9 +29,9 @@ protected void onCreate(Bundle savedInstanceState) { setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true)); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); setContentView(getLayoutResource()); - ThemeManager.loadThemeProperties(this); + ThemeManager.getInstance().loadThemeProperties(this); - ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor()); + ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getInstance().getBackgroundColor()); View title = findViewById(R.id.title); if (title != null && title instanceof AppCompatTextView) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index a35bc960c..1ba65cc96 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -80,23 +80,23 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { if (conversation.hasUnreadMessages()) { holder.unreadView.setVisibility(View.VISIBLE); - holder.snippetView.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - holder.dateView.setTextColor(ThemeManager.getColor()); + holder.snippetView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + holder.dateView.setTextColor(ThemeManager.getInstance().getColor()); } else { holder.unreadView.setVisibility(View.GONE); - holder.snippetView.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); - holder.dateView.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); + holder.snippetView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + holder.dateView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); } if (isInMultiSelectMode()) { holder.mSelected.setVisibility(View.VISIBLE); if (isSelected(conversation.getThreadId())) { holder.mSelected.setImageResource(R.drawable.ic_selected); - holder.mSelected.setColorFilter(ThemeManager.getColor()); + holder.mSelected.setColorFilter(ThemeManager.getInstance().getColor()); holder.mSelected.setAlpha(1f); } else { holder.mSelected.setImageResource(R.drawable.ic_unselected); - holder.mSelected.setColorFilter(ThemeManager.getTextOnBackgroundSecondary()); + holder.mSelected.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary()); holder.mSelected.setAlpha(0.5f); } } else { @@ -127,9 +127,9 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { @Override public void refresh() { - mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mMuted.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + mUnread.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + mError.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); notifyDataSetChanged(); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index f9608d2a5..0a096747c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -88,16 +88,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View view = inflater.inflate(R.layout.fragment_conversations, null); ButterKnife.bind(this, view); - mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); + mEmptyStateIcon.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundPrimary()); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); - mFab.setColorNormal(ThemeManager.getColor()); - mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); + mFab.setColorNormal(ThemeManager.getInstance().getColor()); + mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getInstance().getColor())); mFab.attachToRecyclerView(mRecyclerView); - mFab.setColorFilter(ThemeManager.getTextOnColorPrimary()); + mFab.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary()); mFab.setOnClickListener(v -> { if (mAdapter.isInMultiSelectMode()) { mAdapter.disableMultiSelectMode(true); @@ -307,11 +307,11 @@ public void refresh() { return; } - mFab.setColorNormal(ThemeManager.getColor()); - mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); - mFab.getDrawable().setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mFab.setColorNormal(ThemeManager.getInstance().getColor()); + mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getInstance().getColor())); + mFab.getDrawable().setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); + mEmptyStateIcon.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundPrimary()); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java index ae2a95197..dbcd63d0f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java @@ -110,7 +110,7 @@ private CharSequence formatMessage(Conversation conversation, ConversationLegacy buf.append(mContext.getResources().getString(R.string.draft_separator)); int before = buf.length(); buf.append(mContext.getResources().getString(R.string.has_draft)); - buf.setSpan(new ForegroundColorSpan(ThemeManager.getColor()), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + buf.setSpan(new ForegroundColorSpan(ThemeManager.getInstance().getColor()), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } return buf; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java index eea273196..f60505cf2 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java @@ -27,24 +27,24 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { View view = mContext.getLayoutInflater().inflate(R.layout.dialog_bubbles, null); final QKTextView in1 = (QKTextView) view.findViewById(R.id.in_1); - in1.setBackgroundResource(ThemeManager.getReceivedBubbleRes()); - in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + in1.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleRes()); + in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); final QKTextView in2 = (QKTextView) view.findViewById(R.id.in_2); - in2.setBackgroundResource(ThemeManager.getReceivedBubbleAltRes()); - in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + in2.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleAltRes()); + in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); final QKTextView out1 = (QKTextView) view.findViewById(R.id.out_1); - out1.setBackgroundResource(ThemeManager.getSentBubbleRes()); - out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + out1.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); + out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); final QKTextView out2 = (QKTextView) view.findViewById(R.id.out_2); - out2.setBackgroundResource(ThemeManager.getSentBubbleAltRes()); - out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + out2.setBackgroundResource(ThemeManager.getInstance().getSentBubbleAltRes()); + out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); Preference.OnPreferenceClickListener onPreferenceClickListener = new Preference.OnPreferenceClickListener() { @Override @@ -52,38 +52,38 @@ public boolean onPreferenceClick(Preference preference) { Log.d(TAG, preference.getKey()); switch (preference.getKey()) { case SettingsFragment.BUBBLES_NEW: - ThemeManager.setBubbleStyleNew(((QKSwitchPreference) preference).isChecked()); - in1.setBackgroundResource(ThemeManager.getReceivedBubbleRes()); - in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); - - in2.setBackgroundResource(ThemeManager.getReceivedBubbleAltRes()); - in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); - - out1.setBackgroundResource(ThemeManager.getSentBubbleRes()); - out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); - - out2.setBackgroundResource(ThemeManager.getSentBubbleAltRes()); - out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + ThemeManager.getInstance().setBubbleStyleNew(((QKSwitchPreference) preference).isChecked()); + in1.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleRes()); + in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + + in2.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleAltRes()); + in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + + out1.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); + out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + + out2.setBackgroundResource(ThemeManager.getInstance().getSentBubbleAltRes()); + out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); return true; case SettingsFragment.COLOUR_RECEIVED: - ThemeManager.setReceivedBubbleColored(((QKSwitchPreference) preference).isChecked()); - in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); - in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + ThemeManager.getInstance().setReceivedBubbleColored(((QKSwitchPreference) preference).isChecked()); + in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); return true; case SettingsFragment.COLOUR_SENT: - ThemeManager.setSentBubbleColored(((QKSwitchPreference) preference).isChecked()); - out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); - out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + ThemeManager.getInstance().setSentBubbleColored(((QKSwitchPreference) preference).isChecked()); + out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); return true; } return false; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java index 0f92a9f3d..f6969807c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java @@ -45,7 +45,7 @@ public void showIfNotDefault(ViewGroup viewGroup) { .type(getSnackBarType()) .text(mMessage) .duration(duration) - .actionColor(ThemeManager.getColor()) + .actionColor(ThemeManager.getInstance().getColor()) .actionLabel(R.string.upgrade_now) .actionListener(this); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java index 69d85eed0..c5fa15d79 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java @@ -130,7 +130,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive); mPositiveButtonView.setVisibility(View.VISIBLE); mPositiveButtonView.setText(mPositiveButtonText); - mPositiveButtonView.setTextColor(ThemeManager.getColor()); + mPositiveButtonView.setTextColor(ThemeManager.getInstance().getColor()); mPositiveButtonView.setOnClickListener(mPositiveButtonClickListener); } @@ -443,11 +443,11 @@ public View getView(int position, View convertView, ViewGroup parent) { } QKTextView title = (QKTextView) convertView.findViewById(R.id.list_item_title); - title.setTextColor(ThemeManager.getColor()); + title.setTextColor(ThemeManager.getInstance().getColor()); title.setText(getItem(position).title); QKTextView subtitle = (QKTextView) convertView.findViewById(R.id.list_item_subtitle); - subtitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + subtitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); subtitle.setText(getItem(position).subtitle); ((QKTextView) convertView.findViewById(R.id.list_item_body)) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java index 97d28454e..399ed3615 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java @@ -190,7 +190,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive); mPositiveButtonView.setVisibility(View.VISIBLE); mPositiveButtonView.setText(mPositiveButtonText); - mPositiveButtonView.setTextColor(ThemeManager.getColor()); + mPositiveButtonView.setTextColor(ThemeManager.getInstance().getColor()); mPositiveButtonView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -465,11 +465,11 @@ public View getView(int position, View convertView, ViewGroup parent) { } QKTextView title = (QKTextView) convertView.findViewById(R.id.list_item_title); - title.setTextColor(ThemeManager.getColor()); + title.setTextColor(ThemeManager.getInstance().getColor()); title.setText(getItem(position).title); QKTextView subtitle = (QKTextView) convertView.findViewById(R.id.list_item_subtitle); - subtitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + subtitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); subtitle.setText(getItem(position).subtitle); ((QKTextView) convertView.findViewById(R.id.list_item_body)) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java index 9820e8cde..76b8e4281 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java @@ -130,10 +130,10 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { if (sent) { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getSentBubbleColor() != ThemeManager.getNeutralBubbleColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() != ThemeManager.getInstance().getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); - holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mDeliveredIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mLockedIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); // set up avatar holder.mAvatarView.setImageDrawable(Contact.getMe(true).getAvatar(mContext, null)); @@ -145,10 +145,10 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { } } else { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getReceivedBubbleColor() != ThemeManager.getNeutralBubbleColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() != ThemeManager.getInstance().getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); - holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mDeliveredIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mLockedIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); // set up avatar if (mPrefs.getBoolean(SettingsFragment.HIDE_AVATAR_RECEIVED, false)) { @@ -302,15 +302,15 @@ private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) holder.mDateView.setVisibility(showTimestamp ? View.VISIBLE : View.GONE); holder.mSpace.setVisibility(showAvatar ? View.VISIBLE : View.GONE); - holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getSentBubbleRes() : - ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ? - ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes())); + holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getInstance().getSentBubbleRes() : + ThemeManager.getInstance().getReceivedBubbleRes()) : (messageItem.isMe() ? + ThemeManager.getInstance().getSentBubbleAltRes() : ThemeManager.getInstance().getReceivedBubbleAltRes())); holder.setLiveViewCallback(() -> { if (messageItem.isMe()) { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); } else { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); } }); holder.refresh(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 2bf8667a1..02bf35bd9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -762,7 +762,7 @@ public void onContentOpened() { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } - ThemeManager.setActiveColor(mConversationPrefs.getColor()); + ThemeManager.getInstance().setActiveColor(mConversationPrefs.getColor()); } @Override @@ -787,14 +787,14 @@ public void onContentClosed() { } } - ThemeManager.setActiveColor(ThemeManager.getThemeColor()); + ThemeManager.getInstance().setActiveColor(ThemeManager.getInstance().getThemeColor()); } @Override public void onMenuChanging(float percentOpen) { if (mConversationPrefs != null) { - ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( - percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor())); + ThemeManager.getInstance().setActiveColor((int) mArgbEvaluator.evaluate( + percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getInstance().getThemeColor())); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index ea1fc0eb1..40aefef00 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -381,7 +381,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { String valueString = newValue == null ? "null" : newValue.toString(); if (key.equals(NOTIFICATION_LED_COLOR)) { // Format the color as a nice string if it's the LED color. - valueString = ThemeManager.getColorString(Integer.parseInt(valueString)); + valueString = ThemeManager.getInstance().getColorString(Integer.parseInt(valueString)); } Log.d(TAG, "onPreferenceChange key:" + key + " newValue: " + valueString); @@ -393,13 +393,13 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { switch (key) { case BACKGROUND: - ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); + ThemeManager.getInstance().setTheme(ThemeManager.Theme.fromString((String) newValue)); break; case STATUS_TINT: - ThemeManager.setStatusBarTintEnabled((Boolean) newValue); + ThemeManager.getInstance().setStatusBarTintEnabled((Boolean) newValue); break; case NAVIGATION_TINT: - ThemeManager.setNavigationBarTintEnabled((Boolean) newValue); + ThemeManager.getInstance().setNavigationBarTintEnabled((Boolean) newValue); break; case FONT_FAMILY: preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); @@ -412,10 +412,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); break; case COLOUR_SENT: - ThemeManager.setSentBubbleColored((Boolean) newValue); + ThemeManager.getInstance().setSentBubbleColored((Boolean) newValue); break; case COLOUR_RECEIVED: - ThemeManager.setReceivedBubbleColored((Boolean) newValue); + ThemeManager.getInstance().setReceivedBubbleColored((Boolean) newValue); break; case NIGHT_AUTO: updateAlarmManager(mContext, (Boolean) newValue); @@ -519,13 +519,13 @@ public boolean onPreferenceClick(Preference preference) { switch (key) { case THEME: - ThemeManager.showColourSwatchesDialog(mContext); + ThemeManager.getInstance().showColourSwatchesDialog(mContext); break; case BUBBLES: new BubblePreferenceDialog().setContext(mContext).show(); break; case ICON: - ThemeManager.setIcon(mContext); + ThemeManager.getInstance().setIcon(mContext); break; case BLOCKED_FUTURE: BlockedNumberDialog.showDialog(mContext); @@ -701,7 +701,7 @@ public void refresh() { View view = getView(); if (view != null) { - view.setBackgroundColor(ThemeManager.getBackgroundColor()); + view.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java index 3ddb31a1d..75f9e3477 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java @@ -61,8 +61,8 @@ public void refresh() { FontManager.getFontWeight(mContext, false))); setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); - setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); if (mAdapter != null) { SharedPreferences prefs = mContext.getPrefs(); 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 7e5486bb1..c3537b0e6 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 @@ -261,7 +261,7 @@ private void setImageWhenReady() { getBackground().setColorFilter(0x00000000, PorterDuff.Mode.SRC_ATOP); } else { super.setImageDrawable(TextUtils.isEmpty(mInitial) ? mDefaultDrawable : null); - getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); } } } @@ -279,13 +279,13 @@ protected void onDraw(Canvas canvas) { @Override public void refresh() { - mPaint.setColor(ThemeManager.getTextOnColorPrimary()); - mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mPaint.setColor(ThemeManager.getInstance().getTextOnColorPrimary()); + mDefaultDrawable.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); if (getBackground() == null) { setBackgroundResource(R.drawable.circle); } - getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); } private class QueryHandler extends AsyncQueryHandler { 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 2e1ee6405..302800ed7 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 @@ -951,24 +951,24 @@ public void run() { @Override public void refresh() { - mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); - mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mButtonBackground.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + mButtonBar1.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mButtonBar2.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mAttachmentPanel.setBackgroundColor(ThemeManager.getInstance().getColor()); + mAttach.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mCamera.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); updateDelayButton(); - mProgress.setUnfinishedStrokeColor(ThemeManager.getTextOnColorSecondary()); - mProgress.setFinishedStrokeColor(ThemeManager.getTextOnColorPrimary()); - if (ThemeManager.getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getSentBubbleRes()); - mReplyText.getBackground().setColorFilter(ThemeManager.getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); + mProgress.setUnfinishedStrokeColor(ThemeManager.getInstance().getTextOnColorSecondary()); + mProgress.setFinishedStrokeColor(ThemeManager.getInstance().getTextOnColorPrimary()); + if (ThemeManager.getInstance().getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); + mReplyText.getBackground().setColorFilter(ThemeManager.getInstance().getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); mReplyText.refresh(); - getBackground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getInstance().getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); } private void updateDelayButton() { mDelay.setColorFilter(mDelayedMessagingEnabled ? - ThemeManager.getTextOnColorPrimary() : ThemeManager.getTextOnColorSecondary(), + ThemeManager.getInstance().getTextOnColorPrimary() : ThemeManager.getInstance().getTextOnColorSecondary(), PorterDuff.Mode.SRC_ATOP); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java index 5b2ff0cc9..f5dfdb786 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java @@ -99,8 +99,8 @@ public void refresh() { int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight )); - setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); // Text size int sp = FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java index 911b8d252..db4f0165a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java @@ -44,7 +44,7 @@ public void setImageDrawable(Drawable drawable) { mDrawable = drawable; if (mDrawable != null) { - mDrawable.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mDrawable.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); super.setImageDrawable(drawable); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java index 134629b0f..e6039ff84 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java @@ -50,16 +50,16 @@ private ColorStateList getSwitchThumbColorStateList() { // Disabled state states[0] = new int[]{-android.R.attr.state_enabled}; - colors[0] = mRes.getColor(ThemeManager.isNightMode() ? + colors[0] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? R.color.switch_thumb_disabled_dark : R.color.switch_thumb_disabled_light); // Checked state states[1] = new int[]{android.R.attr.state_checked}; - colors[1] = ThemeManager.getColor(); + colors[1] = ThemeManager.getInstance().getColor(); // Unchecked enabled state state states[2] = new int[0]; - colors[2] = mRes.getColor(ThemeManager.isNightMode() ? + colors[2] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? R.color.switch_thumb_enabled_dark : R.color.switch_thumb_enabled_light); return new ColorStateList(states, colors); @@ -71,19 +71,19 @@ private ColorStateList getSwitchTrackColorStateList() { // Disabled state states[0] = new int[]{-android.R.attr.state_enabled}; - colors[0] = mRes.getColor(ThemeManager.isNightMode() ? + colors[0] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? R.color.switch_track_disabled_dark : R.color.switch_track_disabled_light); // Checked state states[1] = new int[]{android.R.attr.state_checked}; colors[1] = Color.argb(0x4D, // 30% alpha - Color.red(ThemeManager.getColor()), - Color.green(ThemeManager.getColor()), - Color.blue(ThemeManager.getColor())); + Color.red(ThemeManager.getInstance().getColor()), + Color.green(ThemeManager.getInstance().getColor()), + Color.blue(ThemeManager.getInstance().getColor())); // Unchecked enabled state state states[2] = new int[0]; - colors[2] = mRes.getColor(ThemeManager.isNightMode() ? + colors[2] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? R.color.switch_track_enabled_dark : R.color.switch_track_enabled_light); return new ColorStateList(states, colors); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java index 43956443a..1833f1bab 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java @@ -106,19 +106,19 @@ public void setOnColorBackground(boolean onColorBackground) { if (onColorBackground) { if (mType == FontManager.TEXT_TYPE_PRIMARY) { - setTextColor(ThemeManager.getTextOnColorPrimary()); - setLinkTextColor(ThemeManager.getTextOnColorPrimary()); + setTextColor(ThemeManager.getInstance().getTextOnColorPrimary()); + setLinkTextColor(ThemeManager.getInstance().getTextOnColorPrimary()); } else if (mType == FontManager.TEXT_TYPE_SECONDARY || mType == FontManager.TEXT_TYPE_TERTIARY) { - setTextColor(ThemeManager.getTextOnColorSecondary()); + setTextColor(ThemeManager.getInstance().getTextOnColorSecondary()); } } else { if (mType == FontManager.TEXT_TYPE_PRIMARY) { - setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - setLinkTextColor(ThemeManager.getColor()); + setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + setLinkTextColor(ThemeManager.getInstance().getColor()); } else if (mType == FontManager.TEXT_TYPE_SECONDARY || mType == FontManager.TEXT_TYPE_TERTIARY) { - setTextColor(ThemeManager.getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java index 140653a94..a6883c951 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java @@ -58,7 +58,7 @@ protected void onFinishInflate() { super.onFinishInflate(); mFavoritesBackground = (LinearLayout) findViewById(R.id.starred_contacts); - mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); + mFavoritesBackground.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); mTitle = (QKTextView) findViewById(R.id.title); @@ -154,13 +154,13 @@ public void toggle() { } public void expand() { - mTitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + mTitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); mFavorites.setVisibility(View.VISIBLE); mIndicator.setRotation(0f); } public void collapse() { - mTitle.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); + mTitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); mFavorites.setVisibility(View.GONE); mIndicator.setRotation(90f); } @@ -176,7 +176,7 @@ public void onClick(View v) { @Override public void refresh() { - mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); + mIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + mFavoritesBackground.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java index e0291733b..67ebc5ded 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { getSupportActionBar().hide(); mBackground = findViewById(R.id.welcome); - mBackground.setBackgroundColor(ThemeManager.getColor()); + mBackground.setBackgroundColor(ThemeManager.getInstance().getColor()); mPrevious = (ImageView) findViewById(R.id.welcome_previous); mPrevious.setOnClickListener(this); @@ -63,8 +63,8 @@ protected void onCreate(Bundle savedInstanceState) { } public void setColor(int color) { - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ThemeManager.getColor(), color); - colorAnimation.setDuration(ThemeManager.TRANSITION_LENGTH); + ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ThemeManager.getInstance().getColor(), color); + colorAnimation.setDuration(ThemeManager.getInstance().TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override @@ -74,7 +74,7 @@ public void onAnimationUpdate(ValueAnimator animation) { }); colorAnimation.start(); - ThemeManager.setColour(color); + ThemeManager.getInstance().setColour(color); } public void setColorBackground(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java index 870bf6cd5..2ca8e2143 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java @@ -43,8 +43,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onScrollOffsetChanged(WelcomeActivity activity, float offset) { - int colorBackground = (Integer) mArgbEvaluator.evaluate(Math.abs(offset), ThemeManager.getBackgroundColor(), ThemeManager.getColor()); - int colorAccent = (Integer) mArgbEvaluator.evaluate(1 - Math.abs(offset), 0xFFFFFFFF, ThemeManager.getColor()); + int colorBackground = (Integer) mArgbEvaluator.evaluate(Math.abs(offset), ThemeManager.getInstance().getBackgroundColor(), ThemeManager.getInstance().getColor()); + int colorAccent = (Integer) mArgbEvaluator.evaluate(1 - Math.abs(offset), 0xFFFFFFFF, ThemeManager.getInstance().getColor()); activity.setColorBackground(colorBackground); activity.tintIndicators(colorAccent); @@ -66,14 +66,14 @@ public void onScrollOffsetChanged(WelcomeActivity activity, float offset) { @Override public void onClick(View v) { if (v.getId() == R.id.welcome_night_hint) { - boolean night = ThemeManager.getTheme() == ThemeManager.Theme.OFFWHITE; + boolean night = ThemeManager.getInstance().getTheme() == ThemeManager.Theme.OFFWHITE; int backgroundColor = mContext.getResources().getColor(night ? R.color.grey_light_mega_ultra : R.color.grey_material); int newBackgroundColor = mContext.getResources().getColor(night ? R.color.grey_material : R.color.grey_light_mega_ultra); - ThemeManager.setTheme(night ? ThemeManager.Theme.GREY : ThemeManager.Theme.OFFWHITE); + ThemeManager.getInstance().setTheme(night ? ThemeManager.Theme.GREY : ThemeManager.Theme.OFFWHITE); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), backgroundColor, newBackgroundColor); - colorAnimation.setDuration(ThemeManager.TRANSITION_LENGTH); + colorAnimation.setDuration(ThemeManager.getInstance().TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java index 8001682df..2fed97389 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java @@ -21,7 +21,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mPallette = (ColorPickerPalette) view.findViewById(R.id.welcome_themes); mPallette.init(19, 4, this); - mPallette.drawPalette(ThemeManager.PALETTE, ThemeManager.getColor()); + mPallette.drawPalette(ThemeManager.getInstance().PALETTE, ThemeManager.getInstance().getColor()); return view; } @@ -29,7 +29,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onColorSelected(int color) { ((WelcomeActivity) getActivity()).setColor(color); - mPallette.drawPalette(ThemeManager.PALETTE, color); + mPallette.drawPalette(ThemeManager.getInstance().PALETTE, color); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java index 85b96b181..28a7bda85 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java @@ -45,7 +45,7 @@ public class WidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); - ThemeManager.loadThemeProperties(context); + ThemeManager.getInstance().loadThemeProperties(context); for (int appWidgetId : appWidgetIds) { updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId)); @@ -118,10 +118,10 @@ private static void updateWidget(Context context, int appWidgetId, int smallWidg remoteViews.setRemoteAdapter(R.id.conversation_list, intent); remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.title_conversation_list)); - remoteViews.setTextColor(R.id.widget_label, ThemeManager.getTextOnColorPrimary()); + remoteViews.setTextColor(R.id.widget_label, ThemeManager.getInstance().getTextOnColorPrimary()); - remoteViews.setInt(R.id.conversation_list_background, "setColorFilter", ThemeManager.getBackgroundColor()); - remoteViews.setInt(R.id.header_background, "setColorFilter", ThemeManager.getColor()); + remoteViews.setInt(R.id.conversation_list_background, "setColorFilter", ThemeManager.getInstance().getBackgroundColor()); + remoteViews.setInt(R.id.header_background, "setColorFilter", ThemeManager.getInstance().getColor()); // Open Mms's app conversation list when click on header final Intent convIntent = new Intent(context, MainActivity.class); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java index cbfdbe54e..8baf62ff2 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java @@ -224,9 +224,9 @@ private void bindAvatar(RemoteViews remoteViews, Conversation conversation) { } private void bindIndicators(RemoteViews remoteViews, Conversation conversation) { - remoteViews.setInt(R.id.muted, "setColorFilter", ThemeManager.getColor()); - remoteViews.setInt(R.id.error, "setColorFilter", ThemeManager.getColor()); - remoteViews.setInt(R.id.unread, "setColorFilter", ThemeManager.getColor()); + remoteViews.setInt(R.id.muted, "setColorFilter", ThemeManager.getInstance().getColor()); + remoteViews.setInt(R.id.error, "setColorFilter", ThemeManager.getInstance().getColor()); + remoteViews.setInt(R.id.unread, "setColorFilter", ThemeManager.getInstance().getColor()); remoteViews.setViewVisibility(R.id.muted, new ConversationPrefsHelper(mContext, conversation.getThreadId()) .getNotificationsEnabled() ? View.GONE : View.VISIBLE); remoteViews.setViewVisibility(R.id.error, conversation.hasError() ? View.VISIBLE : View.GONE); @@ -234,15 +234,15 @@ private void bindIndicators(RemoteViews remoteViews, Conversation conversation) } private void bindName(RemoteViews remoteViews, Conversation conversation) { - SpannableStringBuilder from = addColor(conversation.getRecipients().formatNames(", "), ThemeManager.getTextOnBackgroundPrimary()); + SpannableStringBuilder from = addColor(conversation.getRecipients().formatNames(", "), ThemeManager.getInstance().getTextOnBackgroundPrimary()); if (conversation.hasDraft()) { from.append(mContext.getResources().getString(R.string.draft_separator)); int before = from.length(); from.append(mContext.getResources().getString(R.string.has_draft)); from.setSpan(new TextAppearanceSpan(mContext, android.R.style.TextAppearance_Small, - ThemeManager.getTextOnBackgroundPrimary()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - from.setSpan(new ForegroundColorSpan(ThemeManager.getColor()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + ThemeManager.getInstance().getTextOnBackgroundPrimary()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + from.setSpan(new ForegroundColorSpan(ThemeManager.getInstance().getColor()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } remoteViews.setTextViewText(R.id.name, from); @@ -250,12 +250,12 @@ private void bindName(RemoteViews remoteViews, Conversation conversation) { private void bindDate(RemoteViews remoteViews, Conversation conversation) { remoteViews.setTextViewText(R.id.date, addColor(MessageUtils.formatTimeStampString(mContext, conversation.getDate()), - conversation.hasUnreadMessages() ? ThemeManager.getColor() : ThemeManager.getTextOnBackgroundSecondary())); + conversation.hasUnreadMessages() ? ThemeManager.getInstance().getColor() : ThemeManager.getInstance().getTextOnBackgroundSecondary())); } private void bindSnippet(RemoteViews remoteViews, Conversation conversation) { remoteViews.setTextViewText(R.id.snippet, addColor(conversation.getSnippet(), conversation.hasUnreadMessages() ? - ThemeManager.getTextOnBackgroundPrimary() : ThemeManager.getTextOnBackgroundSecondary())); + ThemeManager.getInstance().getTextOnBackgroundPrimary() : ThemeManager.getInstance().getTextOnBackgroundSecondary())); } /** From 2ff75f347e882941011c46a8f708172d1a60e080 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 25 Dec 2015 15:12:52 -0500 Subject: [PATCH 18/49] Clean up notification dialog class --- ...onversationNotificationSettingsDialog.java | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java index 03602f50c..7617a6359 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java @@ -20,7 +20,6 @@ import com.moez.QKSMS.ui.view.QKSwitchPreference; import com.moez.QKSMS.ui.view.QKTextView; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog; -import com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch; public class ConversationNotificationSettingsDialog extends QKDialog implements Preference.OnPreferenceClickListener { private final String TAG = "ConversationNotificationSettingsDialog"; @@ -33,7 +32,6 @@ public class ConversationNotificationSettingsDialog extends QKDialog implements private ConversationPrefsHelper mConversationPrefs; private int[] mLedColors; - private ColorPickerDialog mLedColorPickerDialog; private long mThreadId; private ViewGroup.LayoutParams mLayoutParams = new LinearLayout.LayoutParams( @@ -67,17 +65,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mRes.getColor(R.color.red_light), mRes.getColor(R.color.white_pure) }; - mLedColorPickerDialog = new ColorPickerDialog(); - mLedColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt( - mConversationPrefs.getNotificationLedColor()), 3, 2); - mLedColorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() { - - @Override - public void onColorSelected(int color) { - mConversationPrefs.putString(SettingsFragment.NOTIFICATION_LED_COLOR, "" + color); - } - }); - int padding = Units.dpToPx(getActivity(), 16); QKTextView premiumWarning = new QKTextView(getActivity()); premiumWarning.setLayoutParams(mLayoutParams); @@ -117,24 +104,31 @@ public void onColorSelected(int color) { } public boolean onPreferenceClick(Preference preference) { - if (preference.getKey().equals(SettingsFragment.THEME)) { - mContext.makeToast(R.string.test); - } else if (preference.getKey().equals(SettingsFragment.NOTIFICATION_LED_COLOR)) { - mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker"); - return true; - } else if (preference.getKey().equals(SettingsFragment.NOTIFICATION_TONE)) { - Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); - Uri uri = Uri.parse(mConversationPrefs.getString(SettingsFragment.NOTIFICATION_TONE, "content://settings/system/notification_sound")); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pref_ringtone)); - intent.putExtra(ARG_THREAD_ID, mThreadId); - ((MainActivity) getActivity()).getResultForThreadId(mThreadId); - getActivity().startActivityForResult(intent, RINGTONE_REQUEST_CODE); - return true; + switch (preference.getKey()) { + case SettingsFragment.THEME: + mContext.makeToast(R.string.test); + break; + + case SettingsFragment.NOTIFICATION_LED_COLOR: + ColorPickerDialog ledColorPickerDialog = new ColorPickerDialog(); + ledColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt(mConversationPrefs.getNotificationLedColor()), 3, 2); + ledColorPickerDialog.setOnColorSelectedListener(color -> mConversationPrefs.putString(SettingsFragment.NOTIFICATION_LED_COLOR, "" + color)); + ledColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker"); + break; + + case SettingsFragment.NOTIFICATION_TONE: + Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); + Uri uri = Uri.parse(mConversationPrefs.getString(SettingsFragment.NOTIFICATION_TONE, "content://settings/system/notification_sound")); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pref_ringtone)); + intent.putExtra(ARG_THREAD_ID, mThreadId); + ((MainActivity) getActivity()).getResultForThreadId(mThreadId); + getActivity().startActivityForResult(intent, RINGTONE_REQUEST_CODE); + break; } return true; From d1c623694e0b327aee8f005bf894feb444d2bc9a Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Wed, 30 Dec 2015 22:32:47 -0500 Subject: [PATCH 19/49] Static usages of ThemeManager --- .../java/com/moez/QKSMS/QKSMSAppBase.java | 3 +- .../com/moez/QKSMS/common/FontManager.java | 20 +-- .../com/moez/QKSMS/common/ListviewHelper.java | 6 +- .../com/moez/QKSMS/data/ContactHelper.java | 2 +- .../QKSMS/receiver/NightModeAutoReceiver.java | 6 +- .../receiver/WearableIntentReceiver.java | 2 +- .../transaction/NotificationManager.java | 2 +- .../java/com/moez/QKSMS/ui/MainActivity.java | 6 +- .../java/com/moez/QKSMS/ui/ThemeManager.java | 141 ++++++++---------- .../com/moez/QKSMS/ui/base/QKActivity.java | 4 +- .../moez/QKSMS/ui/base/QKContentFragment.java | 2 +- .../com/moez/QKSMS/ui/base/QKFragment.java | 2 +- .../moez/QKSMS/ui/base/QKPopupActivity.java | 4 +- .../ConversationListAdapter.java | 18 +-- .../ConversationListFragment.java | 16 +- .../ConversationListViewHolder.java | 2 +- .../ui/dialog/BubblePreferenceDialog.java | 76 +++++----- .../QKSMS/ui/dialog/DefaultSmsHelper.java | 2 +- .../com/moez/QKSMS/ui/dialog/QKDialog.java | 6 +- .../ui/dialog/mms/MMSDialogFragment.java | 6 +- .../ui/messagelist/MessageListAdapter.java | 22 +-- .../ui/messagelist/MessageListFragment.java | 8 +- .../QKSMS/ui/settings/SettingsFragment.java | 18 +-- .../ui/view/AutoCompleteContactView.java | 4 +- .../com/moez/QKSMS/ui/view/AvatarView.java | 8 +- .../com/moez/QKSMS/ui/view/ComposeView.java | 24 +-- .../com/moez/QKSMS/ui/view/QKEditText.java | 4 +- .../com/moez/QKSMS/ui/view/QKImageView.java | 2 +- .../java/com/moez/QKSMS/ui/view/QKSwitch.java | 16 +- .../com/moez/QKSMS/ui/view/QKTextView.java | 12 +- .../QKSMS/ui/view/StarredContactsView.java | 10 +- .../QKSMS/ui/welcome/WelcomeActivity.java | 8 +- .../ui/welcome/WelcomeNightFragment.java | 10 +- .../ui/welcome/WelcomeThemeFragment.java | 4 +- .../moez/QKSMS/ui/widget/WidgetProvider.java | 8 +- .../moez/QKSMS/ui/widget/WidgetService.java | 16 +- 36 files changed, 246 insertions(+), 254 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java b/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java index 164a4a0ac..cbe1d4f1f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java @@ -41,6 +41,7 @@ import com.moez.QKSMS.data.Contact; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.transaction.NotificationManager; +import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.mms.layout.LayoutManager; import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.RefWatcher; @@ -88,6 +89,7 @@ public void onCreate() { mPduLoaderManager = new PduLoaderManager(context); mThumbnailManager = new ThumbnailManager(context); + ThemeManager.init(this); MmsConfig.init(this); Contact.init(this); DraftCache.init(this); @@ -97,7 +99,6 @@ public void onCreate() { LayoutManager.init(this); NotificationManager.init(this); LiveViewManager.init(this); - //MessagingNotification.init(this); activePendingMessages(); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java index b0ecccad7..8c8c1fd51 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java @@ -89,26 +89,26 @@ public static ColorStateList getTextColor(Context context, int type) { // Colors and font weight switch (type) { case FontManager.TEXT_TYPE_PRIMARY: - boolean isNight = ThemeManager.getInstance().getTheme() == ThemeManager.Theme.GREY || - ThemeManager.getInstance().getTheme() == ThemeManager.Theme.BLACK; + boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.GREY || + ThemeManager.getTheme() == ThemeManager.Theme.BLACK; int id = isNight ? R.color.text_primary_dark : R.color.text_primary_light; return context.getResources().getColorStateList(id); case FontManager.TEXT_TYPE_SECONDARY: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_TERTIARY: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_CATEGORY: - return ColorStateList.valueOf(ThemeManager.getInstance().getColor()); + return ColorStateList.valueOf(ThemeManager.getColor()); case FontManager.TEXT_TYPE_DIALOG_TITLE: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); case FontManager.TEXT_TYPE_DIALOG_MESSAGE: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundSecondary()); case FontManager.TEXT_TYPE_DIALOG_BUTTON: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); case FontManager.TEXT_TYPE_TOOLBAR: - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnColorPrimary()); + return ColorStateList.valueOf(ThemeManager.getTextOnColorPrimary()); } - return ColorStateList.valueOf(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + return ColorStateList.valueOf(ThemeManager.getTextOnBackgroundPrimary()); } public static int getFontWeight(Context context, boolean heavy) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java index bb196dd6c..1e6146976 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/ListviewHelper.java @@ -20,9 +20,9 @@ public static void applyCustomScrollbar(Context context, ListView listView) { try { Drawable drawable = ContextCompat.getDrawable(context, R.drawable.scrollbar); drawable.setColorFilter(Color.argb(64, - Color.red(ThemeManager.getInstance().getTextOnBackgroundSecondary()), - Color.green(ThemeManager.getInstance().getTextOnBackgroundSecondary()), - Color.blue(ThemeManager.getInstance().getTextOnBackgroundSecondary())), + Color.red(ThemeManager.getTextOnBackgroundSecondary()), + Color.green(ThemeManager.getTextOnBackgroundSecondary()), + Color.blue(ThemeManager.getTextOnBackgroundSecondary())), PorterDuff.Mode.SRC_ATOP); Field mScrollCacheField = View.class.getDeclaredField("mScrollCache"); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java index 9f279d729..ea7fff1c4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java @@ -197,7 +197,7 @@ public static Bitmap blankContact(Context context, String name) { int length = Units.dpToPx(context, 64); Bitmap bitmap = Bitmap.createBitmap(length, length, Bitmap.Config.ARGB_8888); - bitmap.eraseColor(ThemeManager.getInstance().getColor()); + bitmap.eraseColor(ThemeManager.getColor()); Canvas canvas = new Canvas(bitmap); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java index 351c468a8..cfcb57589 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java @@ -19,7 +19,7 @@ public class NightModeAutoReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - ThemeManager.getInstance().loadThemeProperties(context); + ThemeManager.loadThemeProperties(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) { @@ -42,11 +42,11 @@ public void onReceive(Context context, Intent intent) { (calendar.get(Calendar.HOUR_OF_DAY) == day.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) <= day.get(Calendar.MINUTE))) { Log.i(TAG, "Switching to night mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_GREY).apply(); - ThemeManager.getInstance().setTheme(ThemeManager.Theme.GREY); + ThemeManager.setTheme(ThemeManager.Theme.GREY); } else { Log.i(TAG, "Switching to day mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_OFFWHITE).apply(); - ThemeManager.getInstance().setTheme(ThemeManager.Theme.OFFWHITE); + ThemeManager.setTheme(ThemeManager.Theme.OFFWHITE); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java index 96f944796..f152b28ab 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/WearableIntentReceiver.java @@ -56,7 +56,7 @@ public static WearableExtender getSingleConversationExtender(Context context, St background = Bitmap.createBitmap(640, 400, Bitmap.Config.ARGB_8888); // We can't use ThemeManager here because it might not be initialized - background.eraseColor(Integer.parseInt(prefs.getString(SettingsFragment.THEME, "" + ThemeManager.getInstance().DEFAULT_COLOR))); + background.eraseColor(Integer.parseInt(prefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR))); } wearableExtender.setBackground(background); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java index e11547884..ee788e2b3 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java @@ -680,7 +680,7 @@ public static void initQuickCompose(Context context, boolean override, boolean o .setContentIntent(composePI) .setSmallIcon(R.drawable.ic_compose) .setPriority(NotificationCompat.PRIORITY_MIN) - .setColor(ThemeManager.getInstance().getColor()); + .setColor(ThemeManager.getColor()); NotificationManager.notify(context, NOTIFICATION_ID_QUICKCOMPOSE, builder.build()); } else { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 0018d3e0f..2612051a4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -648,9 +648,9 @@ public void onClick(View v) { public void refresh() { // Update the background color. This code is important during the welcome screen setup, when the activity // in the ThemeManager isn't the MainActivity - findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); - findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); - findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); } public static class DeleteThreadListener implements DialogInterface.OnClickListener { 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 f995097c7..2999cf6f4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -220,58 +220,49 @@ public static Theme fromString(String color) { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }}; - private int mColor; - private int mActiveColor; - private int mBackgroundColor; - private Theme mTheme; - - private int mTextOnColorPrimary; - private int mTextOnColorSecondary; - private int mTextOnBackgroundPrimary; - private int mtextOnBackgroundSecondary; - private int mSentBubbleRes; - private int mSentBubbleAltRes; - private boolean mSentBubbleColored; - private int mReceivedBubbleRes; - private int mReceivedBubbleAltRes; - private boolean mReceivedBubbleColored; - private Drawable mRippleBackground; - - private Resources mResources; - private SharedPreferences mPrefs; - - private boolean mStatusTintEnabled = false; - private boolean mNavigationTintEnabled = false; - - private QKActivity mActivity; - private Context mContext; - private Window mWindow; - - private static ThemeManager sInstance; - - public static ThemeManager getInstance() { - if (sInstance == null) { - sInstance = new ThemeManager(); - } - - return sInstance; - } - - private ThemeManager() { + private static int mColor; + private static int mActiveColor; + private static int mBackgroundColor; + private static Theme mTheme; + + private static int mTextOnColorPrimary; + private static int mTextOnColorSecondary; + private static int mTextOnBackgroundPrimary; + private static int mtextOnBackgroundSecondary; + private static int mSentBubbleRes; + private static int mSentBubbleAltRes; + private static boolean mSentBubbleColored; + private static int mReceivedBubbleRes; + private static int mReceivedBubbleAltRes; + private static boolean mReceivedBubbleColored; + private static Drawable mRippleBackground; + + private static Resources mResources; + private static SharedPreferences mPrefs; + + private static boolean mStatusTintEnabled = false; + private static boolean mNavigationTintEnabled = false; + + private static QKActivity mActivity; + private static Context mContext; + private static Window mWindow; + + public static void init(Context context) { + mContext = context; + mPrefs = PreferenceManager.getDefaultSharedPreferences(context); + mResources = context.getResources(); } /** * Loads all theme properties. Should be called during onCreate * of each activity that contains fragments that use ThemeManager */ - public void loadThemeProperties(Context context) { - mPrefs = PreferenceManager.getDefaultSharedPreferences(context); - mResources = context.getResources(); + public static void loadThemeProperties(Context context) { mContext = context; - mColor = Integer.parseInt(mPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.getInstance().DEFAULT_COLOR)); + mColor = Integer.parseInt(mPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.DEFAULT_COLOR)); mActiveColor = mColor; if (context instanceof QKActivity) { @@ -296,7 +287,7 @@ public void loadThemeProperties(Context context) { } - public void setTheme(Theme theme) { + public static void setTheme(Theme theme) { int startColor = mBackgroundColor; initializeTheme(theme); int endColor = mBackgroundColor; @@ -343,7 +334,7 @@ public void onAnimationEnd(Animator animation) { } } - public void initializeTheme(Theme theme) { + public static void initializeTheme(Theme theme) { mTheme = theme; switch (theme) { @@ -406,7 +397,7 @@ public void initializeTheme(Theme theme) { } } - public void setIcon(final QKActivity context) { + public static void setIcon(final QKActivity context) { new QKDialog() .setContext(context) .setTitle(R.string.update_icon_title) @@ -459,66 +450,66 @@ public void setIcon(final QKActivity context) { .show(); } - public int getBackgroundColor() { + public static int getBackgroundColor() { return mBackgroundColor; } - public int getTextOnColorPrimary() { + public static int getTextOnColorPrimary() { return mTextOnColorPrimary; } - public int getTextOnColorSecondary() { + public static int getTextOnColorSecondary() { return mTextOnColorSecondary; } - public int getTextOnBackgroundPrimary() { + public static int getTextOnBackgroundPrimary() { return mTextOnBackgroundPrimary; } - public int getTextOnBackgroundSecondary() { + public static int getTextOnBackgroundSecondary() { return mtextOnBackgroundSecondary; } - public int getSentBubbleRes() { + public static int getSentBubbleRes() { return mSentBubbleRes; } - public int getSentBubbleAltRes() { + public static int getSentBubbleAltRes() { return mSentBubbleAltRes; } - public int getSentBubbleColor() { + public static int getSentBubbleColor() { return mSentBubbleColored ? mActiveColor : getNeutralBubbleColor(); } - public int getReceivedBubbleRes() { + public static int getReceivedBubbleRes() { return mReceivedBubbleRes; } - public int getReceivedBubbleAltRes() { + public static int getReceivedBubbleAltRes() { return mReceivedBubbleAltRes; } - public int getReceivedBubbleColor() { + public static int getReceivedBubbleColor() { return mReceivedBubbleColored ? mActiveColor : getNeutralBubbleColor(); } - public void setBubbleStyleNew(boolean styleNew) { + public static void setBubbleStyleNew(boolean styleNew) { mSentBubbleRes = styleNew ? R.drawable.message_sent_2 : R.drawable.message_sent; mSentBubbleAltRes = styleNew ? R.drawable.message_sent_alt_2 : R.drawable.message_sent_alt; mReceivedBubbleRes = styleNew ? R.drawable.message_received_2 : R.drawable.message_received; mReceivedBubbleAltRes = styleNew ? R.drawable.message_received_alt_2 : R.drawable.message_received_alt; } - public void setSentBubbleColored(boolean colored) { + public static void setSentBubbleColored(boolean colored) { mSentBubbleColored = colored; } - public void setReceivedBubbleColored(boolean colored) { + public static void setReceivedBubbleColored(boolean colored) { mReceivedBubbleColored = colored; } - public int getNeutralBubbleColor() { + public static int getNeutralBubbleColor() { if (mTheme == null) { return 0xeeeeee; } @@ -538,27 +529,27 @@ public int getNeutralBubbleColor() { } } - public Drawable getRippleBackground() { + public static Drawable getRippleBackground() { return mRippleBackground; } - public int getColor() { + public static int getColor() { return mActiveColor; } - public int getThemeColor() { + public static int getThemeColor() { return mColor; } - public Theme getTheme() { + public static Theme getTheme() { return mTheme; } - public boolean isNightMode() { + public static boolean isNightMode() { return mTheme == Theme.GREY || mTheme == Theme.BLACK; } - public void showColourSwatchesDialog(final QKActivity context) { + public static void showColourSwatchesDialog(final QKActivity context) { final QKDialog dialog = new QKDialog(); ColorPickerPalette palette = new ColorPickerPalette(context); @@ -578,7 +569,7 @@ public void showColourSwatchesDialog(final QKActivity context) { dialog.show(); } - private void showColourPickerDialog(final QKActivity context, int swatchColour) { + private static void showColourPickerDialog(final QKActivity context, int swatchColour) { final QKDialog dialog = new QKDialog(); ColorPickerPalette palette = new ColorPickerPalette(context); @@ -598,7 +589,7 @@ private void showColourPickerDialog(final QKActivity context, int swatchColour) } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public void setStatusBarTintEnabled(boolean enabled) { + public static void setStatusBarTintEnabled(boolean enabled) { if (mStatusTintEnabled != enabled) { mStatusTintEnabled = enabled; int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; @@ -614,7 +605,7 @@ public void setStatusBarTintEnabled(boolean enabled) { } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public void setNavigationBarTintEnabled(boolean enabled) { + public static void setNavigationBarTintEnabled(boolean enabled) { if (mNavigationTintEnabled != enabled) { mNavigationTintEnabled = enabled; int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; @@ -629,11 +620,11 @@ public void setNavigationBarTintEnabled(boolean enabled) { } } - public String getColorString(int color) { + public static String getColorString(int color) { return String.format("#%08x", color).toUpperCase(); } - public void setColour(int color) { + public static void setColour(int color) { AnalyticsManager.getInstance().sendEvent( AnalyticsManager.CATEGORY_PREFERENCE_CHANGE, @@ -710,7 +701,7 @@ public void onAnimationEnd(Animator animation) { } } - public void setActiveColor(int color) { + public static void setActiveColor(int color) { mActiveColor = color; if (mActivity != null) { @@ -730,7 +721,7 @@ public void setActiveColor(int color) { } } - private boolean isColorDarkEnough(int color) { + private static boolean isColorDarkEnough(int color) { for (int i = 0; i < COLOURS.length; i++) { for (int j = 0; j < COLOURS[i].length; j++) { if (color == COLOURS[i][j]) { @@ -742,7 +733,7 @@ private boolean isColorDarkEnough(int color) { return true; } - public int getSwatchColour(int colour) { + public static int getSwatchColour(int colour) { for (int i = 0; i < COLOURS.length; i++) { for (int j = 0; j < COLOURS[i].length; j++) { if (colour == COLOURS[i][j]) { @@ -754,7 +745,7 @@ public int getSwatchColour(int colour) { return colour; } - private int[] getSwatch(int colour) { + private static int[] getSwatch(int colour) { for (int[] swatch : COLOURS) { for (int swatchColor : swatch) { if (colour == swatchColor) { 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 6e9d4d8d1..c85c31af2 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 @@ -72,7 +72,7 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } - ThemeManager.getInstance().loadThemeProperties(this); + ThemeManager.loadThemeProperties(this); } protected void showBackButton(boolean show) { @@ -173,7 +173,7 @@ public Menu getMenu() { public boolean onPrepareOptionsMenu(Menu menu) { // Save a reference to the menu so that we can quickly access menu icons later. mMenu = menu; - colorMenuIcons(mMenu, ThemeManager.getInstance().getTextOnColorPrimary()); + colorMenuIcons(mMenu, ThemeManager.getTextOnColorPrimary()); return true; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java index 9391c990b..2e45c8080 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java @@ -102,7 +102,7 @@ public void onContentClosed() { public void refresh() { View view = getView(); if (view != null) { - view.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + view.setBackgroundColor(ThemeManager.getBackgroundColor()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java index 17d5d6d7a..e071a7428 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java @@ -37,7 +37,7 @@ public void onDestroy() { @Override public void refresh() { if (getView() != null) { - getView().setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + getView().setBackgroundColor(ThemeManager.getBackgroundColor()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index cd92d99d5..68ba6544b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -29,9 +29,9 @@ protected void onCreate(Bundle savedInstanceState) { setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true)); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); setContentView(getLayoutResource()); - ThemeManager.getInstance().loadThemeProperties(this); + ThemeManager.loadThemeProperties(this); - ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getInstance().getBackgroundColor()); + ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor()); View title = findViewById(R.id.title); if (title != null && title instanceof AppCompatTextView) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index 1ba65cc96..a35bc960c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -80,23 +80,23 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { if (conversation.hasUnreadMessages()) { holder.unreadView.setVisibility(View.VISIBLE); - holder.snippetView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); - holder.dateView.setTextColor(ThemeManager.getInstance().getColor()); + holder.snippetView.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + holder.dateView.setTextColor(ThemeManager.getColor()); } else { holder.unreadView.setVisibility(View.GONE); - holder.snippetView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); - holder.dateView.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + holder.snippetView.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); + holder.dateView.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); } if (isInMultiSelectMode()) { holder.mSelected.setVisibility(View.VISIBLE); if (isSelected(conversation.getThreadId())) { holder.mSelected.setImageResource(R.drawable.ic_selected); - holder.mSelected.setColorFilter(ThemeManager.getInstance().getColor()); + holder.mSelected.setColorFilter(ThemeManager.getColor()); holder.mSelected.setAlpha(1f); } else { holder.mSelected.setImageResource(R.drawable.ic_unselected); - holder.mSelected.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + holder.mSelected.setColorFilter(ThemeManager.getTextOnBackgroundSecondary()); holder.mSelected.setAlpha(0.5f); } } else { @@ -127,9 +127,9 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { @Override public void refresh() { - mMuted.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); - mUnread.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); - mError.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); notifyDataSetChanged(); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index 0a096747c..f9608d2a5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -88,16 +88,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View view = inflater.inflate(R.layout.fragment_conversations, null); ButterKnife.bind(this, view); - mEmptyStateIcon.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); - mFab.setColorNormal(ThemeManager.getInstance().getColor()); - mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getInstance().getColor())); + mFab.setColorNormal(ThemeManager.getColor()); + mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); mFab.attachToRecyclerView(mRecyclerView); - mFab.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary()); + mFab.setColorFilter(ThemeManager.getTextOnColorPrimary()); mFab.setOnClickListener(v -> { if (mAdapter.isInMultiSelectMode()) { mAdapter.disableMultiSelectMode(true); @@ -307,11 +307,11 @@ public void refresh() { return; } - mFab.setColorNormal(ThemeManager.getInstance().getColor()); - mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getInstance().getColor())); - mFab.getDrawable().setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mFab.setColorNormal(ThemeManager.getColor()); + mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); + mFab.getDrawable().setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mEmptyStateIcon.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java index dbcd63d0f..ae2a95197 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListViewHolder.java @@ -110,7 +110,7 @@ private CharSequence formatMessage(Conversation conversation, ConversationLegacy buf.append(mContext.getResources().getString(R.string.draft_separator)); int before = buf.length(); buf.append(mContext.getResources().getString(R.string.has_draft)); - buf.setSpan(new ForegroundColorSpan(ThemeManager.getInstance().getColor()), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + buf.setSpan(new ForegroundColorSpan(ThemeManager.getColor()), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } return buf; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java index f60505cf2..eea273196 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java @@ -27,24 +27,24 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { View view = mContext.getLayoutInflater().inflate(R.layout.dialog_bubbles, null); final QKTextView in1 = (QKTextView) view.findViewById(R.id.in_1); - in1.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleRes()); - in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + in1.setBackgroundResource(ThemeManager.getReceivedBubbleRes()); + in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); final QKTextView in2 = (QKTextView) view.findViewById(R.id.in_2); - in2.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleAltRes()); - in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + in2.setBackgroundResource(ThemeManager.getReceivedBubbleAltRes()); + in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); final QKTextView out1 = (QKTextView) view.findViewById(R.id.out_1); - out1.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); - out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + out1.setBackgroundResource(ThemeManager.getSentBubbleRes()); + out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); final QKTextView out2 = (QKTextView) view.findViewById(R.id.out_2); - out2.setBackgroundResource(ThemeManager.getInstance().getSentBubbleAltRes()); - out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + out2.setBackgroundResource(ThemeManager.getSentBubbleAltRes()); + out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); Preference.OnPreferenceClickListener onPreferenceClickListener = new Preference.OnPreferenceClickListener() { @Override @@ -52,38 +52,38 @@ public boolean onPreferenceClick(Preference preference) { Log.d(TAG, preference.getKey()); switch (preference.getKey()) { case SettingsFragment.BUBBLES_NEW: - ThemeManager.getInstance().setBubbleStyleNew(((QKSwitchPreference) preference).isChecked()); - in1.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleRes()); - in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); - - in2.setBackgroundResource(ThemeManager.getInstance().getReceivedBubbleAltRes()); - in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); - - out1.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); - out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); - - out2.setBackgroundResource(ThemeManager.getInstance().getSentBubbleAltRes()); - out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + ThemeManager.setBubbleStyleNew(((QKSwitchPreference) preference).isChecked()); + in1.setBackgroundResource(ThemeManager.getReceivedBubbleRes()); + in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + + in2.setBackgroundResource(ThemeManager.getReceivedBubbleAltRes()); + in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + + out1.setBackgroundResource(ThemeManager.getSentBubbleRes()); + out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + + out2.setBackgroundResource(ThemeManager.getSentBubbleAltRes()); + out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); return true; case SettingsFragment.COLOUR_RECEIVED: - ThemeManager.getInstance().setReceivedBubbleColored(((QKSwitchPreference) preference).isChecked()); - in1.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in1.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); - in2.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); - in2.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() == ThemeManager.getInstance().getColor()); + ThemeManager.setReceivedBubbleColored(((QKSwitchPreference) preference).isChecked()); + in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); + in2.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); return true; case SettingsFragment.COLOUR_SENT: - ThemeManager.getInstance().setSentBubbleColored(((QKSwitchPreference) preference).isChecked()); - out1.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out1.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); - out2.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); - out2.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() == ThemeManager.getInstance().getColor()); + ThemeManager.setSentBubbleColored(((QKSwitchPreference) preference).isChecked()); + out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); + out2.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); return true; } return false; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java index f6969807c..0f92a9f3d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/DefaultSmsHelper.java @@ -45,7 +45,7 @@ public void showIfNotDefault(ViewGroup viewGroup) { .type(getSnackBarType()) .text(mMessage) .duration(duration) - .actionColor(ThemeManager.getInstance().getColor()) + .actionColor(ThemeManager.getColor()) .actionLabel(R.string.upgrade_now) .actionListener(this); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java index c5fa15d79..69d85eed0 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/QKDialog.java @@ -130,7 +130,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive); mPositiveButtonView.setVisibility(View.VISIBLE); mPositiveButtonView.setText(mPositiveButtonText); - mPositiveButtonView.setTextColor(ThemeManager.getInstance().getColor()); + mPositiveButtonView.setTextColor(ThemeManager.getColor()); mPositiveButtonView.setOnClickListener(mPositiveButtonClickListener); } @@ -443,11 +443,11 @@ public View getView(int position, View convertView, ViewGroup parent) { } QKTextView title = (QKTextView) convertView.findViewById(R.id.list_item_title); - title.setTextColor(ThemeManager.getInstance().getColor()); + title.setTextColor(ThemeManager.getColor()); title.setText(getItem(position).title); QKTextView subtitle = (QKTextView) convertView.findViewById(R.id.list_item_subtitle); - subtitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + subtitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); subtitle.setText(getItem(position).subtitle); ((QKTextView) convertView.findViewById(R.id.list_item_body)) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java index 399ed3615..97d28454e 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/mms/MMSDialogFragment.java @@ -190,7 +190,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive); mPositiveButtonView.setVisibility(View.VISIBLE); mPositiveButtonView.setText(mPositiveButtonText); - mPositiveButtonView.setTextColor(ThemeManager.getInstance().getColor()); + mPositiveButtonView.setTextColor(ThemeManager.getColor()); mPositiveButtonView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -465,11 +465,11 @@ public View getView(int position, View convertView, ViewGroup parent) { } QKTextView title = (QKTextView) convertView.findViewById(R.id.list_item_title); - title.setTextColor(ThemeManager.getInstance().getColor()); + title.setTextColor(ThemeManager.getColor()); title.setText(getItem(position).title); QKTextView subtitle = (QKTextView) convertView.findViewById(R.id.list_item_subtitle); - subtitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + subtitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); subtitle.setText(getItem(position).subtitle); ((QKTextView) convertView.findViewById(R.id.list_item_body)) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java index 1e61b7e67..0a8bd56a1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java @@ -136,10 +136,10 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { if (sent) { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getInstance().getSentBubbleColor() != ThemeManager.getInstance().getNeutralBubbleColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getSentBubbleColor() != ThemeManager.getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); - holder.mDeliveredIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - holder.mLockedIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); // set up avatar holder.mAvatarView.setImageDrawable(Contact.getMe(true).getAvatar(mContext, null)); @@ -151,10 +151,10 @@ private MessageListViewHolder setupViewHolder(View view, boolean sent) { } } else { // set up colors - holder.mBodyTextView.setOnColorBackground(ThemeManager.getInstance().getReceivedBubbleColor() != ThemeManager.getInstance().getNeutralBubbleColor()); + holder.mBodyTextView.setOnColorBackground(ThemeManager.getReceivedBubbleColor() != ThemeManager.getNeutralBubbleColor()); holder.mDateView.setOnColorBackground(false); - holder.mDeliveredIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - holder.mLockedIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mDeliveredIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + holder.mLockedIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); // set up avatar if (mPrefs.getBoolean(SettingsFragment.HIDE_AVATAR_RECEIVED, false)) { @@ -308,15 +308,15 @@ private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) holder.mDateView.setVisibility(showTimestamp ? View.VISIBLE : View.GONE); holder.mSpace.setVisibility(showAvatar ? View.VISIBLE : View.GONE); - holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getInstance().getSentBubbleRes() : - ThemeManager.getInstance().getReceivedBubbleRes()) : (messageItem.isMe() ? - ThemeManager.getInstance().getSentBubbleAltRes() : ThemeManager.getInstance().getReceivedBubbleAltRes())); + holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getSentBubbleRes() : + ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ? + ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes())); holder.setLiveViewCallback(() -> { if (messageItem.isMe()) { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getInstance().getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); } else { - holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getInstance().getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); + holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); } }); holder.refresh(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 02bf35bd9..2bf8667a1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -762,7 +762,7 @@ public void onContentOpened() { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } - ThemeManager.getInstance().setActiveColor(mConversationPrefs.getColor()); + ThemeManager.setActiveColor(mConversationPrefs.getColor()); } @Override @@ -787,14 +787,14 @@ public void onContentClosed() { } } - ThemeManager.getInstance().setActiveColor(ThemeManager.getInstance().getThemeColor()); + ThemeManager.setActiveColor(ThemeManager.getThemeColor()); } @Override public void onMenuChanging(float percentOpen) { if (mConversationPrefs != null) { - ThemeManager.getInstance().setActiveColor((int) mArgbEvaluator.evaluate( - percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getInstance().getThemeColor())); + ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( + percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor())); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 40aefef00..ea1fc0eb1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -381,7 +381,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { String valueString = newValue == null ? "null" : newValue.toString(); if (key.equals(NOTIFICATION_LED_COLOR)) { // Format the color as a nice string if it's the LED color. - valueString = ThemeManager.getInstance().getColorString(Integer.parseInt(valueString)); + valueString = ThemeManager.getColorString(Integer.parseInt(valueString)); } Log.d(TAG, "onPreferenceChange key:" + key + " newValue: " + valueString); @@ -393,13 +393,13 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { switch (key) { case BACKGROUND: - ThemeManager.getInstance().setTheme(ThemeManager.Theme.fromString((String) newValue)); + ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); break; case STATUS_TINT: - ThemeManager.getInstance().setStatusBarTintEnabled((Boolean) newValue); + ThemeManager.setStatusBarTintEnabled((Boolean) newValue); break; case NAVIGATION_TINT: - ThemeManager.getInstance().setNavigationBarTintEnabled((Boolean) newValue); + ThemeManager.setNavigationBarTintEnabled((Boolean) newValue); break; case FONT_FAMILY: preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); @@ -412,10 +412,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); break; case COLOUR_SENT: - ThemeManager.getInstance().setSentBubbleColored((Boolean) newValue); + ThemeManager.setSentBubbleColored((Boolean) newValue); break; case COLOUR_RECEIVED: - ThemeManager.getInstance().setReceivedBubbleColored((Boolean) newValue); + ThemeManager.setReceivedBubbleColored((Boolean) newValue); break; case NIGHT_AUTO: updateAlarmManager(mContext, (Boolean) newValue); @@ -519,13 +519,13 @@ public boolean onPreferenceClick(Preference preference) { switch (key) { case THEME: - ThemeManager.getInstance().showColourSwatchesDialog(mContext); + ThemeManager.showColourSwatchesDialog(mContext); break; case BUBBLES: new BubblePreferenceDialog().setContext(mContext).show(); break; case ICON: - ThemeManager.getInstance().setIcon(mContext); + ThemeManager.setIcon(mContext); break; case BLOCKED_FUTURE: BlockedNumberDialog.showDialog(mContext); @@ -701,7 +701,7 @@ public void refresh() { View view = getView(); if (view != null) { - view.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + view.setBackgroundColor(ThemeManager.getBackgroundColor()); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java index 75f9e3477..3ddb31a1d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java @@ -61,8 +61,8 @@ public void refresh() { FontManager.getFontWeight(mContext, false))); setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); - setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); if (mAdapter != null) { SharedPreferences prefs = mContext.getPrefs(); 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 c3537b0e6..7e5486bb1 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 @@ -261,7 +261,7 @@ private void setImageWhenReady() { getBackground().setColorFilter(0x00000000, PorterDuff.Mode.SRC_ATOP); } else { super.setImageDrawable(TextUtils.isEmpty(mInitial) ? mDefaultDrawable : null); - getBackground().setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); } } } @@ -279,13 +279,13 @@ protected void onDraw(Canvas canvas) { @Override public void refresh() { - mPaint.setColor(ThemeManager.getInstance().getTextOnColorPrimary()); - mDefaultDrawable.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mPaint.setColor(ThemeManager.getTextOnColorPrimary()); + mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); if (getBackground() == null) { setBackgroundResource(R.drawable.circle); } - getBackground().setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); } private class QueryHandler extends AsyncQueryHandler { 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 302800ed7..2e1ee6405 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 @@ -951,24 +951,24 @@ public void run() { @Override public void refresh() { - mButtonBackground.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); - mButtonBar1.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mButtonBar2.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mAttachmentPanel.setBackgroundColor(ThemeManager.getInstance().getColor()); - mAttach.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mCamera.setColorFilter(ThemeManager.getInstance().getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); + mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); updateDelayButton(); - mProgress.setUnfinishedStrokeColor(ThemeManager.getInstance().getTextOnColorSecondary()); - mProgress.setFinishedStrokeColor(ThemeManager.getInstance().getTextOnColorPrimary()); - if (ThemeManager.getInstance().getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getInstance().getSentBubbleRes()); - mReplyText.getBackground().setColorFilter(ThemeManager.getInstance().getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); + mProgress.setUnfinishedStrokeColor(ThemeManager.getTextOnColorSecondary()); + mProgress.setFinishedStrokeColor(ThemeManager.getTextOnColorPrimary()); + if (ThemeManager.getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getSentBubbleRes()); + mReplyText.getBackground().setColorFilter(ThemeManager.getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); mReplyText.refresh(); - getBackground().setColorFilter(ThemeManager.getInstance().getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); } private void updateDelayButton() { mDelay.setColorFilter(mDelayedMessagingEnabled ? - ThemeManager.getInstance().getTextOnColorPrimary() : ThemeManager.getInstance().getTextOnColorSecondary(), + ThemeManager.getTextOnColorPrimary() : ThemeManager.getTextOnColorSecondary(), PorterDuff.Mode.SRC_ATOP); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java index f5dfdb786..5b2ff0cc9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java @@ -99,8 +99,8 @@ public void refresh() { int fontWeight = FontManager.getFontWeight(mContext, false); setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight )); - setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); // Text size int sp = FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java index db4f0165a..911b8d252 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java @@ -44,7 +44,7 @@ public void setImageDrawable(Drawable drawable) { mDrawable = drawable; if (mDrawable != null) { - mDrawable.setColorFilter(ThemeManager.getInstance().getColor(), PorterDuff.Mode.SRC_ATOP); + mDrawable.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); super.setImageDrawable(drawable); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java index e6039ff84..134629b0f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java @@ -50,16 +50,16 @@ private ColorStateList getSwitchThumbColorStateList() { // Disabled state states[0] = new int[]{-android.R.attr.state_enabled}; - colors[0] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? + colors[0] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_thumb_disabled_dark : R.color.switch_thumb_disabled_light); // Checked state states[1] = new int[]{android.R.attr.state_checked}; - colors[1] = ThemeManager.getInstance().getColor(); + colors[1] = ThemeManager.getColor(); // Unchecked enabled state state states[2] = new int[0]; - colors[2] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? + colors[2] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_thumb_enabled_dark : R.color.switch_thumb_enabled_light); return new ColorStateList(states, colors); @@ -71,19 +71,19 @@ private ColorStateList getSwitchTrackColorStateList() { // Disabled state states[0] = new int[]{-android.R.attr.state_enabled}; - colors[0] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? + colors[0] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_track_disabled_dark : R.color.switch_track_disabled_light); // Checked state states[1] = new int[]{android.R.attr.state_checked}; colors[1] = Color.argb(0x4D, // 30% alpha - Color.red(ThemeManager.getInstance().getColor()), - Color.green(ThemeManager.getInstance().getColor()), - Color.blue(ThemeManager.getInstance().getColor())); + Color.red(ThemeManager.getColor()), + Color.green(ThemeManager.getColor()), + Color.blue(ThemeManager.getColor())); // Unchecked enabled state state states[2] = new int[0]; - colors[2] = mRes.getColor(ThemeManager.getInstance().isNightMode() ? + colors[2] = mRes.getColor(ThemeManager.isNightMode() ? R.color.switch_track_enabled_dark : R.color.switch_track_enabled_light); return new ColorStateList(states, colors); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java index 1833f1bab..43956443a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java @@ -106,19 +106,19 @@ public void setOnColorBackground(boolean onColorBackground) { if (onColorBackground) { if (mType == FontManager.TEXT_TYPE_PRIMARY) { - setTextColor(ThemeManager.getInstance().getTextOnColorPrimary()); - setLinkTextColor(ThemeManager.getInstance().getTextOnColorPrimary()); + setTextColor(ThemeManager.getTextOnColorPrimary()); + setLinkTextColor(ThemeManager.getTextOnColorPrimary()); } else if (mType == FontManager.TEXT_TYPE_SECONDARY || mType == FontManager.TEXT_TYPE_TERTIARY) { - setTextColor(ThemeManager.getInstance().getTextOnColorSecondary()); + setTextColor(ThemeManager.getTextOnColorSecondary()); } } else { if (mType == FontManager.TEXT_TYPE_PRIMARY) { - setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); - setLinkTextColor(ThemeManager.getInstance().getColor()); + setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + setLinkTextColor(ThemeManager.getColor()); } else if (mType == FontManager.TEXT_TYPE_SECONDARY || mType == FontManager.TEXT_TYPE_TERTIARY) { - setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + setTextColor(ThemeManager.getTextOnBackgroundSecondary()); } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java index a6883c951..140653a94 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java @@ -58,7 +58,7 @@ protected void onFinishInflate() { super.onFinishInflate(); mFavoritesBackground = (LinearLayout) findViewById(R.id.starred_contacts); - mFavoritesBackground.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); mTitle = (QKTextView) findViewById(R.id.title); @@ -154,13 +154,13 @@ public void toggle() { } public void expand() { - mTitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundPrimary()); + mTitle.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); mFavorites.setVisibility(View.VISIBLE); mIndicator.setRotation(0f); } public void collapse() { - mTitle.setTextColor(ThemeManager.getInstance().getTextOnBackgroundSecondary()); + mTitle.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); mFavorites.setVisibility(View.GONE); mIndicator.setRotation(90f); } @@ -176,7 +176,7 @@ public void onClick(View v) { @Override public void refresh() { - mIndicator.setColorFilter(ThemeManager.getInstance().getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - mFavoritesBackground.setBackgroundColor(ThemeManager.getInstance().getBackgroundColor()); + mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java index 67ebc5ded..e0291733b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { getSupportActionBar().hide(); mBackground = findViewById(R.id.welcome); - mBackground.setBackgroundColor(ThemeManager.getInstance().getColor()); + mBackground.setBackgroundColor(ThemeManager.getColor()); mPrevious = (ImageView) findViewById(R.id.welcome_previous); mPrevious.setOnClickListener(this); @@ -63,8 +63,8 @@ protected void onCreate(Bundle savedInstanceState) { } public void setColor(int color) { - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ThemeManager.getInstance().getColor(), color); - colorAnimation.setDuration(ThemeManager.getInstance().TRANSITION_LENGTH); + ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ThemeManager.getColor(), color); + colorAnimation.setDuration(ThemeManager.TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override @@ -74,7 +74,7 @@ public void onAnimationUpdate(ValueAnimator animation) { }); colorAnimation.start(); - ThemeManager.getInstance().setColour(color); + ThemeManager.setColour(color); } public void setColorBackground(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java index 2ca8e2143..870bf6cd5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java @@ -43,8 +43,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onScrollOffsetChanged(WelcomeActivity activity, float offset) { - int colorBackground = (Integer) mArgbEvaluator.evaluate(Math.abs(offset), ThemeManager.getInstance().getBackgroundColor(), ThemeManager.getInstance().getColor()); - int colorAccent = (Integer) mArgbEvaluator.evaluate(1 - Math.abs(offset), 0xFFFFFFFF, ThemeManager.getInstance().getColor()); + int colorBackground = (Integer) mArgbEvaluator.evaluate(Math.abs(offset), ThemeManager.getBackgroundColor(), ThemeManager.getColor()); + int colorAccent = (Integer) mArgbEvaluator.evaluate(1 - Math.abs(offset), 0xFFFFFFFF, ThemeManager.getColor()); activity.setColorBackground(colorBackground); activity.tintIndicators(colorAccent); @@ -66,14 +66,14 @@ public void onScrollOffsetChanged(WelcomeActivity activity, float offset) { @Override public void onClick(View v) { if (v.getId() == R.id.welcome_night_hint) { - boolean night = ThemeManager.getInstance().getTheme() == ThemeManager.Theme.OFFWHITE; + boolean night = ThemeManager.getTheme() == ThemeManager.Theme.OFFWHITE; int backgroundColor = mContext.getResources().getColor(night ? R.color.grey_light_mega_ultra : R.color.grey_material); int newBackgroundColor = mContext.getResources().getColor(night ? R.color.grey_material : R.color.grey_light_mega_ultra); - ThemeManager.getInstance().setTheme(night ? ThemeManager.Theme.GREY : ThemeManager.Theme.OFFWHITE); + ThemeManager.setTheme(night ? ThemeManager.Theme.GREY : ThemeManager.Theme.OFFWHITE); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), backgroundColor, newBackgroundColor); - colorAnimation.setDuration(ThemeManager.getInstance().TRANSITION_LENGTH); + colorAnimation.setDuration(ThemeManager.TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java index 2fed97389..8001682df 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeThemeFragment.java @@ -21,7 +21,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mPallette = (ColorPickerPalette) view.findViewById(R.id.welcome_themes); mPallette.init(19, 4, this); - mPallette.drawPalette(ThemeManager.getInstance().PALETTE, ThemeManager.getInstance().getColor()); + mPallette.drawPalette(ThemeManager.PALETTE, ThemeManager.getColor()); return view; } @@ -29,7 +29,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onColorSelected(int color) { ((WelcomeActivity) getActivity()).setColor(color); - mPallette.drawPalette(ThemeManager.getInstance().PALETTE, color); + mPallette.drawPalette(ThemeManager.PALETTE, color); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java index 28a7bda85..85b96b181 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java @@ -45,7 +45,7 @@ public class WidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); - ThemeManager.getInstance().loadThemeProperties(context); + ThemeManager.loadThemeProperties(context); for (int appWidgetId : appWidgetIds) { updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId)); @@ -118,10 +118,10 @@ private static void updateWidget(Context context, int appWidgetId, int smallWidg remoteViews.setRemoteAdapter(R.id.conversation_list, intent); remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.title_conversation_list)); - remoteViews.setTextColor(R.id.widget_label, ThemeManager.getInstance().getTextOnColorPrimary()); + remoteViews.setTextColor(R.id.widget_label, ThemeManager.getTextOnColorPrimary()); - remoteViews.setInt(R.id.conversation_list_background, "setColorFilter", ThemeManager.getInstance().getBackgroundColor()); - remoteViews.setInt(R.id.header_background, "setColorFilter", ThemeManager.getInstance().getColor()); + remoteViews.setInt(R.id.conversation_list_background, "setColorFilter", ThemeManager.getBackgroundColor()); + remoteViews.setInt(R.id.header_background, "setColorFilter", ThemeManager.getColor()); // Open Mms's app conversation list when click on header final Intent convIntent = new Intent(context, MainActivity.class); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java index 8baf62ff2..cbfdbe54e 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java @@ -224,9 +224,9 @@ private void bindAvatar(RemoteViews remoteViews, Conversation conversation) { } private void bindIndicators(RemoteViews remoteViews, Conversation conversation) { - remoteViews.setInt(R.id.muted, "setColorFilter", ThemeManager.getInstance().getColor()); - remoteViews.setInt(R.id.error, "setColorFilter", ThemeManager.getInstance().getColor()); - remoteViews.setInt(R.id.unread, "setColorFilter", ThemeManager.getInstance().getColor()); + remoteViews.setInt(R.id.muted, "setColorFilter", ThemeManager.getColor()); + remoteViews.setInt(R.id.error, "setColorFilter", ThemeManager.getColor()); + remoteViews.setInt(R.id.unread, "setColorFilter", ThemeManager.getColor()); remoteViews.setViewVisibility(R.id.muted, new ConversationPrefsHelper(mContext, conversation.getThreadId()) .getNotificationsEnabled() ? View.GONE : View.VISIBLE); remoteViews.setViewVisibility(R.id.error, conversation.hasError() ? View.VISIBLE : View.GONE); @@ -234,15 +234,15 @@ private void bindIndicators(RemoteViews remoteViews, Conversation conversation) } private void bindName(RemoteViews remoteViews, Conversation conversation) { - SpannableStringBuilder from = addColor(conversation.getRecipients().formatNames(", "), ThemeManager.getInstance().getTextOnBackgroundPrimary()); + SpannableStringBuilder from = addColor(conversation.getRecipients().formatNames(", "), ThemeManager.getTextOnBackgroundPrimary()); if (conversation.hasDraft()) { from.append(mContext.getResources().getString(R.string.draft_separator)); int before = from.length(); from.append(mContext.getResources().getString(R.string.has_draft)); from.setSpan(new TextAppearanceSpan(mContext, android.R.style.TextAppearance_Small, - ThemeManager.getInstance().getTextOnBackgroundPrimary()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - from.setSpan(new ForegroundColorSpan(ThemeManager.getInstance().getColor()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + ThemeManager.getTextOnBackgroundPrimary()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + from.setSpan(new ForegroundColorSpan(ThemeManager.getColor()), before, from.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } remoteViews.setTextViewText(R.id.name, from); @@ -250,12 +250,12 @@ private void bindName(RemoteViews remoteViews, Conversation conversation) { private void bindDate(RemoteViews remoteViews, Conversation conversation) { remoteViews.setTextViewText(R.id.date, addColor(MessageUtils.formatTimeStampString(mContext, conversation.getDate()), - conversation.hasUnreadMessages() ? ThemeManager.getInstance().getColor() : ThemeManager.getInstance().getTextOnBackgroundSecondary())); + conversation.hasUnreadMessages() ? ThemeManager.getColor() : ThemeManager.getTextOnBackgroundSecondary())); } private void bindSnippet(RemoteViews remoteViews, Conversation conversation) { remoteViews.setTextViewText(R.id.snippet, addColor(conversation.getSnippet(), conversation.hasUnreadMessages() ? - ThemeManager.getInstance().getTextOnBackgroundPrimary() : ThemeManager.getInstance().getTextOnBackgroundSecondary())); + ThemeManager.getTextOnBackgroundPrimary() : ThemeManager.getTextOnBackgroundSecondary())); } /** From f8c9844b00b7c219653248bcfb870132b0ac624e Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 1 Jan 2016 22:58:02 -0500 Subject: [PATCH 20/49] Initialize ThemeManager on startup --- .../QKSMS/receiver/NightModeAutoReceiver.java | 1 - .../java/com/moez/QKSMS/ui/ThemeManager.java | 81 ++++++++----------- .../com/moez/QKSMS/ui/base/QKActivity.java | 2 +- .../moez/QKSMS/ui/base/QKPopupActivity.java | 2 +- .../ui/messagelist/MessageListFragment.java | 6 +- .../QKSMS/ui/welcome/WelcomeActivity.java | 2 +- .../moez/QKSMS/ui/widget/WidgetProvider.java | 2 - 7 files changed, 41 insertions(+), 55 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java index cfcb57589..f997b60bc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java @@ -19,7 +19,6 @@ public class NightModeAutoReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - ThemeManager.loadThemeProperties(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(SettingsFragment.NIGHT_AUTO, false)) { 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 2999cf6f4..8636328bb 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -243,7 +243,6 @@ public static Theme fromString(String color) { private static boolean mStatusTintEnabled = false; private static boolean mNavigationTintEnabled = false; - private static QKActivity mActivity; private static Context mContext; private static Window mWindow; @@ -252,37 +251,30 @@ public static void init(Context context) { mPrefs = PreferenceManager.getDefaultSharedPreferences(context); 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 * of each activity that contains fragments that use ThemeManager */ - public static void loadThemeProperties(Context context) { - - mContext = context; + public static void themeActivity(QKActivity activity) { - 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"))); + activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mColor)); + mWindow = activity.getWindow(); 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; - if (mActivity != null && mStatusTintEnabled) { - if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(mColor)); - } - if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(mColor)); - } + if (mStatusTintEnabled) { + mWindow.setStatusBarColor(ColorUtils.darken(mColor)); + } + if (mNavigationTintEnabled) { + mWindow.setNavigationBarColor(ColorUtils.darken(mColor)); } } @@ -292,11 +284,11 @@ public static void setTheme(Theme theme) { initializeTheme(theme); int endColor = mBackgroundColor; - if (mActivity instanceof MainActivity) { - final View background = mActivity.findViewById(R.id.menu_frame).getRootView(); - final View menu = mActivity.findViewById(R.id.menu_frame); - final View content = mActivity.findViewById(R.id.content_frame); - final View fragment = ((MainActivity) mActivity).getContent().getView(); + if (mContext instanceof MainActivity) { + final View background = ((MainActivity) mContext).findViewById(R.id.menu_frame).getRootView(); + final View menu = ((MainActivity) mContext).findViewById(R.id.menu_frame); + final View content = ((MainActivity) mContext).findViewById(R.id.content_frame); + final View fragment = ((MainActivity) mContext).getContent().getView(); if (startColor != endColor) { ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); @@ -366,18 +358,18 @@ public static void initializeTheme(Theme theme) { 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) { + /*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) { + /*if (mActivity != null) { mActivity.getToolbar().setPopupTheme(R.style.PopupTheme); - } + }*/ break; } @@ -390,11 +382,11 @@ public static void initializeTheme(Theme theme) { setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); 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, // 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) { @@ -575,7 +567,7 @@ private static void showColourPickerDialog(final QKActivity context, int swatchC ColorPickerPalette palette = new ColorPickerPalette(context); palette.setGravity(Gravity.CENTER); palette.init(getSwatch(swatchColour).length, 4, color -> { - setColour(color); + setColour(context, color); dialog.dismiss(); }); @@ -624,7 +616,7 @@ public static String getColorString(int color) { return String.format("#%08x", color).toUpperCase(); } - public static void setColour(int color) { + public static void setColour(QKActivity activity, int color) { AnalyticsManager.getInstance().sendEvent( AnalyticsManager.CATEGORY_PREFERENCE_CHANGE, @@ -660,10 +652,8 @@ public static void setColour(int color) { colorAnimation.addUpdateListener(animation -> { int color1 = (Integer) animation.getAnimatedValue(); - if (mActivity != null) { - if (mActivity.getSupportActionBar() != null) { - mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color1)); - } + if (activity.getSupportActionBar() != null) { + activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color1)); } if (mStatusTintEnabled) { @@ -683,9 +673,9 @@ public void onAnimationEnd(Animator animation) { 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 QKTextView title = (QKTextView) mActivity.findViewById(R.id.toolbar_title); + final QKTextView title = (QKTextView) activity.findViewById(R.id.toolbar_title); if (title.getCurrentTextColor() != mTextOnColorPrimary) { ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), title.getCurrentTextColor(), mTextOnColorPrimary); @@ -694,21 +684,20 @@ public void onAnimationEnd(Animator animation) { titleColorAnimation.addUpdateListener(animation -> { int color1 = (Integer) animation.getAnimatedValue(); title.setTextColor(color1); - mActivity.colorMenuIcons(mActivity.getMenu(), color1); + activity.colorMenuIcons(activity.getMenu(), color1); }); titleColorAnimation.start(); } } } - public static void setActiveColor(int color) { + public static void setActiveColor(QKActivity activity, int color) { mActiveColor = color; - if (mActivity != null) { - if (mActivity.getSupportActionBar() != null) { - mActivity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(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 c85c31af2..d1cdd1eb6 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 @@ -72,7 +72,7 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } - ThemeManager.loadThemeProperties(this); + ThemeManager.themeActivity(this); } protected void showBackButton(boolean show) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index 68ba6544b..59dc4bed8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) { setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true)); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); setContentView(getLayoutResource()); - ThemeManager.loadThemeProperties(this); + ThemeManager.themeActivity(this); ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor()); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 2bf8667a1..98724d37a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -762,7 +762,7 @@ public void onContentOpened() { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } - ThemeManager.setActiveColor(mConversationPrefs.getColor()); + ThemeManager.setActiveColor(mContext, mConversationPrefs.getColor()); } @Override @@ -787,13 +787,13 @@ public void onContentClosed() { } } - ThemeManager.setActiveColor(ThemeManager.getThemeColor()); + ThemeManager.setActiveColor(mContext, ThemeManager.getThemeColor()); } @Override public void onMenuChanging(float percentOpen) { if (mConversationPrefs != null) { - ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( + ThemeManager.setActiveColor(mContext, (int) mArgbEvaluator.evaluate( percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor())); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java index e0291733b..be12acb54 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java @@ -74,7 +74,7 @@ public void onAnimationUpdate(ValueAnimator animation) { }); colorAnimation.start(); - ThemeManager.setColour(color); + ThemeManager.setColour(this, color); } public void setColorBackground(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java index 85b96b181..8aa61dee5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetProvider.java @@ -45,8 +45,6 @@ public class WidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); - ThemeManager.loadThemeProperties(context); - for (int appWidgetId : appWidgetIds) { updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId)); } From 12a385b8aab57d75428a5a7e9e8187fb1dedd277 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sat, 2 Jan 2016 01:43:14 -0500 Subject: [PATCH 21/49] Rewrote LiveViewManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Essentially now you’ll be registering blocks of code, rather than views. Significant performance and code quality improvements --- .../moez/QKSMS/common/LiveViewManager.java | 176 +++++++----------- .../com/moez/QKSMS/interfaces/LiveView.java | 5 +- .../java/com/moez/QKSMS/ui/MainActivity.java | 24 +-- .../java/com/moez/QKSMS/ui/ThemeManager.java | 20 +- .../moez/QKSMS/ui/base/QKContentFragment.java | 27 +-- .../com/moez/QKSMS/ui/base/QKFragment.java | 25 ++- .../ConversationListAdapter.java | 22 +-- .../ConversationListFragment.java | 31 ++- ...onversationNotificationSettingsDialog.java | 1 - .../ui/messagelist/MessageListAdapter.java | 8 +- .../ui/messagelist/MessageListViewHolder.java | 24 +-- .../moez/QKSMS/ui/popup/QKReplyActivity.java | 1 - .../QKSMS/ui/settings/SettingsFragment.java | 32 +--- .../ui/view/AutoCompleteContactView.java | 46 ++--- .../com/moez/QKSMS/ui/view/AvatarView.java | 27 +-- .../com/moez/QKSMS/ui/view/ComposeView.java | 42 ++--- .../com/moez/QKSMS/ui/view/QKEditText.java | 51 ++--- .../com/moez/QKSMS/ui/view/QKImageView.java | 17 +- .../java/com/moez/QKSMS/ui/view/QKSwitch.java | 21 +-- .../com/moez/QKSMS/ui/view/QKTextView.java | 60 +++--- .../QKSMS/ui/view/StarredContactsView.java | 19 +- .../ui/welcome/WelcomeNightFragment.java | 8 - 22 files changed, 241 insertions(+), 446 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 927a58a5a..c23aa1573 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -3,166 +3,126 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.util.Log; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.interfaces.LiveView; import java.util.Collections; -import java.util.HashSet; +import java.util.HashMap; import java.util.Set; import java.util.WeakHashMap; /** - * Allows LiveViews to register for updates on relevant preferences. + * Allows views to register for updates on preferences + * + * Example: A button may need to know when the theme changes, so it that + * it can change colors accordingly + * + * In order to do this, you can use this class as following: + * LiveViewManager.registerView(QKPreference.THEME, key -> { + * // Change button color + * } + * + * You won't need to initialize the button color in addition to registering it + * in the LiveViewManager, because registering it will trigger a refresh automatically, + * which will initialize it */ public class LiveViewManager implements SharedPreferences.OnSharedPreferenceChangeListener { - - private static final String TAG = "LiveViewManager"; - private static final boolean LOCAL_LOGV = false; + private static final String TAG = "ThemedViewManager"; private static LiveViewManager sInstance; - - private static final Set sSet = Collections.newSetFromMap(new WeakHashMap()); - private static final WeakHashMap> sPrefsMap = new WeakHashMap<>(); + private static final HashMap> sViews = new HashMap<>(); /** - * Private constructor. + * Private constructor */ - private LiveViewManager() {} + private LiveViewManager() { + } - /** - * Initialize a static instance so that we can listen for views. - */ static { sInstance = new LiveViewManager(); } + /** + * Initialize preferences and register a listener for changes + * + * @param context Context + */ public static void init(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.registerOnSharedPreferenceChangeListener(sInstance); } + /** + * Listen for preference changes from the SharedPreferences + * + * @param prefs SharedPreferences instance + * @param key Key of preference that was changed + */ @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { LiveViewManager.refreshViews(key); } /** - * Registers a LiveView for global updates. To get updates for specific preferences, use - * registerPreference. - * @param v - */ - public static void registerView(LiveView v) { - synchronized (sSet) { - sSet.add(v); - } - - synchronized(sPrefsMap) { - // Don't add the view to the prefs map more than once, in case the LiveView has already - // been initalized. - if (!sPrefsMap.containsKey(v)) { - sPrefsMap.put(v, new HashSet()); - } - } - } - - /** - * Unregisters a LiveView for any updates: global, or preference-specific. - * @param v - */ - public static void unregisterView(LiveView v) { - synchronized (sSet) { - sSet.remove(v); - } - - synchronized (sPrefsMap) { - sPrefsMap.remove(v); - } - } - - /** - * Register a LiveView to be notified when this preference is updated. - * Note that you must first register the view, otherwise #refresh() will - * not be called on it + * Convenience method for #registerView(QKPreference, ThemedView) to allow registering a single + * ThemedView to listen for multiple preferences * - * @param v - * @param pref + * @param view The ThemedView + * @param preferences The preferences to listen for */ - public static void registerPreference(LiveView v, String pref) { - synchronized (sPrefsMap) { - Set prefs = sPrefsMap.get(v); - // WeakHashSet: the value might have been removed. - if (prefs != null) { - prefs.add(pref); - } + public static void registerView(LiveView view, QKPreference... preferences) { + for (QKPreference preference : preferences) { + registerView(preference, view); } } /** - * Register a LiveView to be notified when this preference is updated. + * 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 * - * @param v - * @param pref + * @param preference The preference to listen for + * @param view The view */ - public static void unregisterPreference(LiveView v, String pref) { - synchronized (sPrefsMap) { - Set prefs = sPrefsMap.get(v); - // WeakHashSet: the value might have been removed. - if (prefs != null) { - prefs.remove(pref); + public static void registerView(QKPreference preference, LiveView view) { + synchronized (sViews) { + if (sViews.containsKey(preference.getKey())) { + Set views = sViews.get(preference.getKey()); + views.add(view); + } else { + Set set = Collections.newSetFromMap(new WeakHashMap<>()); + set.add(view); + sViews.put(preference.getKey(), set); } } - } - /** - * Refresh all views. - */ - public static void refreshViews() { - synchronized (sSet) { - for (LiveView view : sSet) { - view.refresh(); - } - } + // Fire it off once registered + view.refresh(preference.getKey()); } /** - * Refreshes only the views that are listening for any of the given preferences. - * @param query + * Refresh all views that are registered to listen for updates to the given preference + * Convenience method for #refreshViews(String key) + * + * @param preference The preference */ - public static void refreshViews(String... query) { - Set toRefresh = getViews(query); - - // Refresh those views. - for (LiveView view : toRefresh) { - view.refresh(); - } + public static void refreshViews(QKPreference preference) { + refreshViews(preference.getKey()); } /** - * Returns the set of LiveViews which subscribe to at least one of the given preferences. Can - * be used to build a quick cache of LiveViews for rapid refreshing, i.e. animations. + * Refresh all views that are registered to listen for updates to the given preference + * Convenience method for #refreshViews(String key) * - * @param query - * @return + * @param key The preference key */ - public static Set getViews(String... query) { - // Build a set of the given preferences. - Set querySet = new HashSet<>(); - for (String string : query) { - querySet.add(string); - } + private static void refreshViews(String key) { + Set toRefresh = sViews.get(key); - // Get all the views that have at least one of the changed preferences. - Set result = new HashSet<>(); - synchronized (sPrefsMap) { - for (LiveView view : sPrefsMap.keySet()) { - Set viewPrefs = sPrefsMap.get(view); - if (viewPrefs != null && !Collections.disjoint(querySet, viewPrefs)) { - result.add(view); - } + // Refresh those views. + if (toRefresh != null) { + for (LiveView view : toRefresh) { + view.refresh(key); } } - - if (LOCAL_LOGV) Log.v(TAG, "getViews returned:" + result.size() + " for preferences:" + querySet); - return result; } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/interfaces/LiveView.java b/QKSMS/src/main/java/com/moez/QKSMS/interfaces/LiveView.java index 8755ec255..e9f85de27 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/interfaces/LiveView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/interfaces/LiveView.java @@ -1,8 +1,5 @@ package com.moez.QKSMS.interfaces; -/** - * A simple interface for views that refresh statically for certain actions. - */ public interface LiveView { - public void refresh(); + void refresh(String key); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 2612051a4..e75f97495 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -29,14 +29,14 @@ import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.DonationManager; -import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.QKRateSnack; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.google.DraftCache; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.data.Conversation; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.mmssms.Utils; import com.moez.QKSMS.receiver.IconColorReceiver; import com.moez.QKSMS.transaction.NotificationManager; @@ -61,7 +61,7 @@ import java.util.Collection; -public class MainActivity extends QKActivity implements LiveView, SlidingMenu.SlidingMenuListener { +public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuListener { private final String TAG = "MainActivity"; @@ -122,8 +122,13 @@ public void onCreate(Bundle savedInstanceState) { showDialogIfNeeded(savedInstanceState); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + // Update the background color. This code is important during the welcome screen setup, when the activity + // in the ThemeManager isn't the MainActivity + findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + }); //Adds a small/non intrusive snackbar that asks the user to rate the app SnackEngage.from(this).withSnack(new QKRateSnack().withDuration(BaseSnack.DURATION_LONG)) @@ -644,15 +649,6 @@ public void onClick(View v) { .show(); } - @Override - public void refresh() { - // Update the background color. This code is important during the welcome screen setup, when the activity - // in the ThemeManager isn't the MainActivity - findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); - findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); - findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); - } - public static class DeleteThreadListener implements DialogInterface.OnClickListener { private final Collection mThreadIds; private final Conversation.ConversationQueryHandler mHandler; 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 8636328bb..5747341dc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -26,7 +26,6 @@ import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.receiver.IconColorReceiver; import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.dialog.QKDialog; @@ -35,8 +34,6 @@ import com.moez.QKSMS.ui.view.colorpicker.ColorPickerPalette; import com.moez.QKSMS.ui.widget.WidgetProvider; -import java.util.Set; - public class ThemeManager { private final static String TAG = "ThemeManager"; @@ -306,14 +303,14 @@ public static void setTheme(Theme theme) { @Override public void onAnimationEnd(Animator animation) { // This updates the colors and fonts of all the views. - LiveViewManager.refreshViews(SettingsFragment.BACKGROUND); + LiveViewManager.refreshViews(QKPreference.BACKGROUND); WidgetProvider.notifyThemeChanged(mContext); } }); backgroundAnimation.start(); } else { // This updates the colors and fonts of all the views. - LiveViewManager.refreshViews(SettingsFragment.BACKGROUND); + LiveViewManager.refreshViews(QKPreference.BACKGROUND); background.setBackgroundColor(endColor); menu.setBackgroundColor(endColor); content.setBackgroundColor(endColor); @@ -321,7 +318,7 @@ public void onAnimationEnd(Animator animation) { } } else { // This updates the colors and fonts of all the views. - LiveViewManager.refreshViews(SettingsFragment.BACKGROUND); + LiveViewManager.refreshViews(QKPreference.BACKGROUND); WidgetProvider.notifyThemeChanged(mContext); } } @@ -639,12 +636,7 @@ public static void setColour(QKActivity activity, int color) { // Some views are updated every frame of the animation; get these views here. We // build this list once beforehand since it's a slightly expensive operation. - final Set views = LiveViewManager.getViews(SettingsFragment.THEME); - - // Refresh all the views with the new color. - for (LiveView view : views) { - view.refresh(); - } + LiveViewManager.refreshViews(QKPreference.THEME); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colourFrom, color); colorAnimation.setDuration(TRANSITION_LENGTH); @@ -705,9 +697,7 @@ public static void setActiveColor(QKActivity activity, int color) { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } - for (LiveView view : LiveViewManager.getViews(QKPreference.ACTIVE_THEME.getKey())) { - view.refresh(); - } + LiveViewManager.refreshViews(QKPreference.ACTIVE_THEME); } private static boolean isColorDarkEnough(int color) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java index 2e45c8080..b1135369d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java @@ -1,12 +1,7 @@ package com.moez.QKSMS.ui.base; import android.os.Bundle; -import android.view.View; -import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ContentFragment; -import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; /** * Base class for Fragments. QKSMS uses the recycle pattern as an optimization, and our fragment @@ -22,7 +17,7 @@ * - Manages the current state of the fragment in terms of the animation, i.e. opening, fully * opened, etc. */ -public abstract class QKContentFragment extends QKFragment implements LiveView, ContentFragment { +public abstract class QKContentFragment extends QKFragment implements ContentFragment { /** * It's not strictly necessary, but subclasses should call through to super() in their @@ -60,18 +55,6 @@ public void updateArguments(Bundle args) { onNewArguments(); } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - refresh(); - } - /** * Called when the content is being opened with an animation. */ @@ -97,12 +80,4 @@ public void onContentClosing() { */ public void onContentClosed() { } - - @Override - public void refresh() { - View view = getView(); - if (view != null) { - view.setBackgroundColor(ThemeManager.getBackgroundColor()); - } - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java index e071a7428..8320ab457 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java @@ -3,14 +3,14 @@ import android.app.Activity; import android.app.Fragment; import android.os.Bundle; +import android.view.View; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; import com.squareup.leakcanary.RefWatcher; -public class QKFragment extends Fragment implements LiveView { +public class QKFragment extends Fragment { protected QKActivity mContext; @@ -21,10 +21,14 @@ public void onAttach(Activity activity) { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + if (getView() != null) { + getView().setBackgroundColor(ThemeManager.getBackgroundColor()); + } + }); } @Override @@ -33,11 +37,4 @@ public void onDestroy() { RefWatcher refWatcher = QKSMSApp.getRefWatcher(getActivity()); refWatcher.watch(this); } - - @Override - public void refresh() { - if (getView() != null) { - getView().setBackgroundColor(ThemeManager.getBackgroundColor()); - } - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index a35bc960c..5986c5634 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -11,17 +11,16 @@ import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.emoji.EmojiRegistry; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.DateFormatter; import com.moez.QKSMS.data.Contact; import com.moez.QKSMS.data.Conversation; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.base.RecyclerCursorAdapter; import com.moez.QKSMS.ui.settings.SettingsFragment; -public class ConversationListAdapter extends RecyclerCursorAdapter - implements LiveView { +public class ConversationListAdapter extends RecyclerCursorAdapter { private final SharedPreferences mPrefs; @@ -38,9 +37,12 @@ public ConversationListAdapter(QKActivity context) { mUnread = ContextCompat.getDrawable(context, R.drawable.ic_unread_indicator); mError = ContextCompat.getDrawable(context, R.drawable.ic_error); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); - refresh(); + LiveViewManager.registerView(QKPreference.THEME, key -> { + mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + notifyDataSetChanged(); + }); } protected Conversation getItem(int position) { @@ -124,12 +126,4 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { // Update the avatar and name holder.onUpdate(conversation.getRecipients().size() == 1 ? conversation.getRecipients().get(0) : null); } - - @Override - public void refresh() { - mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - notifyDataSetChanged(); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index f9608d2a5..c7f2a6dce 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -27,10 +27,10 @@ import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.conversationdetails.ConversationDetailsDialog; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.ConversationLegacy; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.ContentFragment; import com.moez.QKSMS.ui.MainActivity; @@ -44,7 +44,7 @@ import java.util.Observer; -public class ConversationListFragment extends QKFragment implements LoaderManager.LoaderCallbacks, LiveView, +public class ConversationListFragment extends QKFragment implements LoaderManager.LoaderCallbacks, RecyclerCursorAdapter.ItemClickListener, RecyclerCursorAdapter.MultiSelectListener, Observer { private final String TAG = "ConversationList"; @@ -79,8 +79,17 @@ public void onCreate(Bundle savedInstanceState) { mLayoutManager = new LinearLayoutManager(mContext); mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager()); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); + LiveViewManager.registerView(QKPreference.THEME, key -> { + if (!mViewHasLoaded) { + return; + } + + mFab.setColorNormal(ThemeManager.getColor()); + mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); + mFab.getDrawable().setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + + mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); + }); } @Override @@ -272,7 +281,6 @@ private void switchFragment(ContentFragment fragment) { @Override public void onDestroy() { super.onDestroy(); - LiveViewManager.unregisterView(this); BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().deleteObserver(this); } @@ -301,19 +309,6 @@ public void onLoaderReset(Loader loader) { } } - @Override - public void refresh() { - if (!mViewHasLoaded) { - return; - } - - mFab.setColorNormal(ThemeManager.getColor()); - mFab.setColorPressed(ColorUtils.lighten(ThemeManager.getColor())); - mFab.getDrawable().setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - - mEmptyStateIcon.setColorFilter(ThemeManager.getTextOnBackgroundPrimary()); - } - @Override public void onMultiSelectStateChanged(boolean enabled) { mContext.invalidateOptionsMenu(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java index 7617a6359..531476b17 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/ConversationNotificationSettingsDialog.java @@ -68,7 +68,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { int padding = Units.dpToPx(getActivity(), 16); QKTextView premiumWarning = new QKTextView(getActivity()); premiumWarning.setLayoutParams(mLayoutParams); - premiumWarning.setType(FontManager.TEXT_TYPE_PRIMARY); premiumWarning.setPadding(padding, padding, padding, padding); LinearLayout list = new LinearLayout(getActivity()); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java index 0a8bd56a1..a59df7ad9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java @@ -14,16 +14,12 @@ import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; -import android.text.style.ClickableSpan; import android.text.style.StyleSpan; -import android.text.style.URLSpan; import android.text.style.UnderlineSpan; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; - import com.android.mms.transaction.Transaction; import com.android.mms.transaction.TransactionBundle; import com.android.mms.transaction.TransactionService; @@ -44,7 +40,6 @@ import com.moez.QKSMS.ui.mms.MmsThumbnailPresenter; import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.AvatarView; - import ezvcard.Ezvcard; import ezvcard.VCard; @@ -312,14 +307,13 @@ private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ? ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes())); - holder.setLiveViewCallback(() -> { + holder.setLiveViewCallback(key -> { if (messageItem.isMe()) { holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); } else { holder.mBodyTextView.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); } }); - holder.refresh(); if (messageItem.isMe() && !mPrefs.getBoolean(SettingsFragment.HIDE_AVATAR_SENT, true)) { holder.mAvatarView.setVisibility(showAvatar ? View.VISIBLE : View.GONE); 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 bacaf5ed7..c032d56d4 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 @@ -13,8 +13,8 @@ import com.moez.QKSMS.common.google.ItemLoadedCallback; import com.moez.QKSMS.common.google.ThumbnailManager; import com.moez.QKSMS.common.preferences.QKPreference; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.interfaces.SlideViewInterface; +import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.base.ClickyViewHolder; import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.mms.Presenter; @@ -23,13 +23,9 @@ import java.util.Map; -public class MessageListViewHolder extends ClickyViewHolder implements SlideViewInterface, LiveView { +public class MessageListViewHolder extends ClickyViewHolder implements SlideViewInterface { private final String TAG = "MessageListViewHolder"; - protected interface LiveViewCallback { - void onRefresh(); - } - // Views protected View mRoot; protected QKTextView mBodyTextView; @@ -51,8 +47,6 @@ protected interface LiveViewCallback { protected ImageLoadedCallback mImageLoadedCallback; protected Presenter mPresenter; - protected LiveViewCallback mLiveViewCallback; - public MessageListViewHolder(QKActivity context, View view) { super(context, view); @@ -65,9 +59,6 @@ public MessageListViewHolder(QKActivity context, View view) { mAvatarView = (AvatarView) view.findViewById(R.id.avatar); mMessageBlock = (LinearLayout) view.findViewById(R.id.message_block); mSpace = view.findViewById(R.id.space); - - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); } protected void showMmsView(boolean visible) { @@ -102,8 +93,8 @@ protected void inflateDownloadControls() { } } - protected void setLiveViewCallback(LiveViewCallback liveViewCallback) { - mLiveViewCallback = liveViewCallback; + protected void setLiveViewCallback(LiveView liveViewCallback) { + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, liveViewCallback); } @Override @@ -225,13 +216,6 @@ public void setVisibility(boolean visible) { } - @Override - public void refresh() { - if (mLiveViewCallback != null) { - mLiveViewCallback.onRefresh(); - } - } - static protected class ImageLoadedCallback implements ItemLoadedCallback { private long mMessageId; private final MessageListViewHolder mListItem; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java index b081a96d1..55987d2d6 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java @@ -72,7 +72,6 @@ public void onCreate(Bundle savedInstanceState) { mComposeView.setActivityLauncher(this); mComposeView.setOnSendListener(this); mComposeView.setLabel("QKReply"); - mComposeView.refresh(); mAdapter = new QKReplyAdapter(this); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index ea1fc0eb1..37b2c710b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -36,10 +36,10 @@ import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.ListviewHelper; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.DateFormatter; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.PackageUtils; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.receiver.NightModeAutoReceiver; import com.moez.QKSMS.transaction.EndlessJabber; import com.moez.QKSMS.transaction.NotificationManager; @@ -66,7 +66,7 @@ import java.util.Stack; public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener, LiveView, ContentFragment { + Preference.OnPreferenceClickListener, ContentFragment { private final String TAG = "PreferenceFragment"; public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance"; @@ -368,9 +368,14 @@ public void onViewCreated(View view, Bundle savedInstanceState) { KeyboardUtils.hide(mContext, view); mListView = (ListView) view.findViewById(android.R.id.list); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - refresh(); + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + ListviewHelper.applyCustomScrollbar(mContext, mListView); + + View view1 = getView(); + if (view1 != null) { + view1.setBackgroundColor(ThemeManager.getBackgroundColor()); + } + }); } @Override @@ -688,23 +693,6 @@ public static void updateAlarmManager(Context context, boolean enabled) { } } - @Override - public void onDestroy() { - super.onDestroy(); - - LiveViewManager.unregisterView(this); - } - - @Override - public void refresh() { - ListviewHelper.applyCustomScrollbar(mContext, mListView); - - View view = getView(); - if (view != null) { - view.setBackgroundColor(ThemeManager.getBackgroundColor()); - } - } - @Override public void onContentOpening() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java index 3ddb31a1d..2a4e74f0e 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java @@ -10,12 +10,12 @@ import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; -import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; -public class AutoCompleteContactView extends RecipientEditTextView implements LiveView { +public class AutoCompleteContactView extends RecipientEditTextView { public static final String TAG = "AutoCompleteContactView"; private QKActivity mContext; @@ -33,40 +33,34 @@ public AutoCompleteContactView(Context context, AttributeSet attrs) { private void init(Context context) { mContext = (QKActivity) context; - SharedPreferences prefs = mContext.getPrefs(); - - // Setup text size, typeface, etc. - refresh(); mAdapter = new BaseRecipientAdapter(BaseRecipientAdapter.QUERY_TYPE_PHONE, getContext()); - mAdapter.setShowMobileOnly(prefs.getBoolean(SettingsFragment.MOBILE_ONLY, false)); setThreshold(1); setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); setAdapter(mAdapter); setOnItemClickListener(this); - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_FAMILY); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_SIZE); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_WEIGHT); - LiveViewManager.registerPreference(this, SettingsFragment.MOBILE_ONLY); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - } + 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); - @Override - public void refresh() { - setTypeface(TypefaceManager.obtainTypeface(mContext, FontManager.getFontFamily(mContext), - FontManager.getFontWeight(mContext, false))); - setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); + LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); + }); - setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); + }); - if (mAdapter != null) { - SharedPreferences prefs = mContext.getPrefs(); - mAdapter.setShowMobileOnly(prefs.getBoolean(SettingsFragment.MOBILE_ONLY, false)); - } + LiveViewManager.registerView(QKPreference.MOBILE_ONLY, key -> { + if (mAdapter != null) { + SharedPreferences prefs1 = mContext.getPrefs(); + mAdapter.setShowMobileOnly(prefs1.getBoolean(SettingsFragment.MOBILE_ONLY, false)); + } + }); } } 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 7e5486bb1..8c877d9a7 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 @@ -28,10 +28,9 @@ import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ImageUtils; import com.moez.QKSMS.common.utils.Units; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; -public class AvatarView extends ImageView implements View.OnClickListener, LiveView { +public class AvatarView extends ImageView implements View.OnClickListener { private final String TAG = "AvatarView"; static final String[] PHONE_LOOKUP_PROJECTION = new String[]{ @@ -90,12 +89,17 @@ public AvatarView(Context context, AttributeSet attrs, int defStyle) { } a.recycle(); - refresh(); setOnClickListener(this); - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + mPaint.setColor(ThemeManager.getTextOnColorPrimary()); + mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + + if (getBackground() == null) { + setBackgroundResource(R.drawable.circle); + } + getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); + }); } } @@ -277,17 +281,6 @@ protected void onDraw(Canvas canvas) { } } - @Override - public void refresh() { - mPaint.setColor(ThemeManager.getTextOnColorPrimary()); - mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - - if (getBackground() == null) { - setBackgroundResource(R.drawable.circle); - } - getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - } - private class QueryHandler extends AsyncQueryHandler { public QueryHandler(ContentResolver cr) { 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 2e1ee6405..99ef06129 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 @@ -36,6 +36,7 @@ import android.widget.LinearLayout; import android.widget.Toast; import com.github.lzyzsd.circleprogress.DonutProgress; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.mmssms.Transaction; import com.moez.QKSMS.mmssms.Utils; @@ -44,9 +45,7 @@ import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.ConversationLegacy; import com.moez.QKSMS.interfaces.ActivityLauncher; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.interfaces.RecipientProvider; -import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.utils.ImageUtils; import com.moez.QKSMS.common.utils.PhoneNumberUtils; import com.moez.QKSMS.common.utils.Units; @@ -66,7 +65,7 @@ import java.text.SimpleDateFormat; import java.util.Date; -public class ComposeView extends LinearLayout implements View.OnClickListener, LiveView { +public class ComposeView extends LinearLayout implements View.OnClickListener { public final static String TAG = "ComposeView"; private final String KEY_DELAYED_INFO_DIALOG_SHOWN = "delayed_info_dialog_shown"; @@ -182,11 +181,23 @@ public void onFinishInflate() { mCancel.setOnClickListener(this); mDelay.setOnClickListener(this); - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, QKPreference.ACTIVE_THEME.getKey()); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, 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); + mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); + mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); + updateDelayButton(); + mProgress.setUnfinishedStrokeColor(ThemeManager.getTextOnColorSecondary()); + mProgress.setFinishedStrokeColor(ThemeManager.getTextOnColorPrimary()); + if (ThemeManager.getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getSentBubbleRes()); + }); - refresh(); + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + mReplyText.getBackground().setColorFilter(ThemeManager.getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); + getBackground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); + }); // There is an option for using the return button instead of the emoticon button in the // keyboard; set that up here. @@ -949,23 +960,6 @@ public void run() { } } - @Override - public void refresh() { - mButtonBackground.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mButtonBar1.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mButtonBar2.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mAttachmentPanel.setBackgroundColor(ThemeManager.getColor()); - mAttach.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - mCamera.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP); - updateDelayButton(); - mProgress.setUnfinishedStrokeColor(ThemeManager.getTextOnColorSecondary()); - mProgress.setFinishedStrokeColor(ThemeManager.getTextOnColorPrimary()); - if (ThemeManager.getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getSentBubbleRes()); - mReplyText.getBackground().setColorFilter(ThemeManager.getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); - mReplyText.refresh(); - getBackground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); - } - private void updateDelayButton() { mDelay.setColorFilter(mDelayedMessagingEnabled ? ThemeManager.getTextOnColorPrimary() : ThemeManager.getTextOnColorSecondary(), diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java index 5b2ff0cc9..6d5197009 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java @@ -8,14 +8,13 @@ import android.text.TextWatcher; import android.util.AttributeSet; import android.util.TypedValue; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; -public class QKEditText extends android.widget.EditText implements LiveView { +public class QKEditText extends android.widget.EditText { public static final String TAG = "QKEditText"; public interface TextChangedListener { @@ -28,7 +27,7 @@ public QKEditText(Context context) { super(context); if (!isInEditMode()) { - init(context, null); + init(context); } } @@ -36,7 +35,7 @@ public QKEditText(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) { - init(context, attrs); + init(context); } } @@ -44,24 +43,29 @@ public QKEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (!isInEditMode()) { - init(context, attrs); + init(context); } } - private void init(Context context, AttributeSet attrs) { + private void init(Context context) { mContext = context; - // Load the properties - refresh(); + 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); - setText(getText()); + LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); + }); + + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + setTextColor(ThemeManager.getTextOnBackgroundPrimary()); + setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); + }); - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_FAMILY); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_SIZE); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_WEIGHT); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); + setText(getText()); } @Override @@ -91,19 +95,4 @@ public void afterTextChanged(Editable s) { }); } } - - @Override - public void refresh() { - // Typeface and colors - int fontFamily = FontManager.getFontFamily(mContext); - int fontWeight = FontManager.getFontWeight(mContext, false); - setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight - )); - setTextColor(ThemeManager.getTextOnBackgroundPrimary()); - setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); - - // Text size - int sp = FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY); - setTextSize(TypedValue.COMPLEX_UNIT_SP, sp); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java index 911b8d252..8941fba99 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java @@ -5,13 +5,11 @@ import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; - import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; -public class QKImageView extends ImageView implements LiveView { +public class QKImageView extends ImageView { private static final String TAG = "QKImageView"; private Drawable mDrawable; @@ -32,9 +30,9 @@ public QKImageView(Context context, AttributeSet attrs, int defStyle) { } public void init() { - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); + LiveViewManager.registerView(QKPreference.THEME, key -> { + setImageDrawable(mDrawable); + }); } @Override @@ -49,11 +47,6 @@ public void setImageDrawable(Drawable drawable) { } } - @Override - public void refresh() { - setImageDrawable(mDrawable); - } - @Override public void onAttachedToWindow() { super.onAttachedToWindow(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java index 134629b0f..c4ca616f4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java @@ -9,11 +9,10 @@ import android.util.AttributeSet; import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; -public class QKSwitch extends SwitchCompat implements LiveView { +public class QKSwitch extends SwitchCompat { private Resources mRes; @@ -30,18 +29,10 @@ public QKSwitch(Context context, AttributeSet attrs) { private void init(Context context) { mRes = context.getResources(); - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.THEME); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - - refresh(); - } - - @Override - public void refresh() { - DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); - DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); + LiveViewManager.registerView(key -> { + DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList()); + DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList()); + }, QKPreference.THEME, QKPreference.BACKGROUND); } private ColorStateList getSwitchThumbColorStateList() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java index 43956443a..396641449 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java @@ -14,12 +14,12 @@ import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.TypefaceManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.MessageUtils; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.settings.SettingsFragment; -public class QKTextView extends TextView implements LiveView { +public class QKTextView extends TextView { private final String TAG = "QKTextView"; private Context mContext; @@ -60,21 +60,32 @@ private void init(Context context, AttributeSet attrs) { array.recycle(); } - refresh(); + setTextColor(FontManager.getTextColor(mContext, mType)); setText(getText()); - // Register this view for live updates. - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_FAMILY); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_SIZE); - LiveViewManager.registerPreference(this, SettingsFragment.FONT_WEIGHT); - LiveViewManager.registerPreference(this, SettingsFragment.MARKDOWN_ENABLED); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - // Register for theme updates if we're text that changes color dynamically. if (mType == FontManager.TEXT_TYPE_CATEGORY) { - LiveViewManager.registerPreference(this, SettingsFragment.THEME); + LiveViewManager.registerView(QKPreference.THEME, key -> + setTextColor(FontManager.getTextColor(mContext, mType))); } + + LiveViewManager.registerView(key -> { + int fontFamily = FontManager.getFontFamily(mContext); + int fontWeight = FontManager.getFontWeight(mContext, FontManager.getIsFontHeavy(mType)); + setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); + }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); + + LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, mType)); + }); + + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + setTextColor(FontManager.getTextColor(mContext, mType)); + }); + + LiveViewManager.registerView(QKPreference.TEXT_FORMATTING, key -> { + setText(getText(), BufferType.NORMAL); + }); } @Override @@ -124,11 +135,6 @@ public void setOnColorBackground(boolean onColorBackground) { } } - public void setType(int type) { - mType = type; - refresh(); - } - @Override public void setText(CharSequence text, BufferType type) { @@ -152,24 +158,4 @@ public void setText(CharSequence text, BufferType type) { } } - - /** - * refresh() is called whenever a user preference around text size, font family, etc. has been - * updated and the view needs to refresh its properties. - */ - @Override - public void refresh() { - // Typeface - int fontFamily = FontManager.getFontFamily(mContext); - int fontWeight = FontManager.getFontWeight(mContext, FontManager.getIsFontHeavy(mType)); - setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight - )); - - // Text size and color - setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, mType)); - setTextColor(FontManager.getTextColor(mContext, mType)); - - // Markdown support enabled - setText(getText(), BufferType.NORMAL); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java index 140653a94..dd28c2e29 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java @@ -16,14 +16,14 @@ import android.widget.LinearLayout; import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.data.Contact; import com.moez.QKSMS.data.ContactHelper; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; -public class StarredContactsView extends LinearLayout implements LoaderManager.LoaderCallbacks, View.OnClickListener, LiveView { +public class StarredContactsView extends LinearLayout implements LoaderManager.LoaderCallbacks, View.OnClickListener { private final String TAG = "StarredContactsView"; private QKActivity mContext; @@ -75,15 +75,16 @@ protected void onFinishInflate() { collapse(); } - LiveViewManager.registerView(this); - LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); - refresh(); + LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); + mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); + }); } public void setComposeScreenViews(AutoCompleteContactView recipients, ComposeView composeView) { mRecipients = recipients; mComposeView = composeView; - ((QKActivity) mContext).getLoaderManager().initLoader(0, null, this); + mContext.getLoaderManager().initLoader(0, null, this); } @Override @@ -173,10 +174,4 @@ public void onClick(View v) { break; } } - - @Override - public void refresh() { - mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); - mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java index 870bf6cd5..648a83dc8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java @@ -10,7 +10,6 @@ import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; import com.moez.QKSMS.R; -import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.QKTextView; @@ -36,8 +35,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mContext.setFinished(); - LiveViewManager.unregisterView(mNightHint); - return view; } @@ -92,9 +89,4 @@ public void onAnimationUpdate(ValueAnimator animation) { .commit(); } } - - @Override - public void refresh() { - // Don't let the super class change the background, since we'll handle animations here - } } From e96504f489f7c81cfea7bf963075aa40c25308b3 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sat, 2 Jan 2016 02:16:57 -0500 Subject: [PATCH 22/49] Make LiveViewManager abstract --- .../moez/QKSMS/common/LiveViewManager.java | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 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 c23aa1573..26194b3ee 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -13,34 +13,23 @@ /** * Allows views to register for updates on preferences - * + *

* Example: A button may need to know when the theme changes, so it that * it can change colors accordingly - * + *

* In order to do this, you can use this class as following: * LiveViewManager.registerView(QKPreference.THEME, key -> { - * // Change button color + * // Change button color * } - * + *

* You won't need to initialize the button color in addition to registering it * in the LiveViewManager, because registering it will trigger a refresh automatically, * which will initialize it */ -public class LiveViewManager implements SharedPreferences.OnSharedPreferenceChangeListener { +public abstract class LiveViewManager { private static final String TAG = "ThemedViewManager"; - private static LiveViewManager sInstance; - private static final HashMap> sViews = new HashMap<>(); - - /** - * Private constructor - */ - private LiveViewManager() { - } - - static { - sInstance = new LiveViewManager(); - } + private static HashMap> sViews = new HashMap<>(); /** * Initialize preferences and register a listener for changes @@ -49,18 +38,7 @@ private LiveViewManager() { */ public static void init(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.registerOnSharedPreferenceChangeListener(sInstance); - } - - /** - * Listen for preference changes from the SharedPreferences - * - * @param prefs SharedPreferences instance - * @param key Key of preference that was changed - */ - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - LiveViewManager.refreshViews(key); + prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> refreshViews(key)); } /** From e943e69e0d3b2034c21ecb7f2399f6c2a4dd2ea9 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 12:17:59 -0500 Subject: [PATCH 23/49] 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 26194b3ee..19be390bf 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 @@ 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 5747341dc..fa262add4 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.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 static void init(Context context) { */ 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 static void setColour(QKActivity activity, int color) { 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 void onAnimationEnd(Animator animation) { 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 d1cdd1eb6..ba94c9d9b 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 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 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + mToolbar.setBackgroundColor(ThemeManager.getColor()); + }); + ThemeManager.themeActivity(this); } From b7608665e5b0c4334f68699567a94c236a2a1ca8 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 15:49:09 -0500 Subject: [PATCH 24/49] Fixed GC issue with LiveViews in LiveViewManager --- .../moez/QKSMS/common/LiveViewManager.java | 51 ++++++++++++------- .../java/com/moez/QKSMS/ui/MainActivity.java | 2 +- .../com/moez/QKSMS/ui/base/QKActivity.java | 3 +- .../com/moez/QKSMS/ui/base/QKFragment.java | 2 +- .../ConversationListAdapter.java | 2 +- .../ConversationListFragment.java | 2 +- .../ui/messagelist/MessageListViewHolder.java | 2 +- .../QKSMS/ui/settings/SettingsFragment.java | 2 +- .../ui/view/AutoCompleteContactView.java | 6 +-- .../com/moez/QKSMS/ui/view/AvatarView.java | 2 +- .../com/moez/QKSMS/ui/view/ComposeView.java | 4 +- .../com/moez/QKSMS/ui/view/QKEditText.java | 4 +- .../com/moez/QKSMS/ui/view/QKImageView.java | 2 +- .../com/moez/QKSMS/ui/view/QKTextView.java | 8 +-- .../QKSMS/ui/view/StarredContactsView.java | 2 +- 15 files changed, 55 insertions(+), 39 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 19be390bf..13a7d8d3a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -6,8 +6,8 @@ import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.interfaces.LiveView; -import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Set; import java.util.WeakHashMap; @@ -27,9 +27,9 @@ * which will initialize it */ public abstract class LiveViewManager { - private static final String TAG = "ThemedViewManager"; + private static final String TAG = "LiveViewManager"; - private static final HashMap> sViews = new HashMap<>(); + private static final HashMap>> sViews = new HashMap<>(); /** * Initialize preferences and register a listener for changes @@ -45,12 +45,17 @@ public static void init(Context context) { * Convenience method for #registerView(QKPreference, ThemedView) to allow registering a single * ThemedView to listen for multiple preferences * - * @param view The ThemedView + * @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, QKPreference... preferences) { + public static void registerView(LiveView view, Object parent, QKPreference... preferences) { for (QKPreference preference : preferences) { - registerView(preference, view); + registerView(preference, parent, view); } } @@ -59,16 +64,25 @@ public static void registerView(LiveView view, QKPreference... preferences) { * We don't need to manually unregister the views because we're using weak sets * * @param preference The preference to listen for - * @param view The view + * @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 view The LiveView */ - public static void registerView(QKPreference preference, LiveView view) { + public static void registerView(QKPreference preference, Object parent, LiveView view) { synchronized (sViews) { if (sViews.containsKey(preference.getKey())) { - Set views = sViews.get(preference.getKey()); - views.add(view); + WeakHashMap> parents = sViews.get(preference.getKey()); + if (!parents.containsKey(parent)) { + parents.put(parent, new HashSet<>()); + } + parents.get(parent).add(view); } else { - Set set = Collections.newSetFromMap(new WeakHashMap<>()); - set.add(view); + WeakHashMap> set = new WeakHashMap<>(); + set.put(parent, new HashSet<>()); + set.get(parent).add(view); sViews.put(preference.getKey(), set); } } @@ -94,12 +108,13 @@ public static void refreshViews(QKPreference preference) { * @param key The preference key */ private static void refreshViews(String key) { - Set toRefresh = sViews.get(key); - - // Refresh those views. - if (toRefresh != null) { - for (LiveView view : toRefresh) { - view.refresh(key); + synchronized (sViews) { + if (sViews.get(key) != null) { + for (Set views : sViews.get(key).values()) { + for (LiveView view : views) { + view.refresh(key); + } + } } } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index e75f97495..2d0acf0d5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -122,7 +122,7 @@ public void onCreate(Bundle savedInstanceState) { showDialogIfNeeded(savedInstanceState); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { // Update the background color. This code is important during the welcome screen setup, when the activity // in the ThemeManager isn't the MainActivity findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); 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 ba94c9d9b..783e87be5 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 @@ -25,6 +25,7 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; +import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.view.QKTextView; @@ -73,7 +74,7 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, key -> { mToolbar.setBackgroundColor(ThemeManager.getColor()); }); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java index 8320ab457..cf8a24564 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java @@ -24,7 +24,7 @@ public void onAttach(Activity activity) { public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { if (getView() != null) { getView().setBackgroundColor(ThemeManager.getBackgroundColor()); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index 5986c5634..906ef0f8d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -37,7 +37,7 @@ public ConversationListAdapter(QKActivity context) { mUnread = ContextCompat.getDrawable(context, R.drawable.ic_unread_indicator); mError = ContextCompat.getDrawable(context, R.drawable.ic_error); - LiveViewManager.registerView(QKPreference.THEME, key -> { + LiveViewManager.registerView(QKPreference.THEME, this, key -> { mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index c7f2a6dce..04327aa64 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -79,7 +79,7 @@ public void onCreate(Bundle savedInstanceState) { mLayoutManager = new LinearLayoutManager(mContext); mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager()); - LiveViewManager.registerView(QKPreference.THEME, key -> { + LiveViewManager.registerView(QKPreference.THEME, this, key -> { if (!mViewHasLoaded) { return; } 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 c032d56d4..2de9dd225 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 @@ protected void inflateDownloadControls() { } protected void setLiveViewCallback(LiveView liveViewCallback) { - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, liveViewCallback); + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, this, liveViewCallback); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 37b2c710b..5f2adcd50 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -368,7 +368,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { KeyboardUtils.hide(mContext, view); mListView = (ListView) view.findViewById(android.R.id.list); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { ListviewHelper.applyCustomScrollbar(mContext, mListView); View view1 = getView(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java index 2a4e74f0e..730f53cfc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/AutoCompleteContactView.java @@ -47,16 +47,16 @@ private void init(Context context) { setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); - LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); }); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { setTextColor(ThemeManager.getTextOnBackgroundPrimary()); setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); }); - LiveViewManager.registerView(QKPreference.MOBILE_ONLY, key -> { + LiveViewManager.registerView(QKPreference.MOBILE_ONLY, this, key -> { if (mAdapter != null) { SharedPreferences prefs1 = mContext.getPrefs(); mAdapter.setShowMobileOnly(prefs1.getBoolean(SettingsFragment.MOBILE_ONLY, false)); 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 8c877d9a7..8b79b5c09 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 AvatarView(Context context, AttributeSet attrs, int defStyle) { setOnClickListener(this); - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, 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 99ef06129..36e621c25 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 void onFinishInflate() { mCancel.setOnClickListener(this); mDelay.setOnClickListener(this); - LiveViewManager.registerView(QKPreference.ACTIVE_THEME, key -> { + LiveViewManager.registerView(QKPreference.ACTIVE_THEME, 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); @@ -194,7 +194,7 @@ public void onFinishInflate() { if (ThemeManager.getSentBubbleRes() != 0) mReplyText.setBackgroundResource(ThemeManager.getSentBubbleRes()); }); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { mReplyText.getBackground().setColorFilter(ThemeManager.getNeutralBubbleColor(), PorterDuff.Mode.SRC_ATOP); getBackground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); }); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java index 6d5197009..cce50c5b9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKEditText.java @@ -56,11 +56,11 @@ private void init(Context context) { setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); - LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY)); }); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { setTextColor(ThemeManager.getTextOnBackgroundPrimary()); setHintTextColor(ThemeManager.getTextOnBackgroundSecondary()); }); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java index 8941fba99..bc1da43eb 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKImageView.java @@ -30,7 +30,7 @@ public QKImageView(Context context, AttributeSet attrs, int defStyle) { } public void init() { - LiveViewManager.registerView(QKPreference.THEME, key -> { + LiveViewManager.registerView(QKPreference.THEME, this, key -> { setImageDrawable(mDrawable); }); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java index 396641449..e41f0a727 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKTextView.java @@ -65,7 +65,7 @@ private void init(Context context, AttributeSet attrs) { // Register for theme updates if we're text that changes color dynamically. if (mType == FontManager.TEXT_TYPE_CATEGORY) { - LiveViewManager.registerView(QKPreference.THEME, key -> + LiveViewManager.registerView(QKPreference.THEME, this, key -> setTextColor(FontManager.getTextColor(mContext, mType))); } @@ -75,15 +75,15 @@ private void init(Context context, AttributeSet attrs) { setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight)); }, QKPreference.FONT_FAMILY, QKPreference.FONT_WEIGHT); - LiveViewManager.registerView(QKPreference.FONT_SIZE, key -> { + LiveViewManager.registerView(QKPreference.FONT_SIZE, this, key -> { setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, mType)); }); - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { setTextColor(FontManager.getTextColor(mContext, mType)); }); - LiveViewManager.registerView(QKPreference.TEXT_FORMATTING, key -> { + LiveViewManager.registerView(QKPreference.TEXT_FORMATTING, this, key -> { setText(getText(), BufferType.NORMAL); }); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java index dd28c2e29..91a11ee8c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java @@ -75,7 +75,7 @@ protected void onFinishInflate() { collapse(); } - LiveViewManager.registerView(QKPreference.BACKGROUND, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP); mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); }); From 87e910a892c260864df76b2c75092eb0da16d3e9 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 15:52:11 -0500 Subject: [PATCH 25/49] Use AppCompatActivity base --- QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 783e87be5..7b80536b5 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 @@ -10,7 +10,7 @@ import android.os.PowerManager; import android.preference.PreferenceManager; import android.support.annotation.StringRes; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; @@ -25,13 +25,12 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; -import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.view.QKTextView; import java.util.ArrayList; -public abstract class QKActivity extends ActionBarActivity { +public abstract class QKActivity extends AppCompatActivity { private final String TAG = "QKActivity"; private Toolbar mToolbar; From 33a061ddccd105c69a14e6b516dbee53fcdb8989 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 16:21:17 -0500 Subject: [PATCH 26/49] 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 7e788ab30..8a92aeea1 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 fa262add4..c1de8a4ac 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 static void initializeTheme(Theme theme) { 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 static void initializeTheme(Theme theme) { 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 static void setColour(QKActivity activity, int color) { 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 static void setActiveColor(QKActivity activity, int color) { 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 7b80536b5..be2eeeda1 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 @@ private void reloadToolbar() { 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 SharedPreferences getPrefs() { 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 void setTitle(CharSequence title) { } } - /** - * 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 2de9dd225..a8d14dfc6 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 @@ protected void inflateDownloadControls() { } 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 8b79b5c09..ead8d0ac7 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 AvatarView(Context context, AttributeSet attrs, int defStyle) { 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 36e621c25..c1881f575 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 void onFinishInflate() { 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); From 6db7f44e2be4b85324951def42da9ee260d9bfd8 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 17:20:55 -0500 Subject: [PATCH 27/49] Use one Preference for all Theme LiveViews --- .../common/preferences/QKPreference.java | 7 +-- .../java/com/moez/QKSMS/ui/ThemeManager.java | 6 +-- .../com/moez/QKSMS/ui/base/QKActivity.java | 4 +- .../ConversationListAdapter.java | 47 ++++++++----------- .../ui/messagelist/MessageListViewHolder.java | 2 +- .../com/moez/QKSMS/ui/view/AvatarView.java | 2 +- .../com/moez/QKSMS/ui/view/ComposeView.java | 2 +- 7 files changed, 31 insertions(+), 39 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 8a92aeea1..ef2e847ea 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 @@ -1,11 +1,13 @@ package com.moez.QKSMS.common.preferences; +import com.moez.QKSMS.ui.ThemeManager; + import java.util.Arrays; import java.util.HashSet; public enum QKPreference { // Appearance - THEME("pref_key_theme", 0xFFFFF), + THEME("pref_key_theme", ThemeManager.DEFAULT_COLOR), ICON("pref_key_icon"), BACKGROUND("pref_key_background", "offwhite"), @@ -87,10 +89,9 @@ public enum QKPreference { TAP_DISMISS("pref_key_quickreply_dismiss", true), // QK Compose - QK_COMPOSE("pref_key_quickcompose", false), + QK_COMPOSE("pref_key_quickcompose", false); // LiveViews - 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 c1de8a4ac..b0424a169 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -371,7 +371,7 @@ public static void initializeTheme(Theme theme) { setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); setBubbleStyleNew(mPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true)); - LiveViewManager.refreshViews(QKPreference.THEME); + LiveViewManager.refreshViews(QKPreference.BACKGROUND); } public static void setIcon(final QKActivity context) { @@ -639,7 +639,7 @@ public static void setColour(QKActivity activity, int color) { mWindow.setNavigationBarColor(ColorUtils.darken(color1)); } - LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR); + LiveViewManager.refreshViews(QKPreference.THEME); }); colorAnimation.addListener(new AnimatorListenerAdapter() { @Override @@ -679,7 +679,7 @@ public static void setActiveColor(QKActivity activity, int color) { mWindow.setNavigationBarColor(ColorUtils.darken(color)); } - LiveViewManager.refreshViews(QKPreference.ACTIVE_COLOR); + LiveViewManager.refreshViews(QKPreference.THEME); } 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 be2eeeda1..ad48ffee8 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,11 +73,11 @@ private void reloadToolbar() { setSupportActionBar(mToolbar); } - LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> { + LiveViewManager.registerView(QKPreference.THEME, this, key -> { mToolbar.setBackgroundColor(ThemeManager.getColor()); }); - LiveViewManager.registerView(QKPreference.THEME, this, key -> { + LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { switch (ThemeManager.getTheme()) { case WHITE: case OFFWHITE: diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index 906ef0f8d..27eb81ee1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -1,9 +1,6 @@ package com.moez.QKSMS.ui.conversationlist; import android.content.SharedPreferences; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -25,24 +22,9 @@ public class ConversationListAdapter extends RecyclerCursorAdapter { - mMuted.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mUnread.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - mError.setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.SRC_ATOP); - notifyDataSetChanged(); - }); } protected Conversation getItem(int position) { @@ -54,7 +36,19 @@ protected Conversation getItem(int position) { public ConversationListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(mContext); View view = inflater.inflate(R.layout.list_item_conversation, null); - return new ConversationListViewHolder(mContext, view); + + ConversationListViewHolder holder = new ConversationListViewHolder(mContext, view); + holder.mutedView.setImageResource(R.drawable.ic_notifications_muted); + holder.unreadView.setImageResource(R.drawable.ic_unread_indicator); + holder.errorIndicator.setImageResource(R.drawable.ic_error); + + LiveViewManager.registerView(QKPreference.THEME, this, key -> { + holder.mutedView.setColorFilter(ThemeManager.getColor()); + holder.unreadView.setColorFilter(ThemeManager.getColor()); + holder.errorIndicator.setColorFilter(ThemeManager.getColor()); + }); + + return holder; } @Override @@ -67,20 +61,13 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { holder.root.setOnClickListener(holder); holder.root.setOnLongClickListener(holder); - // Have to clear the image drawable first, or else it won't reload it at all. - holder.mutedView.setImageDrawable(null); - holder.unreadView.setImageDrawable(null); - holder.errorIndicator.setImageDrawable(null); - holder.mutedView.setImageDrawable(mMuted); - holder.unreadView.setImageDrawable(mUnread); - holder.errorIndicator.setImageDrawable(mError); - holder.mutedView.setVisibility(new ConversationPrefsHelper(mContext, conversation.getThreadId()) .getNotificationsEnabled() ? View.GONE : View.VISIBLE); holder.errorIndicator.setVisibility(conversation.hasError() ? View.VISIBLE : View.GONE); - if (conversation.hasUnreadMessages()) { + final boolean hasUnreadMessages = conversation.hasUnreadMessages(); + if (hasUnreadMessages) { holder.unreadView.setVisibility(View.VISIBLE); holder.snippetView.setTextColor(ThemeManager.getTextOnBackgroundPrimary()); holder.dateView.setTextColor(ThemeManager.getColor()); @@ -90,6 +77,10 @@ public void onBindViewHolder(ConversationListViewHolder holder, int position) { holder.dateView.setTextColor(ThemeManager.getTextOnBackgroundSecondary()); } + LiveViewManager.registerView(QKPreference.THEME, this, key -> { + holder.dateView.setTextColor(hasUnreadMessages ? ThemeManager.getColor() : ThemeManager.getTextOnBackgroundSecondary()); + }); + if (isInMultiSelectMode()) { holder.mSelected.setVisibility(View.VISIBLE); if (isSelected(conversation.getThreadId())) { 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 a8d14dfc6..0b76429c0 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 @@ protected void inflateDownloadControls() { } protected void setLiveViewCallback(LiveView liveViewCallback) { - LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, liveViewCallback); + LiveViewManager.registerView(QKPreference.THEME, 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 ead8d0ac7..c25e0e78c 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 AvatarView(Context context, AttributeSet attrs, int defStyle) { setOnClickListener(this); - LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> { + LiveViewManager.registerView(QKPreference.THEME, 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 c1881f575..83283a7ad 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 void onFinishInflate() { mCancel.setOnClickListener(this); mDelay.setOnClickListener(this); - LiveViewManager.registerView(QKPreference.ACTIVE_COLOR, this, key -> { + LiveViewManager.registerView(QKPreference.THEME, 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); From 16119792c74c0f09e1721821a2995ac5521007bf Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 17:42:08 -0500 Subject: [PATCH 28/49] Allow exclusion of prefers from automatically calling refresh in LiveViewManager --- .../com/moez/QKSMS/common/LiveViewManager.java | 17 ++++++++++++++++- .../java/com/moez/QKSMS/ui/ThemeManager.java | 10 +++------- 2 files changed, 19 insertions(+), 8 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 13a7d8d3a..7031f69f4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -6,6 +6,7 @@ import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.interfaces.LiveView; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -29,8 +30,18 @@ public abstract class LiveViewManager { private static final String TAG = "LiveViewManager"; + /** + * Maps all of the LiveViews to their associated preference + */ private static final HashMap>> sViews = new HashMap<>(); + /** + * A list of preferences to be excluded from LiveView refreshing when the preference changes + */ + private static final HashSet sExcludedPrefs = new HashSet<>(Arrays.asList( + QKPreference.THEME.getKey() + )); + /** * Initialize preferences and register a listener for changes * @@ -38,7 +49,11 @@ public abstract class LiveViewManager { */ public static void init(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> refreshViews(key)); + prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> { + if (!sExcludedPrefs.contains(key)) { + refreshViews(key); + } + }); } /** 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 b0424a169..8b3659f50 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -622,21 +622,17 @@ public static void setColour(QKActivity activity, int color) { mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); - // Some views are updated every frame of the animation; get these views here. We - // build this list once beforehand since it's a slightly expensive operation. - LiveViewManager.refreshViews(QKPreference.THEME); - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colourFrom, color); colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(animation -> { - int color1 = (Integer) animation.getAnimatedValue(); + mActiveColor = (Integer) animation.getAnimatedValue(); if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(color1)); + mWindow.setStatusBarColor(ColorUtils.darken(mActiveColor)); } if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(color1)); + mWindow.setNavigationBarColor(ColorUtils.darken(mActiveColor)); } LiveViewManager.refreshViews(QKPreference.THEME); From 4e54a2a4c2f6f7b44d82270964da1482cbdcddef Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 19:24:31 -0500 Subject: [PATCH 29/49] Simplify color picker dialog showing --- .../java/com/moez/QKSMS/ui/ThemeManager.java | 29 +++++-------------- .../QKSMS/ui/settings/SettingsFragment.java | 2 +- 2 files changed, 8 insertions(+), 23 deletions(-) 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 8b3659f50..c1a0ea08d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -526,14 +526,18 @@ public static boolean isNightMode() { return mTheme == Theme.GREY || mTheme == Theme.BLACK; } - public static void showColourSwatchesDialog(final QKActivity context) { + public static void showColorPickerDialog(final QKActivity context) { final QKDialog dialog = new QKDialog(); ColorPickerPalette palette = new ColorPickerPalette(context); palette.setGravity(Gravity.CENTER); palette.init(19, 4, color -> { - showColourPickerDialog(context, color); - dialog.dismiss(); + palette.init(getSwatch(color).length, 4, color2 -> { + setColour(context, color2); + dialog.dismiss(); + }); + + palette.drawPalette(getSwatch(color), mColor); }); palette.drawPalette(PALETTE, getSwatchColour(mColor)); @@ -546,25 +550,6 @@ public static void showColourSwatchesDialog(final QKActivity context) { dialog.show(); } - private static void showColourPickerDialog(final QKActivity context, int swatchColour) { - final QKDialog dialog = new QKDialog(); - - ColorPickerPalette palette = new ColorPickerPalette(context); - palette.setGravity(Gravity.CENTER); - palette.init(getSwatch(swatchColour).length, 4, color -> { - setColour(context, color); - dialog.dismiss(); - }); - - palette.drawPalette(getSwatch(swatchColour), mColor); - - dialog.setContext(context) - .setTitle(R.string.pref_theme) - .setCustomView(palette) - .setNegativeButton(R.string.cancel, null) - .show(); - } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setStatusBarTintEnabled(boolean enabled) { if (mStatusTintEnabled != enabled) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 5f2adcd50..aff9d45c8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -524,7 +524,7 @@ public boolean onPreferenceClick(Preference preference) { switch (key) { case THEME: - ThemeManager.showColourSwatchesDialog(mContext); + ThemeManager.showColorPickerDialog(mContext); break; case BUBBLES: new BubblePreferenceDialog().setContext(mContext).show(); From ea5977e16800328dd7453ee2d7956cd8ad450e51 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 19:28:31 -0500 Subject: [PATCH 30/49] Fix color spelling --- .../transaction/NotificationManager.java | 20 ++--- .../java/com/moez/QKSMS/ui/ThemeManager.java | 84 +++++++++---------- .../ui/dialog/BubblePreferenceDialog.java | 8 +- .../QKSMS/ui/settings/SettingsFragment.java | 8 +- .../QKSMS/ui/welcome/WelcomeActivity.java | 2 +- .../res/values/{colours.xml => colors.xml} | 0 6 files changed, 61 insertions(+), 61 deletions(-) rename QKSMS/src/main/res/values/{colours.xml => colors.xml} (100%) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java index ee788e2b3..2098a4b1c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java @@ -184,7 +184,7 @@ public void run() { } if (conversationPrefs.getNotificationLedEnabled()) { - builder.setLights(getLedColour(conversationPrefs), 1000, 1000); + builder.setLights(getLedColor(conversationPrefs), 1000, 1000); } Integer privateNotifications = conversationPrefs.getPrivateNotificationsSetting(); @@ -275,7 +275,7 @@ public void run() { .setAutoCancel(true); if (conversationPrefs.getNotificationLedEnabled()) { - builder.setLights(getLedColour(conversationPrefs), 1000, 1000); + builder.setLights(getLedColor(conversationPrefs), 1000, 1000); } Integer privateNotifications = conversationPrefs.getPrivateNotificationsSetting(); @@ -359,7 +359,7 @@ public void run() { } if (sPrefs.getBoolean(SettingsFragment.NOTIFICATION_LED, true)) { - builder.setLights(getLedColour(new ConversationPrefsHelper(context, 0)), 1000, 1000); + builder.setLights(getLedColor(new ConversationPrefsHelper(context, 0)), 1000, 1000); } if (sPrefs.getBoolean(SettingsFragment.NOTIFICATION_TICKER, false)) { @@ -692,18 +692,18 @@ public static void initQuickCompose(Context context, boolean override, boolean o } } - private static int getLedColour(ConversationPrefsHelper conversationPrefs) { - int colour = Integer.parseInt(conversationPrefs.getNotificationLedColor()); + private static int getLedColor(ConversationPrefsHelper conversationPrefs) { + int color = Integer.parseInt(conversationPrefs.getNotificationLedColor()); - if (colour == sRes.getColor(R.color.blue_light) || colour == sRes.getColor(R.color.blue_dark)) + if (color == sRes.getColor(R.color.blue_light) || color == sRes.getColor(R.color.blue_dark)) return sRes.getColor(R.color.blue_dark); - if (colour == sRes.getColor(R.color.purple_light) || colour == sRes.getColor(R.color.purple_dark)) + if (color == sRes.getColor(R.color.purple_light) || color == sRes.getColor(R.color.purple_dark)) return sRes.getColor(R.color.purple_dark); - if (colour == sRes.getColor(R.color.green_light) || colour == sRes.getColor(R.color.green_dark)) + if (color == sRes.getColor(R.color.green_light) || color == sRes.getColor(R.color.green_dark)) return sRes.getColor(R.color.green_dark); - if (colour == sRes.getColor(R.color.yellow_light) || colour == sRes.getColor(R.color.yellow_dark)) + if (color == sRes.getColor(R.color.yellow_light) || color == sRes.getColor(R.color.yellow_dark)) return sRes.getColor(R.color.yellow_dark); - if (colour == sRes.getColor(R.color.red_light) || colour == sRes.getColor(R.color.red_dark)) + if (color == sRes.getColor(R.color.red_light) || color == sRes.getColor(R.color.red_dark)) return sRes.getColor(R.color.red_dark); return sRes.getColor(R.color.white_pure); 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 c1a0ea08d..2a39bd9dd 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -67,8 +67,8 @@ public static Theme fromString(String color) { } } - // Colours copied from http://www.google.com/design/spec/style/color.html#color-ui-color-palette - private static final int[][] COLOURS = {{ + // Colors copied from http://www.google.com/design/spec/style/color.html#color-ui-color-palette + private static final int[][] COLORS = {{ // Red 0xfffde0dc, 0xfff9bdbb, 0xfff69988, 0xfff36c60, 0xffe84e40, 0xffe51c23, 0xffdd191d, 0xffd01716, @@ -151,25 +151,25 @@ public static Theme fromString(String color) { * These are the colors that go in the initial palette. */ public static final int[] PALETTE = { - COLOURS[0][5], // Red - COLOURS[1][5], // Pink - COLOURS[2][5], // Purple - COLOURS[3][5], // Deep purple - COLOURS[4][5], // Indigo - COLOURS[5][5], // Blue - COLOURS[6][5], // Light Blue - COLOURS[7][5], // Cyan - COLOURS[8][5], // Teal - COLOURS[9][5], // Green - COLOURS[10][5], // Light Green - COLOURS[11][5], // Lime - COLOURS[12][5], // Yellow - COLOURS[13][5], // Amber - COLOURS[14][5], // Orange - COLOURS[15][5], // Deep Orange - COLOURS[16][5], // Brown - COLOURS[17][5], // Grey - COLOURS[18][5] // Blue Grey + COLORS[0][5], // Red + COLORS[1][5], // Pink + COLORS[2][5], // Purple + COLORS[3][5], // Deep purple + COLORS[4][5], // Indigo + COLORS[5][5], // Blue + COLORS[6][5], // Light Blue + COLORS[7][5], // Cyan + COLORS[8][5], // Teal + COLORS[9][5], // Green + COLORS[10][5], // Light Green + COLORS[11][5], // Lime + COLORS[12][5], // Yellow + COLORS[13][5], // Amber + COLORS[14][5], // Orange + COLORS[15][5], // Deep Orange + COLORS[16][5], // Brown + COLORS[17][5], // Grey + COLORS[18][5] // Blue Grey }; /** @@ -367,8 +367,8 @@ public static void initializeTheme(Theme theme) { mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); - setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); - setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); + setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOR_SENT, true)); + setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOR_RECEIVED, false)); setBubbleStyleNew(mPrefs.getBoolean(SettingsFragment.BUBBLES_NEW, true)); LiveViewManager.refreshViews(QKPreference.BACKGROUND); @@ -400,7 +400,7 @@ public static void setIcon(final QKActivity context) { // Save the enabled component so we can kill the app with this one when // it's all done. - if (getSwatchColour(mColor) == PALETTE[i]) { + if (getSwatchColor(mColor) == PALETTE[i]) { enabledComponent = componentClassName; } else { @@ -533,14 +533,14 @@ public static void showColorPickerDialog(final QKActivity context) { palette.setGravity(Gravity.CENTER); palette.init(19, 4, color -> { palette.init(getSwatch(color).length, 4, color2 -> { - setColour(context, color2); + setColor(context, color2); dialog.dismiss(); }); palette.drawPalette(getSwatch(color), mColor); }); - palette.drawPalette(PALETTE, getSwatchColour(mColor)); + palette.drawPalette(PALETTE, getSwatchColor(mColor)); dialog.setContext(context) .setTitle(R.string.pref_theme) @@ -586,7 +586,7 @@ public static String getColorString(int color) { return String.format("#%08x", color).toUpperCase(); } - public static void setColour(QKActivity activity, int color) { + public static void setColor(QKActivity activity, int color) { AnalyticsManager.getInstance().sendEvent( AnalyticsManager.CATEGORY_PREFERENCE_CHANGE, @@ -594,20 +594,20 @@ public static void setColour(QKActivity activity, int color) { getColorString(color) ); - int colourFrom = mColor; + int colorFrom = mColor; mColor = color; mActiveColor = color; mPrefs.edit().putString(SettingsFragment.THEME, "" + color).apply(); - setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_SENT, true)); - setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOUR_RECEIVED, false)); + setSentBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOR_SENT, true)); + setReceivedBubbleColored(mPrefs.getBoolean(SettingsFragment.COLOR_RECEIVED, false)); mTextOnColorPrimary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_primary : R.color.theme_light_text_primary); mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colourFrom, color); + ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, color); colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(animation -> { @@ -664,9 +664,9 @@ public static void setActiveColor(QKActivity activity, int color) { } private static boolean isColorDarkEnough(int color) { - for (int i = 0; i < COLOURS.length; i++) { - for (int j = 0; j < COLOURS[i].length; j++) { - if (color == COLOURS[i][j]) { + for (int i = 0; i < COLORS.length; i++) { + for (int j = 0; j < COLORS[i].length; j++) { + if (color == COLORS[i][j]) { return TEXT_MODE[i][j] == 1; } } @@ -675,22 +675,22 @@ private static boolean isColorDarkEnough(int color) { return true; } - public static int getSwatchColour(int colour) { - for (int i = 0; i < COLOURS.length; i++) { - for (int j = 0; j < COLOURS[i].length; j++) { - if (colour == COLOURS[i][j]) { + public static int getSwatchColor(int color) { + for (int i = 0; i < COLORS.length; i++) { + for (int j = 0; j < COLORS[i].length; j++) { + if (color == COLORS[i][j]) { return PALETTE[i]; } } } - return colour; + return color; } - private static int[] getSwatch(int colour) { - for (int[] swatch : COLOURS) { + private static int[] getSwatch(int color) { + for (int[] swatch : COLORS) { for (int swatchColor : swatch) { - if (colour == swatchColor) { + if (color == swatchColor) { return swatch; } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java index eea273196..5399f5624 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/dialog/BubblePreferenceDialog.java @@ -70,7 +70,7 @@ public boolean onPreferenceClick(Preference preference) { out2.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); return true; - case SettingsFragment.COLOUR_RECEIVED: + case SettingsFragment.COLOR_RECEIVED: ThemeManager.setReceivedBubbleColored(((QKSwitchPreference) preference).isChecked()); in1.getBackground().setColorFilter(ThemeManager.getReceivedBubbleColor(), PorterDuff.Mode.SRC_ATOP); in1.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); @@ -78,7 +78,7 @@ public boolean onPreferenceClick(Preference preference) { in2.setOnColorBackground(ThemeManager.getReceivedBubbleColor() == ThemeManager.getColor()); return true; - case SettingsFragment.COLOUR_SENT: + case SettingsFragment.COLOR_SENT: ThemeManager.setSentBubbleColored(((QKSwitchPreference) preference).isChecked()); out1.getBackground().setColorFilter(ThemeManager.getSentBubbleColor(), PorterDuff.Mode.SRC_ATOP); out1.setOnColorBackground(ThemeManager.getSentBubbleColor() == ThemeManager.getColor()); @@ -93,9 +93,9 @@ public boolean onPreferenceClick(Preference preference) { LinearLayout prefsLayout = (LinearLayout) view.findViewById(R.id.prefs); prefsLayout.addView(new QKSwitchPreference(mContext, onPreferenceClickListener, SettingsFragment.BUBBLES_NEW, prefs, true, R.string.pref_bubble_style_new, 0).getView()); - prefsLayout.addView(new QKSwitchPreference(mContext, onPreferenceClickListener, SettingsFragment.COLOUR_RECEIVED, + prefsLayout.addView(new QKSwitchPreference(mContext, onPreferenceClickListener, SettingsFragment.COLOR_RECEIVED, prefs, false, R.string.pref_color_received, 0).getView()); - prefsLayout.addView(new QKSwitchPreference(mContext, onPreferenceClickListener, SettingsFragment.COLOUR_SENT, + prefsLayout.addView(new QKSwitchPreference(mContext, onPreferenceClickListener, SettingsFragment.COLOR_SENT, prefs, true, R.string.pref_color_sent, 0).getView()); setTitle(R.string.pref_bubbles); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index aff9d45c8..8563586a2 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -88,8 +88,8 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O public static final String BACKGROUND = "pref_key_background"; public static final String BUBBLES = "pref_key_bubbles"; public static final String BUBBLES_NEW = "pref_key_new_bubbles"; - public static final String COLOUR_SENT = "pref_key_colour_sent"; - public static final String COLOUR_RECEIVED = "pref_key_colour_received"; + public static final String COLOR_SENT = "pref_key_colour_sent"; + public static final String COLOR_RECEIVED = "pref_key_colour_received"; public static final String HIDE_AVATAR_CONVERSATIONS = "pref_key_hide_avatar_conversations"; public static final String HIDE_AVATAR_SENT = "pref_key_hide_avatar_sent"; public static final String HIDE_AVATAR_RECEIVED = "pref_key_hide_avatar_received"; @@ -416,10 +416,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { int i = Integer.parseInt("" + newValue); preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); break; - case COLOUR_SENT: + case COLOR_SENT: ThemeManager.setSentBubbleColored((Boolean) newValue); break; - case COLOUR_RECEIVED: + case COLOR_RECEIVED: ThemeManager.setReceivedBubbleColored((Boolean) newValue); break; case NIGHT_AUTO: diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java index be12acb54..5241e1176 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeActivity.java @@ -74,7 +74,7 @@ public void onAnimationUpdate(ValueAnimator animation) { }); colorAnimation.start(); - ThemeManager.setColour(this, color); + ThemeManager.setColor(this, color); } public void setColorBackground(int color) { diff --git a/QKSMS/src/main/res/values/colours.xml b/QKSMS/src/main/res/values/colors.xml similarity index 100% rename from QKSMS/src/main/res/values/colours.xml rename to QKSMS/src/main/res/values/colors.xml From 39d6709abf48a704827d6d60873db64edecd2039 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 20:15:40 -0500 Subject: [PATCH 31/49] Migrate more activity theming code from ThemeManager --- .../java/com/moez/QKSMS/ui/ThemeManager.java | 85 +++++-------------- .../com/moez/QKSMS/ui/base/QKActivity.java | 28 +++++- .../ui/messagelist/MessageListFragment.java | 6 +- .../QKSMS/ui/settings/SettingsFragment.java | 4 +- 4 files changed, 52 insertions(+), 71 deletions(-) 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 2a39bd9dd..afabc1528 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -17,7 +17,6 @@ import android.util.Log; import android.view.Gravity; import android.view.View; -import android.view.Window; import android.view.animation.DecelerateInterpolator; import android.widget.LinearLayout; import com.moez.QKSMS.R; @@ -236,11 +235,7 @@ public static Theme fromString(String color) { private static Resources mResources; private static SharedPreferences mPrefs; - private static boolean mStatusTintEnabled = false; - private static boolean mNavigationTintEnabled = false; - private static Context mContext; - private static Window mWindow; public static void init(Context context) { mContext = context; @@ -259,19 +254,6 @@ public static void init(Context context) { * of each activity that contains fragments that use ThemeManager */ public static void themeActivity(QKActivity activity) { - - mWindow = activity.getWindow(); - - 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; - - if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(mColor)); - } - if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(mColor)); - } - } public static void setTheme(Theme theme) { @@ -551,35 +533,29 @@ public static void showColorPickerDialog(final QKActivity context) { } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static void setStatusBarTintEnabled(boolean enabled) { - if (mStatusTintEnabled != enabled) { - mStatusTintEnabled = enabled; - int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; - int colorTo = enabled ? mColor : mResources.getColor(R.color.black); - - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); - colorAnimation.setDuration(TRANSITION_LENGTH); - colorAnimation.addUpdateListener(animation -> { - mWindow.setStatusBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); - }); - colorAnimation.start(); - } + public static void setStatusBarTintEnabled(QKActivity activity, boolean enabled) { + int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; + int colorTo = enabled ? mColor : mResources.getColor(R.color.black); + + ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); + colorAnimation.setDuration(TRANSITION_LENGTH); + colorAnimation.addUpdateListener(animation -> { + activity.getWindow().setStatusBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); + }); + colorAnimation.start(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static void setNavigationBarTintEnabled(boolean enabled) { - if (mNavigationTintEnabled != enabled) { - mNavigationTintEnabled = enabled; - int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; - int colorTo = enabled ? mColor : mResources.getColor(R.color.black); - - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); - colorAnimation.setDuration(TRANSITION_LENGTH); - colorAnimation.addUpdateListener(animation -> { - mWindow.setNavigationBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); - }); - colorAnimation.start(); - } + public static void setNavigationBarTintEnabled(QKActivity activity, boolean enabled) { + int colorFrom = enabled ? mResources.getColor(R.color.black) : mColor; + int colorTo = enabled ? mColor : mResources.getColor(R.color.black); + + ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); + colorAnimation.setDuration(TRANSITION_LENGTH); + colorAnimation.addUpdateListener(animation -> { + activity.getWindow().setNavigationBarColor(ColorUtils.darken((Integer) animation.getAnimatedValue())); + }); + colorAnimation.start(); } public static String getColorString(int color) { @@ -611,16 +587,7 @@ public static void setColor(QKActivity activity, int color) { colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(animation -> { - mActiveColor = (Integer) animation.getAnimatedValue(); - - if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(mActiveColor)); - } - if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(mActiveColor)); - } - - LiveViewManager.refreshViews(QKPreference.THEME); + setActiveColor((Integer) animation.getAnimatedValue()); }); colorAnimation.addListener(new AnimatorListenerAdapter() { @Override @@ -650,16 +617,8 @@ public void onAnimationEnd(Animator animation) { } } - public static void setActiveColor(QKActivity activity, int color) { + public static void setActiveColor(int color) { mActiveColor = color; - - if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(color)); - } - if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(color)); - } - LiveViewManager.refreshViews(QKPreference.THEME); } 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 ad48ffee8..1762d1643 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 @@ -25,7 +25,9 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.preferences.QKPreference; +import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.ui.ThemeManager; +import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.QKTextView; import java.util.ArrayList; @@ -42,6 +44,9 @@ public abstract class QKActivity extends AppCompatActivity { protected Resources mRes; protected SharedPreferences mPrefs; + private static boolean mStatusTintEnabled = true; + private static boolean mNavigationTintEnabled = false; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -51,14 +56,24 @@ protected void onCreate(Bundle savedInstanceState) { mProgressDialog = new ProgressDialog(this); mProgressDialog.setIndeterminate(true); mProgressDialog.setCancelable(false); + + LiveViewManager.registerView(QKPreference.TINTED_STATUS, this, key -> { + mStatusTintEnabled = getBoolean(QKPreference.TINTED_STATUS) && + Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + }); + + LiveViewManager.registerView(QKPreference.TINTED_NAV, this, key -> { + mNavigationTintEnabled = getBoolean(QKPreference.TINTED_NAV) && + Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + }); } /** * Reloads the toolbar and it's view references. - *

+ *

* This is called every time the content view of the activity is set, since the * toolbar is now a part of the activity layout. - *

+ *

* TODO: If someone ever wants to manage the Toolbar dynamically instead of keeping it in their * TODO layout file, we can add an alternate way of setting the toolbar programmatically. */ @@ -75,6 +90,13 @@ private void reloadToolbar() { LiveViewManager.registerView(QKPreference.THEME, this, key -> { mToolbar.setBackgroundColor(ThemeManager.getColor()); + + if (mStatusTintEnabled) { + getWindow().setStatusBarColor(ColorUtils.darken(ThemeManager.getColor())); + } + if (mNavigationTintEnabled) { + getWindow().setNavigationBarColor(ColorUtils.darken(ThemeManager.getColor())); + } }); LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { @@ -217,7 +239,7 @@ public void setContentView(View view, ViewGroup.LayoutParams params) { /** * Sets the title of the activity, displayed on the toolbar - *

+ *

* Make sure this is only called AFTER setContentView, or else the Toolbar * is likely not initialized yet and this method will do nothing * diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 98724d37a..2bf8667a1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -762,7 +762,7 @@ public void onContentOpened() { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } - ThemeManager.setActiveColor(mContext, mConversationPrefs.getColor()); + ThemeManager.setActiveColor(mConversationPrefs.getColor()); } @Override @@ -787,13 +787,13 @@ public void onContentClosed() { } } - ThemeManager.setActiveColor(mContext, ThemeManager.getThemeColor()); + ThemeManager.setActiveColor(ThemeManager.getThemeColor()); } @Override public void onMenuChanging(float percentOpen) { if (mConversationPrefs != null) { - ThemeManager.setActiveColor(mContext, (int) mArgbEvaluator.evaluate( + ThemeManager.setActiveColor((int) mArgbEvaluator.evaluate( percentOpen, 0xFF000000 | mConversationPrefs.getColor(), 0xFF000000 | ThemeManager.getThemeColor())); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 8563586a2..e7e849417 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -401,10 +401,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); break; case STATUS_TINT: - ThemeManager.setStatusBarTintEnabled((Boolean) newValue); + ThemeManager.setStatusBarTintEnabled(mContext, (Boolean) newValue); break; case NAVIGATION_TINT: - ThemeManager.setNavigationBarTintEnabled((Boolean) newValue); + ThemeManager.setNavigationBarTintEnabled(mContext, (Boolean) newValue); break; case FONT_FAMILY: preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); From 2d75fc8e11e1395ea28fb461d2c24f5d5732664f Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 3 Jan 2016 20:45:44 -0500 Subject: [PATCH 32/49] Remove unused method --- QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java | 7 ------- QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java | 3 --- .../main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java | 1 - 3 files changed, 11 deletions(-) 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 afabc1528..e044a72a0 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -249,13 +249,6 @@ public static void init(Context context) { initializeTheme(Theme.fromString(mPrefs.getString(SettingsFragment.BACKGROUND, "offwhite"))); } - /** - * Loads all theme properties. Should be called during onCreate - * of each activity that contains fragments that use ThemeManager - */ - public static void themeActivity(QKActivity activity) { - } - public static void setTheme(Theme theme) { int startColor = mBackgroundColor; initializeTheme(theme); 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 1762d1643..15eea0ac1 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 @@ -27,7 +27,6 @@ import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.QKTextView; import java.util.ArrayList; @@ -113,8 +112,6 @@ private void reloadToolbar() { } ((QKTextView) findViewById(R.id.toolbar_title)).setTextColor(ThemeManager.getTextOnColorPrimary()); }); - - ThemeManager.themeActivity(this); } protected void showBackButton(boolean show) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index 59dc4bed8..d6c3313a5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -29,7 +29,6 @@ protected void onCreate(Bundle savedInstanceState) { setFinishOnTouchOutside(mPrefs.getBoolean(SettingsFragment.QUICKREPLY_TAP_DISMISS, true)); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); setContentView(getLayoutResource()); - ThemeManager.themeActivity(this); ((QKLinearLayout) findViewById(R.id.popup)).setBackgroundTint(ThemeManager.getBackgroundColor()); From 07078f5c88249368bf87ab9622f7261233417b8c Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Mon, 4 Jan 2016 00:17:16 -0500 Subject: [PATCH 33/49] Fix activity theme setting --- .../java/com/moez/QKSMS/ui/ThemeManager.java | 8 -------- .../com/moez/QKSMS/ui/base/QKActivity.java | 19 +++++++++++++++++++ .../moez/QKSMS/ui/base/QKPopupActivity.java | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) 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 e044a72a0..367417672 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -302,23 +302,15 @@ public static void initializeTheme(Theme theme) { switch (theme) { case WHITE: mBackgroundColor = mResources.getColor(R.color.white_pure); - if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? - R.style.AppThemeWhite : R.style.AppThemeWhiteDialog); break; case OFFWHITE: mBackgroundColor = mResources.getColor(R.color.grey_light_mega_ultra); - if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? - R.style.AppThemeLight : R.style.AppThemeLightDialog); break; case GREY: mBackgroundColor = mResources.getColor(R.color.grey_material); - if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? - R.style.AppThemeDark : R.style.AppThemeDarkDialog); break; case BLACK: mBackgroundColor = mResources.getColor(R.color.black); - if (mContext != null) mContext.setTheme(mContext instanceof MainActivity ? - R.style.AppThemeDarkAmoled : R.style.AppThemeDarkAmoledDialog); break; } 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 15eea0ac1..71cc36508 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 @@ -99,6 +99,7 @@ private void reloadToolbar() { }); LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { + setTheme(getThemeRes()); switch (ThemeManager.getTheme()) { case WHITE: case OFFWHITE: @@ -260,6 +261,24 @@ public boolean isScreenOn() { } } + protected int getThemeRes() { + switch (ThemeManager.getTheme()) { + case WHITE: + return R.style.AppThemeWhite; + + case OFFWHITE: + return R.style.AppThemeLight; + + case GREY: + return R.style.AppThemeDark; + + case BLACK: + return R.style.AppThemeDarkAmoled; + } + + return R.style.AppThemeLight; + } + public void makeToast(@StringRes int message) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index d6c3313a5..c46ed99c1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -38,5 +38,24 @@ protected void onCreate(Bundle savedInstanceState) { } } + @Override + protected int getThemeRes() { + switch (ThemeManager.getTheme()) { + case WHITE: + return R.style.AppThemeWhiteDialog; + + case OFFWHITE: + return R.style.AppThemeLightDialog; + + case GREY: + return R.style.AppThemeDarkDialog; + + case BLACK: + return R.style.AppThemeDarkAmoledDialog; + } + + return R.style.AppThemeLightDialog; + } + protected abstract int getLayoutResource(); } From 3e7c7d77f98be134170de326e1f485b9b864f0be Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Mon, 4 Jan 2016 00:40:24 -0500 Subject: [PATCH 34/49] Remove holo theme --- .../com/moez/QKSMS/common/FontManager.java | 2 +- .../QKSMS/receiver/NightModeAutoReceiver.java | 4 +- .../java/com/moez/QKSMS/ui/ThemeManager.java | 43 +++++++------------ .../com/moez/QKSMS/ui/base/QKActivity.java | 13 ++---- .../moez/QKSMS/ui/base/QKPopupActivity.java | 8 +--- .../ui/welcome/WelcomeNightFragment.java | 4 +- QKSMS/src/main/res/values-cs/strings.xml | 1 - QKSMS/src/main/res/values-da/strings.xml | 1 - QKSMS/src/main/res/values-de/strings.xml | 1 - QKSMS/src/main/res/values-es/strings.xml | 1 - QKSMS/src/main/res/values-fa/strings.xml | 1 - QKSMS/src/main/res/values-fi/strings.xml | 1 - QKSMS/src/main/res/values-fr/strings.xml | 1 - QKSMS/src/main/res/values-hi/strings.xml | 1 - QKSMS/src/main/res/values-in/strings.xml | 1 - QKSMS/src/main/res/values-it/strings.xml | 1 - QKSMS/src/main/res/values-iw/strings.xml | 1 - QKSMS/src/main/res/values-ja/strings.xml | 1 - QKSMS/src/main/res/values-ko/strings.xml | 1 - QKSMS/src/main/res/values-lt/strings.xml | 1 - QKSMS/src/main/res/values-ne/strings.xml | 1 - QKSMS/src/main/res/values-nl/strings.xml | 1 - QKSMS/src/main/res/values-no/strings.xml | 1 - QKSMS/src/main/res/values-pl/strings.xml | 1 - QKSMS/src/main/res/values-pt-rBR/strings.xml | 1 - QKSMS/src/main/res/values-pt/strings.xml | 1 - QKSMS/src/main/res/values-ro/strings.xml | 1 - QKSMS/src/main/res/values-ru/strings.xml | 1 - QKSMS/src/main/res/values-sk/strings.xml | 1 - QKSMS/src/main/res/values-sr/strings.xml | 1 - QKSMS/src/main/res/values-sv/strings.xml | 1 - QKSMS/src/main/res/values-tl/strings.xml | 1 - QKSMS/src/main/res/values-tr/strings.xml | 1 - QKSMS/src/main/res/values-zh-rCN/strings.xml | 1 - QKSMS/src/main/res/values-zh/strings.xml | 1 - QKSMS/src/main/res/values/donottranslate.xml | 3 +- QKSMS/src/main/res/values/strings.xml | 5 +-- QKSMS/src/main/res/values/themes.xml | 12 ------ .../src/main/res/xml/settings_appearance.xml | 2 +- QKSMS/src/main/res/xml/settings_main.xml | 2 +- QKSMS/src/main/res/xml/settings_simple.xml | 2 +- 41 files changed, 31 insertions(+), 98 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java index 8c8c1fd51..3fba18059 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java @@ -89,7 +89,7 @@ public static ColorStateList getTextColor(Context context, int type) { // Colors and font weight switch (type) { case FontManager.TEXT_TYPE_PRIMARY: - boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.GREY || + boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.DARK || ThemeManager.getTheme() == ThemeManager.Theme.BLACK; int id = isNight ? R.color.text_primary_dark : R.color.text_primary_light; return context.getResources().getColorStateList(id); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java index f997b60bc..c8cc1929d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/NightModeAutoReceiver.java @@ -41,11 +41,11 @@ public void onReceive(Context context, Intent intent) { (calendar.get(Calendar.HOUR_OF_DAY) == day.get(Calendar.HOUR_OF_DAY) && calendar.get(Calendar.MINUTE) <= day.get(Calendar.MINUTE))) { Log.i(TAG, "Switching to night mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_GREY).apply(); - ThemeManager.setTheme(ThemeManager.Theme.GREY); + ThemeManager.setTheme(ThemeManager.Theme.DARK); } else { Log.i(TAG, "Switching to day mode"); prefs.edit().putString(SettingsFragment.BACKGROUND, ThemeManager.Theme.PREF_OFFWHITE).apply(); - ThemeManager.setTheme(ThemeManager.Theme.OFFWHITE); + ThemeManager.setTheme(ThemeManager.Theme.LIGHT); } } } 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 367417672..0bee3052c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -39,29 +39,25 @@ public class ThemeManager { public static final int TRANSITION_LENGTH = 500; public enum Theme { - WHITE, - OFFWHITE, - GREY, + LIGHT, + DARK, BLACK; - public static final String PREF_WHITE = "white"; - public static final String PREF_OFFWHITE = "offwhite"; + public static final String PREF_OFFWHITE = "light"; public static final String PREF_GREY = "grey"; public static final String PREF_BLACK = "black"; public static Theme fromString(String color) { switch (color) { - case PREF_WHITE: - return WHITE; case PREF_OFFWHITE: - return OFFWHITE; + return LIGHT; case PREF_GREY: - return GREY; + return DARK; case PREF_BLACK: return BLACK; default: Log.w(TAG, "Tried to set theme with invalid string: " + color); - return OFFWHITE; + return LIGHT; } } } @@ -300,13 +296,10 @@ public static void initializeTheme(Theme theme) { mTheme = theme; switch (theme) { - case WHITE: - mBackgroundColor = mResources.getColor(R.color.white_pure); - break; - case OFFWHITE: + case LIGHT: mBackgroundColor = mResources.getColor(R.color.grey_light_mega_ultra); break; - case GREY: + case DARK: mBackgroundColor = mResources.getColor(R.color.grey_material); break; case BLACK: @@ -315,13 +308,12 @@ public static void initializeTheme(Theme theme) { } switch (mTheme) { - case WHITE: - case OFFWHITE: + case LIGHT: 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); break; - case GREY: + case DARK: case BLACK: mTextOnBackgroundPrimary = mResources.getColor(R.color.theme_dark_text_primary); mtextOnBackgroundSecondary = mResources.getColor(R.color.theme_dark_text_secondary); @@ -459,17 +451,14 @@ public static int getNeutralBubbleColor() { } switch (mTheme) { - case WHITE: - return mResources.getColor(R.color.grey_light_mega_ultra); - - case OFFWHITE: - return mResources.getColor(R.color.white_pure); - - case GREY: + case DARK: return mResources.getColor(R.color.grey_dark); - default: + case BLACK: return mResources.getColor(R.color.grey_material); + + default: + return mResources.getColor(R.color.white_pure); } } @@ -490,7 +479,7 @@ public static Theme getTheme() { } public static boolean isNightMode() { - return mTheme == Theme.GREY || mTheme == Theme.BLACK; + return mTheme == Theme.DARK || mTheme == Theme.BLACK; } public static void showColorPickerDialog(final QKActivity context) { 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 71cc36508..6ec2312e3 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 @@ -101,12 +101,11 @@ private void reloadToolbar() { LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { setTheme(getThemeRes()); switch (ThemeManager.getTheme()) { - case WHITE: - case OFFWHITE: + case LIGHT: mToolbar.setPopupTheme(R.style.PopupThemeLight); break; - case GREY: + case DARK: case BLACK: mToolbar.setPopupTheme(R.style.PopupTheme); break; @@ -263,13 +262,7 @@ public boolean isScreenOn() { protected int getThemeRes() { switch (ThemeManager.getTheme()) { - case WHITE: - return R.style.AppThemeWhite; - - case OFFWHITE: - return R.style.AppThemeLight; - - case GREY: + case DARK: return R.style.AppThemeDark; case BLACK: diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java index c46ed99c1..52c704400 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKPopupActivity.java @@ -41,13 +41,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected int getThemeRes() { switch (ThemeManager.getTheme()) { - case WHITE: - return R.style.AppThemeWhiteDialog; - - case OFFWHITE: - return R.style.AppThemeLightDialog; - - case GREY: + case DARK: return R.style.AppThemeDarkDialog; case BLACK: diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java index 648a83dc8..210e0c310 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java @@ -63,11 +63,11 @@ public void onScrollOffsetChanged(WelcomeActivity activity, float offset) { @Override public void onClick(View v) { if (v.getId() == R.id.welcome_night_hint) { - boolean night = ThemeManager.getTheme() == ThemeManager.Theme.OFFWHITE; + boolean night = ThemeManager.getTheme() == ThemeManager.Theme.LIGHT; int backgroundColor = mContext.getResources().getColor(night ? R.color.grey_light_mega_ultra : R.color.grey_material); int newBackgroundColor = mContext.getResources().getColor(night ? R.color.grey_material : R.color.grey_light_mega_ultra); - ThemeManager.setTheme(night ? ThemeManager.Theme.GREY : ThemeManager.Theme.OFFWHITE); + ThemeManager.setTheme(night ? ThemeManager.Theme.DARK : ThemeManager.Theme.LIGHT); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), backgroundColor, newBackgroundColor); colorAnimation.setDuration(ThemeManager.TRANSITION_LENGTH); diff --git a/QKSMS/src/main/res/values-cs/strings.xml b/QKSMS/src/main/res/values-cs/strings.xml index f5e3bfdac..b6c583dc7 100755 --- a/QKSMS/src/main/res/values-cs/strings.xml +++ b/QKSMS/src/main/res/values-cs/strings.xml @@ -469,7 +469,6 @@ Odstranit zprávu - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-da/strings.xml b/QKSMS/src/main/res/values-da/strings.xml index 3cfd69a61..eff03e1ac 100755 --- a/QKSMS/src/main/res/values-da/strings.xml +++ b/QKSMS/src/main/res/values-da/strings.xml @@ -468,7 +468,6 @@ Slet besked - Hvid Hvidligt Mørk grå Sort diff --git a/QKSMS/src/main/res/values-de/strings.xml b/QKSMS/src/main/res/values-de/strings.xml index 91009a7de..18b26fb87 100755 --- a/QKSMS/src/main/res/values-de/strings.xml +++ b/QKSMS/src/main/res/values-de/strings.xml @@ -468,7 +468,6 @@ Nachricht löschen - Weiß Grau Dunkelgrau Schwarz diff --git a/QKSMS/src/main/res/values-es/strings.xml b/QKSMS/src/main/res/values-es/strings.xml index 2d547d743..ce74ecca7 100755 --- a/QKSMS/src/main/res/values-es/strings.xml +++ b/QKSMS/src/main/res/values-es/strings.xml @@ -468,7 +468,6 @@ Eliminar mensaje - Blanco Off-white Gris oscuro Negro diff --git a/QKSMS/src/main/res/values-fa/strings.xml b/QKSMS/src/main/res/values-fa/strings.xml index 4f0d40601..042883946 100755 --- a/QKSMS/src/main/res/values-fa/strings.xml +++ b/QKSMS/src/main/res/values-fa/strings.xml @@ -467,7 +467,6 @@ Delete message - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-fi/strings.xml b/QKSMS/src/main/res/values-fi/strings.xml index 608e1f437..df6012870 100755 --- a/QKSMS/src/main/res/values-fi/strings.xml +++ b/QKSMS/src/main/res/values-fi/strings.xml @@ -468,7 +468,6 @@ Poista viesti - Valkoinen Luonnonvalkoinen Tummanharmaa Musta diff --git a/QKSMS/src/main/res/values-fr/strings.xml b/QKSMS/src/main/res/values-fr/strings.xml index f16e2ddab..ec7e43f8b 100755 --- a/QKSMS/src/main/res/values-fr/strings.xml +++ b/QKSMS/src/main/res/values-fr/strings.xml @@ -468,7 +468,6 @@ Supprimer le message - Blanc Blanc cassé Gris foncé Noir diff --git a/QKSMS/src/main/res/values-hi/strings.xml b/QKSMS/src/main/res/values-hi/strings.xml index c5789cb93..50d02903f 100755 --- a/QKSMS/src/main/res/values-hi/strings.xml +++ b/QKSMS/src/main/res/values-hi/strings.xml @@ -468,7 +468,6 @@ संदेश हटाएं - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-in/strings.xml b/QKSMS/src/main/res/values-in/strings.xml index ef4836431..fc562b613 100755 --- a/QKSMS/src/main/res/values-in/strings.xml +++ b/QKSMS/src/main/res/values-in/strings.xml @@ -467,7 +467,6 @@ Hapus pesan - Putih Off-white Abu-abu gelap Hitam diff --git a/QKSMS/src/main/res/values-it/strings.xml b/QKSMS/src/main/res/values-it/strings.xml index 75d9c5488..b93c34a7b 100755 --- a/QKSMS/src/main/res/values-it/strings.xml +++ b/QKSMS/src/main/res/values-it/strings.xml @@ -468,7 +468,6 @@ Elimina il messaggio - Bianco Bianco sporco Grigio scuro Nero diff --git a/QKSMS/src/main/res/values-iw/strings.xml b/QKSMS/src/main/res/values-iw/strings.xml index b2fd6f18c..f933002fb 100755 --- a/QKSMS/src/main/res/values-iw/strings.xml +++ b/QKSMS/src/main/res/values-iw/strings.xml @@ -473,7 +473,6 @@ מחק הודעה - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-ja/strings.xml b/QKSMS/src/main/res/values-ja/strings.xml index e3249f36a..e6fd4a539 100755 --- a/QKSMS/src/main/res/values-ja/strings.xml +++ b/QKSMS/src/main/res/values-ja/strings.xml @@ -467,7 +467,6 @@ メッセージを削除 - オフホワイト ダークグレー diff --git a/QKSMS/src/main/res/values-ko/strings.xml b/QKSMS/src/main/res/values-ko/strings.xml index 01a559173..89dfa5b22 100755 --- a/QKSMS/src/main/res/values-ko/strings.xml +++ b/QKSMS/src/main/res/values-ko/strings.xml @@ -467,7 +467,6 @@ 메시지 삭제 - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-lt/strings.xml b/QKSMS/src/main/res/values-lt/strings.xml index ab92324b8..956ed58f9 100755 --- a/QKSMS/src/main/res/values-lt/strings.xml +++ b/QKSMS/src/main/res/values-lt/strings.xml @@ -469,7 +469,6 @@ Ištrinti žinutę - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-ne/strings.xml b/QKSMS/src/main/res/values-ne/strings.xml index 283a56457..a49d7d158 100755 --- a/QKSMS/src/main/res/values-ne/strings.xml +++ b/QKSMS/src/main/res/values-ne/strings.xml @@ -468,7 +468,6 @@ Delete message - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-nl/strings.xml b/QKSMS/src/main/res/values-nl/strings.xml index a2d843333..63efa3712 100755 --- a/QKSMS/src/main/res/values-nl/strings.xml +++ b/QKSMS/src/main/res/values-nl/strings.xml @@ -468,7 +468,6 @@ Bericht verwijderen - Wit Gebroken wit Donkergrijs Zwart diff --git a/QKSMS/src/main/res/values-no/strings.xml b/QKSMS/src/main/res/values-no/strings.xml index 97ed060a5..4b541cef9 100755 --- a/QKSMS/src/main/res/values-no/strings.xml +++ b/QKSMS/src/main/res/values-no/strings.xml @@ -468,7 +468,6 @@ Slett melding - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-pl/strings.xml b/QKSMS/src/main/res/values-pl/strings.xml index 9bf012e57..e93ffad21 100755 --- a/QKSMS/src/main/res/values-pl/strings.xml +++ b/QKSMS/src/main/res/values-pl/strings.xml @@ -469,7 +469,6 @@ Usuń wiadomość - Biały Złamana biel Ciemnoszary Czarny diff --git a/QKSMS/src/main/res/values-pt-rBR/strings.xml b/QKSMS/src/main/res/values-pt-rBR/strings.xml index a29f40401..03aa2e5fc 100755 --- a/QKSMS/src/main/res/values-pt-rBR/strings.xml +++ b/QKSMS/src/main/res/values-pt-rBR/strings.xml @@ -470,7 +470,6 @@ Plural form: Conversas serão excluídas. Excluir mensagem - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-pt/strings.xml b/QKSMS/src/main/res/values-pt/strings.xml index f1f0f6c6b..a0ca8b3e3 100755 --- a/QKSMS/src/main/res/values-pt/strings.xml +++ b/QKSMS/src/main/res/values-pt/strings.xml @@ -468,7 +468,6 @@ Apagar mensagem - Branco Branco (off) Cinzento Preto diff --git a/QKSMS/src/main/res/values-ro/strings.xml b/QKSMS/src/main/res/values-ro/strings.xml index 7f6d11c8c..cd1c260a3 100755 --- a/QKSMS/src/main/res/values-ro/strings.xml +++ b/QKSMS/src/main/res/values-ro/strings.xml @@ -469,7 +469,6 @@ Ştergeţi mesajul - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-ru/strings.xml b/QKSMS/src/main/res/values-ru/strings.xml index c8749897a..74fcfdc91 100755 --- a/QKSMS/src/main/res/values-ru/strings.xml +++ b/QKSMS/src/main/res/values-ru/strings.xml @@ -470,7 +470,6 @@ Удалить сообщение - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-sk/strings.xml b/QKSMS/src/main/res/values-sk/strings.xml index 717d1fd63..a0b4ca6df 100755 --- a/QKSMS/src/main/res/values-sk/strings.xml +++ b/QKSMS/src/main/res/values-sk/strings.xml @@ -469,7 +469,6 @@ Odstrániť správu - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-sr/strings.xml b/QKSMS/src/main/res/values-sr/strings.xml index 26fd07d95..7a473743f 100755 --- a/QKSMS/src/main/res/values-sr/strings.xml +++ b/QKSMS/src/main/res/values-sr/strings.xml @@ -469,7 +469,6 @@ Избриши поруку - Бела Беличаста Тамно-сива Црна diff --git a/QKSMS/src/main/res/values-sv/strings.xml b/QKSMS/src/main/res/values-sv/strings.xml index acea66ab5..8360201ba 100755 --- a/QKSMS/src/main/res/values-sv/strings.xml +++ b/QKSMS/src/main/res/values-sv/strings.xml @@ -468,7 +468,6 @@ Ta bort meddelande - Vit Av-vit Mörkgrå Svart diff --git a/QKSMS/src/main/res/values-tl/strings.xml b/QKSMS/src/main/res/values-tl/strings.xml index 219067c68..8602bda20 100755 --- a/QKSMS/src/main/res/values-tl/strings.xml +++ b/QKSMS/src/main/res/values-tl/strings.xml @@ -468,7 +468,6 @@ Burahin ang mensahe - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values-tr/strings.xml b/QKSMS/src/main/res/values-tr/strings.xml index c0fb09037..d09b67dcc 100755 --- a/QKSMS/src/main/res/values-tr/strings.xml +++ b/QKSMS/src/main/res/values-tr/strings.xml @@ -468,7 +468,6 @@ Mesajı sil - Beyaz Kirli beyaz Koyu gri Siyah diff --git a/QKSMS/src/main/res/values-zh-rCN/strings.xml b/QKSMS/src/main/res/values-zh-rCN/strings.xml index 34068b0d2..06f918622 100755 --- a/QKSMS/src/main/res/values-zh-rCN/strings.xml +++ b/QKSMS/src/main/res/values-zh-rCN/strings.xml @@ -467,7 +467,6 @@ 删除信息 - Off-white Dark grey diff --git a/QKSMS/src/main/res/values-zh/strings.xml b/QKSMS/src/main/res/values-zh/strings.xml index e558804ed..08d84576f 100755 --- a/QKSMS/src/main/res/values-zh/strings.xml +++ b/QKSMS/src/main/res/values-zh/strings.xml @@ -470,7 +470,6 @@ 刪除訊息 - White Off-white Dark grey Black diff --git a/QKSMS/src/main/res/values/donottranslate.xml b/QKSMS/src/main/res/values/donottranslate.xml index 4513ca982..a19ddf6db 100644 --- a/QKSMS/src/main/res/values/donottranslate.xml +++ b/QKSMS/src/main/res/values/donottranslate.xml @@ -4,8 +4,7 @@ QKSMS - white - offwhite + light grey black diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index 1c50db8a9..483a09201 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -744,9 +744,8 @@ - White - Off-white - Dark grey + Material Light + Material Dark Black diff --git a/QKSMS/src/main/res/values/themes.xml b/QKSMS/src/main/res/values/themes.xml index 3f92a3f5b..01c003cd8 100644 --- a/QKSMS/src/main/res/values/themes.xml +++ b/QKSMS/src/main/res/values/themes.xml @@ -1,18 +1,6 @@ - - - - - -