From 85aa0299aba6dab31287947ec5a428f3fea48a27 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 28 Apr 2015 02:36:34 +0800 Subject: [PATCH] fixed overflow icon sometimes not applied to theme color --- .../v7/app/ThemedAppCompatDelegate.java | 32 ++++++++++++++++++- .../activity/support/LinkHandlerActivity.java | 19 ++++++++--- .../fragment/support/SearchFragment.java | 2 +- .../mariotaku/twidere/util/ThemeUtils.java | 12 +++++-- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/twidere/src/main/java/android/support/v7/app/ThemedAppCompatDelegate.java b/twidere/src/main/java/android/support/v7/app/ThemedAppCompatDelegate.java index 92c9fd869..9c258b050 100644 --- a/twidere/src/main/java/android/support/v7/app/ThemedAppCompatDelegate.java +++ b/twidere/src/main/java/android/support/v7/app/ThemedAppCompatDelegate.java @@ -23,12 +23,18 @@ import android.app.Activity; import android.content.Context; import android.os.Build; import android.support.v4.view.LayoutInflaterCompat; +import android.support.v7.widget.ActionMenuView; +import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.Window; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.activity.iface.IThemedActivity; +import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.ThemedLayoutInflaterFactory; +import org.mariotaku.twidere.util.support.ViewSupport; + +import java.lang.reflect.Field; /** * Created by mariotaku on 15/4/22. @@ -54,9 +60,33 @@ public class ThemedAppCompatDelegate implements Constants { private final IThemedActivity themed; - private ThemedAppCompatDelegateImplV11(IThemedActivity themed, Context context, Window window, AppCompatCallback callback) { + private ThemedAppCompatDelegateImplV11(final IThemedActivity themed, final Context context, + Window window, AppCompatCallback callback) { super(context, window, callback); this.themed = themed; +// try { +// final Field field = AppCompatDelegateImplV7.class.getDeclaredField("mInvalidatePanelMenuRunnable"); +// field.setAccessible(true); +// final Runnable old = (Runnable) field.get(this); +// field.set(this, new Runnable() { +// @Override +// public void run() { +// if (old != null) { +// old.run(); +// } +// final int themeColor = themed.getCurrentThemeColor(); +// final int themeId = themed.getCurrentThemeResourceId(); +// final int itemColor = ThemeUtils.getContrastActionBarItemColor(context, themeId, themeColor); +// final Toolbar toolbar = ThemeUtils.getToolbarFromActivity((Activity) themed); +// if (toolbar != null) { +// ThemeUtils.setActionBarOverflowColor(toolbar, itemColor); +// ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor); +// } +// } +// }); +// } catch (Exception ignore) { +// +// } } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java index 343032c59..35b8e02fd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java @@ -234,9 +234,21 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System } @Override - public boolean onPrepareOptionsMenu(Menu menu) { - final boolean result = super.onPrepareOptionsMenu(menu); - if (!shouldSetActionItemColor()) return result; + public boolean onPreparePanel(int featureId, View view, Menu menu) { + final boolean result = super.onPreparePanel(featureId, view, menu); + if (shouldSetActionItemColor()) { + setupToolbarMenuItemColor(); + mActionBarContainer.post(new Runnable() { + @Override + public void run() { + setupToolbarMenuItemColor(); + } + }); + } + return result; + } + + private void setupToolbarMenuItemColor() { final Toolbar toolbar = peekActionBarToolbar(); if (toolbar != null) { final int themeColor = getCurrentThemeColor(); @@ -245,7 +257,6 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System ThemeUtils.setActionBarOverflowColor(toolbar, itemColor); ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor); } - return result; } public final void setSubtitle(CharSequence subtitle) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java index abd18ed78..9011c50f8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java @@ -65,9 +65,9 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll private ViewPager mViewPager; private View mPagerWindowOverlay; + private TabPagerIndicator mPagerIndicator; private SupportTabsAdapter mPagerAdapter; - private TabPagerIndicator mPagerIndicator; private int mControlBarOffsetPixels; private int mControlBarHeight; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java index e480e82c0..566c0ba03 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java @@ -71,6 +71,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IThemedActivity; +import org.mariotaku.twidere.activity.support.LinkHandlerActivity; import org.mariotaku.twidere.graphic.ActionBarColorDrawable; import org.mariotaku.twidere.graphic.ActionIconDrawable; import org.mariotaku.twidere.text.ParagraphSpacingSpan; @@ -1070,9 +1071,7 @@ public class ThemeUtils implements Constants { } } if (!(overflowView instanceof ImageView)) return; - final Drawable drawable = ((ImageView) overflowView).getDrawable(); - if (drawable == null) return; - drawable.setColorFilter(itemColor, Mode.SRC_ATOP); + ((ImageView) overflowView).setColorFilter(itemColor, Mode.SRC_ATOP); } public static void setActionBarOverflowColor(ActionMenuView actionMenuView, int itemColor) { @@ -1262,4 +1261,11 @@ public class ThemeUtils implements Constants { } return 0; } + + @Nullable + public static Toolbar getToolbarFromActivity(Activity activity) { + if (activity instanceof LinkHandlerActivity) + return ((LinkHandlerActivity) activity).peekActionBarToolbar(); + return null; + } }