Cherish:Battery Saver Profiles [2/2]

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Maitreya29
2021-08-01 17:11:55 +05:30
committed by Hưng Phan
parent 28d592a2a1
commit 12d27fdc9d
6 changed files with 146 additions and 0 deletions

View File

@@ -1356,4 +1356,21 @@
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>
</string-array> </string-array>
<!-- Power Profiles -->
<string-array name="power_profile_type_entries">
<item>@string/power_profile_light</item>
<item>@string/power_profile_default</item>
<item>@string/power_profile_med</item>
<item>@string/power_profile_high</item>
<item>@string/power_profile_ext</item>
</string-array>
<string-array name="power_profile_type_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
</resources> </resources>

View File

@@ -32,4 +32,6 @@
<!-- FOD icon picker --> <!-- FOD icon picker -->
<color name="fod_item_background_stroke_color">#d6d6d6</color> <color name="fod_item_background_stroke_color">#d6d6d6</color>
<color name="preview_container_border">@*android:color/accent_device_default_light</color> <color name="preview_container_border">@*android:color/accent_device_default_light</color>
<color name="white">#FFF</color>
</resources> </resources>

View File

@@ -1327,4 +1327,14 @@
<string name="hide_apps_from_recents_summary">Hide apps from appearing in recents</string> <string name="hide_apps_from_recents_summary">Hide apps from appearing in recents</string>
<string name="hide_from_recents_add_app">Add app</string> <string name="hide_from_recents_add_app">Add app</string>
<string name="title_activity_spark_recents_settings">Recents</string> <string name="title_activity_spark_recents_settings">Recents</string>
<!-- Power Profiles -->
<string name="powersave_title">Power Saving</string>
<string name="power_profile">Battery saver profile</string>
<string name="power_profile_default">Default</string>
<string name="power_profile_light">Light</string>
<string name="power_profile_med">Moderate</string>
<string name="power_profile_high">High</string>
<string name="power_profile_ext">Extreme</string>
<string name="powersave_summary">Options to extend your battery life</string>
</resources> </resources>

View File

@@ -129,6 +129,13 @@
<intent android:action="android.intent.action.MAIN" <intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings" android:targetPackage="com.android.settings"
android:targetClass="com.cherish.settings.fragments.HAFRAppListActivity" /> android:targetClass="com.cherish.settings.fragments.HAFRAppListActivity" />
<Preference
android:key="ps_cat"
android:title="@string/powersave_title"
android:summary="@string/powersave_summary"
android:fragment="com.cherish.settings.fragments.PowerSaving"/>
</PreferenceScreen> </PreferenceScreen>
<PreferenceCategory <PreferenceCategory

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 NezukoOS
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"
android:title=" "
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="power_profile_type"
android:title="@string/power_profile"
android:dialogTitle="@string/power_profile"
android:entries="@array/power_profile_type_entries"
android:defaultValue="1"
android:entryValues="@array/power_profile_type_values"/>
</PreferenceScreen>

View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2021 NezukoOS
*
* Licensed under the Apache License, Version 2.0 (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 java.util.ArrayList;
import android.content.DialogInterface;
import android.app.AlertDialog;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.Context;
import android.content.ContentResolver;
import android.os.UserHandle;
import com.cherish.settings.preferences.SystemSettingListPreference;
import androidx.preference.*;
import android.provider.Settings;
import android.widget.Toast;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.MetricsLogger;
import androidx.preference.Preference.OnPreferenceChangeListener;
import android.os.Bundle;
public class PowerSaving extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
private static final String POWER_PROFILE = "power_profile_type";
private SystemSettingListPreference mPowerProfile;
public static final String[] POWER_MODE_PROFILES = {
"advertise_is_enabled=false,datasaver_disabled=true,enable_night_mode=false,launch_boost_disabled=false,vibration_disabled=false,animation_disabled=false,soundtrigger_disabled=false,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=false,gps_mode=4,adjust_brightness_disabled=true,adjust_brightness_factor=0.5,force_all_apps_standby=false,force_background_check=false,optional_sensors_disabled=true,aod_disabled=false,quick_doze_enabled=true",
"null",
"advertise_is_enabled=true,datasaver_disabled=true,enable_night_mode=true,launch_boost_disabled=false,vibration_disabled=false,animation_disabled=false,soundtrigger_disabled=false,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=false,gps_mode=4,adjust_brightness_disabled=true,adjust_brightness_factor=0.75,force_all_apps_standby=false,force_background_check=false,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
"advertise_is_enabled=true,datasaver_disabled=false,enable_night_mode=true,launch_boost_disabled=true,vibration_disabled=true,animation_disabled=false,soundtrigger_disabled=true,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=true,gps_mode=2,adjust_brightness_disabled=false,adjust_brightness_factor=0.6,force_all_apps_standby=true,force_background_check=true,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
"advertise_is_enabled=true,datasaver_disabled=false,enable_night_mode=true,launch_boost_disabled=true,vibration_disabled=true,animation_disabled=true,soundtrigger_disabled=true,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=true,gps_mode=2,adjust_brightness_disabled=false,adjust_brightness_factor=0.5,force_all_apps_standby=true,force_background_check=true,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.cherish_settings_powersave);
ContentResolver resolver = getActivity().getContentResolver();
mPowerProfile = (SystemSettingListPreference) findPreference(POWER_PROFILE);
mPowerProfile.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mPowerProfile){
int profile = Integer.valueOf((String) newValue);
for (int i = 0; i < POWER_MODE_PROFILES.length; i++) {
if(profile == i){
if (profile != 1){
Settings.Global.putString(getActivity().getContentResolver(), Settings.Global.BATTERY_SAVER_CONSTANTS, POWER_MODE_PROFILES[i]);
} else{
Settings.Global.putString(getActivity().getContentResolver(), Settings.Global.BATTERY_SAVER_CONSTANTS, null);
}
}
}
return true;
}
return false;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}