|
@@ -22,12 +22,14 @@
|
|
|
*/
|
|
|
package com.owncloud.android.utils.theme;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
import android.content.res.ColorStateList;
|
|
|
import android.graphics.Color;
|
|
|
|
|
|
import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
|
|
|
+import androidx.appcompat.app.AppCompatDelegate;
|
|
|
import androidx.appcompat.widget.AppCompatCheckBox;
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
@@ -54,17 +56,24 @@ public final class ThemeCheckableUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void tintSwitch(SwitchCompat switchView, int color) {
|
|
|
- int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));
|
|
|
-
|
|
|
- // setting the thumb color
|
|
|
- DrawableCompat.setTintList(switchView.getThumbDrawable(), new ColorStateList(
|
|
|
- new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
- new int[]{color, Color.WHITE}));
|
|
|
-
|
|
|
- // setting the track color
|
|
|
- DrawableCompat.setTintList(switchView.getTrackDrawable(), new ColorStateList(
|
|
|
+ public static void tintSwitch(SwitchCompat switchView) {
|
|
|
+ int trackColor = switchView.getContext().getResources().getColor(R.color.grey_200);
|
|
|
+ ColorStateList thumbColorStateList = null;
|
|
|
+ ColorStateList trackColorStateList = null;
|
|
|
+ int thumbColor = ThemeColorUtils.primaryAccentColor(switchView.getContext());
|
|
|
+ if (ThemeColorUtils.darkTheme(switchView.getContext()) &&
|
|
|
+ AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
|
|
|
+ thumbColor = Color.WHITE;
|
|
|
+ trackColor = Color.DKGRAY;
|
|
|
+ }
|
|
|
+ thumbColorStateList = new ColorStateList(
|
|
|
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
- new int[]{trackColor, MainApp.getAppContext().getResources().getColor(R.color.switch_track_color_unchecked)}));
|
|
|
+ new int[]{thumbColor, switchView.getContext().getResources().getColor(R.color.switch_thumb_color_unchecked)});
|
|
|
+ trackColorStateList = new ColorStateList(
|
|
|
+ new int[][]{new int[]{android.R.attr.state_checked},
|
|
|
+ new int[]{}},
|
|
|
+ new int[]{trackColor, trackColor});
|
|
|
+ DrawableCompat.setTintList(switchView.getThumbDrawable(), thumbColorStateList);
|
|
|
+ DrawableCompat.setTintList(switchView.getTrackDrawable(), trackColorStateList);
|
|
|
}
|
|
|
}
|