Covert to kotlin

This commit is contained in:
hemanths@live.com 2018-12-26 08:57:41 +05:30
parent 4531393db6
commit 79e0db37ef
53 changed files with 22 additions and 3196 deletions

View file

@ -1,124 +0,0 @@
package code.name.monkey.appthemehelper;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import code.name.monkey.appthemehelper.util.ColorUtil;
import code.name.monkey.appthemehelper.util.TintHelper;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public final class ATH {
private ATH() {
}
@SuppressLint("CommitPrefEdits")
public static boolean didThemeValuesChange(@NonNull Context context, long since) {
return ThemeStore.isConfigured(context)
&& ThemeStore.prefs(context).getLong(ThemeStore.VALUES_CHANGED, -1) > since;
}
public static void setStatusbarColorAuto(Activity activity) {
setStatusbarColor(activity, ThemeStore.statusBarColor(activity));
}
public static void setStatusbarColor(Activity activity, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().setStatusBarColor(color);
setLightStatusbarAuto(activity, color);
}
}
public static void setLightStatusbarAuto(Activity activity, int bgColor) {
setLightStatusbar(activity, ColorUtil.isColorLight(bgColor));
}
public static void setLightStatusbar(Activity activity, boolean enabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final View decorView = activity.getWindow().getDecorView();
final int systemUiVisibility = decorView.getSystemUiVisibility();
if (enabled) {
decorView.setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decorView.setSystemUiVisibility(systemUiVisibility & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
}
public static void setLightNavigationbar(Activity activity, boolean enabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final View decorView = activity.getWindow().getDecorView();
int systemUiVisibility = decorView.getSystemUiVisibility();
if (enabled) {
systemUiVisibility |= SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
} else {
systemUiVisibility &= ~SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
decorView.setSystemUiVisibility(systemUiVisibility);
}
}
public static void setLightNavigationbarAuto(Activity activity, int bgColor) {
setLightNavigationbar(activity, ColorUtil.isColorLight(bgColor));
}
public static void setNavigationbarColorAuto(Activity activity) {
setNavigationbarColor(activity, ThemeStore.navigationBarColor(activity));
}
public static void setNavigationbarColor(Activity activity, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.getWindow().setNavigationBarColor(color);
} else {
activity.getWindow().setNavigationBarColor(ColorUtil.darkenColor(color));
}
setLightNavigationbarAuto(activity, color);
}
public static void setActivityToolbarColorAuto(Activity activity, @Nullable Toolbar toolbar) {
setActivityToolbarColor(activity, toolbar, ThemeStore.primaryColor(activity));
}
public static void setActivityToolbarColor(Activity activity, @Nullable Toolbar toolbar,
int color) {
if (toolbar == null) {
return;
}
toolbar.setBackgroundColor(color);
ToolbarContentTintHelper.setToolbarContentColorBasedOnToolbarColor(activity, toolbar, color);
}
public static void setTaskDescriptionColorAuto(@NonNull Activity activity) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity));
}
public static void setTaskDescriptionColor(@NonNull Activity activity, @ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Task description requires fully opaque color
color = ColorUtil.stripAlpha(color);
// Sets color of entry in the system recents page
activity.setTaskDescription(new ActivityManager.TaskDescription((String) activity.getTitle(), null, color));
}
}
public static void setTint(@NonNull View view, @ColorInt int color) {
TintHelper.setTintAuto(view, color, false);
}
public static void setBackgroundTint(@NonNull View view, @ColorInt int color) {
TintHelper.setTintAuto(view, color, true);
}
}

View file

@ -1,51 +0,0 @@
package code.name.monkey.appthemehelper;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatActivity;
/**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/
public class ATHActivity extends AppCompatActivity {
private long updateTime = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(getThemeRes());
super.onCreate(savedInstanceState);
updateTime = System.currentTimeMillis();
}
@Override
protected void onResume() {
super.onResume();
if (ATH.didThemeValuesChange(this, updateTime)) {
onThemeChanged();
}
}
public void onThemeChanged() {
postRecreate();
}
public void postRecreate() {
// hack to prevent java.lang.RuntimeException: Performing pause of activity that is not resumed
// makes sure recreate() is called right after and not in onResume()
new Handler().post(new Runnable() {
@Override
public void run() {
recreate();
}
});
}
@StyleRes
protected int getThemeRes() {
return ThemeStore.activityTheme(this);
}
}

View file

@ -1,325 +0,0 @@
package code.name.monkey.appthemehelper;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import androidx.annotation.AttrRes;
import androidx.annotation.CheckResult;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.core.content.ContextCompat;
import code.name.monkey.appthemehelper.util.ATHUtil;
import code.name.monkey.appthemehelper.util.ColorUtil;
/**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/
public final class ThemeStore implements ThemeStorePrefKeys, ThemeStoreInterface {
private final Context mContext;
private final SharedPreferences.Editor mEditor;
@SuppressLint("CommitPrefEdits")
private ThemeStore(@NonNull Context context) {
mContext = context;
mEditor = prefs(context).edit();
}
public static ThemeStore editTheme(@NonNull Context context) {
return new ThemeStore(context);
}
@CheckResult
@NonNull
protected static SharedPreferences prefs(@NonNull Context context) {
return context.getSharedPreferences(CONFIG_PREFS_KEY_DEFAULT, Context.MODE_PRIVATE);
}
public static void markChanged(@NonNull Context context) {
new ThemeStore(context).commit();
}
@CheckResult
@StyleRes
public static int activityTheme(@NonNull Context context) {
return prefs(context).getInt(KEY_ACTIVITY_THEME, 0);
}
@CheckResult
@ColorInt
public static int primaryColor(@NonNull Context context) {
return prefs(context).getInt(KEY_PRIMARY_COLOR, ATHUtil.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")));
}
@CheckResult
@ColorInt
public static int primaryColorDark(@NonNull Context context) {
return prefs(context).getInt(KEY_PRIMARY_COLOR_DARK, ATHUtil.resolveColor(context, R.attr.colorPrimaryDark, Color.parseColor("#37474F")));
}
@CheckResult
@ColorInt
public static int accentColor(@NonNull Context context) {
return prefs(context).getInt(KEY_ACCENT_COLOR, ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")));
}
@CheckResult
@ColorInt
public static int statusBarColor(@NonNull Context context) {
if (!coloredStatusBar(context)) {
return Color.BLACK;
}
return prefs(context).getInt(KEY_STATUS_BAR_COLOR, primaryColorDark(context));
}
@CheckResult
@ColorInt
public static int navigationBarColor(@NonNull Context context) {
if (!coloredNavigationBar(context)) {
return Color.BLACK;
}
return prefs(context).getInt(KEY_NAVIGATION_BAR_COLOR, primaryColor(context));
}
@CheckResult
@ColorInt
public static int textColorPrimary(@NonNull Context context) {
return prefs(context).getInt(KEY_TEXT_COLOR_PRIMARY, ATHUtil.resolveColor(context, android.R.attr.textColorPrimary));
}
@CheckResult
@ColorInt
public static int textColorPrimaryInverse(@NonNull Context context) {
return prefs(context).getInt(KEY_TEXT_COLOR_PRIMARY_INVERSE, ATHUtil.resolveColor(context, android.R.attr.textColorPrimaryInverse));
}
@CheckResult
@ColorInt
public static int textColorSecondary(@NonNull Context context) {
return prefs(context).getInt(KEY_TEXT_COLOR_SECONDARY, ATHUtil.resolveColor(context, android.R.attr.textColorSecondary));
}
@CheckResult
@ColorInt
public static int textColorSecondaryInverse(@NonNull Context context) {
return prefs(context).getInt(KEY_TEXT_COLOR_SECONDARY_INVERSE, ATHUtil.resolveColor(context, android.R.attr.textColorSecondaryInverse));
}
@CheckResult
public static boolean coloredStatusBar(@NonNull Context context) {
return prefs(context).getBoolean(KEY_APPLY_PRIMARYDARK_STATUSBAR, true);
}
@CheckResult
public static boolean coloredNavigationBar(@NonNull Context context) {
return prefs(context).getBoolean(KEY_APPLY_PRIMARY_NAVBAR, false);
}
@CheckResult
public static boolean autoGeneratePrimaryDark(@NonNull Context context) {
return prefs(context).getBoolean(KEY_AUTO_GENERATE_PRIMARYDARK, true);
}
@CheckResult
public static boolean isConfigured(Context context) {
return prefs(context).getBoolean(IS_CONFIGURED_KEY, false);
}
@SuppressLint("CommitPrefEdits")
public static boolean isConfigured(Context context, @IntRange(from = 0, to = Integer.MAX_VALUE) int version) {
final SharedPreferences prefs = prefs(context);
final int lastVersion = prefs.getInt(IS_CONFIGURED_VERSION_KEY, -1);
if (version > lastVersion) {
prefs.edit().putInt(IS_CONFIGURED_VERSION_KEY, version).commit();
return false;
}
return true;
}
@Override
public ThemeStore activityTheme(@StyleRes int theme) {
mEditor.putInt(KEY_ACTIVITY_THEME, theme);
return this;
}
@Override
public ThemeStore primaryColor(@ColorInt int color) {
mEditor.putInt(KEY_PRIMARY_COLOR, color);
if (autoGeneratePrimaryDark(mContext))
primaryColorDark(ColorUtil.darkenColor(color));
return this;
}
@Override
public ThemeStore primaryColorRes(@ColorRes int colorRes) {
return primaryColor(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore primaryColorAttr(@AttrRes int colorAttr) {
return primaryColor(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore primaryColorDark(@ColorInt int color) {
mEditor.putInt(KEY_PRIMARY_COLOR_DARK, color);
return this;
}
@Override
public ThemeStore primaryColorDarkRes(@ColorRes int colorRes) {
return primaryColorDark(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore primaryColorDarkAttr(@AttrRes int colorAttr) {
return primaryColorDark(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore accentColor(@ColorInt int color) {
mEditor.putInt(KEY_ACCENT_COLOR, color);
return this;
}
@Override
public ThemeStore accentColorRes(@ColorRes int colorRes) {
return accentColor(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore accentColorAttr(@AttrRes int colorAttr) {
return accentColor(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore statusBarColor(@ColorInt int color) {
mEditor.putInt(KEY_STATUS_BAR_COLOR, color);
return this;
}
@Override
public ThemeStore statusBarColorRes(@ColorRes int colorRes) {
return statusBarColor(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore statusBarColorAttr(@AttrRes int colorAttr) {
return statusBarColor(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore navigationBarColor(@ColorInt int color) {
mEditor.putInt(KEY_NAVIGATION_BAR_COLOR, color);
return this;
}
// Commit method
@Override
public ThemeStore navigationBarColorRes(@ColorRes int colorRes) {
return navigationBarColor(ContextCompat.getColor(mContext, colorRes));
}
// Static getters
@Override
public ThemeStore navigationBarColorAttr(@AttrRes int colorAttr) {
return navigationBarColor(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore textColorPrimary(@ColorInt int color) {
mEditor.putInt(KEY_TEXT_COLOR_PRIMARY, color);
return this;
}
@Override
public ThemeStore textColorPrimaryRes(@ColorRes int colorRes) {
return textColorPrimary(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore textColorPrimaryAttr(@AttrRes int colorAttr) {
return textColorPrimary(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore textColorPrimaryInverse(@ColorInt int color) {
mEditor.putInt(KEY_TEXT_COLOR_PRIMARY_INVERSE, color);
return this;
}
@Override
public ThemeStore textColorPrimaryInverseRes(@ColorRes int colorRes) {
return textColorPrimaryInverse(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore textColorPrimaryInverseAttr(@AttrRes int colorAttr) {
return textColorPrimaryInverse(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore textColorSecondary(@ColorInt int color) {
mEditor.putInt(KEY_TEXT_COLOR_SECONDARY, color);
return this;
}
@Override
public ThemeStore textColorSecondaryRes(@ColorRes int colorRes) {
return textColorSecondary(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore textColorSecondaryAttr(@AttrRes int colorAttr) {
return textColorSecondary(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore textColorSecondaryInverse(@ColorInt int color) {
mEditor.putInt(KEY_TEXT_COLOR_SECONDARY_INVERSE, color);
return this;
}
@Override
public ThemeStore textColorSecondaryInverseRes(@ColorRes int colorRes) {
return textColorSecondaryInverse(ContextCompat.getColor(mContext, colorRes));
}
@Override
public ThemeStore textColorSecondaryInverseAttr(@AttrRes int colorAttr) {
return textColorSecondaryInverse(ATHUtil.resolveColor(mContext, colorAttr));
}
@Override
public ThemeStore coloredStatusBar(boolean colored) {
mEditor.putBoolean(KEY_APPLY_PRIMARYDARK_STATUSBAR, colored);
return this;
}
@Override
public ThemeStore coloredNavigationBar(boolean applyToNavBar) {
mEditor.putBoolean(KEY_APPLY_PRIMARY_NAVBAR, applyToNavBar);
return this;
}
@Override
public ThemeStore autoGeneratePrimaryDark(boolean autoGenerate) {
mEditor.putBoolean(KEY_AUTO_GENERATE_PRIMARYDARK, autoGenerate);
return this;
}
@SuppressWarnings("unchecked")
@Override
public void commit() {
mEditor.putLong(VALUES_CHANGED, System.currentTimeMillis())
.putBoolean(IS_CONFIGURED_KEY, true)
.commit();
}
}

View file

@ -1,94 +0,0 @@
package code.name.monkey.appthemehelper;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.StyleRes;
/**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/
interface ThemeStoreInterface {
// Activity theme
ThemeStore activityTheme(@StyleRes int theme);
// Primary colors
ThemeStore primaryColor(@ColorInt int color);
ThemeStore primaryColorRes(@ColorRes int colorRes);
ThemeStore primaryColorAttr(@AttrRes int colorAttr);
ThemeStore autoGeneratePrimaryDark(boolean autoGenerate);
ThemeStore primaryColorDark(@ColorInt int color);
ThemeStore primaryColorDarkRes(@ColorRes int colorRes);
ThemeStore primaryColorDarkAttr(@AttrRes int colorAttr);
// Accent colors
ThemeStore accentColor(@ColorInt int color);
ThemeStore accentColorRes(@ColorRes int colorRes);
ThemeStore accentColorAttr(@AttrRes int colorAttr);
// Status bar color
ThemeStore statusBarColor(@ColorInt int color);
ThemeStore statusBarColorRes(@ColorRes int colorRes);
ThemeStore statusBarColorAttr(@AttrRes int colorAttr);
// Navigation bar color
ThemeStore navigationBarColor(@ColorInt int color);
ThemeStore navigationBarColorRes(@ColorRes int colorRes);
ThemeStore navigationBarColorAttr(@AttrRes int colorAttr);
// Primary text color
ThemeStore textColorPrimary(@ColorInt int color);
ThemeStore textColorPrimaryRes(@ColorRes int colorRes);
ThemeStore textColorPrimaryAttr(@AttrRes int colorAttr);
ThemeStore textColorPrimaryInverse(@ColorInt int color);
ThemeStore textColorPrimaryInverseRes(@ColorRes int colorRes);
ThemeStore textColorPrimaryInverseAttr(@AttrRes int colorAttr);
// Secondary text color
ThemeStore textColorSecondary(@ColorInt int color);
ThemeStore textColorSecondaryRes(@ColorRes int colorRes);
ThemeStore textColorSecondaryAttr(@AttrRes int colorAttr);
ThemeStore textColorSecondaryInverse(@ColorInt int color);
ThemeStore textColorSecondaryInverseRes(@ColorRes int colorRes);
ThemeStore textColorSecondaryInverseAttr(@AttrRes int colorAttr);
// Toggle configurations
ThemeStore coloredStatusBar(boolean colored);
ThemeStore coloredNavigationBar(boolean applyToNavBar);
// Commit/apply
void commit();
}

View file

@ -1,29 +0,0 @@
package code.name.monkey.appthemehelper;
/**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/
interface ThemeStorePrefKeys {
String CONFIG_PREFS_KEY_DEFAULT = "[[kabouzeid_app-theme-helper]]";
String IS_CONFIGURED_KEY = "is_configured";
String IS_CONFIGURED_VERSION_KEY = "is_configured_version";
String VALUES_CHANGED = "values_changed";
String KEY_ACTIVITY_THEME = "activity_theme";
String KEY_PRIMARY_COLOR = "primary_color";
String KEY_PRIMARY_COLOR_DARK = "primary_color_dark";
String KEY_ACCENT_COLOR = "accent_color";
String KEY_STATUS_BAR_COLOR = "status_bar_color";
String KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color";
String KEY_TEXT_COLOR_PRIMARY = "text_color_primary";
String KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse";
String KEY_TEXT_COLOR_SECONDARY = "text_color_secondary";
String KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse";
String KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar";
String KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar";
String KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark";
}

View file

@ -1,13 +0,0 @@
package code.name.monkey.appthemehelper.common;
import androidx.appcompat.widget.Toolbar;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
public class ATHActionBarActivity extends ATHToolbarActivity {
@Override
protected Toolbar getATHToolbar() {
return ToolbarContentTintHelper.getSupportActionBarView(getSupportActionBar());
}
}

View file

@ -1,91 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.ThemeStore;
import java.lang.reflect.Field;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATECheckBoxPreference extends CheckBoxPreference {
public ATECheckBoxPreference(Context context) {
super(context);
init(context, null);
}
public ATECheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATECheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATECheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
try {
Field canRecycleLayoutField = Preference.class.getDeclaredField("mCanRecycleLayout");
canRecycleLayoutField.setAccessible(true);
canRecycleLayoutField.setBoolean(this, true);
} catch (Exception ignored) {
}
try {
Field hasSpecifiedLayout = Preference.class.getDeclaredField("mHasSpecifiedLayout");
hasSpecifiedLayout.setAccessible(true);
hasSpecifiedLayout.setBoolean(this, true);
} catch (Exception ignored) {
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
View parentCheckbox = findCheckboxView(view);
if (parentCheckbox != null) {
ATH.setTint(parentCheckbox, ThemeStore.accentColor(view.getContext()));
}
}
@Nullable
private View findCheckboxView(View view) {
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View child = ((ViewGroup) view).getChildAt(i);
if (child instanceof CheckBox) {
return child;
} else if (child instanceof ViewGroup) {
View potentialCheckbox = findCheckboxView(child);
if (potentialCheckbox != null) return potentialCheckbox;
}
}
} else if (view instanceof CheckBox) {
return view;
}
return null;
}
}

View file

@ -1,66 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEColorPreference extends Preference {
private View mView;
private int color;
private int border;
public ATEColorPreference(Context context) {
this(context, null, 0);
init(context, null);
}
public ATEColorPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
init(context, attrs);
}
public ATEColorPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
setWidgetLayoutResource(R.layout.ate_preference_color);
setPersistent(false);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
mView = view;
invalidateColor();
}
public void setColor(int color, int border) {
this.color = color;
this.border = border;
invalidateColor();
}
private void invalidateColor() {
if (mView != null) {
BorderCircleView circle = (BorderCircleView) mView.findViewById(R.id.circle);
if (this.color != 0) {
circle.setVisibility(View.VISIBLE);
circle.setBackgroundColor(color);
circle.setBorderColor(border);
} else {
circle.setVisibility(View.GONE);
}
}
}
}

View file

@ -1,39 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.util.AttributeSet;
import com.afollestad.materialdialogs.prefs.MaterialDialogPreference;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEDialogPreference extends MaterialDialogPreference {
public ATEDialogPreference(Context context) {
super(context);
init(context, null);
}
public ATEDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
}
}

View file

@ -1,36 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.util.AttributeSet;
import com.afollestad.materialdialogs.prefs.MaterialEditTextPreference;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEEditTextPreference extends MaterialEditTextPreference {
public ATEEditTextPreference(Context context) {
super(context);
init(context, null);
}
public ATEEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(code.name.monkey.appthemehelper.R.layout.ate_preference_custom);
}
}

View file

@ -1,39 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.util.AttributeSet;
import com.afollestad.materialdialogs.prefs.MaterialListPreference;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEListPreference extends MaterialListPreference {
public ATEListPreference(Context context) {
super(context);
init(context, null);
}
public ATEListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
if (getSummary() == null || getSummary().toString().trim().isEmpty())
setSummary("%s");
}
}

View file

@ -1,37 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.util.AttributeSet;
import com.afollestad.materialdialogs.prefs.MaterialListPreference;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEMultiSelectPreference extends MaterialListPreference {
public ATEMultiSelectPreference(Context context) {
super(context);
init(context, null);
}
public ATEMultiSelectPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEMultiSelectPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEMultiSelectPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
}
}

View file

@ -1,40 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.Preference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEPreference extends Preference {
public ATEPreference(Context context) {
super(context);
init(context, null);
}
public ATEPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATEPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
}
}

View file

@ -1,38 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.PreferenceCategory;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import code.name.monkey.appthemehelper.ThemeStore;
public class ATEPreferenceCategory extends PreferenceCategory {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATEPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public ATEPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ATEPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ATEPreferenceCategory(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
TextView mTitle = (TextView) view.findViewById(android.R.id.title);
mTitle.setTextColor(ThemeStore.accentColor(view.getContext()));
}
}

View file

@ -1,114 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.Preference;
import android.preference.SwitchPreference;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.appthemehelper.common.views.ATESwitch;
import java.lang.reflect.Field;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATESwitchPreference extends SwitchPreference {
static final boolean COMPAT_MODE = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
private ATESwitch mSwitch;
public ATESwitchPreference(Context context) {
super(context);
init(context, null);
}
public ATESwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATESwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATESwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom);
if (COMPAT_MODE) {
setWidgetLayoutResource(R.layout.ate_preference_switch);
} else {
try {
Field canRecycleLayoutField = Preference.class.getDeclaredField("mCanRecycleLayout");
canRecycleLayoutField.setAccessible(true);
canRecycleLayoutField.setBoolean(this, true);
} catch (Exception ignored) {
}
try {
Field hasSpecifiedLayout = Preference.class.getDeclaredField("mHasSpecifiedLayout");
hasSpecifiedLayout.setAccessible(true);
hasSpecifiedLayout.setBoolean(this, true);
} catch (Exception ignored) {
}
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
if (COMPAT_MODE) {
mSwitch = (ATESwitch) view.findViewById(R.id.switchWidget);
mSwitch.setChecked(isChecked());
} else {
View parentSwitch = findSwitchView(view);
if (parentSwitch != null) {
ATH.setTint(parentSwitch, ThemeStore.accentColor(view.getContext()));
}
}
}
@Nullable
private View findSwitchView(View view) {
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View child = ((ViewGroup) view).getChildAt(i);
if (child instanceof Switch || child instanceof SwitchCompat) {
return child;
} else if (child instanceof ViewGroup) {
View potentialSwitch = findSwitchView(child);
if (potentialSwitch != null) return potentialSwitch;
}
}
} else if (view instanceof Switch || view instanceof SwitchCompat) {
return view;
}
return null;
}
@Override
public void setChecked(boolean checked) {
super.setChecked(checked);
if (COMPAT_MODE) {
if (mSwitch != null) {
mSwitch.setChecked(checked);
}
}
}
}

View file

@ -1,112 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import code.name.monkey.appthemehelper.R;
public class BorderCircleView extends FrameLayout {
private final Drawable mCheck;
private final Paint paint;
private final Paint paintBorder;
private final int borderWidth;
private Paint paintCheck;
private PorterDuffColorFilter blackFilter;
private PorterDuffColorFilter whiteFilter;
public BorderCircleView(Context context) {
this(context, null, 0);
}
public BorderCircleView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BorderCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mCheck = ContextCompat.getDrawable(context, R.drawable.ate_check);
borderWidth = (int) getResources().getDimension(R.dimen.ate_circleview_border);
paint = new Paint();
paint.setAntiAlias(true);
paintBorder = new Paint();
paintBorder.setAntiAlias(true);
paintBorder.setColor(Color.BLACK);
setWillNotDraw(false);
}
@Override
public void setBackgroundColor(int color) {
paint.setColor(color);
requestLayout();
invalidate();
}
public void setBorderColor(int color) {
paintBorder.setColor(color);
requestLayout();
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) {
int width = MeasureSpec.getSize(widthMeasureSpec);
//noinspection SuspiciousNameCombination
int height = width;
if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));
}
setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int canvasSize = canvas.getWidth();
if (canvas.getHeight() < canvasSize) {
canvasSize = canvas.getHeight();
}
int circleCenter = (canvasSize - (borderWidth * 2)) / 2;
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, ((canvasSize - (borderWidth * 2)) / 2) + borderWidth - 4.0f, paintBorder);
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, ((canvasSize - (borderWidth * 2)) / 2) - 4.0f, paint);
if (isActivated()) {
final int offset = (canvasSize / 2) - (mCheck.getIntrinsicWidth() / 2);
if (paintCheck == null) {
paintCheck = new Paint();
paintCheck.setAntiAlias(true);
}
if (whiteFilter == null || blackFilter == null) {
blackFilter = new PorterDuffColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
whiteFilter = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
}
if (paint.getColor() == Color.WHITE) {
paintCheck.setColorFilter(blackFilter);
} else {
paintCheck.setColorFilter(whiteFilter);
}
mCheck.setBounds(offset, offset, mCheck.getIntrinsicWidth() - offset, mCheck.getIntrinsicHeight() - offset);
mCheck.draw(canvas);
}
}
}

View file

@ -1,42 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import androidx.preference.CheckBoxPreference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATECheckBoxPreference extends CheckBoxPreference {
public ATECheckBoxPreference(Context context) {
super(context);
init(context, null);
}
public ATECheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATECheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATECheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
setWidgetLayoutResource(R.layout.ate_preference_checkbox);
}
}

View file

@ -1,68 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.View;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.common.prefs.BorderCircleView;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEColorPreference extends Preference {
private View mView;
private int color;
private int border;
public ATEColorPreference(Context context) {
this(context, null, 0);
init(context, null);
}
public ATEColorPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
init(context, attrs);
}
public ATEColorPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
setWidgetLayoutResource(R.layout.ate_preference_color);
setPersistent(false);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mView = holder.itemView;
invalidateColor();
}
public void setColor(int color, int border) {
this.color = color;
this.border = border;
invalidateColor();
}
private void invalidateColor() {
if (mView != null) {
BorderCircleView circle = (BorderCircleView) mView.findViewById(R.id.circle);
if (this.color != 0) {
circle.setVisibility(View.VISIBLE);
circle.setBackgroundColor(color);
circle.setBorderColor(border);
} else {
circle.setVisibility(View.GONE);
}
}
}
}

View file

@ -1,38 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context;
import androidx.preference.DialogPreference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEDialogPreference extends DialogPreference {
public ATEDialogPreference(Context context) {
super(context);
init(context, null);
}
public ATEDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
}
}

View file

@ -1,38 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context;
import androidx.preference.EditTextPreference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEEditTextPreference extends EditTextPreference {
public ATEEditTextPreference(Context context) {
super(context);
init(context, null);
}
public ATEEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
}
}

View file

@ -1,39 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context;
import androidx.preference.ListPreference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEListPreference extends ListPreference {
public ATEListPreference(Context context) {
super(context);
init(context, null);
}
public ATEListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
if (getSummary() == null || getSummary().toString().trim().isEmpty())
setSummary("%s");
}
}

View file

@ -1,40 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import androidx.preference.Preference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEPreference extends Preference {
public ATEPreference(Context context) {
super(context);
init(context, null);
}
public ATEPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATEPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
}
}

View file

@ -1,47 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.widget.TextView;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.ThemeStore;
public class ATEPreferenceCategory extends PreferenceCategory {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATEPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
public ATEPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public ATEPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEPreferenceCategory(Context context) {
super(context);
init(context, null);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
TextView mTitle = (TextView) holder.itemView;
mTitle.setTextColor(ThemeStore.accentColor(getContext()));
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_category);
}
}

View file

@ -1,52 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEEditTextPreferenceDialogFragmentCompat;
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat;
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public abstract class ATEPreferenceFragmentCompat extends PreferenceFragmentCompat {
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (this.getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
((OnPreferenceDisplayDialogCallback) this.getCallbackFragment()).onPreferenceDisplayDialog(this, preference);
return;
}
if (this.getActivity() instanceof OnPreferenceDisplayDialogCallback) {
((OnPreferenceDisplayDialogCallback) this.getActivity()).onPreferenceDisplayDialog(this, preference);
return;
}
if (this.getFragmentManager().findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
DialogFragment dialogFragment = onCreatePreferenceDialog(preference);
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(this.getFragmentManager(), "android.support.v7.preference.PreferenceFragment.DIALOG");
return;
}
}
super.onDisplayPreferenceDialog(preference);
}
@Nullable
public DialogFragment onCreatePreferenceDialog(Preference preference) {
if (preference instanceof ATEEditTextPreference) {
return ATEEditTextPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} else if (preference instanceof ATEListPreference) {
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} else if (preference instanceof ATEDialogPreference) {
return ATEPreferenceDialogFragment.newInstance(preference.getKey());
}
return null;
}
}

View file

@ -1,29 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.content.Context;
import android.util.AttributeSet;
import androidx.preference.SeekBarPreference;
public class ATESeekBarPreference extends SeekBarPreference {
public ATESeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public ATESeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ATESeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ATESeekBarPreference(Context context) {
super(context);
init(context);
}
private void init(Context context) {
}
}

View file

@ -1,41 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import androidx.preference.CheckBoxPreference;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.R;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATESwitchPreference extends CheckBoxPreference {
public ATESwitchPreference(Context context) {
super(context);
init(context, null);
}
public ATESwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATESwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATESwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.ate_preference_custom_support);
setWidgetLayoutResource(R.layout.ate_preference_switch_support);
}
}

View file

@ -1,53 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.afollestad.materialdialogs.MaterialDialog;
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEEditTextPreference;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class ATEEditTextPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment implements MaterialDialog.InputCallback {
private CharSequence input;
public static ATEEditTextPreferenceDialogFragmentCompat newInstance(String key) {
ATEEditTextPreferenceDialogFragmentCompat fragment = new ATEEditTextPreferenceDialogFragmentCompat();
Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
private ATEEditTextPreference getEditTextPreference() {
return (ATEEditTextPreference) getPreference();
}
@Override
protected void onPrepareDialogBuilder(MaterialDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.input("", getEditTextPreference().getText(), this);
}
protected boolean needInputMethod() {
return true;
}
public void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
String value = input.toString();
if (this.getEditTextPreference().callChangeListener(value)) {
this.getEditTextPreference().setText(value);
}
}
}
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
this.input = input;
}
}

View file

@ -1,74 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.os.Bundle;
import androidx.preference.ListPreference;
import android.view.View;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment implements MaterialDialog.ListCallbackSingleChoice {
private int mClickedDialogEntryIndex;
public static ATEListPreferenceDialogFragmentCompat newInstance(String key) {
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
private ATEListPreference getListPreference() {
return (ATEListPreference) getPreference();
}
@Override
protected void onPrepareDialogBuilder(MaterialDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
final ListPreference preference = getListPreference();
if (preference.getEntries() == null || preference.getEntryValues() == null) {
throw new IllegalStateException(
"ListPreference requires an entries array and an entryValues array.");
}
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
builder.items(preference.getEntries())
.alwaysCallSingleChoiceCallback()
.itemsCallbackSingleChoice(mClickedDialogEntryIndex, this);
/*
* The typical interaction for list-based dialogs is to have
* click-on-an-item dismiss the dialog instead of the user having to
* press 'Ok'.
*/
builder.positiveText("");
builder.negativeText("");
builder.neutralText("");
}
@Override
public void onDialogClosed(boolean positiveResult) {
final ListPreference preference = getListPreference();
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
preference.getEntryValues() != null) {
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
if (preference.callChangeListener(value)) {
preference.setValue(value);
}
}
}
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
mClickedDialogEntryIndex = which;
onClick(dialog, DialogAction.POSITIVE);
dismiss();
return true;
}
}

View file

@ -1,95 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.DialogPreference;
import android.view.Window;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class ATEPreferenceDialogFragment extends DialogFragment implements MaterialDialog.SingleButtonCallback {
private DialogAction mWhichButtonClicked;
protected static final String ARG_KEY = "key";
private DialogPreference mPreference;
public static ATEPreferenceDialogFragment newInstance(String key) {
ATEPreferenceDialogFragment fragment = new ATEPreferenceDialogFragment();
Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fragment rawFragment = this.getTargetFragment();
if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
throw new IllegalStateException("Target fragment must implement TargetFragment interface");
} else {
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;
String key = this.getArguments().getString(ARG_KEY);
this.mPreference = (DialogPreference) fragment.findPreference(key);
}
}
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
FragmentActivity context = this.getActivity();
MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.title(this.mPreference.getDialogTitle())
.icon(this.mPreference.getDialogIcon())
.onAny(this)
.positiveText(this.mPreference.getPositiveButtonText())
.negativeText(this.mPreference.getNegativeButtonText());
builder.content(this.mPreference.getDialogMessage());
this.onPrepareDialogBuilder(builder);
MaterialDialog dialog = builder.build();
if (this.needInputMethod()) {
this.requestInputMethod(dialog);
}
return dialog;
}
public DialogPreference getPreference() {
return this.mPreference;
}
protected void onPrepareDialogBuilder(MaterialDialog.Builder builder) {
}
protected boolean needInputMethod() {
return false;
}
private void requestInputMethod(Dialog dialog) {
Window window = dialog.getWindow();
window.setSoftInputMode(5);
}
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
mWhichButtonClicked = which;
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
onDialogClosed(mWhichButtonClicked == DialogAction.POSITIVE);
}
public void onDialogClosed(boolean positiveResult) {
}
}

