2014-07-03 07:48:39 +02:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.mariotaku.twidere.util;
|
|
|
|
|
2015-04-03 23:12:33 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.app.ActionBar;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2014-12-24 05:39:21 +01:00
|
|
|
import android.content.res.ColorStateList;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.PorterDuff;
|
2014-10-29 07:48:07 +01:00
|
|
|
import android.graphics.PorterDuff.Mode;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.graphics.Typeface;
|
2014-12-01 17:04:55 +01:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.os.Build;
|
2014-08-07 19:58:42 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2015-04-03 17:49:08 +02:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.support.v4.view.ViewCompat;
|
2015-04-03 23:12:33 +02:00
|
|
|
import android.support.v7.internal.app.WindowDecorActionBar;
|
|
|
|
import android.support.v7.internal.app.WindowDecorActionBar.ActionModeImpl;
|
|
|
|
import android.support.v7.internal.view.SupportActionModeWrapper;
|
|
|
|
import android.support.v7.internal.view.SupportActionModeWrapperTrojan;
|
2015-01-17 19:58:29 +01:00
|
|
|
import android.support.v7.internal.view.menu.ActionMenuItemView;
|
2015-04-04 00:06:08 +02:00
|
|
|
import android.support.v7.internal.widget.ActionBarOverlayLayout;
|
2015-01-17 19:58:29 +01:00
|
|
|
import android.support.v7.widget.ActionMenuView;
|
2015-04-13 18:34:10 +02:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2014-11-22 15:12:54 +01:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.Spanned;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.text.TextPaint;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
2015-04-03 23:12:33 +02:00
|
|
|
import android.view.ActionMode;
|
2014-10-25 12:45:50 +02:00
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.view.ContextThemeWrapper;
|
2014-10-25 12:45:50 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.view.View;
|
2015-01-17 19:58:29 +01:00
|
|
|
import android.view.View.OnLongClickListener;
|
2015-04-13 18:34:10 +02:00
|
|
|
import android.view.Window;
|
2015-04-14 17:38:50 +02:00
|
|
|
import android.view.WindowManager;
|
2014-12-24 05:39:21 +01:00
|
|
|
import android.widget.CompoundButton;
|
2015-04-13 18:34:10 +02:00
|
|
|
import android.widget.ImageView;
|
2014-12-24 05:39:21 +01:00
|
|
|
import android.widget.ProgressBar;
|
2014-10-29 07:48:07 +01:00
|
|
|
import android.widget.TextView;
|
2014-07-03 07:48:39 +02:00
|
|
|
|
2015-01-11 10:28:45 +01:00
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.Constants;
|
|
|
|
import org.mariotaku.twidere.R;
|
|
|
|
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
2014-12-08 16:16:33 +01:00
|
|
|
import org.mariotaku.twidere.graphic.ActionBarColorDrawable;
|
2015-01-17 19:58:29 +01:00
|
|
|
import org.mariotaku.twidere.graphic.ActionIconDrawable;
|
2014-11-22 15:12:54 +01:00
|
|
|
import org.mariotaku.twidere.text.ParagraphSpacingSpan;
|
2014-11-03 16:44:32 +01:00
|
|
|
import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
|
2015-04-03 17:49:08 +02:00
|
|
|
import org.mariotaku.twidere.view.TabPagerIndicator;
|
2014-12-24 05:39:21 +01:00
|
|
|
import org.mariotaku.twidere.view.iface.IThemedView;
|
2014-07-03 07:48:39 +02:00
|
|
|
|
|
|
|
import java.lang.reflect.Constructor;
|
2015-04-03 23:12:33 +02:00
|
|
|
import java.lang.reflect.Field;
|
2014-07-03 07:48:39 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
public class ThemeUtils implements Constants {
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
private static final int[] ANIM_OPEN_STYLE_ATTRS = {android.R.attr.activityOpenEnterAnimation,
|
|
|
|
android.R.attr.activityOpenExitAnimation};
|
|
|
|
private static final int[] ANIM_CLOSE_STYLE_ATTRS = {android.R.attr.activityCloseEnterAnimation,
|
|
|
|
android.R.attr.activityCloseExitAnimation};
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
private static final String[] sClassPrefixList = {"android.widget.", "android.webkit.", "org.mariotaku.twidere.view"};
|
2014-07-27 14:58:15 +02:00
|
|
|
|
|
|
|
private ThemeUtils() {
|
|
|
|
throw new AssertionError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void applyActionBarBackground(final ActionBar actionBar, final Context context, final int themeRes) {
|
|
|
|
if (actionBar == null || context == null) return;
|
|
|
|
actionBar.setBackgroundDrawable(getActionBarBackground(context, themeRes));
|
|
|
|
actionBar.setSplitBackgroundDrawable(getActionBarSplitBackground(context, themeRes));
|
2015-04-03 17:49:08 +02:00
|
|
|
// actionBar.setStackedBackgroundDrawable(getActionBarStackedBackground(context, themeRes));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2014-12-01 17:04:55 +01:00
|
|
|
|
|
|
|
public static void applyActionBarBackground(final ActionBar actionBar, final Context context,
|
2015-04-01 12:28:26 +02:00
|
|
|
final int themeRes, final int accentColor, boolean outlineEnabled) {
|
2014-12-01 17:04:55 +01:00
|
|
|
if (actionBar == null || context == null) return;
|
2015-04-01 12:28:26 +02:00
|
|
|
actionBar.setBackgroundDrawable(getActionBarBackground(context, themeRes, accentColor, outlineEnabled));
|
2014-12-01 17:04:55 +01:00
|
|
|
actionBar.setSplitBackgroundDrawable(getActionBarSplitBackground(context, themeRes));
|
2015-04-03 17:49:08 +02:00
|
|
|
actionBar.setStackedBackgroundDrawable(getActionBarBackground(context, themeRes, accentColor, outlineEnabled));
|
2014-12-01 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
|
|
|
|
public static void applyActionBarBackground(final android.support.v7.app.ActionBar actionBar, final Context context,
|
2015-04-01 12:28:26 +02:00
|
|
|
final int themeRes, final int accentColor, boolean outlineEnabled) {
|
2015-01-17 19:58:29 +01:00
|
|
|
if (actionBar == null || context == null) return;
|
2015-04-01 12:28:26 +02:00
|
|
|
actionBar.setBackgroundDrawable(getActionBarBackground(context, themeRes, accentColor, outlineEnabled));
|
2015-01-17 19:58:29 +01:00
|
|
|
actionBar.setSplitBackgroundDrawable(getActionBarSplitBackground(context, themeRes));
|
2015-04-03 17:49:08 +02:00
|
|
|
actionBar.setStackedBackgroundDrawable(getActionBarStackedBackground(context, themeRes, accentColor, outlineEnabled));
|
2015-01-17 19:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static void applyBackground(final View view) {
|
|
|
|
if (view == null) return;
|
2014-10-29 07:48:07 +01:00
|
|
|
applyBackground(view, getUserAccentColor(view.getContext()));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void applyBackground(final View view, final int color) {
|
|
|
|
if (view == null) return;
|
|
|
|
try {
|
|
|
|
final Drawable bg = view.getBackground();
|
|
|
|
if (bg == null) return;
|
|
|
|
final Drawable mutated = bg.mutate();
|
|
|
|
if (mutated == null) return;
|
|
|
|
mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
|
|
|
view.invalidate();
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 23:12:33 +02:00
|
|
|
public static void applySupportActionModeBackground(ActionMode mode, FragmentActivity activity,
|
|
|
|
int themeRes, int accentColor, boolean outlineEnabled) {
|
|
|
|
// Very dirty implementation
|
|
|
|
if (!(mode instanceof SupportActionModeWrapper) || !(activity instanceof IThemedActivity))
|
|
|
|
return;
|
|
|
|
final android.support.v7.view.ActionMode modeCompat =
|
|
|
|
SupportActionModeWrapperTrojan.getWrappedObject((SupportActionModeWrapper) mode);
|
|
|
|
if (!(modeCompat instanceof ActionModeImpl)) return;
|
|
|
|
try {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (actionBar == null) return;
|
|
|
|
final Field contextViewField = WindowDecorActionBar.class.getDeclaredField("mContextView");
|
|
|
|
contextViewField.setAccessible(true);
|
|
|
|
final View view = (View) contextViewField.get(actionBar);
|
|
|
|
if (view == null) return;
|
2015-04-13 18:34:10 +02:00
|
|
|
ViewUtils.setBackground(view, getActionBarBackground(activity, themeRes, accentColor, outlineEnabled));
|
2015-04-03 23:12:33 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static void applyWindowBackground(Context context, Window window, int theme, String option, int alpha) {
|
2015-04-14 17:42:46 +02:00
|
|
|
if (isWindowFloating(context, theme)) return;
|
2015-04-14 17:38:50 +02:00
|
|
|
if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option)) {
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
|
|
|
|
window.setBackgroundDrawable(ThemeUtils.getWindowBackgroundApplyAlpha(context, alpha));
|
|
|
|
} else if (VALUE_THEME_BACKGROUND_SOLID.equals(option)) {
|
|
|
|
window.setBackgroundDrawable(new ColorDrawable(isDarkTheme(theme) ? Color.BLACK : Color.WHITE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 00:06:08 +02:00
|
|
|
public static Drawable getCompatToolbarOverlay(Activity activity) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return null;
|
|
|
|
final View view = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
|
|
|
|
if (!(view instanceof ActionBarOverlayLayout)) return null;
|
|
|
|
try {
|
|
|
|
final Field field = ActionBarOverlayLayout.class.getDeclaredField("mWindowContentOverlay");
|
|
|
|
field.setAccessible(true);
|
|
|
|
return (Drawable) field.get(view);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 17:49:08 +02:00
|
|
|
public static void initPagerIndicatorAsActionBarTab(FragmentActivity activity, TabPagerIndicator indicator) {
|
|
|
|
final float supportActionBarElevation = getSupportActionBarElevation(activity);
|
|
|
|
ViewCompat.setElevation(indicator, supportActionBarElevation);
|
|
|
|
if (!(activity instanceof IThemedActivity)) return;
|
|
|
|
final int themeRes = ((IThemedActivity) activity).getCurrentThemeResourceId();
|
|
|
|
final int themeColor = ((IThemedActivity) activity).getCurrentThemeColor();
|
|
|
|
final int contrastColor = ColorUtils.getContrastYIQ(themeColor, 192);
|
2015-04-13 18:34:10 +02:00
|
|
|
ViewUtils.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, true));
|
2015-04-03 17:49:08 +02:00
|
|
|
if (isDarkTheme(themeRes)) {
|
|
|
|
final int foregroundColor = getThemeForegroundColor(activity);
|
|
|
|
indicator.setIconColor(foregroundColor);
|
|
|
|
indicator.setLabelColor(foregroundColor);
|
|
|
|
indicator.setStripColor(themeColor);
|
|
|
|
} else {
|
|
|
|
indicator.setIconColor(contrastColor);
|
|
|
|
indicator.setLabelColor(contrastColor);
|
|
|
|
indicator.setStripColor(contrastColor);
|
|
|
|
}
|
|
|
|
indicator.updateAppearance();
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static boolean isWindowFloating(Context context, int theme) {
|
|
|
|
final TypedArray a;
|
|
|
|
if (theme != 0) {
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
a = context.obtainStyledAttributes(null, new int[]{android.R.attr.windowIsFloating}, 0, theme);
|
|
|
|
} else {
|
|
|
|
a = context.obtainStyledAttributes(new int[]{android.R.attr.windowIsFloating});
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return a.getBoolean(0, false);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
public static void resetCheatSheet(ActionMenuView menuView) {
|
|
|
|
final OnLongClickListener listener = new OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
if (((ActionMenuItemView) v).hasText()) return false;
|
|
|
|
final MenuItem menuItem = ((ActionMenuItemView) v).getItemData();
|
|
|
|
Utils.showMenuItemToast(v, menuItem.getTitle(), true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (int i = 0, j = menuView.getChildCount(); i < j; i++) {
|
|
|
|
final View child = menuView.getChildAt(i);
|
|
|
|
if (!(child instanceof ActionMenuItemView)) continue;
|
|
|
|
final ActionMenuItemView itemView = (ActionMenuItemView) child;
|
|
|
|
final MenuItem menuItem = itemView.getItemData();
|
|
|
|
if (menuItem.hasSubMenu()) continue;
|
|
|
|
itemView.setOnLongClickListener(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
@SuppressLint("NewApi")
|
|
|
|
public static void setActionBarOverflowColor(Toolbar toolbar, int itemColor) {
|
|
|
|
if (toolbar == null) return;
|
|
|
|
final ActionMenuView actionMenuView = ViewUtils.findViewByType(toolbar, ActionMenuView.class);
|
|
|
|
if (actionMenuView == null) return;
|
|
|
|
View overflowView = null;
|
|
|
|
for (int i = 0, j = actionMenuView.getChildCount(); i < j; i++) {
|
|
|
|
final View child = actionMenuView.getChildAt(i);
|
|
|
|
final ActionMenuView.LayoutParams lp = (ActionMenuView.LayoutParams) child.getLayoutParams();
|
|
|
|
if (lp.isOverflowButton) {
|
|
|
|
overflowView = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(overflowView instanceof ImageView)) return;
|
|
|
|
final Drawable drawable = ((ImageView) overflowView).getDrawable();
|
|
|
|
if (drawable == null) return;
|
|
|
|
drawable.setColorFilter(itemColor, Mode.SRC_ATOP);
|
|
|
|
}
|
|
|
|
|
2015-04-04 00:06:08 +02:00
|
|
|
public static void setCompatToolbarOverlay(Activity activity, Drawable background) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return;
|
|
|
|
final View view = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
|
|
|
|
if (!(view instanceof ActionBarOverlayLayout)) return;
|
|
|
|
try {
|
|
|
|
final Field field = ActionBarOverlayLayout.class.getDeclaredField("mWindowContentOverlay");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(view, background);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
public static void wrapMenuIcon(@NonNull Menu menu, int itemColor, int subItemColor, int... excludeGroups) {
|
|
|
|
for (int i = 0, j = menu.size(); i < j; i++) {
|
|
|
|
final MenuItem item = menu.getItem(i);
|
|
|
|
wrapMenuItemIcon(item, itemColor, excludeGroups);
|
|
|
|
if (item.hasSubMenu()) {
|
|
|
|
wrapMenuIcon(item.getSubMenu(), subItemColor, subItemColor, excludeGroups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void wrapMenuItemIcon(@NonNull MenuItem item, int itemColor, int... excludeGroups) {
|
|
|
|
if (ArrayUtils.contains(excludeGroups, item.getGroupId())) return;
|
|
|
|
final Drawable icon = item.getIcon();
|
|
|
|
if (icon == null) return;
|
2015-04-13 18:34:10 +02:00
|
|
|
if (icon instanceof ActionIconDrawable) {
|
|
|
|
((ActionIconDrawable) icon).setDefaultColor(itemColor);
|
|
|
|
item.setIcon(icon);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-17 19:58:29 +01:00
|
|
|
icon.mutate();
|
|
|
|
final Drawable.Callback callback = icon.getCallback();
|
|
|
|
final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor);
|
|
|
|
newIcon.setCallback(callback);
|
|
|
|
item.setIcon(newIcon);
|
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) {
|
|
|
|
final Resources resources = view.getResources();
|
|
|
|
final int colorDark = resources.getColor(R.color.action_icon_dark);
|
|
|
|
final int colorLight = resources.getColor(R.color.action_icon_light);
|
2015-04-13 18:34:10 +02:00
|
|
|
wrapMenuIcon(view, colorDark, colorLight, excludeGroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void wrapMenuIcon(ActionMenuView view, int colorDark, int colorLight, int... excludeGroups) {
|
|
|
|
final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
|
|
|
|
final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(), view.getPopupTheme());
|
2015-01-17 19:58:29 +01:00
|
|
|
final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
|
|
|
|
final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight);
|
|
|
|
final Menu menu = view.getMenu();
|
|
|
|
final int childCount = view.getChildCount();
|
|
|
|
for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
|
|
|
|
final MenuItem item = menu.getItem(i);
|
|
|
|
wrapMenuItemIcon(item, itemColor, excludeGroups);
|
|
|
|
if (item.hasSubMenu()) {
|
|
|
|
wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
|
|
|
|
}
|
|
|
|
if (item.isVisible()) {
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 17:19:57 +01:00
|
|
|
}
|
2015-01-17 19:58:29 +01:00
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
public static void wrapToolbarMenuIcon(Toolbar view, int itemColor, int popupItemColor, int... excludeGroups) {
|
|
|
|
final Menu menu = view.getMenu();
|
|
|
|
final int childCount = view.getChildCount();
|
|
|
|
for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
|
|
|
|
final MenuItem item = menu.getItem(i);
|
|
|
|
wrapMenuItemIcon(item, itemColor, excludeGroups);
|
|
|
|
if (item.hasSubMenu()) {
|
|
|
|
wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
|
|
|
|
}
|
|
|
|
if (item.isVisible()) {
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
|
2015-03-19 17:19:57 +01:00
|
|
|
public static void wrapMenuIcon(Context context, Menu menu, int... excludeGroups) {
|
|
|
|
final int backgroundColor = ThemeUtils.getThemeBackgroundColor(context);
|
|
|
|
wrapMenuIcon(context, backgroundColor, backgroundColor, menu, excludeGroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = ColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
|
|
|
|
final int popupItemColor = ColorUtils.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);
|
|
|
|
if (item.hasSubMenu()) {
|
|
|
|
wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
|
|
|
|
}
|
|
|
|
if (item.isVisible()) {
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 19:58:29 +01:00
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static void applyThemeAlphaToDrawable(final Context context, final Drawable d) {
|
|
|
|
if (context == null || d == null) return;
|
|
|
|
d.setAlpha(getThemeAlpha(getThemeResource(context)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void applyThemeBackgroundAlphaToDrawable(final Context context, final Drawable d) {
|
|
|
|
if (context == null || d == null) return;
|
|
|
|
d.setAlpha(getUserThemeBackgroundAlpha(context));
|
|
|
|
}
|
|
|
|
|
2015-01-17 19:58:29 +01:00
|
|
|
|
|
|
|
public static int getActionBarPopupThemeRes(final Context context) {
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return 0;
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressLint("InlinedApi")
|
2015-01-17 19:58:29 +01:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.actionBarPopupTheme});
|
|
|
|
try {
|
|
|
|
return a.getResourceId(0, 0);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 17:57:31 +01:00
|
|
|
public static void applyColorFilterToMenuIcon(Activity activity, Menu menu) {
|
|
|
|
final ActionBar actionBar = activity.getActionBar();
|
|
|
|
final Context context = actionBar != null ? actionBar.getThemedContext() : activity;
|
|
|
|
final int color = getThemeForegroundColor(context);
|
2015-01-17 19:58:29 +01:00
|
|
|
final int popupTheme = getActionBarPopupThemeRes(context);
|
|
|
|
final int popupColor = getThemeForegroundColor(context, popupTheme);
|
|
|
|
final int highlightColor = getUserAccentColor(activity);
|
|
|
|
applyColorFilterToMenuIcon(menu, color, popupColor, highlightColor, Mode.SRC_ATOP);
|
2014-11-01 17:57:31 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 07:48:07 +01:00
|
|
|
public static void applyColorFilterToMenuIcon(final Menu menu, final int color,
|
|
|
|
final int highlightColor, final Mode mode,
|
|
|
|
final int... excludedGroups) {
|
|
|
|
applyColorFilterToMenuIcon(menu, color, color, highlightColor, mode, excludedGroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor,
|
|
|
|
final int highlightColor, final Mode mode,
|
|
|
|
final int... excludedGroups) {
|
2014-10-25 12:45:50 +02:00
|
|
|
for (int i = 0, j = menu.size(); i < j; i++) {
|
|
|
|
final MenuItem item = menu.getItem(i);
|
|
|
|
final Drawable icon = item.getIcon();
|
|
|
|
final ContextMenuInfo info = item.getMenuInfo();
|
2014-10-29 07:48:07 +01:00
|
|
|
if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) {
|
|
|
|
icon.mutate();
|
2015-01-17 19:58:29 +01:00
|
|
|
if (info instanceof TwidereMenuInfo) {
|
2014-11-03 16:44:32 +01:00
|
|
|
final TwidereMenuInfo sInfo = (TwidereMenuInfo) info;
|
2014-11-25 16:15:05 +01:00
|
|
|
icon.setColorFilter(sInfo.isHighlight() ?
|
|
|
|
sInfo.getHighlightColor(highlightColor) : color, mode);
|
2014-10-26 14:38:48 +01:00
|
|
|
} else {
|
2014-10-29 07:48:07 +01:00
|
|
|
icon.setColorFilter(color, mode);
|
2014-10-26 14:38:48 +01:00
|
|
|
}
|
2014-10-25 12:45:50 +02:00
|
|
|
}
|
|
|
|
if (item.hasSubMenu()) {
|
2014-11-01 17:57:31 +01:00
|
|
|
// SubMenu item is always in popup
|
|
|
|
applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode, excludedGroups);
|
2014-10-25 12:45:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
public static View createView(final String name, final Context context,
|
|
|
|
final AttributeSet attrs) {
|
|
|
|
return createView(name, context, attrs, 0);
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
public static View createView(final String name, final Context context,
|
|
|
|
final AttributeSet attrs, final int tintColor) {
|
|
|
|
View view = null;
|
2014-07-27 14:58:15 +02:00
|
|
|
try {
|
2014-12-24 05:39:21 +01:00
|
|
|
view = newViewInstance(name, context, attrs);
|
2014-07-27 14:58:15 +02:00
|
|
|
} catch (final Exception e) {
|
|
|
|
// In this case we want to let the base class take a crack
|
|
|
|
// at it.
|
|
|
|
}
|
|
|
|
for (final String prefix : sClassPrefixList) {
|
|
|
|
try {
|
2014-12-24 05:39:21 +01:00
|
|
|
view = newViewInstance(prefix + name, context, attrs);
|
2014-07-27 14:58:15 +02:00
|
|
|
} catch (final Exception e) {
|
|
|
|
// In this case we want to let the base class take a crack
|
|
|
|
// at it.
|
|
|
|
}
|
|
|
|
}
|
2014-12-24 05:39:21 +01:00
|
|
|
if (view != null) {
|
|
|
|
applyColorTintForView(view, tintColor);
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2015-01-08 10:13:20 +01:00
|
|
|
public static int getOptimalLinkColor(int linkColor, int color) {
|
|
|
|
final int[] yiq = new int[3];
|
|
|
|
ColorUtils.colorToYIQ(color, yiq);
|
|
|
|
final int y = yiq[0];
|
|
|
|
ColorUtils.colorToYIQ(linkColor, yiq);
|
|
|
|
if (y < 32 && yiq[0] < 192) {
|
|
|
|
return linkColor;
|
|
|
|
} else if (y > 192 && yiq[0] > 32) {
|
|
|
|
return linkColor;
|
|
|
|
}
|
|
|
|
yiq[0] = yiq[0] + (y - yiq[0]) / 2;
|
|
|
|
return ColorUtils.YIQToColor(Color.alpha(linkColor), yiq);
|
|
|
|
}
|
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
public static int getQuickSearchBarThemeResource(final Context context) {
|
|
|
|
return getQuickSearchBarThemeResource(getThemeNameOption(context));
|
2015-01-06 16:46:07 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
public static int getQuickSearchBarThemeResource(final String name) {
|
|
|
|
if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Dark_QuickSearchBar;
|
|
|
|
return R.style.Theme_Twidere_Light_QuickSearchBar;
|
2015-01-06 16:46:07 +01:00
|
|
|
}
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
private static void applyColorTintForView(View view, int tintColor) {
|
|
|
|
if (view instanceof IThemedView) {
|
|
|
|
final ColorStateList tintList = ColorStateList.valueOf(tintColor);
|
|
|
|
((IThemedView) view).setThemeTintColor(tintList);
|
|
|
|
} else if (view instanceof ProgressBar) {
|
|
|
|
final ColorStateList tintList = ColorStateList.valueOf(tintColor);
|
|
|
|
final ProgressBar progressBar = (ProgressBar) view;
|
2015-04-13 18:34:10 +02:00
|
|
|
ViewUtils.setProgressTintList(progressBar, tintList);
|
|
|
|
ViewUtils.setProgressBackgroundTintList(progressBar, tintList);
|
|
|
|
ViewUtils.setIndeterminateTintList(progressBar, tintList);
|
2014-12-24 05:39:21 +01:00
|
|
|
} else if (view instanceof CompoundButton) {
|
|
|
|
final ColorStateList tintList = ColorStateList.valueOf(tintColor);
|
|
|
|
final CompoundButton compoundButton = (CompoundButton) view;
|
2015-04-13 18:34:10 +02:00
|
|
|
ViewUtils.setButtonTintList(compoundButton, tintList);
|
2014-12-24 05:39:21 +01:00
|
|
|
}
|
2015-03-19 09:34:30 +01:00
|
|
|
// TODO support TintableBackgroundView
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 12:28:26 +02:00
|
|
|
public static float getSupportActionBarElevation(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2015-04-01 12:28:26 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{R.attr.elevation}, R.attr.actionBarStyle, 0);
|
|
|
|
try {
|
|
|
|
return a.getDimension(0, 0);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float getActionBarElevation(final Context context) {
|
2015-04-03 23:12:33 +02:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return 0;
|
|
|
|
@SuppressLint("InlinedApi")
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2015-04-03 23:12:33 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.elevation},
|
|
|
|
android.R.attr.actionBarStyle, 0);
|
2015-04-01 12:28:26 +02:00
|
|
|
try {
|
|
|
|
return a.getDimension(0, 0);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 14:58:15 +02:00
|
|
|
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
@Deprecated
|
2014-07-27 14:58:15 +02:00
|
|
|
public static Drawable getActionBarBackground(final Context context, final int themeRes) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2015-01-22 12:16:22 +01:00
|
|
|
final TypedArray a1 = context.obtainStyledAttributes(null, new int[]{android.R.attr.background},
|
|
|
|
R.attr.actionBarStyle, themeRes);
|
|
|
|
try {
|
|
|
|
if (a1.hasValue(0)) {
|
2015-04-14 17:38:50 +02:00
|
|
|
return applyActionBarDrawable(context, a1.getDrawable(0), isTransparentBackground(context));
|
2015-01-22 12:16:22 +01:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
a1.recycle();
|
|
|
|
}
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2015-01-22 12:16:22 +01:00
|
|
|
final TypedArray a2 = context.obtainStyledAttributes(null, new int[]{android.R.attr.background},
|
2014-07-27 14:58:15 +02:00
|
|
|
android.R.attr.actionBarStyle, themeRes);
|
2015-01-22 12:16:22 +01:00
|
|
|
try {
|
|
|
|
if (a2.hasValue(0)) {
|
2015-04-14 17:38:50 +02:00
|
|
|
return applyActionBarDrawable(context, a2.getDrawable(0), isTransparentBackground(context));
|
2015-01-22 12:16:22 +01:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
a2.recycle();
|
|
|
|
}
|
|
|
|
return null;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 17:49:08 +02:00
|
|
|
@NonNull
|
2014-12-01 17:04:55 +01:00
|
|
|
public static Drawable getActionBarBackground(final Context context, final int themeRes,
|
2015-04-01 12:28:26 +02:00
|
|
|
final int accentColor, boolean outlineEnabled) {
|
2015-04-03 17:49:08 +02:00
|
|
|
final int actionBarColor;
|
|
|
|
if (isDarkTheme(themeRes)) {
|
|
|
|
actionBarColor = context.getResources().getColor(R.color.background_color_action_bar_dark);
|
|
|
|
} else {
|
|
|
|
actionBarColor = accentColor;
|
2014-12-01 17:04:55 +01:00
|
|
|
}
|
2015-04-03 17:49:08 +02:00
|
|
|
final ColorDrawable d = new ActionBarColorDrawable(actionBarColor, outlineEnabled);
|
2015-04-14 17:38:50 +02:00
|
|
|
return applyActionBarDrawable(context, d, isTransparentBackground(context));
|
2015-04-03 17:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static Drawable getActionBarStackedBackground(final Context context, final int themeRes,
|
|
|
|
final int accentColor, boolean outlineEnabled) {
|
|
|
|
final int actionBarColor;
|
|
|
|
if (isDarkTheme(themeRes)) {
|
|
|
|
actionBarColor = context.getResources().getColor(R.color.background_color_action_bar_dark);
|
|
|
|
} else {
|
|
|
|
actionBarColor = accentColor;
|
|
|
|
}
|
|
|
|
final ColorDrawable d = new ActionBarColorDrawable(actionBarColor, outlineEnabled);
|
2015-04-14 17:38:50 +02:00
|
|
|
return applyActionBarDrawable(context, d, isTransparentBackground(context));
|
2014-12-01 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static Context getActionBarContext(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressLint("InlinedApi")
|
2015-01-22 12:16:22 +01:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.actionBarTheme,
|
|
|
|
R.attr.actionBarWidgetTheme, android.R.attr.actionBarTheme,
|
2014-10-26 14:38:48 +01:00
|
|
|
android.R.attr.actionBarWidgetTheme});
|
|
|
|
final int resId;
|
2015-01-22 12:16:22 +01:00
|
|
|
if (a.hasValue(0) || a.hasValue(1)) {
|
2014-10-26 14:38:48 +01:00
|
|
|
resId = a.hasValue(0) ? a.getResourceId(0, 0) : a.getResourceId(1, 0);
|
2015-01-22 12:16:22 +01:00
|
|
|
} else {
|
|
|
|
resId = a.hasValue(2) ? a.getResourceId(2, 0) : a.getResourceId(3, 0);
|
2014-10-26 14:38:48 +01:00
|
|
|
}
|
2015-01-22 12:16:22 +01:00
|
|
|
a.recycle();
|
2014-11-01 17:57:31 +01:00
|
|
|
if (resId == 0) return context;
|
|
|
|
return new ContextThemeWrapper(context, resId);
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Drawable getActionBarSplitBackground(final Context context, final int themeRes) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2014-07-27 14:58:15 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.backgroundSplit},
|
|
|
|
android.R.attr.actionBarStyle, themeRes);
|
|
|
|
final Drawable d = a.getDrawable(0);
|
|
|
|
a.recycle();
|
2015-04-14 17:38:50 +02:00
|
|
|
return applyActionBarDrawable(context, d, isTransparentBackground(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
public static int getCardBackgroundColor(final Context context) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.cardItemBackgroundColor});
|
|
|
|
final int color = a.getColor(0, Color.TRANSPARENT);
|
|
|
|
a.recycle();
|
|
|
|
final int themeAlpha = getThemeAlpha(context);
|
|
|
|
return themeAlpha << 24 | (0x00FFFFFF & color);
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static int getComposeThemeResource(final Context context) {
|
2015-04-13 18:34:10 +02:00
|
|
|
return getComposeThemeResource(getThemeNameOption(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
public static int getComposeThemeResource(final String name) {
|
2014-10-29 07:48:07 +01:00
|
|
|
if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Dark_Compose;
|
|
|
|
return R.style.Theme_Twidere_Light_Compose;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Context getDialogThemedContext(final Context context) {
|
2014-11-01 17:57:31 +01:00
|
|
|
return new ContextThemeWrapper(context, getDialogThemeResource(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDialogThemeResource(final Context context) {
|
|
|
|
return getDialogThemeResource(getThemeNameOption(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDialogThemeResource(final String name) {
|
|
|
|
if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Dark_Dialog;
|
|
|
|
return R.style.Theme_Twidere_Light_Dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDrawerThemeResource(final Context context) {
|
|
|
|
return getDrawerThemeResource(getThemeResource(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDrawerThemeResource(final int themeRes) {
|
|
|
|
return R.style.Theme_Twidere_Drawer_Dark;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Drawable getImageHighlightDrawable(final Context context) {
|
|
|
|
final Drawable d = getSelectableItemBackgroundDrawable(context);
|
|
|
|
if (d != null) {
|
|
|
|
d.setAlpha(0x80);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getNoDisplayThemeResource(final Context context) {
|
|
|
|
if (context == null) return R.style.Theme_Twidere_Dark_NoDisplay;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
2014-07-27 14:58:15 +02:00
|
|
|
final String theme = pref.getString(KEY_THEME, VALUE_THEME_NAME_TWIDERE);
|
|
|
|
if (VALUE_THEME_NAME_DARK.equals(theme)) return R.style.Theme_Twidere_Dark_NoDisplay;
|
|
|
|
return R.style.Theme_Twidere_Light_NoDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Resources getResources(final Context context) {
|
|
|
|
return context.getResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Drawable getSelectableItemBackgroundDrawable(final Context context) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
|
|
|
|
try {
|
|
|
|
return a.getDrawable(0);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSettingsThemeResource(final Context context) {
|
2015-04-13 18:34:10 +02:00
|
|
|
return getSettingsThemeResource(getThemeNameOption(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
public static int getSettingsThemeResource(final String name) {
|
2014-07-27 14:58:15 +02:00
|
|
|
if (VALUE_THEME_NAME_TWIDERE.equals(name) || VALUE_THEME_NAME_LIGHT.equals(name))
|
2015-04-13 18:34:10 +02:00
|
|
|
return R.style.Theme_Twidere_Settings_Light_DarkActionBar;
|
2014-07-27 14:58:15 +02:00
|
|
|
else if (VALUE_THEME_NAME_DARK.equals(name)) return R.style.Theme_Twidere_Settings_Dark;
|
|
|
|
return R.style.Theme_Twidere_Settings_Light_DarkActionBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getTextAppearanceLarge(final Context context) {
|
|
|
|
// final Context wrapped = getThemedContext(context,
|
|
|
|
// getResources(context));
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.textAppearanceLarge});
|
|
|
|
final int textAppearance = a.getResourceId(0, android.R.style.TextAppearance_Holo_Large);
|
|
|
|
a.recycle();
|
|
|
|
return textAppearance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getTextColorPrimary(final Context context) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
|
|
|
try {
|
|
|
|
return a.getColor(0, Color.TRANSPARENT);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getTextColorSecondary(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2014-07-27 14:58:15 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary});
|
|
|
|
try {
|
|
|
|
return a.getColor(0, Color.TRANSPARENT);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeAlpha(final Context context) {
|
|
|
|
return getThemeAlpha(getThemeResource(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeAlpha(final int themeRes) {
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getThemeBackgroundOption(final Context context) {
|
|
|
|
if (context == null) return VALUE_THEME_BACKGROUND_DEFAULT;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
2014-07-27 14:58:15 +02:00
|
|
|
return pref.getString(KEY_THEME_BACKGROUND, VALUE_THEME_BACKGROUND_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeColor(final Context context) {
|
2015-04-14 18:05:02 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.colorActivatedHighlight});
|
2014-07-27 14:58:15 +02:00
|
|
|
try {
|
2015-04-14 18:05:02 +02:00
|
|
|
final Resources resources = context.getResources();
|
|
|
|
return a.getColor(0, resources.getColor(R.color.material_light_blue));
|
2014-07-27 14:58:15 +02:00
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Context getThemedContext(final Context context) {
|
2014-11-01 17:57:31 +01:00
|
|
|
return context;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Context getThemedContext(final Context context, final Resources res) {
|
2014-11-01 17:57:31 +01:00
|
|
|
return context;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getThemeFontFamily(final Context context) {
|
|
|
|
if (context == null) return VALUE_THEME_FONT_FAMILY_REGULAR;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
2014-07-27 14:58:15 +02:00
|
|
|
final String fontFamily = pref.getString(KEY_THEME_FONT_FAMILY, VALUE_THEME_FONT_FAMILY_REGULAR);
|
|
|
|
if (!TextUtils.isEmpty(fontFamily)) return fontFamily;
|
|
|
|
return VALUE_THEME_FONT_FAMILY_REGULAR;
|
|
|
|
}
|
|
|
|
|
2014-10-29 07:48:07 +01:00
|
|
|
public static int getThemeBackgroundColor(final Context context) {
|
2015-01-17 19:58:29 +01:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
|
2014-10-29 07:48:07 +01:00
|
|
|
try {
|
2015-01-17 19:58:29 +01:00
|
|
|
return a.getColor(0, 0);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeBackgroundColor(final Context context, int themeRes) {
|
|
|
|
if (themeRes == 0) {
|
|
|
|
return getThemeBackgroundColor(context);
|
|
|
|
}
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2015-01-17 19:58:29 +01:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.colorBackground},
|
|
|
|
0, themeRes);
|
|
|
|
try {
|
|
|
|
return a.getColor(0, 0);
|
2014-10-29 07:48:07 +01:00
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static int getThemeForegroundColor(final Context context) {
|
2014-11-01 17:57:31 +01:00
|
|
|
return getThemeForegroundColor(context, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeForegroundColor(final Context context, int theme) {
|
|
|
|
final Context wrapped = theme != 0 ? new ContextThemeWrapper(context, theme) : context;
|
2014-07-27 14:58:15 +02:00
|
|
|
final TypedArray a = wrapped.obtainStyledAttributes(new int[]{android.R.attr.colorForeground});
|
|
|
|
try {
|
2014-11-01 17:57:31 +01:00
|
|
|
return a.getColor(0, 0);
|
2014-07-27 14:58:15 +02:00
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 17:57:31 +01:00
|
|
|
|
2014-08-07 19:58:42 +02:00
|
|
|
@NonNull
|
|
|
|
private static SharedPreferencesWrapper getSharedPreferencesWrapper(Context context) {
|
|
|
|
final Context appContext = context.getApplicationContext();
|
|
|
|
return SharedPreferencesWrapper.getInstance(appContext, SHARED_PREFERENCES_NAME,
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static String getThemeNameOption(final Context context) {
|
|
|
|
if (context == null) return VALUE_THEME_NAME_TWIDERE;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
|
|
|
return pref.getString(KEY_THEME, VALUE_THEME_NAME_TWIDERE);
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeResource(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
return getThemeResource(getThemeNameOption(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getDialogWhenLargeThemeResource(final Context context) {
|
|
|
|
return getDialogWhenLargeThemeResource(getThemeNameOption(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThemeResource(final String name) {
|
|
|
|
if (VALUE_THEME_NAME_DARK.equals(name)) {
|
2014-07-27 14:58:15 +02:00
|
|
|
return R.style.Theme_Twidere_Dark;
|
|
|
|
}
|
2014-10-29 07:48:07 +01:00
|
|
|
return R.style.Theme_Twidere_Light;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static int getDialogWhenLargeThemeResource(final String name) {
|
|
|
|
if (VALUE_THEME_NAME_DARK.equals(name)) {
|
|
|
|
return R.style.Theme_Twidere_Dark_DialogWhenLarge;
|
|
|
|
}
|
|
|
|
return R.style.Theme_Twidere_Light_DialogWhenLarge;
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static int getTitleTextAppearance(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2014-07-27 14:58:15 +02:00
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.titleTextStyle},
|
|
|
|
android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
|
|
|
|
final int textAppearance = a.getResourceId(0, android.R.style.TextAppearance_Holo);
|
|
|
|
a.recycle();
|
|
|
|
return textAppearance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getUserHighlightColor(final Context context) {
|
|
|
|
final int color = getUserLinkTextColor(context);
|
|
|
|
final int red = Color.red(color), green = Color.green(color), blue = Color.blue(color);
|
|
|
|
return Color.argb(0x66, red, green, blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getUserLinkTextColor(final Context context) {
|
|
|
|
if (context == null) return new TextPaint().linkColor;
|
2014-10-29 07:48:07 +01:00
|
|
|
final int themeColor = getUserAccentColor(context);
|
2014-07-27 14:58:15 +02:00
|
|
|
final float[] hsv = new float[3];
|
|
|
|
Color.colorToHSV(themeColor, hsv);
|
|
|
|
if (isDarkTheme(context)) {
|
|
|
|
hsv[2] = MathUtils.clamp(hsv[2], 1, 0.5f);
|
|
|
|
} else {
|
|
|
|
hsv[2] = MathUtils.clamp(hsv[2], 0.1f, 0.75f);
|
|
|
|
}
|
|
|
|
return Color.HSVToColor(hsv);
|
|
|
|
}
|
|
|
|
|
2014-11-01 17:57:31 +01:00
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static int getUserThemeBackgroundAlpha(final Context context) {
|
|
|
|
if (context == null) return DEFAULT_THEME_BACKGROUND_ALPHA;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
2014-07-27 14:58:15 +02:00
|
|
|
return pref.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA);
|
|
|
|
}
|
|
|
|
|
2014-10-29 07:48:07 +01:00
|
|
|
public static int getUserAccentColor(final Context context) {
|
2014-07-27 14:58:15 +02:00
|
|
|
if (context == null) return Color.TRANSPARENT;
|
2014-08-07 19:58:42 +02:00
|
|
|
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
|
2015-04-14 18:05:02 +02:00
|
|
|
final Resources res = context.getResources();
|
2015-03-29 15:31:04 +02:00
|
|
|
final int def = res.getColor(R.color.branding_color);
|
2014-08-07 19:58:42 +02:00
|
|
|
return pref.getInt(KEY_THEME_COLOR, def);
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static Typeface getUserTypeface(final Context context, final Typeface defTypeface) {
|
|
|
|
if (context == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|
|
|
|
return Typeface.DEFAULT;
|
|
|
|
final int fontStyle = defTypeface != null ? defTypeface.getStyle() : Typeface.NORMAL;
|
|
|
|
final String fontFamily = getThemeFontFamily(context);
|
|
|
|
final Typeface tf = Typeface.create(fontFamily, fontStyle);
|
|
|
|
if (tf != null) return tf;
|
|
|
|
return Typeface.create(Typeface.DEFAULT, fontStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getViewerThemeResource(final Context context) {
|
2015-01-23 17:09:03 +01:00
|
|
|
return R.style.Theme_Twidere_Viewer;
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Drawable getWindowBackground(final Context context) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowBackground});
|
|
|
|
final Drawable d = a.getDrawable(0);
|
|
|
|
a.recycle();
|
|
|
|
if (isTransparentBackground(context)) {
|
|
|
|
applyThemeBackgroundAlphaToDrawable(context, d);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static Drawable getWindowBackground(final Context context, int theme) {
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.windowBackground}, 0, theme);
|
2014-07-27 14:58:15 +02:00
|
|
|
final Drawable d = a.getDrawable(0);
|
|
|
|
a.recycle();
|
2015-04-14 17:38:50 +02:00
|
|
|
if (isTransparentBackground(context)) {
|
2014-07-27 14:58:15 +02:00
|
|
|
applyThemeBackgroundAlphaToDrawable(context, d);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static Drawable getWindowBackgroundApplyAlpha(final Context context, final int alpha) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowBackground});
|
|
|
|
final Drawable d = a.getDrawable(0);
|
|
|
|
a.recycle();
|
|
|
|
if (d != null) {
|
|
|
|
d.setAlpha(alpha);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:58:15 +02:00
|
|
|
public static Drawable getWindowContentOverlay(final Context context) {
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowContentOverlay});
|
|
|
|
final Drawable d = a.getDrawable(0);
|
|
|
|
a.recycle();
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isDarkTheme(final Context context) {
|
|
|
|
return isDarkTheme(getThemeResource(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isDarkTheme(final int themeRes) {
|
|
|
|
switch (themeRes) {
|
|
|
|
case R.style.Theme_Twidere_Dark:
|
|
|
|
case R.style.Theme_Twidere_Dark_Dialog:
|
2015-04-14 17:38:50 +02:00
|
|
|
case R.style.Theme_Twidere_Dark_DialogWhenLarge:
|
2014-07-27 14:58:15 +02:00
|
|
|
case R.style.Theme_Twidere_Dark_Compose:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isTransparentBackground(final Context context) {
|
2015-04-14 17:38:50 +02:00
|
|
|
return isTransparentBackground(getThemeBackgroundOption(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static boolean isTransparentBackground(final String option) {
|
|
|
|
return VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option);
|
2014-07-27 14:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void overrideActivityCloseAnimation(final Activity activity) {
|
|
|
|
TypedArray a = activity.obtainStyledAttributes(new int[]{android.R.attr.windowAnimationStyle});
|
|
|
|
final int windowAnimationStyleResId = a.getResourceId(0, 0);
|
|
|
|
a.recycle();
|
|
|
|
// Now retrieve the resource ids of the actual animations used in the
|
|
|
|
// animation style pointed to by
|
|
|
|
// the window animation resource id.
|
|
|
|
a = activity.obtainStyledAttributes(windowAnimationStyleResId, ANIM_CLOSE_STYLE_ATTRS);
|
|
|
|
final int activityCloseEnterAnimation = a.getResourceId(0, 0);
|
|
|
|
final int activityCloseExitAnimation = a.getResourceId(1, 0);
|
|
|
|
a.recycle();
|
|
|
|
activity.overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void overrideActivityOpenAnimation(final Activity activity) {
|
|
|
|
|
|
|
|
TypedArray a = activity.obtainStyledAttributes(new int[]{android.R.attr.windowAnimationStyle});
|
|
|
|
final int windowAnimationStyleResId = a.getResourceId(0, 0);
|
|
|
|
a.recycle();
|
|
|
|
// Now retrieve the resource ids of the actual animations used in the
|
|
|
|
// animation style pointed to by
|
|
|
|
// the window animation resource id.
|
|
|
|
a = activity.obtainStyledAttributes(windowAnimationStyleResId, ANIM_OPEN_STYLE_ATTRS);
|
|
|
|
final int activityOpenEnterAnimation = a.getResourceId(0, 0);
|
|
|
|
final int activityOpenExitAnimation = a.getResourceId(1, 0);
|
|
|
|
a.recycle();
|
|
|
|
activity.overridePendingTransition(activityOpenEnterAnimation, activityOpenExitAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void overrideNormalActivityCloseAnimation(final Activity activity) {
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2014-07-28 12:42:48 +02:00
|
|
|
final TypedArray a = activity.obtainStyledAttributes(null, ANIM_CLOSE_STYLE_ATTRS,
|
|
|
|
0, android.R.style.Animation_Activity);
|
2014-07-27 14:58:15 +02:00
|
|
|
final int activityCloseEnterAnimation = a.getResourceId(0, 0);
|
|
|
|
final int activityCloseExitAnimation = a.getResourceId(1, 0);
|
|
|
|
a.recycle();
|
|
|
|
activity.overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Drawable applyActionBarDrawable(final Context context, final Drawable d, final boolean applyAlpha) {
|
|
|
|
if (d == null) return null;
|
|
|
|
d.mutate();
|
2015-03-19 10:03:30 +01:00
|
|
|
// DrawableCompat.setTint(d, getUserAccentColor(context));
|
2014-07-27 14:58:15 +02:00
|
|
|
if (applyAlpha) {
|
|
|
|
d.setAlpha(getThemeAlpha(context));
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static View newViewInstance(final String className, final Context context, final AttributeSet attrs)
|
|
|
|
throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException,
|
|
|
|
InvocationTargetException {
|
|
|
|
final Class<?> viewCls = Class.forName(className);
|
|
|
|
final Constructor<?> constructor = viewCls.getConstructor(Context.class, AttributeSet.class);
|
|
|
|
return (View) constructor.newInstance(context, attrs);
|
|
|
|
}
|
|
|
|
|
2014-08-07 19:58:42 +02:00
|
|
|
public static int getThemeColor(Context context, int themeResourceId) {
|
|
|
|
final Context appContext = context.getApplicationContext();
|
|
|
|
final Resources res = appContext.getResources();
|
2015-04-14 17:38:50 +02:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2014-08-07 19:58:42 +02:00
|
|
|
final TypedArray a = appContext.obtainStyledAttributes(null,
|
|
|
|
new int[]{android.R.attr.colorActivatedHighlight}, 0, themeResourceId);
|
|
|
|
try {
|
2014-12-01 08:00:37 +01:00
|
|
|
return a.getColor(0, res.getColor(R.color.material_light_blue));
|
2014-08-07 19:58:42 +02:00
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 07:48:07 +01:00
|
|
|
|
|
|
|
public static boolean isColoredActionBar(int themeRes) {
|
|
|
|
return !isDarkTheme(themeRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void initTextView(TextView view) {
|
|
|
|
if (view.isInEditMode()) return;
|
|
|
|
final Context context = view.getContext();
|
2015-01-14 09:47:51 +01:00
|
|
|
// view.setLinkTextColor(ThemeUtils.getUserLinkTextColor(context));
|
|
|
|
// view.setHighlightColor(ThemeUtils.getUserHighlightColor(context));
|
2014-10-29 07:48:07 +01:00
|
|
|
view.setTypeface(ThemeUtils.getUserTypeface(context, view.getTypeface()));
|
|
|
|
}
|
2014-11-22 15:12:54 +01:00
|
|
|
|
|
|
|
public static void applyParagraphSpacing(TextView textView, float multiplier) {
|
|
|
|
final SpannableStringBuilder builder = SpannableStringBuilder.valueOf(textView.getText());
|
|
|
|
int prevLineBreak, currLineBreak = 0;
|
|
|
|
for (int i = 0, j = builder.length(); i < j; i++) {
|
|
|
|
if (builder.charAt(i) == '\n') {
|
|
|
|
prevLineBreak = currLineBreak;
|
|
|
|
currLineBreak = i;
|
|
|
|
if (currLineBreak > 0) {
|
|
|
|
builder.setSpan(new ParagraphSpacingSpan(multiplier), prevLineBreak, currLineBreak,
|
|
|
|
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
textView.setText(builder);
|
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
public static void setActionBarItemsColor(Window window, android.support.v7.app.ActionBar actionBar, int itemColor) {
|
|
|
|
final Drawable drawable = getActionBarHomeAsUpIndicator(actionBar);
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setColorFilter(itemColor, Mode.SRC_ATOP);
|
|
|
|
}
|
|
|
|
actionBar.setHomeAsUpIndicator(drawable);
|
|
|
|
setActionBarTitleTextColor(window, itemColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setActionBarTitleTextColor(Window window, int itemColor) {
|
|
|
|
final View actionBarView = window.findViewById(android.support.v7.appcompat.R.id.action_bar);
|
|
|
|
if (actionBarView instanceof Toolbar) {
|
|
|
|
((Toolbar) actionBarView).setTitleTextColor(itemColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
public static void setActionBarSubtitleTextColor(Window window, int itemColor) {
|
|
|
|
final View actionBarView = window.findViewById(android.support.v7.appcompat.R.id.action_bar);
|
|
|
|
if (actionBarView instanceof Toolbar) {
|
|
|
|
((Toolbar) actionBarView).setSubtitleTextColor(itemColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:10 +02:00
|
|
|
public static Drawable getActionBarHomeAsUpIndicator(android.support.v7.app.ActionBar actionBar) {
|
|
|
|
final Context context = actionBar.getThemedContext();
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
final TypedArray a = context.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle, 0);
|
|
|
|
try {
|
|
|
|
return a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
|
|
|
|
} finally {
|
|
|
|
a.recycle();
|
|
|
|
}
|
|
|
|
}
|
2014-07-03 07:48:39 +02:00
|
|
|
}
|