From 5493ab43f1e163f6d3df4fac1a8a05fbad4dde71 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 23 Dec 2016 09:26:52 +0800 Subject: [PATCH] improved text color --- .../org/mariotaku/chameleon/Chameleon.java | 10 ++++ .../internal/ChameleonInflationFactory.java | 5 ++ .../internal/ChameleonTypedArray.java | 10 ++-- .../view/ChameleonAutoCompleteTextView.java | 2 +- .../chameleon/view/ChameleonEditText.java | 2 +- .../ChameleonMultiAutoCompleteTextView.java | 2 +- .../chameleon/view/ChameleonTextView.java | 60 ++++++++++--------- chameleon/src/main/res/values/attrs.xml | 3 + .../twidere/view/PreferencesItemIconView.java | 36 +++++++++++ .../twidere/activity/HomeActivity.kt | 14 ++--- .../twidere/constant/PreferenceKeys.kt | 5 +- .../twidere/fragment/CustomTabsFragment.kt | 8 ++- .../twidere/util/StatusLinkClickHandler.kt | 6 +- .../main/res/layout/list_item_custom_tab.xml | 4 +- .../src/main/res/layout/list_item_draft.xml | 1 + .../list_item_preference_header_category.xml | 5 +- .../list_item_preference_header_item.xml | 4 +- .../layout/simple_list_item_activated_1.xml | 16 ++--- .../layout/simple_list_item_activated_2.xml | 16 ++--- 19 files changed, 145 insertions(+), 64 deletions(-) create mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/PreferencesItemIconView.java diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/Chameleon.java b/chameleon/src/main/java/org/mariotaku/chameleon/Chameleon.java index 8c0ef49f1..dbd44413a 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/Chameleon.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/Chameleon.java @@ -169,6 +169,7 @@ public class Chameleon { private int colorControlNormal; private int colorControlActivated; + private int colorControlHighlight; private int statusBarColor; private int navigationBarColor; @@ -348,6 +349,14 @@ public class Chameleon { this.colorControlActivated = color; } + public int getColorControlHighlight() { + return colorControlHighlight; + } + + public void setColorControlHighlight(int colorControlHighlight) { + this.colorControlHighlight = colorControlHighlight; + } + public void setLightStatusBarMode(@LightStatusBarMode int mode) { this.lightStatusBarMode = mode; } @@ -379,6 +388,7 @@ public class Chameleon { theme.setColorControlNormal(a.getColor(R.styleable.ChameleonTheme_colorControlNormal, 0)); theme.setColorControlActivated(a.getColor(R.styleable.ChameleonTheme_colorControlActivated, 0)); + theme.setColorControlHighlight(a.getColor(R.styleable.ChameleonTheme_colorControlHighlight, 0)); theme.setStatusBarColor(a.getColor(R.styleable.ChameleonTheme_android_statusBarColor, 0)); theme.setNavigationBarColor(a.getColor(R.styleable.ChameleonTheme_android_navigationBarColor, Color.BLACK)); diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonInflationFactory.java b/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonInflationFactory.java index daf844891..6df0d3ec7 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonInflationFactory.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonInflationFactory.java @@ -5,6 +5,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.util.ArrayMap; import android.support.v4.view.LayoutInflaterFactory; import android.support.v7.app.AppCompatDelegate; @@ -170,6 +171,10 @@ public class ChameleonInflationFactory implements LayoutInflaterFactory { R.styleable.ChameleonView, mTheme); Drawable background = a.getDrawable(R.styleable.ChameleonView_android_background); if (background != null) { + int tint = a.getColor(R.styleable.ChameleonView_backgroundTint, 0); + if (tint != 0) { + DrawableCompat.setTint(background, tint); + } SupportMethods.setBackground(view, background); } a.recycle(); diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonTypedArray.java b/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonTypedArray.java index eb57d537f..af90730d8 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonTypedArray.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/internal/ChameleonTypedArray.java @@ -49,10 +49,6 @@ public class ChameleonTypedArray { return new ChameleonTypedArray(array, hasAttribute, attributeReferences, theme); } - public int getColor(int index) { - return wrapped.getColor(index, 0); - } - public int getColor(int index, int defValue) { final int ref = attributeReferences[index]; int color = getCommonColorReference(ref); @@ -76,6 +72,12 @@ public class ChameleonTypedArray { return theme.getColorPrimaryDark(); } else if (ref == android.support.design.R.attr.colorAccent) { return theme.getColorAccent(); + } else if (ref == android.support.design.R.attr.colorControlNormal) { + return theme.getColorControlNormal(); + } else if (ref == android.support.design.R.attr.colorControlActivated) { + return theme.getColorControlActivated(); + } else if (ref == android.support.design.R.attr.colorControlHighlight) { + return theme.getColorControlHighlight(); } else if (ref == R.attr.colorToolbar) { return theme.getColorToolbar(); } diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonAutoCompleteTextView.java b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonAutoCompleteTextView.java index 9befe8db9..1959087bd 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonAutoCompleteTextView.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonAutoCompleteTextView.java @@ -34,7 +34,7 @@ public class ChameleonAutoCompleteTextView extends AppCompatAutoCompleteTextView @Nullable @Override public ChameleonEditText.Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { - return ChameleonTextView.Appearance.create(context, attributeSet, theme); + return ChameleonTextView.Appearance.create(this, context, attributeSet, theme); } diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonEditText.java b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonEditText.java index 9d49db6d5..db58e62a5 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonEditText.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonEditText.java @@ -34,7 +34,7 @@ public class ChameleonEditText extends AppCompatEditText implements ChameleonVie @Nullable @Override public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { - return ChameleonTextView.Appearance.create(context, attributeSet, theme); + return ChameleonTextView.Appearance.create(this, context, attributeSet, theme); } diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonMultiAutoCompleteTextView.java b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonMultiAutoCompleteTextView.java index 0f8e92d23..06f473d3c 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonMultiAutoCompleteTextView.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonMultiAutoCompleteTextView.java @@ -34,7 +34,7 @@ public class ChameleonMultiAutoCompleteTextView extends AppCompatMultiAutoComple @Nullable @Override public ChameleonEditText.Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { - return ChameleonTextView.Appearance.create(context, attributeSet, theme); + return ChameleonTextView.Appearance.create(this, context, attributeSet, theme); } diff --git a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonTextView.java b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonTextView.java index 05f52dea2..07abbcc45 100644 --- a/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonTextView.java +++ b/chameleon/src/main/java/org/mariotaku/chameleon/view/ChameleonTextView.java @@ -45,37 +45,59 @@ public class ChameleonTextView extends AppCompatTextView implements ChameleonVie @Nullable @Override public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { - Appearance appearance = new Appearance(); - ChameleonTypedArray a = ChameleonTypedArray.obtain(context, attributeSet, - R.styleable.ChameleonTextView, theme); - appearance.setLinkTextColor(a.getColor(R.styleable.ChameleonTextView_android_textColorLink, theme.getTextColorLink())); - a.recycle(); - return appearance; + return Appearance.create(this, context, attributeSet, theme); } @Override public void applyAppearance(@NonNull ChameleonView.Appearance appearance) { - final Appearance a = (Appearance) appearance; - setLinkTextColor(a.getLinkTextColor()); + Appearance.apply(this, (Appearance) appearance); } public static class Appearance implements ChameleonView.Appearance { + private int textColor; private int linkTextColor; private int backgroundColor; - public static void apply(TextView view, ChameleonTextView.Appearance appearance) { + + public int getLinkTextColor() { + return linkTextColor; + } + + public void setLinkTextColor(int linkTextColor) { + this.linkTextColor = linkTextColor; + } + + public int getBackgroundColor() { + return backgroundColor; + } + + public void setBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public int getTextColor() { + return textColor; + } + + public void setTextColor(int textColor) { + this.textColor = textColor; + } + + public static void apply(TextView view, Appearance appearance) { view.setLinkTextColor(appearance.getLinkTextColor()); + view.setTextColor(appearance.getTextColor()); ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(appearance.getBackgroundColor())); setCursorTint(view, appearance.getBackgroundColor()); setHandlerTint(view, appearance.getBackgroundColor()); view.setHighlightColor(ChameleonUtils.adjustAlpha(appearance.getBackgroundColor(), 0.4f)); } - public static ChameleonEditText.Appearance create(Context context, AttributeSet attributeSet, Chameleon.Theme theme) { - ChameleonTextView.Appearance appearance = new ChameleonTextView.Appearance(); + public static Appearance create(TextView view, Context context, AttributeSet attributeSet, Chameleon.Theme theme) { + Appearance appearance = new Appearance(); ChameleonTypedArray a = ChameleonTypedArray.obtain(context, attributeSet, R.styleable.ChameleonEditText, theme); + appearance.setTextColor(a.getColor(R.styleable.ChameleonEditText_android_textColor, view.getCurrentTextColor())); appearance.setLinkTextColor(a.getColor(R.styleable.ChameleonEditText_android_textColorLink, theme.getTextColorLink())); appearance.setBackgroundColor(a.getColor(R.styleable.ChameleonEditText_backgroundTint, theme.getColorAccent())); a.recycle(); @@ -132,21 +154,5 @@ public class ChameleonTextView extends AppCompatTextView implements ChameleonVie field.setAccessible(true); field.set(object, value); } - - public int getLinkTextColor() { - return linkTextColor; - } - - public void setLinkTextColor(int linkTextColor) { - this.linkTextColor = linkTextColor; - } - - public int getBackgroundColor() { - return backgroundColor; - } - - public void setBackgroundColor(int backgroundColor) { - this.backgroundColor = backgroundColor; - } } } diff --git a/chameleon/src/main/res/values/attrs.xml b/chameleon/src/main/res/values/attrs.xml index 4764eefe2..73dc1396b 100644 --- a/chameleon/src/main/res/values/attrs.xml +++ b/chameleon/src/main/res/values/attrs.xml @@ -35,11 +35,14 @@ + + + diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/PreferencesItemIconView.java b/twidere/src/main/java/org/mariotaku/twidere/view/PreferencesItemIconView.java new file mode 100644 index 000000000..c1616b34a --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/view/PreferencesItemIconView.java @@ -0,0 +1,36 @@ +package org.mariotaku.twidere.view; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; + +import org.mariotaku.chameleon.Chameleon; +import org.mariotaku.chameleon.ChameleonUtils; + +/** + * Created by mariotaku on 2016/12/23. + */ + +public class PreferencesItemIconView extends IconActionView { + public PreferencesItemIconView(Context context) { + super(context); + } + + public PreferencesItemIconView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public PreferencesItemIconView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Nullable + @Override + public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { + Appearance appearance = new Appearance(); + appearance.setActivatedColor(ChameleonUtils.getColorDependent(theme.getColorControlActivated())); + appearance.setDefaultColor(theme.getColorForeground()); + return appearance; + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt index d04f67501..b6758a6be 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt @@ -314,9 +314,9 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp signInIntent.setClass(this, SignInActivity::class.java) startActivity(signInIntent) finish() - if (defaultAutoRefreshKeyAsked !in kPreferences) { + if (defaultAutoRefreshAskedKey !in kPreferences) { // Assume first install - kPreferences[defaultAutoRefreshKeyAsked] = false + kPreferences[defaultAutoRefreshAskedKey] = false } return } else { @@ -347,16 +347,16 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp } mainTabs.setTabDisplayOption(tabDisplayOptionInt) mainTabs.setTabExpandEnabled(tabDisplayOptionInt and TabPagerIndicator.DisplayOption.LABEL == 0) - mainTabs.setDisplayBadge(preferences.getBoolean(SharedPreferenceConstants.KEY_UNREAD_COUNT, true)) + mainTabs.setDisplayBadge(preferences[unreadCountKey]) mainTabs.updateAppearance() - if (preferences.getBoolean(SharedPreferenceConstants.KEY_DRAWER_TOGGLE)) { + if (preferences[drawerToggleKey]) { drawerToggleButton.visibility = View.VISIBLE } else { drawerToggleButton.visibility = View.GONE } - if (preferences.getBoolean(SharedPreferenceConstants.KEY_FAB_VISIBLE)) { + if (preferences[fabVisibleKey]) { actionsButton.visibility = View.VISIBLE } else { actionsButton.visibility = View.GONE @@ -400,7 +400,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp startService(Intent(this, StreamingService::class.java)) } - if (!showDrawerTutorial() && !kPreferences[defaultAutoRefreshKeyAsked]) { + if (!showDrawerTutorial() && !kPreferences[defaultAutoRefreshAskedKey]) { showAutoRefreshConfirm() } } @@ -947,7 +947,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp } override fun onDismiss(dialog: DialogInterface?) { - kPreferences[defaultAutoRefreshKeyAsked] = true + kPreferences[defaultAutoRefreshAskedKey] = true super.onDismiss(dialog) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt index 378750125..1c6f625db 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -43,7 +43,10 @@ val bugReportsKey = KBooleanKey(KEY_BUG_REPORTS, BuildConfig.DEBUG) val readFromBottomKey = KBooleanKey(KEY_READ_FROM_BOTTOM, false) val randomizeAccountNameKey = KBooleanKey(KEY_RANDOMIZE_ACCOUNT_NAME, false) val defaultAutoRefreshKey = KBooleanKey(KEY_DEFAULT_AUTO_REFRESH, false) -val defaultAutoRefreshKeyAsked = KBooleanKey("default_auto_refresh_asked", true) +val defaultAutoRefreshAskedKey = KBooleanKey("default_auto_refresh_asked", true) +val unreadCountKey = KBooleanKey(KEY_UNREAD_COUNT, true) +val drawerToggleKey = KBooleanKey(KEY_DRAWER_TOGGLE, false) +val fabVisibleKey = KBooleanKey(KEY_FAB_VISIBLE, true) object refreshIntervalKey : KSimpleKey(KEY_REFRESH_INTERVAL, 15) { override fun read(preferences: SharedPreferences): Long { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt index e55b646d4..929354fdd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt @@ -68,6 +68,7 @@ import org.mariotaku.twidere.util.CustomTabUtils import org.mariotaku.twidere.util.DataStoreUtils import org.mariotaku.twidere.util.ThemeUtils import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder +import java.lang.ref.WeakReference class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks, MultiChoiceModeListener { @@ -149,7 +150,12 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks, Mult val icon = conf.icon.createDrawable(context) icon.mutate().setColorFilter(theme.textColorPrimary, Mode.SRC_ATOP) subItem.icon = icon + val weakFragment = WeakReference(this) subItem.setOnMenuItemClickListener { item -> + val fragment = weakFragment.get() ?: return@setOnMenuItemClickListener false + val adapter = fragment.adapter + val fm = fragment.childFragmentManager + val df = TabEditorDialogFragment() df.arguments = Bundle { this[EXTRA_TAB_TYPE] = type @@ -157,7 +163,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks, Mult this[EXTRA_TAB_POSITION] = adapter.getTab(adapter.count - 1).position + 1 } } - df.show(fragmentManager, TabEditorDialogFragment.TAG_ADD_TAB) + df.show(fm, TabEditorDialogFragment.TAG_ADD_TAB) return@setOnMenuItemClickListener true } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusLinkClickHandler.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusLinkClickHandler.kt index 44176b1d2..fa1bdbe5a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusLinkClickHandler.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusLinkClickHandler.kt @@ -29,7 +29,11 @@ import org.mariotaku.twidere.model.UserKey /** * Created by mariotaku on 15/1/23. */ -open class StatusLinkClickHandler(context: Context, manager: MultiSelectManager, preferences: SharedPreferencesWrapper) : OnLinkClickHandler(context, manager, preferences), Constants { +open class StatusLinkClickHandler( + context: Context, + manager: MultiSelectManager, + preferences: SharedPreferencesWrapper +) : OnLinkClickHandler(context, manager, preferences), Constants { var status: ParcelableStatus? = null diff --git a/twidere/src/main/res/layout/list_item_custom_tab.xml b/twidere/src/main/res/layout/list_item_custom_tab.xml index a5b72c977..e5592b2d2 100644 --- a/twidere/src/main/res/layout/list_item_custom_tab.xml +++ b/twidere/src/main/res/layout/list_item_custom_tab.xml @@ -19,6 +19,7 @@ + android:tag="tint_background|accent_color" + app:backgroundTint="?colorControlActivated"> diff --git a/twidere/src/main/res/layout/list_item_preference_header_category.xml b/twidere/src/main/res/layout/list_item_preference_header_category.xml index 6133faa7a..78ada560d 100644 --- a/twidere/src/main/res/layout/list_item_preference_header_category.xml +++ b/twidere/src/main/res/layout/list_item_preference_header_category.xml @@ -26,6 +26,5 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:tag="text_color|accent_color" - android:textColor="?colorAccent" - android:maxLines="1"/> + android:maxLines="1" + android:textColor="?colorAccent"/> diff --git a/twidere/src/main/res/layout/list_item_preference_header_item.xml b/twidere/src/main/res/layout/list_item_preference_header_item.xml index 283e93a9e..a29d85f12 100644 --- a/twidere/src/main/res/layout/list_item_preference_header_item.xml +++ b/twidere/src/main/res/layout/list_item_preference_header_item.xml @@ -26,9 +26,9 @@ android:gravity="center_vertical" android:minHeight="?listPreferredItemHeightSmall" android:orientation="horizontal" - android:tag="tint_background|accent_color"> + app:backgroundTint="?colorControlActivated"> - + android:textAppearance="?android:textAppearanceListItemSmall" + app:backgroundTint="?colorControlActivated"/> diff --git a/twidere/src/main/res/layout/simple_list_item_activated_2.xml b/twidere/src/main/res/layout/simple_list_item_activated_2.xml index 9a64c26b2..3430f0bf7 100644 --- a/twidere/src/main/res/layout/simple_list_item_activated_2.xml +++ b/twidere/src/main/res/layout/simple_list_item_activated_2.xml @@ -16,23 +16,25 @@ + android:tag="tint_background|accent_color" + app:backgroundTint="?colorControlActivated"> + android:textAppearance="?android:textAppearanceListItem"/>