Cherish:Introduce RGB Gradient Picker [2/2]

This commit is contained in:
SuperDroidBond
2020-01-08 15:44:53 +07:00
committed by Hung Phan
parent 22b278cc53
commit b6057bf285
4 changed files with 39 additions and 1 deletions

View File

@@ -242,4 +242,6 @@
<string name="themes_hub_summary">Chủ đề màu nhấn Gradients</string> <string name="themes_hub_summary">Chủ đề màu nhấn Gradients</string>
<string name="accent_color">Chọn màu nhấn</string> <string name="accent_color">Chọn màu nhấn</string>
<string name="accent_summary">Tự làm Gradient</string> <string name="accent_summary">Tự làm Gradient</string>
<string name="gradient_color">Chọn Gradient</string>
<string name="gradient_summary">Làm hiệu ứng Gradient</string>
</resources> </resources>

View File

@@ -277,5 +277,7 @@
<string name="themes_hub_summary">Accents-Gradients-Themes</string> <string name="themes_hub_summary">Accents-Gradients-Themes</string>
<string name="accent_color">Accent picker</string> <string name="accent_color">Accent picker</string>
<string name="accent_summary">Gradient Maker</string> <string name="accent_summary">Gradient Maker</string>
<string name="gradient_color">Gradient picker</string>
<string name="gradient_summary">Gradient effect maker</string>
</resources> </resources>

View File

@@ -47,5 +47,13 @@
android:defaultValue="0xffffff" android:defaultValue="0xffffff"
android:persistent="false" /> android:persistent="false" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="gradient_color"
android:icon="@drawable/ic_accent_picker"
android:title="@string/gradient_color"
android:summary="@string/gradient_summary"
android:defaultValue="0xffffff"
android:persistent="false" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -4,12 +4,15 @@ import com.android.internal.logging.nano.MetricsProto;
import static android.os.UserHandle.USER_SYSTEM; import static android.os.UserHandle.USER_SYSTEM;
import android.app.UiModeManager; import android.app.UiModeManager;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.SystemProperties;
import android.os.ServiceManager;
import android.content.om.IOverlayManager; import android.content.om.IOverlayManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.content.ContentResolver; import android.content.ContentResolver;
@@ -42,9 +45,11 @@ public class ThemeSettings extends SettingsPreferenceFragment implements
private static final String PREF_THEME_SWITCH = "theme_switch"; private static final String PREF_THEME_SWITCH = "theme_switch";
private static final String ACCENT_COLOR = "accent_color"; private static final String ACCENT_COLOR = "accent_color";
private static final String ACCENT_COLOR_PROP = "persist.sys.theme.accentcolor"; private static final String ACCENT_COLOR_PROP = "persist.sys.theme.accentcolor";
private static final String GRADIENT_COLOR = "gradient_color";
private static final String GRADIENT_COLOR_PROP = "persist.sys.theme.gradientcolor";
private ColorPickerPreference mThemeColor; private ColorPickerPreference mThemeColor;
private ColorPickerPreference mGradientColor;
private UiModeManager mUiModeManager; private UiModeManager mUiModeManager;
private IOverlayManager mOverlayService; private IOverlayManager mOverlayService;
private ListPreference mThemeSwitch; private ListPreference mThemeSwitch;
@@ -62,6 +67,7 @@ public class ThemeSettings extends SettingsPreferenceFragment implements
mUiModeManager = getContext().getSystemService(UiModeManager.class); mUiModeManager = getContext().getSystemService(UiModeManager.class);
setupThemeSwitchPref(); setupThemeSwitchPref();
setupAccentPref(); setupAccentPref();
setupGradientPref();
} }
@Override @Override
@@ -123,6 +129,16 @@ public class ThemeSettings extends SettingsPreferenceFragment implements
mOverlayService.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT); mOverlayService.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT);
} catch (RemoteException ignored) { } catch (RemoteException ignored) {
} }
} else if (preference == mGradientColor) {
int color = (Integer) objValue;
String hexColor = String.format("%08X", (0xFFFFFFFF & color));
SystemProperties.set(GRADIENT_COLOR_PROP, hexColor);
try {
mOverlayService.reloadAndroidAssets(UserHandle.USER_CURRENT);
mOverlayService.reloadAssets("com.android.settings", UserHandle.USER_CURRENT);
mOverlayService.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT);
} catch (RemoteException ignored) {
}
} }
return true; return true;
} }
@@ -170,6 +186,16 @@ public class ThemeSettings extends SettingsPreferenceFragment implements
mThemeColor.setOnPreferenceChangeListener(this); mThemeColor.setOnPreferenceChangeListener(this);
} }
private void setupGradientPref() {
mGradientColor = (ColorPickerPreference) findPreference(GRADIENT_COLOR);
String colorVal = SystemProperties.get(GRADIENT_COLOR_PROP, "-1");
int color = "-1".equals(colorVal)
? Color.WHITE
: Color.parseColor("#" + colorVal);
mGradientColor.setNewPreviewColor(color);
mGradientColor.setOnPreferenceChangeListener(this);
}
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS; return MetricsProto.MetricsEvent.CHERISH_SETTINGS;