trying to fix overflow icon color
This commit is contained in:
parent
a8ab005aae
commit
ee605af79c
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
@ -41,6 +41,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory;
|
||||
|
@ -379,6 +380,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
mActionsButton.setOnLongClickListener(this);
|
||||
mEmptyTabHint.setOnClickListener(this);
|
||||
|
||||
ViewCompat.setElevation(mActionBar, ThemeUtils.getSupportActionBarElevation(this));
|
||||
ThemeUtils.setCompatToolbarOverlay(this, new EmptyDrawable());
|
||||
ThemeUtils.setCompatContentViewOverlay(this, new EmptyDrawable());
|
||||
setupSlidingMenu();
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.preference.Preference;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.internal.view.SupportMenuInflater;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.CardView;
|
||||
|
@ -114,6 +115,7 @@ public class ThemePreviewPreference extends Preference implements Constants, OnS
|
|||
ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
ViewSupport.setBackground(actionBarView, ThemeUtils.getActionBarBackground(context, themeRes,
|
||||
accentColor, backgroundOption, true));
|
||||
ViewCompat.setElevation(actionBarView, ThemeUtils.getSupportActionBarElevation(context));
|
||||
ViewSupport.setBackground(actionBarOverlay, ThemeUtils.getWindowContentOverlay(context));
|
||||
cardView.setCardBackgroundColor(cardBackgroundColor);
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ import android.support.v7.internal.widget.ActionBarContainer;
|
|||
import android.support.v7.internal.widget.ActionBarContextView;
|
||||
import android.support.v7.internal.widget.ActionBarOverlayLayout;
|
||||
import android.support.v7.internal.widget.ContentFrameLayout;
|
||||
import android.support.v7.widget.ActionMenuPresenter;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
@ -225,15 +226,8 @@ public class ThemeUtils implements Constants {
|
|||
View contextView = null;
|
||||
Context actionBarContext = null;
|
||||
if (modeCompat instanceof ActionModeImpl) {
|
||||
WindowDecorActionBar actionBar = null;
|
||||
final Field[] fields = ActionModeImpl.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (WindowDecorActionBar.class.isAssignableFrom(field.getType())) {
|
||||
field.setAccessible(true);
|
||||
actionBar = (WindowDecorActionBar) field.get(modeCompat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
WindowDecorActionBar actionBar = (WindowDecorActionBar) Utils.findFieldOfTypes(modeCompat,
|
||||
ActionModeImpl.class, WindowDecorActionBar.class);
|
||||
if (actionBar == null) return;
|
||||
actionBarContext = actionBar.getThemedContext();
|
||||
final Field contextViewField = WindowDecorActionBar.class.getDeclaredField("mContextView");
|
||||
|
@ -1074,6 +1068,19 @@ public class ThemeUtils implements Constants {
|
|||
((ImageView) overflowView).setColorFilter(itemColor, Mode.SRC_ATOP);
|
||||
}
|
||||
|
||||
public static void setActionBarOverflowColor(ActionMenuPresenter presenter, int itemColor) {
|
||||
if (presenter == null) return;
|
||||
View overflowView = null;
|
||||
View view = (View) Utils.findFieldOfTypes(presenter, ActionMenuPresenter.class, ActionMenuView.ActionMenuChildView.class, View.class);
|
||||
if (view == null) return;
|
||||
final ActionMenuView.LayoutParams lp = (ActionMenuView.LayoutParams) view.getLayoutParams();
|
||||
if (lp.isOverflowButton) {
|
||||
overflowView = view;
|
||||
}
|
||||
if (!(overflowView instanceof ImageView)) return;
|
||||
((ImageView) overflowView).setColorFilter(itemColor, Mode.SRC_ATOP);
|
||||
}
|
||||
|
||||
public static void setActionBarOverflowColor(ActionMenuView actionMenuView, int itemColor) {
|
||||
if (actionMenuView == null) return;
|
||||
View overflowView = null;
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -41,9 +42,11 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.AppCompatPreferenceActivity;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
import org.mariotaku.twidere.view.TwidereToolbar;
|
||||
import org.mariotaku.twidere.view.iface.IThemedView;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
@ -119,24 +122,27 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory {
|
|||
}
|
||||
|
||||
private static void initViewTint(View view, IThemedActivity activity) {
|
||||
final int noTintColor, tintColor;
|
||||
final int noTintColor, tintColor, actionBarColor;
|
||||
final boolean isColorTint;
|
||||
// View context is not derived from ActionBar, apply color tint directly
|
||||
final Resources resources = ((Activity) activity).getResources();
|
||||
final boolean isActionBarContext = isActionBarContext(view.getContext(), getActionBarContext((Activity) activity));
|
||||
final int themeResourceId = activity.getCurrentThemeResourceId();
|
||||
if (!isActionBarContext) {
|
||||
tintColor = activity.getCurrentThemeColor();
|
||||
tintColor = actionBarColor = activity.getCurrentThemeColor();
|
||||
noTintColor = TwidereColorUtils.getContrastYIQ(tintColor, ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
isColorTint = true;
|
||||
} else if (ThemeUtils.isDarkTheme(activity.getCurrentThemeResourceId())) {
|
||||
} else if (ThemeUtils.isDarkTheme(themeResourceId)) {
|
||||
// View context is derived from ActionBar but is currently dark theme, so we should show
|
||||
// light
|
||||
actionBarColor = resources.getColor(R.color.background_color_action_bar_dark);
|
||||
noTintColor = Color.WHITE;
|
||||
tintColor = activity.getCurrentThemeColor();
|
||||
isColorTint = true;
|
||||
} else {
|
||||
// View context is derived from ActionBar and it's light theme, so we use contrast color
|
||||
final int themeColor = activity.getCurrentThemeColor();
|
||||
tintColor = TwidereColorUtils.getContrastYIQ(themeColor, ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
actionBarColor = activity.getCurrentThemeColor();
|
||||
tintColor = TwidereColorUtils.getContrastYIQ(actionBarColor, ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
noTintColor = TwidereColorUtils.getContrastYIQ(tintColor, ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
isColorTint = false;
|
||||
}
|
||||
|
@ -163,6 +169,10 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory {
|
|||
}
|
||||
} else if (view instanceof EditText) {
|
||||
ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(tintColor));
|
||||
} else if (view instanceof TwidereToolbar) {
|
||||
final int itemColor = ThemeUtils.getContrastActionBarItemColor((Context) activity,
|
||||
themeResourceId, actionBarColor);
|
||||
((TwidereToolbar) view).setItemColor(itemColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -226,6 +226,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
|
@ -4231,6 +4232,23 @@ public final class Utils implements Constants, TwitterConstants {
|
|||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static <T> Object findFieldOfTypes(T obj, Class<? extends T> cls, Class<?>... checkTypes) {
|
||||
labelField:
|
||||
for (Field field : cls.getDeclaredFields()) {
|
||||
final Class<?> type = field.getType();
|
||||
View view = null;
|
||||
for (Class<?> checkType : checkTypes) {
|
||||
if (!checkType.isAssignableFrom(type)) continue labelField;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
return field.get(obj);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static class UtilsL {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
|
|
@ -20,34 +20,51 @@
|
|||
package org.mariotaku.twidere.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.widget.ActionMenuPresenter;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Menu;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/1/16.
|
||||
*/
|
||||
public class TwidereToolbar extends Toolbar {
|
||||
|
||||
private int mItemColor;
|
||||
|
||||
public TwidereToolbar(Context context) {
|
||||
super(context, null);
|
||||
super(context);
|
||||
}
|
||||
|
||||
public TwidereToolbar(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.toolbarStyle);
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public TwidereToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(getThemedContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
|
||||
final TypedArray a = getContext().obtainStyledAttributes(attrs, new int[]{R.attr.elevation}, defStyleAttr, 0);
|
||||
ViewCompat.setElevation(this, a.getDimension(0, 0));
|
||||
a.recycle();
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private static Context getThemedContext(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
return ThemeUtils.getActionBarContext(context);
|
||||
@Override
|
||||
public Menu getMenu() {
|
||||
final Menu menu = super.getMenu();
|
||||
ThemeUtils.setActionBarOverflowColor(this, mItemColor);
|
||||
final ActionMenuView menuView = (ActionMenuView) Utils.findFieldOfTypes(this, Toolbar.class,
|
||||
ActionMenuView.class);
|
||||
if (menuView != null) {
|
||||
final ActionMenuPresenter presenter = (ActionMenuPresenter) Utils.findFieldOfTypes(menuView,
|
||||
ActionMenuView.class, ActionMenuPresenter.class);
|
||||
if (presenter != null) {
|
||||
ThemeUtils.setActionBarOverflowColor(presenter, mItemColor);
|
||||
}
|
||||
}
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setItemColor(int itemColor) {
|
||||
mItemColor = itemColor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
android:touchscreenBlocksFocus="true"
|
||||
tools:ignore="UnusedAttribute">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
<org.mariotaku.twidere.view.TwidereToolbar
|
||||
android:id="@+id/action_bar"
|
||||
style="?attr/toolbarStyle"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.mariotaku.twidere.view.TwidereToolbar
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/actionbar"
|
||||
style="?actionBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -56,7 +56,7 @@
|
|||
app:tabExpandEnabled="true"
|
||||
app:tabHorizontalPadding="@dimen/element_spacing_normal"/>
|
||||
|
||||
</org.mariotaku.twidere.view.TwidereToolbar>
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<View
|
||||
android:id="@+id/actionbar_overlay"
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.mariotaku.twidere.view.TwidereToolbar
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/actionbar"
|
||||
style="?actionBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue