[Cleanup] Fixing Warnings
This commit is contained in:
parent
1fdd537253
commit
fa976b1cba
68 changed files with 242 additions and 498 deletions
|
@ -74,7 +74,7 @@ object ATH {
|
|||
setActivityToolbarColor(activity, toolbar, ThemeStore.primaryColor(activity))
|
||||
}
|
||||
|
||||
fun setActivityToolbarColor(
|
||||
private fun setActivityToolbarColor(
|
||||
activity: Activity, toolbar: Toolbar?,
|
||||
color: Int
|
||||
) {
|
||||
|
|
|
@ -23,7 +23,7 @@ open class ATHActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
fun onThemeChanged() {
|
||||
private fun onThemeChanged() {
|
||||
postRecreate()
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ATEPreferenceDialogFragment extends DialogFragment implements Dialo
|
|||
} else {
|
||||
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;
|
||||
String key = this.getArguments().getString(ARG_KEY);
|
||||
this.mPreference = (DialogPreference) fragment.findPreference(key);
|
||||
this.mPreference = fragment.findPreference(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class ATEPreferenceDialogFragment extends DialogFragment implements Dialo
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
Log.i(TAG, "onDismiss: " + mWhichButtonClicked);
|
||||
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);
|
||||
|
|
|
@ -3,6 +3,7 @@ package code.name.monkey.appthemehelper.util
|
|||
import android.graphics.Color
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.FloatRange
|
||||
import kotlin.math.*
|
||||
|
||||
object ColorUtil {
|
||||
fun desaturateColor(color: Int, ratio: Float): Int {
|
||||
|
@ -59,7 +60,7 @@ object ColorUtil {
|
|||
|
||||
@ColorInt
|
||||
fun adjustAlpha(@ColorInt color: Int, @FloatRange(from = 0.0, to = 1.0) factor: Float): Int {
|
||||
val alpha = Math.round(Color.alpha(color) * factor)
|
||||
val alpha = (Color.alpha(color) * factor).roundToInt()
|
||||
val red = Color.red(color)
|
||||
val green = Color.green(color)
|
||||
val blue = Color.blue(color)
|
||||
|
@ -68,7 +69,7 @@ object ColorUtil {
|
|||
|
||||
@ColorInt
|
||||
fun withAlpha(@ColorInt baseColor: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float): Int {
|
||||
val a = Math.min(255, Math.max(0, (alpha * 255).toInt())) shl 24
|
||||
val a = min(255, max(0, (alpha * 255).toInt())) shl 24
|
||||
val rgb = 0x00ffffff and baseColor
|
||||
return a + rgb
|
||||
}
|
||||
|
@ -100,15 +101,15 @@ object ColorUtil {
|
|||
}
|
||||
|
||||
fun isColorSaturated(@ColorInt color: Int): Boolean {
|
||||
val max = Math.max(
|
||||
val max = max(
|
||||
0.299 * Color.red(color),
|
||||
Math.max(0.587 * Color.green(color), 0.114 * Color.blue(color))
|
||||
max(0.587 * Color.green(color), 0.114 * Color.blue(color))
|
||||
)
|
||||
val min = Math.min(
|
||||
val min = min(
|
||||
0.299 * Color.red(color),
|
||||
Math.min(0.587 * Color.green(color), 0.114 * Color.blue(color))
|
||||
min(0.587 * Color.green(color), 0.114 * Color.blue(color))
|
||||
)
|
||||
val diff = Math.abs(max - min)
|
||||
val diff = abs(max - min)
|
||||
return diff > 20
|
||||
}
|
||||
|
||||
|
@ -121,10 +122,10 @@ object ColorUtil {
|
|||
)
|
||||
}
|
||||
|
||||
fun getDifference(@ColorInt color1: Int, @ColorInt color2: Int): Double {
|
||||
var diff = Math.abs(0.299 * (Color.red(color1) - Color.red(color2)))
|
||||
diff += Math.abs(0.587 * (Color.green(color1) - Color.green(color2)))
|
||||
diff += Math.abs(0.114 * (Color.blue(color1) - Color.blue(color2)))
|
||||
private fun getDifference(@ColorInt color1: Int, @ColorInt color2: Int): Double {
|
||||
var diff = abs(0.299 * (Color.red(color1) - Color.red(color2)))
|
||||
diff += abs(0.587 * (Color.green(color1) - Color.green(color2)))
|
||||
diff += abs(0.114 * (Color.blue(color1) - Color.blue(color2)))
|
||||
return diff
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.res.ColorStateList;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
@ -149,40 +148,14 @@ public final class TintHelper {
|
|||
useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
|
||||
color
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
radioButton.setButtonTintList(sl);
|
||||
} else {
|
||||
Drawable d = createTintedDrawable(
|
||||
ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl);
|
||||
radioButton.setButtonDrawable(d);
|
||||
}
|
||||
radioButton.setButtonTintList(sl);
|
||||
}
|
||||
|
||||
public static void setTint(@NonNull SeekBar seekBar, @ColorInt int color, boolean useDarker) {
|
||||
final ColorStateList s1 = getDisabledColorStateList(color, ContextCompat.getColor(seekBar.getContext(),
|
||||
useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
seekBar.setThumbTintList(s1);
|
||||
seekBar.setProgressTintList(s1);
|
||||
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
Drawable progressDrawable = createTintedDrawable(seekBar.getProgressDrawable(), s1);
|
||||
seekBar.setProgressDrawable(progressDrawable);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
Drawable thumbDrawable = createTintedDrawable(seekBar.getThumb(), s1);
|
||||
seekBar.setThumb(thumbDrawable);
|
||||
}
|
||||
} else {
|
||||
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
mode = PorterDuff.Mode.MULTIPLY;
|
||||
}
|
||||
if (seekBar.getIndeterminateDrawable() != null) {
|
||||
seekBar.getIndeterminateDrawable().setColorFilter(color, mode);
|
||||
}
|
||||
if (seekBar.getProgressDrawable() != null) {
|
||||
seekBar.getProgressDrawable().setColorFilter(color, mode);
|
||||
}
|
||||
}
|
||||
seekBar.setThumbTintList(s1);
|
||||
seekBar.setProgressTintList(s1);
|
||||
}
|
||||
|
||||
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color) {
|
||||
|
@ -191,23 +164,10 @@ public final class TintHelper {
|
|||
|
||||
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
|
||||
ColorStateList sl = ColorStateList.valueOf(color);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
progressBar.setProgressTintList(sl);
|
||||
progressBar.setSecondaryProgressTintList(sl);
|
||||
if (!skipIndeterminate) {
|
||||
progressBar.setIndeterminateTintList(sl);
|
||||
}
|
||||
} else {
|
||||
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
mode = PorterDuff.Mode.MULTIPLY;
|
||||
}
|
||||
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null) {
|
||||
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
|
||||
}
|
||||
if (progressBar.getProgressDrawable() != null) {
|
||||
progressBar.getProgressDrawable().setColorFilter(color, mode);
|
||||
}
|
||||
progressBar.setProgressTintList(sl);
|
||||
progressBar.setSecondaryProgressTintList(sl);
|
||||
if (!skipIndeterminate) {
|
||||
progressBar.setIndeterminateTintList(sl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,7 +185,7 @@ public final class TintHelper {
|
|||
});
|
||||
if (editText instanceof AppCompatEditText) {
|
||||
((AppCompatEditText) editText).setSupportBackgroundTintList(editTextColorStateList);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
} else {
|
||||
editText.setBackgroundTintList(editTextColorStateList);
|
||||
}
|
||||
setCursorTint(editText, color);
|
||||
|
@ -243,13 +203,7 @@ public final class TintHelper {
|
|||
useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
|
||||
color
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
box.setButtonTintList(sl);
|
||||
} else {
|
||||
Drawable drawable = createTintedDrawable(
|
||||
ContextCompat.getDrawable(box.getContext(), R.drawable.abc_btn_check_material), sl);
|
||||
box.setButtonDrawable(drawable);
|
||||
}
|
||||
box.setButtonTintList(sl);
|
||||
}
|
||||
|
||||
public static void setTint(@NonNull ImageView image, @ColorInt int color) {
|
||||
|
@ -257,9 +211,6 @@ public final class TintHelper {
|
|||
}
|
||||
|
||||
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
return;
|
||||
}
|
||||
if (switchView.getTrackDrawable() != null) {
|
||||
switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
|
||||
switchView.getTrackDrawable(), color, false, false, useDarker));
|
||||
|
@ -286,7 +237,6 @@ public final class TintHelper {
|
|||
setTintAuto(view, color, background, ATHUtil.INSTANCE.isWindowBackgroundDark(view.getContext()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void setTintAuto(final @NonNull View view, final @ColorInt int color,
|
||||
boolean background, final boolean isDark) {
|
||||
if (!background) {
|
||||
|
@ -312,8 +262,7 @@ public final class TintHelper {
|
|||
background = true;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
|
||||
!background && view.getBackground() instanceof RippleDrawable) {
|
||||
if (!background && view.getBackground() instanceof RippleDrawable) {
|
||||
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
|
||||
RippleDrawable rd = (RippleDrawable) view.getBackground();
|
||||
@SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(),
|
||||
|
@ -348,7 +297,6 @@ 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.INSTANCE.isColorLight(color);
|
||||
|
@ -363,8 +311,7 @@ public final class TintHelper {
|
|||
final ColorStateList sl;
|
||||
if (view instanceof Button) {
|
||||
sl = getDisabledColorStateList(color, disabled);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
|
||||
view.getBackground() instanceof RippleDrawable) {
|
||||
if (view.getBackground() instanceof RippleDrawable) {
|
||||
RippleDrawable rd = (RippleDrawable) view.getBackground();
|
||||
rd.setColor(ColorStateList.valueOf(rippleColor));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -17,6 +16,7 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -35,11 +35,13 @@ import androidx.appcompat.widget.AppCompatImageView;
|
|||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.appcompat.widget.ToolbarWidgetWrapper;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import code.name.monkey.appthemehelper.R;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import code.name.monkey.appthemehelper.R;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
|
||||
public final class ToolbarContentTintHelper {
|
||||
|
||||
public static class InternalToolbarContentTintUtil {
|
||||
|
@ -92,30 +94,27 @@ public final class ToolbarContentTintHelper {
|
|||
if (toolbar == null) {
|
||||
return;
|
||||
}
|
||||
toolbar.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
|
||||
f1.setAccessible(true);
|
||||
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
|
||||
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
|
||||
f2.setAccessible(true);
|
||||
toolbar.post(() -> {
|
||||
try {
|
||||
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
|
||||
f1.setAccessible(true);
|
||||
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
|
||||
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
|
||||
f2.setAccessible(true);
|
||||
|
||||
// Actually ActionMenuPresenter
|
||||
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
|
||||
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
|
||||
f3.setAccessible(true);
|
||||
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
|
||||
setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);
|
||||
// Actually ActionMenuPresenter
|
||||
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
|
||||
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
|
||||
f3.setAccessible(true);
|
||||
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
|
||||
setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);
|
||||
|
||||
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
|
||||
f4.setAccessible(true);
|
||||
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
|
||||
setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
|
||||
f4.setAccessible(true);
|
||||
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
|
||||
setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -172,28 +171,19 @@ public final class ToolbarContentTintHelper {
|
|||
CheckBox check = (CheckBox) checkboxField.get(iv);
|
||||
if (check != null) {
|
||||
TintHelper.setTint(check, color, isDark);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
check.setBackground(null);
|
||||
}
|
||||
check.setBackground(null);
|
||||
}
|
||||
|
||||
RadioButton radioButton = (RadioButton) radioButtonField.get(iv);
|
||||
if (radioButton != null) {
|
||||
TintHelper.setTint(radioButton, color, isDark);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
radioButton.setBackground(null);
|
||||
}
|
||||
radioButton.setBackground(null);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -202,7 +192,6 @@ public final class ToolbarContentTintHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu,
|
||||
final @ColorInt int color) {
|
||||
try {
|
||||
|
@ -338,13 +327,8 @@ public final class ToolbarContentTintHelper {
|
|||
|
||||
//Important to set the color filter in seperate thread, by adding it to the message queue
|
||||
//Won't work otherwise.
|
||||
innerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((ActionMenuItemView) innerView).getCompoundDrawables()[finalK]
|
||||
.setColorFilter(colorFilter);
|
||||
}
|
||||
});
|
||||
innerView.post(() -> ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK]
|
||||
.setColorFilter(colorFilter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +347,7 @@ public final class ToolbarContentTintHelper {
|
|||
|
||||
@Nullable
|
||||
public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) {
|
||||
if (ab == null || !(ab instanceof WindowDecorActionBar)) {
|
||||
if (!(ab instanceof WindowDecorActionBar)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -411,7 +395,6 @@ public final class ToolbarContentTintHelper {
|
|||
secondaryTextColor, menuWidgetColor);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void setToolbarContentColor(@NonNull Context context,
|
||||
Toolbar toolbar,
|
||||
@Nullable Menu menu,
|
||||
|
@ -577,7 +560,7 @@ public final class ToolbarContentTintHelper {
|
|||
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
final ArrayList<View> outViews = new ArrayList<View>();
|
||||
final ArrayList<View> outViews = new ArrayList<>();
|
||||
decorView.findViewsWithText(outViews, overflowDescription,
|
||||
View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
|
||||
if (outViews.isEmpty()) {
|
||||
|
@ -605,7 +588,7 @@ public final class ToolbarContentTintHelper {
|
|||
final View actionView = item.getActionView();
|
||||
final View expandActivitiesButton = actionView.findViewById(R.id.expand_activities_button);
|
||||
if (expandActivitiesButton != null) {
|
||||
final ImageView image = (ImageView) expandActivitiesButton.findViewById(R.id.image);
|
||||
final ImageView image = expandActivitiesButton.findViewById(R.id.image);
|
||||
if (image != null) {
|
||||
final Drawable drawable = image.getDrawable();
|
||||
final Drawable wrapped = DrawableCompat.wrap(drawable);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="m3_accent_color">@android:color/system_accent1_200</color>
|
||||
<color name="m3_selection_color">@android:color/system_accent1_800</color>
|
||||
<color name="m3_selection_color">@android:color/system_accent1_500</color>
|
||||
</resources>
|
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources></resources>
|
Loading…
Add table
Add a link
Reference in a new issue