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;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package code.name.monkey.retromusic.views
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
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)
|
||||
*/
|
||||
class ATESwitch : SwitchCompat {
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
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 && isVisible
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue