Revert "add CompoundButton hook"

This reverts commit 04488314b5.
This commit is contained in:
gdlbo
2022-12-12 22:16:08 +03:00
parent 012dfa7063
commit 1010821cf4
11 changed files with 1323 additions and 262 deletions
@@ -2,10 +2,18 @@ package ru.vtosters.lite.themes;
import android.view.View;
import android.view.ViewGroup;
import ru.vtosters.lite.themes.hooks.*;
import java.util.ArrayList;
import ru.vtosters.lite.themes.hooks.BaseHook;
import ru.vtosters.lite.themes.hooks.ButtonHook;
import ru.vtosters.lite.themes.hooks.ImageViewHook;
import ru.vtosters.lite.themes.hooks.ProgressWheelHook;
import ru.vtosters.lite.themes.hooks.TabLayoutHook;
import ru.vtosters.lite.themes.hooks.TextViewHook;
import ru.vtosters.lite.themes.hooks.ToolbarHook;
import ru.vtosters.lite.themes.hooks.VKImageViewHook;
public class ViewInjector {
public static ArrayList<BaseHook> hooks = new ArrayList<>();
@@ -17,7 +25,6 @@ public class ViewInjector {
hooks.add(new ToolbarHook());
hooks.add(new VKImageViewHook());
hooks.add(new ProgressWheelHook());
hooks.add(new CompoundButtonHook());
}
public static View inject(View view, int i, boolean z) {
@@ -1,77 +0,0 @@
package ru.vtosters.lite.themes.hooks;
import android.content.res.ColorStateList;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.Switch;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.CompoundButtonCompat;
import com.vk.core.ui.themes.VKThemeHelper;
import com.vk.core.util.ColorUtils;
import com.vtosters.lite.R;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.ThemesUtils;
public class CompoundButtonHook implements BaseHook {
private static final int[][] STATES = new int[][]{
{ android.R.attr.state_enabled, -android.R.attr.state_checked },
{ -android.R.attr.state_enabled, android.R.attr.state_checked },
{ -android.R.attr.state_checked },
{ android.R.attr.state_checked }
};
@Override
public void inject(View view, int i, boolean z) {
if (view instanceof CheckBox || view instanceof RadioButton)
recolorCompoundButton((CompoundButton) view);
else if (view instanceof Switch)
recolorSwitch((Switch) view);
else if (view instanceof SwitchCompat)
recolorSwitchCompat((SwitchCompat) view);
}
private void recolorCompoundButton(CompoundButton cb) {
var colors = new int[] {
ColorUtils.b(VKThemeHelper.d(R.attr.selection_off_icon), 0.4F),
ColorUtils.b(ThemesUtils.getAccentColor(), 0.4F),
VKThemeHelper.d(R.attr.selection_off_icon),
ThemesUtils.getAccentColor()
};
CompoundButtonCompat.setButtonTintList(cb,
new ColorStateList(STATES, colors));
}
private int[] getThumbColors() {
return new int[] {
AndroidUtils.getResources().getColor(
ThemesUtils.getCurrentTheme().a() ? R.color.steel_gray_150: R.color.white),
AndroidUtils.getResources().getColor(
ThemesUtils.getCurrentTheme().a() ? R.color.switch_disabled_on_dark : R.color.switch_disabled_on_light),
AndroidUtils.getResources().getColor(R.color.gray_20),
VKThemeHelper.d(R.attr.accent)
};
}
private int[] getTrackColors() {
return new int[] {
ColorUtils.b(VKThemeHelper.d(R.attr.loader_track_fill), 0.4F),
ColorUtils.b(ThemesUtils.getAccentColor(), 0.12F),
VKThemeHelper.d(R.attr.loader_track_fill),
ColorUtils.b(ThemesUtils.getAccentColor(), 0.48F)
};
}
private void recolorSwitch(Switch s) {
DrawableCompat.setTintList(DrawableCompat.wrap(s.getThumbDrawable()), new ColorStateList(STATES, getThumbColors()));
DrawableCompat.setTintList(DrawableCompat.wrap(s.getTrackDrawable()), new ColorStateList(STATES, getTrackColors()));
}
private void recolorSwitchCompat(SwitchCompat s) {
DrawableCompat.setTintList(DrawableCompat.wrap(s.getThumbDrawable()), new ColorStateList(STATES, getThumbColors()));
DrawableCompat.setTintList(DrawableCompat.wrap(s.getTrackDrawable()), new ColorStateList(STATES, getTrackColors()));
}
}