mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Navigation tinting support
This commit is contained in:
@@ -4,6 +4,7 @@ import android.animation.Animator;
|
|||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -87,7 +88,8 @@ public class ThemeManager {
|
|||||||
private static Resources sResources;
|
private static Resources sResources;
|
||||||
private static SharedPreferences sPrefs;
|
private static SharedPreferences sPrefs;
|
||||||
|
|
||||||
private static boolean status_tint = false;
|
private static boolean sStatusTintEnabled = false;
|
||||||
|
private static boolean sNavigationTintEnabled = false;
|
||||||
|
|
||||||
private static QKActivity mActivity;
|
private static QKActivity mActivity;
|
||||||
private static Context mContext;
|
private static Context mContext;
|
||||||
@@ -262,10 +264,16 @@ public class ThemeManager {
|
|||||||
|
|
||||||
initializeTheme(Theme.fromString(sPrefs.getString(SettingsFragment.BACKGROUND, "offwhite")));
|
initializeTheme(Theme.fromString(sPrefs.getString(SettingsFragment.BACKGROUND, "offwhite")));
|
||||||
|
|
||||||
status_tint = sPrefs.getBoolean(SettingsFragment.STATUS_TINT, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
sStatusTintEnabled = sPrefs.getBoolean(SettingsFragment.STATUS_TINT, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
sNavigationTintEnabled = sPrefs.getBoolean(SettingsFragment.NAVIGATION_TINT, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
|
||||||
if (mActivity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (mActivity != null && sStatusTintEnabled) {
|
||||||
mWindow.setStatusBarColor(status_tint ? sColor : sResources.getColor(R.color.black));
|
if (sStatusTintEnabled) {
|
||||||
|
mWindow.setStatusBarColor(sColor);
|
||||||
|
}
|
||||||
|
if (sNavigationTintEnabled) {
|
||||||
|
mWindow.setNavigationBarColor(sColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -557,18 +565,33 @@ public class ThemeManager {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
public static void setStatusBarTintEnabled(boolean enabled) {
|
public static void setStatusBarTintEnabled(boolean enabled) {
|
||||||
if (status_tint != enabled) {
|
if (sStatusTintEnabled != enabled) {
|
||||||
status_tint = enabled;
|
sStatusTintEnabled = enabled;
|
||||||
int colorFrom = enabled ? sResources.getColor(R.color.black) : sColor;
|
int colorFrom = enabled ? sResources.getColor(R.color.black) : sColor;
|
||||||
int colorTo = enabled ? sColor : sResources.getColor(R.color.black);
|
int colorTo = enabled ? sColor : sResources.getColor(R.color.black);
|
||||||
|
|
||||||
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
|
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
|
||||||
colorAnimation.setDuration(TRANSITION_LENGTH);
|
colorAnimation.setDuration(TRANSITION_LENGTH);
|
||||||
colorAnimation.addUpdateListener(animation -> {
|
colorAnimation.addUpdateListener(animation -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
mWindow.setStatusBarColor((Integer) animation.getAnimatedValue());
|
||||||
mWindow.setStatusBarColor((Integer) animation.getAnimatedValue());
|
});
|
||||||
}
|
colorAnimation.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
public static void setNavigationBarTintEnabled(boolean enabled) {
|
||||||
|
if (sNavigationTintEnabled != enabled) {
|
||||||
|
sNavigationTintEnabled = enabled;
|
||||||
|
int colorFrom = enabled ? sResources.getColor(R.color.black) : sColor;
|
||||||
|
int colorTo = enabled ? sColor : sResources.getColor(R.color.black);
|
||||||
|
|
||||||
|
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
|
||||||
|
colorAnimation.setDuration(TRANSITION_LENGTH);
|
||||||
|
colorAnimation.addUpdateListener(animation -> {
|
||||||
|
mWindow.setNavigationBarColor((Integer) animation.getAnimatedValue());
|
||||||
});
|
});
|
||||||
colorAnimation.start();
|
colorAnimation.start();
|
||||||
}
|
}
|
||||||
@@ -619,9 +642,12 @@ public class ThemeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status_tint && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (sStatusTintEnabled) {
|
||||||
mWindow.setStatusBarColor(color1);
|
mWindow.setStatusBarColor(color1);
|
||||||
}
|
}
|
||||||
|
if (sNavigationTintEnabled) {
|
||||||
|
mWindow.setNavigationBarColor(color1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
colorAnimation.addListener(new AnimatorListenerAdapter() {
|
colorAnimation.addListener(new AnimatorListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import android.content.res.Resources;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -77,11 +76,12 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
public static final String CATEGORY_ABOUT = "pref_key_category_about";
|
public static final String CATEGORY_ABOUT = "pref_key_category_about";
|
||||||
|
|
||||||
// Sub-categories
|
// Sub-categories
|
||||||
public static final String CATEGORY_APPEARANCE_STATUS_BARS = "pref_key_category_appearance_status_bars";
|
public static final String CATEGORY_APPEARANCE_SYSTEM_BARS = "pref_key_category_appearance_system_bars";
|
||||||
|
|
||||||
public static final String THEME = "pref_key_theme";
|
public static final String THEME = "pref_key_theme";
|
||||||
public static final String ICON = "pref_key_icon";
|
public static final String ICON = "pref_key_icon";
|
||||||
public static final String STATUS_TINT = "pref_key_status_tint";
|
public static final String STATUS_TINT = "pref_key_status_tint";
|
||||||
|
public static final String NAVIGATION_TINT = "pref_key_navigation_tint";
|
||||||
public static final String BACKGROUND = "pref_key_background";
|
public static final String BACKGROUND = "pref_key_background";
|
||||||
public static final String BUBBLES = "pref_key_bubbles";
|
public static final String BUBBLES = "pref_key_bubbles";
|
||||||
public static final String BUBBLES_NEW = "pref_key_new_bubbles";
|
public static final String BUBBLES_NEW = "pref_key_new_bubbles";
|
||||||
@@ -239,11 +239,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
icon.setOnPreferenceClickListener(this);
|
icon.setOnPreferenceClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckBoxPreference status_tint = (CheckBoxPreference) findPreference(STATUS_TINT);
|
|
||||||
if (status_tint != null) {
|
|
||||||
status_tint.setOnPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
mThemeLed = findPreference(NOTIFICATION_LED_COLOR);
|
mThemeLed = findPreference(NOTIFICATION_LED_COLOR);
|
||||||
if (mThemeLed != null) {
|
if (mThemeLed != null) {
|
||||||
|
|
||||||
@@ -332,7 +327,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
|
|
||||||
// Status and nav bar tinting are only supported on kit kat or above.
|
// Status and nav bar tinting are only supported on kit kat or above.
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
removePreference(CATEGORY_APPEARANCE_STATUS_BARS);
|
removePreference(CATEGORY_APPEARANCE_SYSTEM_BARS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +398,9 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
case STATUS_TINT:
|
case STATUS_TINT:
|
||||||
ThemeManager.setStatusBarTintEnabled((Boolean) newValue);
|
ThemeManager.setStatusBarTintEnabled((Boolean) newValue);
|
||||||
break;
|
break;
|
||||||
|
case NAVIGATION_TINT:
|
||||||
|
ThemeManager.setNavigationBarTintEnabled((Boolean) newValue);
|
||||||
|
break;
|
||||||
case FONT_FAMILY:
|
case FONT_FAMILY:
|
||||||
preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]);
|
preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_key_category_appearance_status_bars"
|
android:key="pref_key_category_appearance_system_bars"
|
||||||
android:layout="@layout/list_item_preference_category"
|
android:layout="@layout/list_item_preference_category"
|
||||||
android:title="@string/pref_subcat_system_bars">
|
android:title="@string/pref_subcat_system_bars">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
@@ -65,6 +65,12 @@
|
|||||||
android:layout="@layout/list_item_preference"
|
android:layout="@layout/list_item_preference"
|
||||||
android:title="@string/pref_status_tint"
|
android:title="@string/pref_status_tint"
|
||||||
android:widgetLayout="@layout/view_checkbox" />
|
android:widgetLayout="@layout/view_checkbox" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="pref_key_navigation_tint"
|
||||||
|
android:layout="@layout/list_item_preference"
|
||||||
|
android:title="@string/pref_navigation_tint"
|
||||||
|
android:widgetLayout="@layout/view_checkbox" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|||||||
Reference in New Issue
Block a user