View file

@ -1,34 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import androidx.appcompat.widget.AppCompatCheckBox;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATECheckBox extends AppCompatCheckBox {
public ATECheckBox(Context context) {
super(context);
init(context, null);
}
public ATECheckBox(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATECheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
}

View file

@ -1,35 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import androidx.appcompat.widget.AppCompatEditText;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEEditText extends AppCompatEditText {
public ATEEditText(Context context) {
super(context);
init(context, null);
}
public ATEEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
setTextColor(ThemeStore.textColorPrimary(context));
}
}

View file

@ -1,35 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import androidx.appcompat.widget.AppCompatTextView;
import android.text.Layout;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEPrimaryTextView extends AppCompatTextView {
public ATEPrimaryTextView(Context context) {
super(context);
init(context, null);
}
public ATEPrimaryTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEPrimaryTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setTextColor(ThemeStore.textColorPrimary(context));
}
}

View file

@ -1,42 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ProgressBar;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEProgressBar extends ProgressBar {
public ATEProgressBar(Context context) {
super(context);
init(context, null);
}
public ATEProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATEProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
}

View file

@ -1,41 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.RadioButton;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATERadioButton extends RadioButton {
public ATERadioButton(Context context) {
super(context);
init(context, null);
}
public ATERadioButton(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATERadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATERadioButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
}

View file

@ -1,32 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import androidx.appcompat.widget.AppCompatTextView;
import android.util.AttributeSet;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATESecondaryTextView extends AppCompatTextView {
public ATESecondaryTextView(Context context) {
super(context);
init(context, null);
}
public ATESecondaryTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATESecondaryTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
setTextColor(ThemeStore.textColorSecondary(context));
}
}

