MD3 Accent color for Switch
This commit is contained in:
parent
531623b9b2
commit
b2a1cb1e2e
6 changed files with 34 additions and 10 deletions
|
@ -22,14 +22,20 @@ import android.graphics.Color;
|
|||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.palette.graphics.Palette;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil;
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils;
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
public class RetroColorUtil {
|
||||
public static int desaturateColor(int color, float ratio) {
|
||||
|
@ -216,6 +222,14 @@ public class RetroColorUtil {
|
|||
return color;
|
||||
}
|
||||
|
||||
public static int getMD3AccentColor(@NotNull Context context) {
|
||||
if (VersionUtils.hasS()) {
|
||||
return ContextCompat.getColor(context, R.color.m3_accent_color);
|
||||
} else {
|
||||
return ThemeStore.Companion.accentColor(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SwatchComparator implements Comparator<Palette.Swatch> {
|
||||
|
||||
private static SwatchComparator sInstance;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package code.name.monkey.appthemehelper.common.views
|
||||
package code.name.monkey.retromusic.views
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.view.isVisible
|
||||
import code.name.monkey.appthemehelper.ATH
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad)
|
||||
|
@ -20,15 +22,23 @@ class ATESwitch : SwitchCompat {
|
|||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
private fun init(context: Context) {
|
||||
if (PreferenceUtil.materialYou) {
|
||||
ATH.setTint(this, RetroColorUtil.getMD3AccentColor(context))
|
||||
} else {
|
||||
ATH.setTint(this, ThemeStore.accentColor(context))
|
||||
}
|
||||
}
|
||||
|
||||
override fun isShown(): Boolean {
|
||||
return parent != null && visibility == View.VISIBLE
|
||||
return parent != null && isVisible
|
||||
}
|
||||
}
|
|
@ -72,7 +72,7 @@
|
|||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" />
|
||||
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch
|
||||
<code.name.monkey.retromusic.views.ATESwitch
|
||||
android:id="@android:id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" />
|
||||
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch
|
||||
<code.name.monkey.retromusic.views.ATESwitch
|
||||
android:id="@android:id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package code.name.monkey.appthemehelper.util
|
||||
|
||||
import android.os.Build
|
||||
import androidx.annotation.ChecksSdkIntAtLeast
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
|
@ -59,6 +58,7 @@ object VersionUtils {
|
|||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun hasS(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<code.name.monkey.retromusic.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"
|
||||
|
|
Loading…
Reference in a new issue