mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Tinting support for QKSwitch
This commit is contained in:
@@ -533,6 +533,10 @@ public class ThemeManager {
|
|||||||
return sTheme;
|
return sTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNightMode() {
|
||||||
|
return sTheme == Theme.GREY || sTheme == Theme.BLACK;
|
||||||
|
}
|
||||||
|
|
||||||
public static void showColourSwatchesDialog(final QKActivity context) {
|
public static void showColourSwatchesDialog(final QKActivity context) {
|
||||||
final QKDialog dialog = new QKDialog();
|
final QKDialog dialog = new QKDialog();
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,91 @@
|
|||||||
package com.moez.QKSMS.ui.view;
|
package com.moez.QKSMS.ui.view;
|
||||||
|
|
||||||
import android.content.Context;
|
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.support.v7.widget.SwitchCompat;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import com.moez.QKSMS.R;
|
||||||
import com.moez.QKSMS.common.LiveViewManager;
|
import com.moez.QKSMS.common.LiveViewManager;
|
||||||
import com.moez.QKSMS.interfaces.LiveView;
|
import com.moez.QKSMS.interfaces.LiveView;
|
||||||
|
import com.moez.QKSMS.ui.ThemeManager;
|
||||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||||
|
|
||||||
public class QKSwitch extends SwitchCompat implements LiveView {
|
public class QKSwitch extends SwitchCompat implements LiveView {
|
||||||
|
|
||||||
|
private Resources mRes;
|
||||||
|
|
||||||
public QKSwitch(Context context) {
|
public QKSwitch(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public QKSwitch(Context context, AttributeSet attrs) {
|
public QKSwitch(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init();
|
init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init(Context context) {
|
||||||
|
mRes = context.getResources();
|
||||||
|
|
||||||
// Register this view for live updates.
|
// Register this view for live updates.
|
||||||
LiveViewManager.registerView(this);
|
LiveViewManager.registerView(this);
|
||||||
LiveViewManager.registerPreference(this, SettingsFragment.THEME);
|
LiveViewManager.registerPreference(this, SettingsFragment.THEME);
|
||||||
|
LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
//getThumbDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
|
DrawableCompat.setTintList(getThumbDrawable(), getSwitchThumbColorStateList());
|
||||||
//getTrackDrawable().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
|
DrawableCompat.setTintList(getTrackDrawable(), getSwitchTrackColorStateList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private ColorStateList getSwitchThumbColorStateList() {
|
||||||
public void setChecked(boolean checked) {
|
final int[][] states = new int[3][];
|
||||||
super.setChecked(checked);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,4 +26,14 @@
|
|||||||
<color name="theme_light_text_secondary">#8A000000</color>
|
<color name="theme_light_text_secondary">#8A000000</color>
|
||||||
<color name="theme_dark_text_primary">#FFFFFFFF</color>
|
<color name="theme_dark_text_primary">#FFFFFFFF</color>
|
||||||
<color name="theme_dark_text_secondary">#B3FFFFFF</color>
|
<color name="theme_dark_text_secondary">#B3FFFFFF</color>
|
||||||
|
|
||||||
|
<!-- Color states for `SwitchCompat` views -->
|
||||||
|
<color name="switch_thumb_enabled_light">#ECECEC</color>
|
||||||
|
<color name="switch_track_enabled_light">#A6A6A6</color>
|
||||||
|
<color name="switch_thumb_disabled_light">#B9B9B9</color>
|
||||||
|
<color name="switch_track_disabled_light">#D6D6D6</color>
|
||||||
|
<color name="switch_thumb_enabled_dark">#B9B9B9</color>
|
||||||
|
<color name="switch_track_enabled_dark">#646464</color>
|
||||||
|
<color name="switch_thumb_disabled_dark">#595959</color>
|
||||||
|
<color name="switch_track_disabled_dark">#383838</color>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user