View file

@ -1,42 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.SeekBar;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATESeekBar extends SeekBar {
public ATESeekBar(Context context) {
super(context);
init(context, null);
}
public ATESeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATESeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ATESeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
}

View file

@ -1,40 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Switch;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATEStockSwitch extends Switch {
public ATEStockSwitch(Context context) {
super(context);
init(context, null);
}
public ATEStockSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATEStockSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
@Override
public boolean isShown() {
return getParent() != null && getVisibility() == View.VISIBLE;
}
}

View file

@ -1,40 +0,0 @@
package code.name.monkey.appthemehelper.common.views;
import android.content.Context;
import androidx.appcompat.widget.SwitchCompat;
import android.util.AttributeSet;
import android.view.View;
import code.name.monkey.appthemehelper.ATH;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Aidan Follestad (afollestad)
*/
public class ATESwitch extends SwitchCompat {
public ATESwitch(Context context) {
super(context);
init(context, null);
}
public ATESwitch(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ATESwitch(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
ATH.setTint(this, ThemeStore.accentColor(context));
}
@Override
public boolean isShown() {
return getParent() != null && getVisibility() == View.VISIBLE;
}
}

View file

@ -1,48 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.Context;
import android.content.res.TypedArray;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
/**
* @author Aidan Follestad (afollestad)
*/
public final class ATHUtil {
public static boolean isWindowBackgroundDark(Context context) {
return !ColorUtil.isColorLight(ATHUtil.resolveColor(context, android.R.attr.windowBackground));
}
public static int resolveColor(Context context, @AttrRes int attr) {
return resolveColor(context, attr, 0);
}
public static int resolveColor(Context context, @AttrRes int attr, int fallback) {
TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
try {
return a.getColor(0, fallback);
} finally {
a.recycle();
}
}
public static boolean isInClassPath(@NonNull String clsName) {
try {
return inClassPath(clsName) != null;
} catch (Throwable t) {
return false;
}
}
public static Class<?> inClassPath(@NonNull String clsName) {
try {
return Class.forName(clsName);
} catch (Throwable t) {
throw new IllegalStateException(String.format("%s is not in your class path! You must include the associated library.", clsName));
}
}
private ATHUtil() {
}
}

View file

@ -1,77 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
public final class ColorUtil {
public static int stripAlpha(@ColorInt int color) {
return 0xff000000 | color;
}
@ColorInt
public static int shiftColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 2.0f) float by) {
if (by == 1f) return color;
int alpha = Color.alpha(color);
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= by; // value component
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
}
@ColorInt
public static int darkenColor(@ColorInt int color) {
return shiftColor(color, 0.9f);
}
@ColorInt
public static int lightenColor(@ColorInt int color) {
return shiftColor(color, 1.1f);
}
public static boolean isColorLight(@ColorInt int color) {
final double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
return darkness < 0.4;
}
@ColorInt
public static int invertColor(@ColorInt int color) {
final int r = 255 - Color.red(color);
final int g = 255 - Color.green(color);
final int b = 255 - Color.blue(color);
return Color.argb(Color.alpha(color), r, g, b);
}
@ColorInt
public static int adjustAlpha(@ColorInt int color, @FloatRange(from = 0.0, to = 1.0) float factor) {
int alpha = Math.round(Color.alpha(color) * factor);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}
@ColorInt
public static int withAlpha(@ColorInt int baseColor, @FloatRange(from = 0.0, to = 1.0) float alpha) {
int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
int rgb = 0x00ffffff & baseColor;
return a + rgb;
}
/**
* Taken from CollapsingToolbarLayout's CollapsingTextHelper class.
*/
public static int blendColors(int color1, int color2, @FloatRange(from = 0.0, to = 1.0) float ratio) {
final float inverseRatio = 1f - ratio;
float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
return Color.argb((int) a, (int) r, (int) g, (int) b);
}
private ColorUtil() {
}
}

View file

@ -1,26 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import androidx.annotation.ColorInt;
public final class DrawableUtil {
public static TransitionDrawable createTransitionDrawable(@ColorInt int startColor, @ColorInt int endColor) {
return createTransitionDrawable(new ColorDrawable(startColor), new ColorDrawable(endColor));
}
public static TransitionDrawable createTransitionDrawable(Drawable start, Drawable end) {
final Drawable[] drawables = new Drawable[2];
drawables[0] = start;
drawables[1] = end;
return new TransitionDrawable(drawables);
}
private DrawableUtil() {
}
}

View file

