Cherish: Smart Pixels [2/2]
Change-Id: I55775e02e849ad5db5b1187be0ca77b7c09f1081 Signed-off-by: Shubham Singh <coolsks94@gmail.com> Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -1201,4 +1201,49 @@
|
||||
<item>16</item>
|
||||
<item>17</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Smart Pixels -->
|
||||
<string-array name="smart_pixels_percent_strings" translatable="false">
|
||||
<item>12</item>
|
||||
<item>25</item>
|
||||
<item>38</item>
|
||||
<item>50</item>
|
||||
<item>62</item>
|
||||
<item>75</item>
|
||||
<item>88</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="smart_pixels_percent_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="smart_pixels_shift_times">
|
||||
<item>15 seconds</item>
|
||||
<item>30 seconds</item>
|
||||
<item>1 minute</item>
|
||||
<item>2 minutes</item>
|
||||
<item>5 minutes</item>
|
||||
<item>10 minutes</item>
|
||||
<item>20 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
<item>1 hour</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="smart_pixels_shift_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -1079,4 +1079,12 @@
|
||||
<string name="incall_vibrate_connect_title">Vibrate on connect</string>
|
||||
<string name="incall_vibrate_call_wait_title">Vibrate on call waiting</string>
|
||||
<string name="incall_vibrate_disconnect_title">Vibrate on disconnect</string>
|
||||
|
||||
<!-- Smart Pixels -->
|
||||
<string name="smart_pixels_title">Smart Pixels</string>
|
||||
<string name="smart_pixels_summary">Save battery by shutting off extra pixels</string>
|
||||
<string name="smart_pixels_on_power_save_title">Auto-enable on battery saver</string>
|
||||
<string name="smart_pixels_on_power_save_summary">Enable with battery saver to increase power savings</string>
|
||||
<string name="smart_pixels_percent">Percent of pixels to disable</string>
|
||||
<string name="smart_pixels_shift">Burn-in protection interval</string>
|
||||
</resources>
|
||||
|
||||
@@ -77,6 +77,12 @@
|
||||
android:summary="@string/volume_steps_summary"
|
||||
android:icon="@drawable/ic_volume"
|
||||
android:fragment="com.cherish.settings.fragments.VolumeStepsFragment" />
|
||||
|
||||
<Preference
|
||||
android:key="smart_pixels"
|
||||
android:fragment="com.cherish.settings.fragments.SmartPixels"
|
||||
android:title="@string/smart_pixels_title"
|
||||
android:summary="@string/smart_pixels_summary" />
|
||||
|
||||
<!-- Rounded Corners -->
|
||||
<PreferenceCategory
|
||||
|
||||
50
res/xml/cherish_settings_smart_pixels.xml
Normal file
50
res/xml/cherish_settings_smart_pixels.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 CarbonROM
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/smart_pixels_title" >
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="smart_pixels_enable"
|
||||
android:title="@string/smart_pixels_title"
|
||||
android:summary="@string/smart_pixels_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="smart_pixels_on_power_save"
|
||||
android:title="@string/smart_pixels_on_power_save_title"
|
||||
android:summary="@string/smart_pixels_on_power_save_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="smart_pixels_pattern"
|
||||
android:entries="@array/smart_pixels_percent_strings"
|
||||
android:entryValues="@array/smart_pixels_percent_values"
|
||||
android:defaultValue="3"
|
||||
android:title="@string/smart_pixels_percent"
|
||||
android:dialogTitle="@string/smart_pixels_percent" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="smart_pixels_shift_timeout"
|
||||
android:entries="@array/smart_pixels_shift_times"
|
||||
android:entryValues="@array/smart_pixels_shift_values"
|
||||
android:defaultValue="5"
|
||||
android:title="@string/smart_pixels_shift"
|
||||
android:dialogTitle="@string/smart_pixels_shift" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -34,15 +34,29 @@ import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
public class MiscSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
private static final String SMART_PIXELS = "smart_pixels";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_misc);
|
||||
updateSmartPixelsPreference();
|
||||
|
||||
}
|
||||
|
||||
private void updateSmartPixelsPreference() {
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
boolean enableSmartPixels = getContext().getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_enableSmartPixels);
|
||||
Preference smartPixels = findPreference(SMART_PIXELS);
|
||||
|
||||
if (!enableSmartPixels){
|
||||
prefSet.removePreference(smartPixels);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
return false;
|
||||
|
||||
127
src/com/cherish/settings/preferences/fragments/SmartPixels.java
Normal file
127
src/com/cherish/settings/preferences/fragments/SmartPixels.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2018 CarbonROM
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class SmartPixels extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "SmartPixels";
|
||||
|
||||
private static final String ON_POWER_SAVE = "smart_pixels_on_power_save";
|
||||
|
||||
private SystemSettingSwitchPreference mSmartPixelsOnPowerSave;
|
||||
|
||||
ContentResolver resolver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_smart_pixels);
|
||||
|
||||
resolver = getActivity().getContentResolver();
|
||||
|
||||
mSmartPixelsOnPowerSave = (SystemSettingSwitchPreference) findPreference(ON_POWER_SAVE);
|
||||
|
||||
updateDependency();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
final String key = preference.getKey();
|
||||
updateDependency();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateDependency() {
|
||||
boolean mUseOnPowerSave = (Settings.System.getIntForUser(
|
||||
resolver, Settings.System.SMART_PIXELS_ON_POWER_SAVE,
|
||||
0, UserHandle.USER_CURRENT) == 1);
|
||||
PowerManager pm = (PowerManager)getActivity().getSystemService(Context.POWER_SERVICE);
|
||||
if (pm.isPowerSaveMode() && mUseOnPowerSave) {
|
||||
mSmartPixelsOnPowerSave.setEnabled(false);
|
||||
} else {
|
||||
mSmartPixelsOnPowerSave.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
if (context.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_enableSmartPixels)) {
|
||||
sir.xmlResId = R.xml.cherish_settings_smart_pixels;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user