diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java
index b7b95d13..a2f2e30f 100644
--- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java
+++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java
@@ -533,6 +533,10 @@ public class ThemeManager {
return sTheme;
}
+ public static boolean isNightMode() {
+ return sTheme == Theme.GREY || sTheme == Theme.BLACK;
+ }
+
public static void showColourSwatchesDialog(final QKActivity context) {
final QKDialog dialog = new QKDialog();
diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java
index 67031f16..134629b0 100644
--- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java
+++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/QKSwitch.java
@@ -1,40 +1,91 @@
package com.moez.QKSMS.ui.view;
import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.SwitchCompat;
import android.util.AttributeSet;
+import com.moez.QKSMS.R;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.interfaces.LiveView;
+import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;
public class QKSwitch extends SwitchCompat implements LiveView {
+ private Resources mRes;
+
public QKSwitch(Context context) {
super(context);
- init();
+ init(context);
}
public QKSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
- init();
+ init(context);
}
- private void init() {
+ private void init(Context context) {
+ mRes = context.getResources();
+
// Register this view for live updates.
LiveViewManager.registerView(this);
LiveViewManager.registerPreference(this, SettingsFragment.THEME);
+ LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND);
refresh();
}
@Override
public void refresh() {
- //getThumbDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
- //getTrackDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
+ DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList());
+ DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList());
}
- @Override
- public void setChecked(boolean checked) {
- super.setChecked(checked);
+ private ColorStateList getSwitchThumbColorStateList() {
+ final int[][] states = new int[3][];
+ final int[] colors = new int[3];
+
+ // Disabled state
+ states[0] = new int[]{-android.R.attr.state_enabled};
+ colors[0] = mRes.getColor(ThemeManager.isNightMode() ?
+ R.color.switch_thumb_disabled_dark : R.color.switch_thumb_disabled_light);
+
+ // Checked state
+ states[1] = new int[]{android.R.attr.state_checked};
+ colors[1] = ThemeManager.getColor();
+
+ // Unchecked enabled state state
+ states[2] = new int[0];
+ colors[2] = mRes.getColor(ThemeManager.isNightMode() ?
+ R.color.switch_thumb_enabled_dark : R.color.switch_thumb_enabled_light);
+
+ return new ColorStateList(states, colors);
+ }
+
+ private ColorStateList getSwitchTrackColorStateList() {
+ final int[][] states = new int[3][];
+ final int[] colors = new int[3];
+
+ // Disabled state
+ states[0] = new int[]{-android.R.attr.state_enabled};
+ colors[0] = mRes.getColor(ThemeManager.isNightMode() ?
+ R.color.switch_track_disabled_dark : R.color.switch_track_disabled_light);
+
+ // Checked state
+ states[1] = new int[]{android.R.attr.state_checked};
+ colors[1] = Color.argb(0x4D, // 30% alpha
+ Color.red(ThemeManager.getColor()),
+ Color.green(ThemeManager.getColor()),
+ Color.blue(ThemeManager.getColor()));
+
+ // Unchecked enabled state state
+ states[2] = new int[0];
+ colors[2] = mRes.getColor(ThemeManager.isNightMode() ?
+ R.color.switch_track_enabled_dark : R.color.switch_track_enabled_light);
+
+ return new ColorStateList(states, colors);
}
}
\ No newline at end of file
diff --git a/QKSMS/src/main/res/values/colours.xml b/QKSMS/src/main/res/values/colours.xml
index e47f95d6..2b905431 100644
--- a/QKSMS/src/main/res/values/colours.xml
+++ b/QKSMS/src/main/res/values/colours.xml
@@ -26,4 +26,14 @@
#8A000000
#FFFFFFFF
#B3FFFFFF
+
+
+ #ECECEC
+ #A6A6A6
+ #B9B9B9
+ #D6D6D6
+ #B9B9B9
+ #646464
+ #595959
+ #383838
\ No newline at end of file