@ -1,334 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.annotation.TargetApi;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import androidx.core.widget.EdgeEffectCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.RecyclerView;
import android.widget.AbsListView;
import android.widget.EdgeEffect;
import android.widget.ScrollView;
import code.name.monkey.appthemehelper.BuildConfig;
import java.lang.reflect.Field;
public class EdgeGlowUtil {
protected EdgeGlowUtil() {
}
// Invalidation methods
private static Field EDGE_GLOW_FIELD_EDGE;
private static Field EDGE_GLOW_FIELD_GLOW;
private static Field EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT;
private static void invalidateEdgeEffectFields() {
if (EDGE_GLOW_FIELD_EDGE != null && EDGE_GLOW_FIELD_GLOW != null &&
EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT != null) {
EDGE_GLOW_FIELD_EDGE.setAccessible(true);
EDGE_GLOW_FIELD_GLOW.setAccessible(true);
EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.setAccessible(true);
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Field edge = null, glow = null;
Class cls = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
cls = Class.forName("android.widget.EdgeGlow");
} catch (ClassNotFoundException e) {
if (BuildConfig.DEBUG) e.printStackTrace();
}
} else {
cls = EdgeEffect.class;
}
if (cls != null) {
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mEdge":
f.setAccessible(true);
edge = f;
break;
case "mGlow":
f.setAccessible(true);
glow = f;
break;
}
}
}
EDGE_GLOW_FIELD_EDGE = edge;
EDGE_GLOW_FIELD_GLOW = glow;
} else {
EDGE_GLOW_FIELD_EDGE = null;
EDGE_GLOW_FIELD_GLOW = null;
}
Field efc = null;
try {
efc = EdgeEffectCompat.class.getDeclaredField("mEdgeEffect");
} catch (NoSuchFieldException e) {
if (BuildConfig.DEBUG) e.printStackTrace();
}
EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT = efc;
}
private static Field SCROLL_VIEW_FIELD_EDGE_GLOW_TOP;
private static Field SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM;
private static void invalidateScrollViewFields() {
if (SCROLL_VIEW_FIELD_EDGE_GLOW_TOP != null && SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM != null) {
SCROLL_VIEW_FIELD_EDGE_GLOW_TOP.setAccessible(true);
SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM.setAccessible(true);
return;
}
final Class<?> cls = ScrollView.class;
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mEdgeGlowTop":
f.setAccessible(true);
SCROLL_VIEW_FIELD_EDGE_GLOW_TOP = f;
break;
case "mEdgeGlowBottom":
f.setAccessible(true);
SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM = f;
break;
}
}
}
private static Field NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_TOP;
private static Field NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM;
private static void invalidateNestedScrollViewFields() {
if (NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_TOP != null && NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM != null) {
NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_TOP.setAccessible(true);
NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM.setAccessible(true);
return;
}
final Class<?> cls = ATHUtil.inClassPath("android.support.v4.widget.NestedScrollView");
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mEdgeGlowTop":
f.setAccessible(true);
NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_TOP = f;
break;
case "mEdgeGlowBottom":
f.setAccessible(true);
NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM = f;
break;
}
}
}
private static Field LIST_VIEW_FIELD_EDGE_GLOW_TOP;
private static Field LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM;
private static void invalidateListViewFields() {
if (LIST_VIEW_FIELD_EDGE_GLOW_TOP != null && LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM != null) {
LIST_VIEW_FIELD_EDGE_GLOW_TOP.setAccessible(true);
LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM.setAccessible(true);
return;
}
final Class<?> cls = AbsListView.class;
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mEdgeGlowTop":
f.setAccessible(true);
LIST_VIEW_FIELD_EDGE_GLOW_TOP = f;
break;
case "mEdgeGlowBottom":
f.setAccessible(true);
LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM = f;
break;
}
}
}
private static Field RECYCLER_VIEW_FIELD_EDGE_GLOW_TOP;
private static Field RECYCLER_VIEW_FIELD_EDGE_GLOW_LEFT;
private static Field RECYCLER_VIEW_FIELD_EDGE_GLOW_RIGHT;
private static Field RECYCLER_VIEW_FIELD_EDGE_GLOW_BOTTOM;
private static void invalidateRecyclerViewFields() {
if (RECYCLER_VIEW_FIELD_EDGE_GLOW_TOP != null && RECYCLER_VIEW_FIELD_EDGE_GLOW_LEFT != null &&
RECYCLER_VIEW_FIELD_EDGE_GLOW_RIGHT != null && RECYCLER_VIEW_FIELD_EDGE_GLOW_BOTTOM != null) {
RECYCLER_VIEW_FIELD_EDGE_GLOW_TOP.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_LEFT.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_RIGHT.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_BOTTOM.setAccessible(true);
return;
}
final Class<?> cls = ATHUtil.inClassPath("android.support.v7.widget.RecyclerView");
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mTopGlow":
f.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_TOP = f;
break;
case "mBottomGlow":
f.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_BOTTOM = f;
break;
case "mLeftGlow":
f.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_LEFT = f;
break;
case "mRightGlow":
f.setAccessible(true);
RECYCLER_VIEW_FIELD_EDGE_GLOW_RIGHT = f;
break;
}
}
}
private static Field VIEW_PAGER_FIELD_EDGE_GLOW_LEFT;
private static Field VIEW_PAGER_FIELD_EDGE_GLOW_RIGHT;
private static void invalidateViewPagerFields() {
if (VIEW_PAGER_FIELD_EDGE_GLOW_LEFT != null && VIEW_PAGER_FIELD_EDGE_GLOW_RIGHT != null) {
VIEW_PAGER_FIELD_EDGE_GLOW_LEFT.setAccessible(true);
VIEW_PAGER_FIELD_EDGE_GLOW_RIGHT.setAccessible(true);
return;
}
final Class<?> cls = ATHUtil.inClassPath("android.support.v4.view.ViewPager");
for (Field f : cls.getDeclaredFields()) {
switch (f.getName()) {
case "mLeftEdge":
f.setAccessible(true);
VIEW_PAGER_FIELD_EDGE_GLOW_LEFT = f;
break;
case "mRightEdge":
f.setAccessible(true);
VIEW_PAGER_FIELD_EDGE_GLOW_RIGHT = f;
break;
}
}
}
// Setter methods
public static void setEdgeGlowColor(@NonNull ScrollView scrollView, @ColorInt int color) {
invalidateScrollViewFields();
try {
Object ee;
ee = SCROLL_VIEW_FIELD_EDGE_GLOW_TOP.get(scrollView);
setEffectColor(ee, color);
ee = SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(scrollView);
setEffectColor(ee, color);
} catch (Exception ex) {
if (BuildConfig.DEBUG) ex.printStackTrace();
}
}
public static void setEdgeGlowColor(@NonNull NestedScrollView scrollView, @ColorInt int color) {
invalidateNestedScrollViewFields();
try {
Object ee;
ee = NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_TOP.get(scrollView);
setEffectColor(ee, color);
ee = NESTED_SCROLL_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(scrollView);
setEffectColor(ee, color);
} catch (Exception ex) {
if (BuildConfig.DEBUG) ex.printStackTrace();
}
}
public static void setEdgeGlowColor(@NonNull AbsListView listView, @ColorInt int color) {
invalidateListViewFields();
try {
Object ee;
ee = LIST_VIEW_FIELD_EDGE_GLOW_TOP.get(listView);
setEffectColor(ee, color);
ee = LIST_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(listView);
setEffectColor(ee, color);
} catch (Exception ex) {
if (BuildConfig.DEBUG) ex.printStackTrace();
}
}
public static void setEdgeGlowColor(@NonNull RecyclerView scrollView, final @ColorInt int color, @Nullable RecyclerView.OnScrollListener scrollListener) {
invalidateRecyclerViewFields();
invalidateRecyclerViewFields();
if (scrollListener == null) {
scrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
EdgeGlowUtil.setEdgeGlowColor(recyclerView, color, this);
}
};
scrollView.addOnScrollListener(scrollListener);
}
try {
Object ee;
ee = RECYCLER_VIEW_FIELD_EDGE_GLOW_TOP.get(scrollView);
setEffectColor(ee, color);
ee = RECYCLER_VIEW_FIELD_EDGE_GLOW_BOTTOM.get(scrollView);
setEffectColor(ee, color);
ee = RECYCLER_VIEW_FIELD_EDGE_GLOW_LEFT.get(scrollView);
setEffectColor(ee, color);
ee = RECYCLER_VIEW_FIELD_EDGE_GLOW_RIGHT.get(scrollView);
setEffectColor(ee, color);
} catch (Exception ex) {
if (BuildConfig.DEBUG) ex.printStackTrace();
}
}
public static void setEdgeGlowColor(@NonNull ViewPager pager, @ColorInt int color) {
invalidateViewPagerFields();
try {
Object ee;
ee = VIEW_PAGER_FIELD_EDGE_GLOW_LEFT.get(pager);
setEffectColor(ee, color);
ee = VIEW_PAGER_FIELD_EDGE_GLOW_RIGHT.get(pager);
setEffectColor(ee, color);
} catch (Exception ex) {
if (BuildConfig.DEBUG) ex.printStackTrace();
}
}
// Utilities
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void setEffectColor(Object edgeEffect, @ColorInt int color) {
invalidateEdgeEffectFields();
if (edgeEffect instanceof EdgeEffectCompat) {
// EdgeEffectCompat
try {
EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.setAccessible(true);
edgeEffect = EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.get(edgeEffect);
} catch (IllegalAccessException e) {
e.printStackTrace();
return;
}
}
if (edgeEffect == null)
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// EdgeGlow
try {
EDGE_GLOW_FIELD_EDGE.setAccessible(true);
final Drawable mEdge = (Drawable) EDGE_GLOW_FIELD_EDGE.get(edgeEffect);
EDGE_GLOW_FIELD_GLOW.setAccessible(true);
final Drawable mGlow = (Drawable) EDGE_GLOW_FIELD_GLOW.get(edgeEffect);
mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
mEdge.setCallback(null); // free up any references
mGlow.setCallback(null); // free up any references
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
// EdgeEffect
((EdgeEffect) edgeEffect).setColor(color);
}
}
}

View file

@ -1,27 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.Context;
import android.content.res.ColorStateList;
import com.afollestad.materialdialogs.internal.ThemeSingleton;
import code.name.monkey.appthemehelper.ThemeStore;
public final class MaterialDialogsUtil {
public static void updateMaterialDialogsThemeSingleton(Context context) {
final ThemeSingleton md = ThemeSingleton.get();
md.titleColor = ThemeStore.textColorPrimary(context);
md.contentColor = ThemeStore.textColorSecondary(context);
md.itemColor = md.titleColor;
md.widgetColor = ThemeStore.accentColor(context);
md.linkColor = ColorStateList.valueOf(md.widgetColor);
md.positiveColor = ColorStateList.valueOf(md.widgetColor);
md.neutralColor = ColorStateList.valueOf(md.widgetColor);
md.negativeColor = ColorStateList.valueOf(md.widgetColor);
md.darkTheme = ATHUtil.isWindowBackgroundDark(context);
}
private MaterialDialogsUtil() {
}
}

View file

