simplified some code of applying action bar icon color to improve performance
This commit is contained in:
parent
1b5708101d
commit
6e98c63b80
|
@ -25,12 +25,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory.ThemedAppCompatDelegate;
|
||||
import android.support.v7.internal.widget.NativeActionModeAwareLayout;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -46,15 +41,12 @@ import org.mariotaku.twidere.Constants;
|
|||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.graphic.EmptyDrawable;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereActionModeForChildListener;
|
||||
import org.mariotaku.twidere.util.TwidereColorUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||
import org.mariotaku.twidere.util.support.view.ViewOutlineProviderCompat;
|
||||
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
|
||||
import org.mariotaku.twidere.view.TintedStatusFrameLayout;
|
||||
|
||||
|
@ -229,7 +221,7 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity
|
|||
if (actionBarView instanceof Toolbar) {
|
||||
final int themeColor = getCurrentThemeColor();
|
||||
final int themeId = getCurrentThemeResourceId();
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
final int itemColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
final Toolbar toolbar = (Toolbar) actionBarView;
|
||||
final int popupColor = ThemeUtils.getThemeForegroundColor(toolbar.getContext(), toolbar.getPopupTheme());
|
||||
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(actionBarView, ActionMenuView.class), itemColor, popupColor);
|
||||
|
@ -280,7 +272,7 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity
|
|||
final String option = getThemeBackgroundOption();
|
||||
ThemeUtils.applyActionBarBackground(actionBar, this, themeId, themeColor, option, isActionBarOutlineEnabled());
|
||||
// final int titleColor = ThemeUtils.getContrastActionBarTitleColor(this, themeId, themeColor);
|
||||
// final int actionBarItemsColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
// final int actionBarItemsColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
// ThemeUtils.setActionBarColor(getWindow(), actionBar, titleColor, actionBarItemsColor);
|
||||
}
|
||||
|
||||
|
|
|
@ -806,17 +806,17 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
ThemeUtils.getColorForegroundAndInverse(this, foregroundColors);
|
||||
if (ThemeUtils.isDarkTheme(themeResId)) {
|
||||
statusBarColor = getResources().getColor(R.color.background_color_action_bar_dark);
|
||||
final int actionItemColor = ThemeUtils.getContrastForegroundColor(this,
|
||||
getCurrentThemeResourceId(), themeColor);
|
||||
homeActionButton.setButtonColor(statusBarColor);
|
||||
homeActionButton.setIconColor(resources.getColor(R.color.action_icon_light), Mode.SRC_ATOP);
|
||||
homeActionButton.setIconColor(actionItemColor, Mode.SRC_ATOP);
|
||||
mTabIndicator.setStripColor(themeColor);
|
||||
mTabIndicator.setIconColor(foregroundColors[0]);
|
||||
mTabIndicator.setLabelColor(foregroundColors[0]);
|
||||
} else {
|
||||
statusBarColor = themeColor;
|
||||
final int colorDark = resources.getColor(R.color.action_icon_dark);
|
||||
final int colorLight = resources.getColor(R.color.action_icon_light);
|
||||
final int actionItemColor = TwidereColorUtils.getContrastYIQ(themeColor,
|
||||
ThemeUtils.ACCENT_COLOR_THRESHOLD, colorDark, colorLight);
|
||||
final int actionItemColor = ThemeUtils.getContrastForegroundColor(this,
|
||||
getCurrentThemeResourceId(), themeColor);
|
||||
final int contrastColor = TwidereColorUtils.getContrastYIQ(themeColor,
|
||||
ThemeUtils.ACCENT_COLOR_THRESHOLD, foregroundColors[0], foregroundColors[1]);
|
||||
homeActionButton.setButtonColor(themeColor);
|
||||
|
|
|
@ -263,7 +263,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
|
|||
if (toolbar != null) {
|
||||
final int themeColor = getCurrentThemeColor();
|
||||
final int themeId = getCurrentThemeResourceId();
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
final int itemColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor);
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
|
|||
final int themeColor = getCurrentThemeColor();
|
||||
final int themeId = getCurrentThemeResourceId();
|
||||
final String option = getThemeBackgroundOption();
|
||||
int actionBarItemsColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
int actionBarItemsColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
final ActionBarContainer actionBarContainer = (ActionBarContainer) findViewById(R.id.twidere_action_bar_container);
|
||||
switch (linkId) {
|
||||
case LINK_ID_SEARCH:
|
||||
|
|
|
@ -275,7 +275,7 @@ public class SignInActivity extends BaseAppCompatActivity implements TwitterCons
|
|||
if (toolbar != null) {
|
||||
final int themeColor = getCurrentThemeColor();
|
||||
final int themeId = getCurrentThemeResourceId();
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
final int itemColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor);
|
||||
}
|
||||
return result;
|
||||
|
@ -544,7 +544,7 @@ public class SignInActivity extends BaseAppCompatActivity implements TwitterCons
|
|||
final int themeColor = getCurrentThemeColor();
|
||||
final int themeId = getCurrentThemeResourceId();
|
||||
final String option = getThemeBackgroundOption();
|
||||
final int actionBarItemsColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
|
||||
final int actionBarItemsColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor);
|
||||
ThemeUtils.applyActionBarBackground(actionBar, this, themeId, themeColor, option, isActionBarOutlineEnabled());
|
||||
final Toolbar toolbar = peekActionBarToolbar();
|
||||
if (toolbar != null) {
|
||||
|
|
|
@ -140,6 +140,7 @@ import org.mariotaku.twidere.view.ProfileBannerImageView;
|
|||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
import org.mariotaku.twidere.view.TabPagerIndicator;
|
||||
import org.mariotaku.twidere.view.TintedStatusFrameLayout;
|
||||
import org.mariotaku.twidere.view.TwidereToolbar;
|
||||
import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -897,6 +898,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
|||
final HeaderDrawerLayout drawer = mHeaderDrawerLayout;
|
||||
if (drawer != null) {
|
||||
final int offset = drawer.getPaddingTop() - drawer.getHeaderTop();
|
||||
mPreviousActionBarItemIsDark = 0;
|
||||
mPreviousTabItemIsDark = 0;
|
||||
updateScrollOffset(offset);
|
||||
}
|
||||
}
|
||||
|
@ -1514,19 +1517,17 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
|||
final boolean actionItemIsDark = TwidereColorUtils.getYIQLuminance(barColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD;
|
||||
if (mPreviousActionBarItemIsDark == 0 || (actionItemIsDark ? 1 : -1) != mPreviousActionBarItemIsDark) {
|
||||
StatusBarProxy.setStatusBarDarkIcon(activity.getWindow(), actionItemIsDark);
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor(activity, themeId, barColor);
|
||||
// final int titleColor = ThemeUtils.getContrastActionBarTitleColor(activity, themeId, barColor);
|
||||
final int contrastForegroundColor = ThemeUtils.getContrastForegroundColor(activity, themeId, barColor);
|
||||
final Toolbar actionBarView = activity.getActionBarToolbar();
|
||||
if (actionBarView != null) {
|
||||
// actionBarView.setTitleTextColor(titleColor);
|
||||
// actionBarView.setSubtitleTextColor(titleColor);
|
||||
ThemeUtils.setActionBarOverflowColor(actionBarView, itemColor);
|
||||
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(actionBarView, ActionMenuView.class), itemColor, itemColor);
|
||||
final Drawable navigationIcon = actionBarView.getNavigationIcon();
|
||||
if (navigationIcon != null) {
|
||||
navigationIcon.setColorFilter(itemColor, Mode.SRC_ATOP);
|
||||
actionBarView.setTitleTextColor(contrastForegroundColor);
|
||||
actionBarView.setSubtitleTextColor(contrastForegroundColor);
|
||||
ThemeUtils.setActionBarOverflowColor(actionBarView, contrastForegroundColor);
|
||||
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(actionBarView, ActionMenuView.class),
|
||||
contrastForegroundColor, contrastForegroundColor);
|
||||
if (actionBarView instanceof TwidereToolbar) {
|
||||
((TwidereToolbar) actionBarView).setItemColor(contrastForegroundColor);
|
||||
}
|
||||
actionBarView.setNavigationIcon(navigationIcon);
|
||||
}
|
||||
}
|
||||
mPreviousActionBarItemIsDark = actionItemIsDark ? 1 : -1;
|
||||
|
|
|
@ -245,7 +245,7 @@ public class ThemeUtils implements Constants {
|
|||
} else {
|
||||
actionBarColor = accentColor;
|
||||
}
|
||||
final int itemColor = getContrastActionBarItemColor(context, themeRes, actionBarColor);
|
||||
final int itemColor = getContrastForegroundColor(context, themeRes, actionBarColor);
|
||||
if (actionModeCloseButton != null) {
|
||||
actionModeCloseButton.setColorFilter(itemColor, Mode.SRC_ATOP);
|
||||
}
|
||||
|
@ -376,23 +376,19 @@ public class ThemeUtils implements Constants {
|
|||
return R.style.Theme_Twidere_Light_Compose;
|
||||
}
|
||||
|
||||
public static int getContrastActionBarItemColor(Context context, int theme, int color) {
|
||||
public static int getContrastForegroundColor(Context context, int theme, int color) {
|
||||
final int[] colors = new int[2];
|
||||
getDarkLightForegroundColors(context, theme, colors);
|
||||
if (isDarkTheme(theme) || TwidereColorUtils.getYIQLuminance(color) <= ACCENT_COLOR_THRESHOLD) {
|
||||
//return light text color
|
||||
return context.getResources().getColor(R.color.action_icon_light);
|
||||
return colors[1];
|
||||
}
|
||||
//return dark text color
|
||||
return context.getResources().getColor(R.color.action_icon_dark);
|
||||
return colors[0];
|
||||
}
|
||||
|
||||
public static int getContrastActionBarItemColor(Context context) {
|
||||
final int colorBackground = getColorFromAttribute(context, android.R.attr.colorBackground, 0);
|
||||
if (TwidereColorUtils.getYIQLuminance(colorBackground) <= ACCENT_COLOR_THRESHOLD) {
|
||||
//return light text color
|
||||
return context.getResources().getColor(R.color.action_icon_light);
|
||||
}
|
||||
//return dark text color
|
||||
return context.getResources().getColor(R.color.action_icon_dark);
|
||||
return getColorFromAttribute(context, android.R.attr.colorForeground, 0);
|
||||
}
|
||||
|
||||
public static int getDialogThemeResource(final Context context) {
|
||||
|
@ -1156,15 +1152,15 @@ public class ThemeUtils implements Constants {
|
|||
public static void wrapMenuIcon(Context context, int backgroundColor, int popupBackgroundColor,
|
||||
Menu menu, int... excludeGroups) {
|
||||
final Resources resources = context.getResources();
|
||||
final int colorDark = resources.getColor(R.color.action_icon_dark);
|
||||
final int colorLight = resources.getColor(R.color.action_icon_light);
|
||||
final int itemColor = TwidereColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
|
||||
final int popupItemColor = TwidereColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight);
|
||||
// final int colorDark = resources.getColor(R.color.action_icon_dark);
|
||||
// final int colorLight = resources.getColor(R.color.action_icon_light);
|
||||
// final int itemColor = TwidereColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
|
||||
// final int popupItemColor = TwidereColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight);
|
||||
for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
|
||||
final MenuItem item = menu.getItem(i);
|
||||
wrapMenuItemIcon(item, itemColor, excludeGroups);
|
||||
// wrapMenuItemIcon(item, itemColor, excludeGroups);
|
||||
if (item.hasSubMenu()) {
|
||||
wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
|
||||
// wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
|
||||
}
|
||||
if (item.isVisible()) {
|
||||
k++;
|
||||
|
|
|
@ -182,7 +182,7 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory {
|
|||
applyTintableBackgroundViewTint(tintable, accentColor, noTintColor, backgroundTintColor, isColorTint);
|
||||
}
|
||||
} else if (view instanceof TwidereToolbar) {
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor((Context) activity,
|
||||
final int itemColor = ThemeUtils.getContrastForegroundColor((Context) activity,
|
||||
themeResourceId, actionBarColor);
|
||||
((TwidereToolbar) view).setItemColor(itemColor);
|
||||
} else if (view instanceof EditText) {
|
||||
|
|
|
@ -88,11 +88,11 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
|
|||
final Drawable foreground = ((FrameLayout) child).getForeground();
|
||||
if (foreground != null) {
|
||||
final Resources resources = getResources();
|
||||
final int colorDark = resources.getColor(R.color.action_icon_dark);
|
||||
final int colorLight = resources.getColor(R.color.action_icon_light);
|
||||
final int contrastColor = TwidereColorUtils.getContrastYIQ(color,
|
||||
ThemeUtils.ACCENT_COLOR_THRESHOLD, colorDark, colorLight);
|
||||
foreground.setColorFilter(contrastColor, Mode.MULTIPLY);
|
||||
// final int colorDark = resources.getColor(R.color.action_icon_dark);
|
||||
// final int colorLight = resources.getColor(R.color.action_icon_light);
|
||||
// final int contrastColor = TwidereColorUtils.getContrastYIQ(color,
|
||||
// ThemeUtils.ACCENT_COLOR_THRESHOLD, colorDark, colorLight);
|
||||
// foreground.setColorFilter(contrastColor, Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
package org.mariotaku.twidere.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.ActionMenuPresenter;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
@ -64,7 +66,16 @@ public class TwidereToolbar extends Toolbar {
|
|||
return menu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationIcon(Drawable icon) {
|
||||
if (icon != null && mItemColor != 0) {
|
||||
icon.setColorFilter(mItemColor, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
super.setNavigationIcon(icon);
|
||||
}
|
||||
|
||||
public void setItemColor(int itemColor) {
|
||||
mItemColor = itemColor;
|
||||
setNavigationIcon(getNavigationIcon());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
xmlns:tool="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:clipToPadding="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/element_spacing_msmall">
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_light</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
@ -35,8 +33,6 @@
|
|||
<item name="profileImageStyleLarge">@style/Widget.Light.ProfileImage.Large</item>
|
||||
<item name="cardItemBackgroundColor">#f8f8f8</item>
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_dark</item>
|
||||
<item name="menuIconColorDisabled">@color/action_icon_dark_disabled</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -52,9 +48,6 @@
|
|||
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<!--<item name="menuIconColor">@color/action_icon_light</item>-->
|
||||
<item name="menuIconColor">#fff</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
@ -69,8 +62,6 @@
|
|||
<item name="profileImageStyleLarge">@style/Widget.Light.ProfileImage.Large</item>
|
||||
<item name="cardItemBackgroundColor">#f8f8f8</item>
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_dark</item>
|
||||
<item name="menuIconColorDisabled">@color/action_icon_dark_disabled</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -86,9 +77,6 @@
|
|||
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<!--<item name="menuIconColor">@color/action_icon_light</item>-->
|
||||
<item name="menuIconColor">#fff</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
@ -104,8 +92,6 @@
|
|||
<item name="cardItemBackgroundColor">#f8f8f8</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_dark</item>
|
||||
<item name="menuIconColorDisabled">@color/action_icon_dark_disabled</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -121,8 +107,6 @@
|
|||
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_light</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
@ -138,8 +122,6 @@
|
|||
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_dark</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -166,8 +148,6 @@
|
|||
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_light</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
@ -194,8 +174,6 @@
|
|||
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_dark</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -235,8 +213,6 @@
|
|||
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_light</item>
|
||||
<item name="menuIconColorActionBar">?menuIconColor</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
</style>
|
||||
|
||||
|
|
Loading…
Reference in New Issue