1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-23 14:38:48 +01:00

removed unused methods

This commit is contained in:
Mariotaku Lee 2016-03-26 13:21:31 +08:00
parent 005cd50b3a
commit 2ca623bd92

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.util;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@ -37,15 +36,12 @@ import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.view.menu.ActionMenuItemView;
import android.support.v7.widget.ActionBarOverlayLayout;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.ContentFrameLayout;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.TwidereToolbar;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextThemeWrapper;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -66,18 +62,12 @@ import org.mariotaku.twidere.preference.ThemeBackgroundPreference;
import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
import org.mariotaku.twidere.util.support.ViewSupport;
import java.lang.reflect.Field;
public class ThemeUtils implements Constants {
public static final int ACCENT_COLOR_THRESHOLD = 192;
public static final int DARK_COLOR_THRESHOLD = 64;
public static final int[] ATTRS_TEXT_COLOR_PRIMARY = {android.R.attr.textColorPrimary};
public static final int[] ATTRS_TEXT_COLOR_PRIMARY_AND_INVERSE = {android.R.attr.textColorPrimary,
android.R.attr.textColorPrimaryInverse};
public static final int[] ATTRS_COLOR_FOREGROUND_AND_INVERSE = {android.R.attr.colorForeground,
android.R.attr.colorForegroundInverse};
private ThemeUtils() {
throw new AssertionError("ThemeUtils should never be instantiated");
@ -148,26 +138,6 @@ public class ThemeUtils implements Constants {
}
}
public static Drawable getCompatToolbarOverlay(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return null;
final Window window = activity.getWindow();
final View view = window.findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
if (!(view instanceof ActionBarOverlayLayout)) {
final View contentLayout = window.findViewById(android.support.v7.appcompat.R.id.action_bar_activity_content);
if (contentLayout instanceof ContentFrameLayout) {
return contentLayout.getForeground();
}
return null;
}
try {
final Field field = ActionBarOverlayLayout.class.getDeclaredField("mWindowContentOverlay");
field.setAccessible(true);
return (Drawable) field.get(view);
} catch (Exception ignore) {
}
return null;
}
public static int getContrastColor(int color, int darkColor, int lightColor) {
if (TwidereColorUtils.getYIQLuminance(color) <= ACCENT_COLOR_THRESHOLD) {
@ -276,16 +246,6 @@ public class ThemeUtils implements Constants {
return pref.getString(KEY_THEME_BACKGROUND, VALUE_THEME_BACKGROUND_DEFAULT);
}
public static int getThemeColor(Context context) {
final Context appContext = context.getApplicationContext();
final TypedArray a = appContext.obtainStyledAttributes(new int[]{R.attr.colorPrimary});
try {
return a.getColor(0, ContextCompat.getColor(context, R.color.material_light_blue));
} finally {
a.recycle();
}
}
public static String getThemeFontFamily(@NonNull final SharedPreferences pref) {
final String fontFamily = pref.getString(KEY_THEME_FONT_FAMILY, VALUE_THEME_FONT_FAMILY_REGULAR);
if (!TextUtils.isEmpty(fontFamily)) return fontFamily;
@ -316,12 +276,6 @@ public class ThemeUtils implements Constants {
return 0;
}
public static String getThemeNameOption(final Context context) {
if (context == null) return VALUE_THEME_NAME_LIGHT;
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
return pref.getString(KEY_THEME, VALUE_THEME_NAME_LIGHT);
}
public static int getTitleTextAppearance(final Context context) {
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.titleTextStyle},
android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
@ -336,29 +290,6 @@ public class ThemeUtils implements Constants {
return pref.getInt(KEY_THEME_COLOR, def);
}
public static int getOptimalAccentColor(final Context context, boolean isActionBarContext) {
return getOptimalAccentColor(context, getUserAccentColor(context), isActionBarContext);
}
public static int getOptimalAccentColor(final Context context, final int accentColor, boolean isActionBarContext) {
final int backgroundColorApprox;
final boolean isDarkTheme = !isLightTheme(context);
if (!isActionBarContext) {
backgroundColorApprox = isDarkTheme ? Color.BLACK : Color.WHITE;
} else if (isDarkTheme) {
// View context is derived from ActionBar but is currently dark theme, so we should show
// light
backgroundColorApprox = Color.BLACK;
} else {
// View context is derived from ActionBar and it's light theme, so we use contrast color
backgroundColorApprox = Color.WHITE;
}
if (Math.abs(TwidereColorUtils.getYIQContrast(backgroundColorApprox, accentColor)) > DARK_COLOR_THRESHOLD)
return accentColor;
return getColorFromAttribute(context, R.attr.colorAccent,
ContextCompat.getColor(context, R.color.branding_color));
}
public static int getUserThemeBackgroundAlpha(final Context context) {
if (context == null) return DEFAULT_THEME_BACKGROUND_ALPHA;
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
@ -406,19 +337,6 @@ public class ThemeUtils implements Constants {
return d;
}
public static Drawable getWindowContentOverlay(final Context context) {
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowContentOverlay});
try {
return a.getDrawable(0);
} finally {
a.recycle();
}
}
public static Drawable getNormalWindowContentOverlay(final Context context) {
return getWindowContentOverlay(context);
}
public static boolean isLightTheme(final Context context) {
final TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.isLightTheme});
try {
@ -481,19 +399,6 @@ public class ThemeUtils implements Constants {
}
}
public static void setCompatToolbarOverlay(Activity activity, Drawable overlay) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return;
final Window window = activity.getWindow();
final View view = window.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, overlay);
} catch (Exception ignore) {
}
}
public static void setCompatContentViewOverlay(Window window, Drawable overlay) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return;
View contentLayout = window.findViewById(android.support.v7.appcompat.R.id.action_bar_activity_content);
@ -505,16 +410,6 @@ public class ThemeUtils implements Constants {
}
}
public static void setWindowOverlayViewOverlay(Activity activity, Drawable overlay) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return;
final Window window = activity.getWindow();
final View windowOverlay = window.findViewById(R.id.window_overlay);
if (windowOverlay == null) {
return;
}
ViewSupport.setBackground(windowOverlay, overlay);
}
public static void setupDrawerBackground(Context context, View view) {
if (!(context instanceof IThemedActivity)) return;
final String backgroundOption = ((IThemedActivity) context).getThemeBackgroundOption();
@ -646,41 +541,6 @@ public class ThemeUtils implements Constants {
return 0;
}
public static Context getActionBarThemedContext(Context base) {
final TypedValue outValue = new TypedValue();
final Resources.Theme baseTheme = base.getTheme();
baseTheme.resolveAttribute(android.support.v7.appcompat.R.attr.actionBarTheme, outValue, true);
if (outValue.resourceId != 0) {
final Resources.Theme actionBarTheme = base.getResources().newTheme();
actionBarTheme.setTo(baseTheme);
actionBarTheme.applyStyle(outValue.resourceId, true);
final ActionBarContextThemeWrapper actionBarContext = new ActionBarContextThemeWrapper(base, outValue.resourceId);
actionBarContext.getTheme().setTo(actionBarTheme);
return actionBarContext;
} else {
return base;
}
}
public static Context getActionBarThemedContext(Context base, int accentColor) {
final int actionBarThemeId;
if (!isLightTheme(base) || TwidereColorUtils.getYIQLuminance(accentColor) <= ACCENT_COLOR_THRESHOLD) {
actionBarThemeId = R.style.Theme_Twidere;
} else {
actionBarThemeId = R.style.Theme_Twidere;
}
final Resources.Theme baseTheme = base.getTheme();
final Resources.Theme actionBarTheme = base.getResources().newTheme();
actionBarTheme.setTo(baseTheme);
actionBarTheme.applyStyle(actionBarThemeId, true);
final ActionBarContextThemeWrapper actionBarContext = new ActionBarContextThemeWrapper(base, actionBarThemeId);
actionBarContext.getTheme().setTo(actionBarTheme);
return actionBarContext;
}
public static void applyToolbarItemColor(Context context, Toolbar toolbar, int toolbarColor) {
if (toolbar == null) {
return;
@ -761,10 +621,4 @@ public class ThemeUtils implements Constants {
}
public static final class ActionBarContextThemeWrapper extends android.support.v7.view.ContextThemeWrapper {
public ActionBarContextThemeWrapper(Context base, int themeres) {
super(base, themeres);
}
}
}