@ -1,61 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.Context;
import android.content.res.ColorStateList;
import androidx.annotation.NonNull;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputLayout;
import code.name.monkey.appthemehelper.ThemeStore;
public class MaterialUtil {
public static void setTint(@NonNull MaterialButton button, boolean background) {
setTint(button, background, ThemeStore.accentColor(button.getContext()));
}
public static void setTint(@NonNull MaterialButton button) {
setTint(button, ThemeStore.accentColor(button.getContext()));
}
private static void setTint(MaterialButton button, int accentColor) {
final Context context = button.getContext();
final ColorStateList textColor = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(accentColor)));
button.setTextColor(textColor);
}
public static void setTint(@NonNull MaterialButton button, boolean background, int color) {
//button.setPadding(48, 48, 48, 48);
button.setAllCaps(false);
final Context context = button.getContext();
final ColorStateList colorState = ColorStateList.valueOf(color);
final ColorStateList textColor = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color)));
if (background) {
button.setBackgroundTintList(colorState);
button.setTextColor(textColor);
button.setIconTint(textColor);
} else {
button.setStrokeColor(colorState);
button.setTextColor(colorState);
button.setIconTint(colorState);
}
}
public static void setTint(TextInputLayout textInputLayout, boolean background) {
final Context context = textInputLayout.getContext();
final int accentColor = ThemeStore.accentColor(context);
final ColorStateList colorState = ColorStateList.valueOf(accentColor);
if (background) {
textInputLayout.setBackgroundTintList(colorState);
textInputLayout.setDefaultHintTextColor(colorState);
} else {
textInputLayout.setBoxStrokeColor(accentColor);
textInputLayout.setDefaultHintTextColor(colorState);
}
}
}

View file

@ -1,51 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import code.name.monkey.appthemehelper.R;
public final class MaterialValueHelper {
@SuppressLint("PrivateResource")
@ColorInt
public static int getPrimaryTextColor(final Context context, boolean dark) {
if (dark) {
return ContextCompat.getColor(context, R.color.primary_text_default_material_light);
}
return ContextCompat.getColor(context, R.color.primary_text_default_material_dark);
}
@SuppressLint("PrivateResource")
@ColorInt
public static int getSecondaryTextColor(final Context context, boolean dark) {
if (dark) {
return ContextCompat.getColor(context, R.color.secondary_text_default_material_light);
}
return ContextCompat.getColor(context, R.color.secondary_text_default_material_dark);
}
@SuppressLint("PrivateResource")
@ColorInt
public static int getPrimaryDisabledTextColor(final Context context, boolean dark) {
if (dark) {
return ContextCompat.getColor(context, R.color.primary_text_disabled_material_light);
}
return ContextCompat.getColor(context, R.color.primary_text_disabled_material_dark);
}
@SuppressLint("PrivateResource")
@ColorInt
public static int getSecondaryDisabledTextColor(final Context context, boolean dark) {
if (dark) {
return ContextCompat.getColor(context, R.color.secondary_text_disabled_material_light);
}
return ContextCompat.getColor(context, R.color.secondary_text_disabled_material_dark);
}
private MaterialValueHelper() {
}
}

View file

@ -1,74 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import code.name.monkey.appthemehelper.ThemeStore;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public final class NavigationViewUtil {
private NavigationViewUtil() {
}
public static void setItemIconColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
final ColorStateList iconSl = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
},
new int[]{
normalColor,
selectedColor
});
navigationView.setItemIconTintList(iconSl);
Drawable drawable = navigationView.getItemBackground();
navigationView.setItemBackground(TintHelper.createTintedDrawable(drawable, ColorUtil.withAlpha(ThemeStore.accentColor(navigationView.getContext()), 0.2f)));
}
public static void setItemTextColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
final ColorStateList textSl = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
},
new int[]{
normalColor,
selectedColor
});
navigationView.setItemTextColor(textSl);
}
public static void setItemIconColors(@NonNull BottomNavigationView bottomNavigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
final ColorStateList iconSl = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
},
new int[]{
normalColor,
selectedColor
});
bottomNavigationView.setItemIconTintList(iconSl);
}
public static void setItemTextColors(@NonNull BottomNavigationView bottomNavigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
final ColorStateList textSl = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
},
new int[]{
normalColor,
selectedColor
});
bottomNavigationView.setItemTextColor(textSl);
}
}

View file

@ -1,33 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.res.ColorStateList;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
public final class TabLayoutUtil {
public static void setTabIconColors(@Nullable TabLayout tabLayout, @ColorInt int normalColor, @ColorInt int selectedColor) {
if (tabLayout == null)
return;
final ColorStateList sl = new ColorStateList(new int[][]{
new int[]{-android.R.attr.state_selected},
new int[]{android.R.attr.state_selected}
},
new int[]{
normalColor,
selectedColor
});
for (int i = 0; i < tabLayout.getTabCount(); i++) {
final TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null && tab.getIcon() != null) {
tab.setIcon(TintHelper.createTintedDrawable(tab.getIcon(), sl));
}
}
}
private TabLayoutUtil() {
}
}

View file

@ -1,37 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.content.res.ColorStateList;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import com.google.android.material.textfield.TextInputLayout;
import java.lang.reflect.Field;
/**
* @author Aidan Follestad (afollestad)
*/
public final class TextInputLayoutUtil {
public static void setHint(@NonNull TextInputLayout view, @ColorInt int hintColor) {
try {
final Field mDefaultTextColorField = TextInputLayout.class.getDeclaredField("mDefaultTextColor");
mDefaultTextColorField.setAccessible(true);
mDefaultTextColorField.set(view, ColorStateList.valueOf(hintColor));
} catch (Throwable t) {
throw new RuntimeException("Failed to set TextInputLayout hint (collapsed) color: " + t.getLocalizedMessage(), t);
}
}
public static void setAccent(@NonNull TextInputLayout view, @ColorInt int accentColor) {
try {
final Field mFocusedTextColorField = TextInputLayout.class.getDeclaredField("mFocusedTextColor");
mFocusedTextColorField.setAccessible(true);
mFocusedTextColorField.set(view, ColorStateList.valueOf(accentColor));
} catch (Throwable t) {
throw new RuntimeException("Failed to set TextInputLayout accent (expanded) color: " + t.getLocalizedMessage(), t);
}
}
private TextInputLayoutUtil() {
}
}

View file

@ -60,10 +60,10 @@ public final class TintHelper {
@SuppressWarnings("deprecation")
public static void setTintSelector(@NonNull View view, @ColorInt final int color, final boolean darker, final boolean useDarkTheme) {
final boolean isColorLight = ColorUtil.isColorLight(color);
final boolean isColorLight = ColorUtil.INSTANCE.isColorLight(color);
final int disabled = ContextCompat.getColor(view.getContext(), useDarkTheme ? R.color.ate_button_disabled_dark : R.color.ate_button_disabled_light);
final int pressed = ColorUtil.shiftColor(color, darker ? 0.9f : 1.1f);
final int activated = ColorUtil.shiftColor(color, darker ? 1.1f : 0.9f);
final int pressed = ColorUtil.INSTANCE.shiftColor(color, darker ? 0.9f : 1.1f);
final int activated = ColorUtil.INSTANCE.shiftColor(color, darker ? 1.1f : 0.9f);
final int rippleColor = getDefaultRippleColor(view.getContext(), isColorLight);
final int textColor = ContextCompat.getColor(view.getContext(), isColorLight ? R.color.ate_primary_text_light : R.color.ate_primary_text_dark);
@ -117,7 +117,7 @@ public final class TintHelper {
Drawable drawable = view.getBackground();
if (drawable != null) {
drawable = createTintedDrawable(drawable, sl);
ViewUtil.setBackgroundCompat(view, drawable);
ViewUtil.INSTANCE.setBackgroundCompat(view, drawable);
}
if (view instanceof TextView && !(view instanceof Button)) {
@ -128,7 +128,7 @@ public final class TintHelper {
public static void setTintAuto(final @NonNull View view, final @ColorInt int color,
boolean background) {
setTintAuto(view, color, background, ATHUtil.isWindowBackgroundDark(view.getContext()));
setTintAuto(view, color, background, ATHUtil.INSTANCE.isWindowBackgroundDark(view.getContext()));
}
@SuppressWarnings("deprecation")
@ -159,7 +159,7 @@ public final class TintHelper {
RippleDrawable rd = (RippleDrawable) view.getBackground();
@SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(),
isDark ? R.color.ripple_material_dark : R.color.ripple_material_light);
final int checked = ColorUtil.adjustAlpha(color, 0.4f);
final int checked = ColorUtil.INSTANCE.adjustAlpha(color, 0.4f);
final ColorStateList sl = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked},
@ -183,7 +183,7 @@ public final class TintHelper {
Drawable drawable = view.getBackground();
if (drawable != null) {
drawable = createTintedDrawable(drawable, color);
ViewUtil.setBackgroundCompat(view, drawable);
ViewUtil.INSTANCE.setBackgroundCompat(view, drawable);
}
}
}
@ -197,7 +197,7 @@ public final class TintHelper {
new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}
}, new int[]{
// Rdio button includes own alpha for disabled state
ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)),
ColorUtil.INSTANCE.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)),
ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
color
});
@ -298,9 +298,9 @@ public final class TintHelper {
private static Drawable modifySwitchDrawable(@NonNull Context context, @NonNull Drawable from, @ColorInt int tint, boolean thumb, boolean compatSwitch, boolean useDarker) {
if (useDarker) {
tint = ColorUtil.shiftColor(tint, 1.1f);
tint = ColorUtil.INSTANCE.shiftColor(tint, 1.1f);
}
tint = ColorUtil.adjustAlpha(tint, (compatSwitch && !thumb) ? 0.5f : 1.0f);
tint = ColorUtil.INSTANCE.adjustAlpha(tint, (compatSwitch && !thumb) ? 0.5f : 1.0f);
int disabled;
int normal;
if (thumb) {
@ -313,7 +313,7 @@ public final class TintHelper {
// Stock switch includes its own alpha
if (!compatSwitch) {
normal = ColorUtil.stripAlpha(normal);
normal = ColorUtil.INSTANCE.stripAlpha(normal);
}
final ColorStateList sl = new ColorStateList(

View file

@ -140,8 +140,8 @@ public final class ToolbarContentTintHelper {
}
//Step 3: Changing the color of title and subtitle.
toolbarView.setTitleTextColor(ThemeStore.textColorPrimary(activity));
toolbarView.setSubtitleTextColor(ThemeStore.textColorSecondary(activity));
toolbarView.setTitleTextColor(ThemeStore.Companion.textColorPrimary(activity));
toolbarView.setSubtitleTextColor(ThemeStore.Companion.textColorSecondary(activity));
//Step 4: Changing the color of the Overflow Menu icon.
setOverflowButtonColor(activity, toolbarView, toolbarIconsColor);
@ -204,7 +204,7 @@ public final class ToolbarContentTintHelper {
public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context,
Toolbar toolbar, @Nullable Menu menu, int toolbarColor) {
setToolbarContentColorBasedOnToolbarColor(context, toolbar, menu, toolbarColor,
ThemeStore.accentColor(context));
ThemeStore.Companion.accentColor(context));
}
public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context,
@ -309,7 +309,7 @@ public final class ToolbarContentTintHelper {
}
public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar) {
handleOnPrepareOptionsMenu(activity, toolbar, ThemeStore.accentColor(activity));
handleOnPrepareOptionsMenu(activity, toolbar, ThemeStore.Companion.accentColor(activity));
}
public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar,
@ -332,7 +332,7 @@ public final class ToolbarContentTintHelper {
@CheckResult
@ColorInt
public static int toolbarContentColor(@NonNull Context context, @ColorInt int toolbarColor) {
if (ColorUtil.isColorLight(toolbarColor)) {
if (ColorUtil.INSTANCE.isColorLight(toolbarColor)) {
return toolbarSubtitleColor(context, toolbarColor);
}
return toolbarTitleColor(context, toolbarColor);
@ -341,13 +341,13 @@ public final class ToolbarContentTintHelper {
@CheckResult
@ColorInt
public static int toolbarSubtitleColor(@NonNull Context context, @ColorInt int toolbarColor) {
return MaterialValueHelper.getSecondaryTextColor(context, ColorUtil.isColorLight(toolbarColor));
return MaterialValueHelper.INSTANCE.getSecondaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor));
}
@CheckResult
@ColorInt
public static int toolbarTitleColor(@NonNull Context context, @ColorInt int toolbarColor) {
return MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(toolbarColor));
return MaterialValueHelper.INSTANCE.getPrimaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor));
}
private static class ATHMenuPresenterCallback implements MenuPresenter.Callback {
@ -485,8 +485,8 @@ public final class ToolbarContentTintHelper {
.getDeclaredField("mRadioButton");
radioButtonField.setAccessible(true);
final boolean isDark = !ColorUtil.isColorLight(
ATHUtil.resolveColor(context, android.R.attr.windowBackground));
final boolean isDark = !ColorUtil.INSTANCE.isColorLight(
ATHUtil.INSTANCE.resolveColor(context, android.R.attr.windowBackground));
for (int i = 0; i < listView.getChildCount(); i++) {
View v = listView.getChildAt(i);
@ -545,7 +545,7 @@ public final class ToolbarContentTintHelper {
}
final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color));
ViewUtil.removeOnGlobalLayoutListener(decorView, this);
ViewUtil.INSTANCE.removeOnGlobalLayoutListener(decorView, this);
}
});
}
@ -576,7 +576,7 @@ public final class ToolbarContentTintHelper {
mSearchSrcTextViewField.setAccessible(true);
final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(searchView);
mSearchSrcTextView.setTextColor(color);
mSearchSrcTextView.setHintTextColor(ColorUtil.adjustAlpha(color, 0.5f));
mSearchSrcTextView.setHintTextColor(ColorUtil.INSTANCE.adjustAlpha(color, 0.5f));
TintHelper.setCursorTint(mSearchSrcTextView, color);
Field field = cls.getDeclaredField("mSearchButton");

View file

@ -1,49 +0,0 @@
package code.name.monkey.appthemehelper.util;
/**
* @author Aidan Follestad (afollestad)
*/
import android.content.Context;
import android.graphics.Typeface;
import androidx.collection.SimpleArrayMap;
/*
Each call to Typeface.createFromAsset will load a new instance of the typeface into memory,
and this memory is not consistently get garbage collected
http://code.google.com/p/android/issues/detail?id=9904
(It states released but even on Lollipop you can see the typefaces accumulate even after
multiple GC passes)
You can detect this by running:
adb shell dumpsys meminfo com.your.packagenage
You will see output like:
Asset Allocations
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Regular.ttf: 123K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
*/
public final class TypefaceHelper {
private static final SimpleArrayMap<String, Typeface> cache = new SimpleArrayMap<>();
public static Typeface get(Context c, String name) {
synchronized (cache) {
if (!cache.containsKey(name)) {
try {
Typeface t = Typeface.createFromAsset(c.getAssets(), name);
cache.put(name, t);
return t;
} catch (RuntimeException e) {
return null;
}
}
return cache.get(name);
}
}
}

View file

@ -1,59 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.os.Build;
/**
* @author Hemanth S (h4h13).
*/
public final class VersionUtils {
/**
* @return true if device is running API >= 19
*/
public static boolean hasKitKat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
/**
* @return true if device is running API >= 20
*/
public static boolean hasAndroidLPreview() {
return Build.VERSION.SDK_INT >= 20;
}
/**
* @return true if device is running API >= 21
*/
public static boolean hasLollipop() {
return Build.VERSION.SDK_INT >= 21;
}
/**
* @return true if device is running API >= 23
*/
public static boolean hasMarshmallow() {
return Build.VERSION.SDK_INT >= 23;
}
/**
* @return true if device is running API >= 24
*/
public static boolean hasNougat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
}
/**
* @return true if device is running API >= 24
*/
public static boolean hasNougatMR() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
}
/**
* @return true if device is running API >= 26
*/
public static boolean hasOreo() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
}

View file

@ -1,53 +0,0 @@
package code.name.monkey.appthemehelper.util;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.View;
import android.view.ViewTreeObserver;
public final class ViewUtil {
@SuppressWarnings("deprecation")
public static void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
} else {
v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
}
}
@SuppressWarnings("deprecation")
public static void setBackgroundCompat(@NonNull View view, @Nullable Drawable drawable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
view.setBackground(drawable);
else view.setBackgroundDrawable(drawable);
}
public static TransitionDrawable setBackgroundTransition(@NonNull View view, @NonNull Drawable newDrawable) {
TransitionDrawable transition = DrawableUtil.createTransitionDrawable(view.getBackground(), newDrawable);
setBackgroundCompat(view, transition);
return transition;
}
public static TransitionDrawable setBackgroundColorTransition(@NonNull View view, @ColorInt int newColor) {
final Drawable oldColor = view.getBackground();
Drawable start = oldColor != null ? oldColor : new ColorDrawable(view.getSolidColor());
Drawable end = new ColorDrawable(newColor);
TransitionDrawable transition = DrawableUtil.createTransitionDrawable(start, end);
setBackgroundCompat(view, transition);
return transition;
}
private ViewUtil() {
}
}