Skip to content

Commit

Permalink
Settings: Add charging control preferences
Browse files Browse the repository at this point in the history
Change-Id: I936add4df464eb9818258de4955b651266c67ec3
Signed-off-by: Mohammad Hasan Keramat J <ikeramat@protonmail.com>

ChargingControl: Don't index settings if it is not supported

Change-Id: I8e7e26d39ffdd31fd35d0d25a2f6bd8b7dcbe3f4
Signed-off-by: Mohammad Hasan Keramat J <ikeramat@protonmail.com>
  • Loading branch information
dtrunk90 authored and bheatleyyy committed Sep 28, 2023
1 parent 98d2143 commit b01f75a
Show file tree
Hide file tree
Showing 12 changed files with 819 additions and 0 deletions.
30 changes: 30 additions & 0 deletions res/layout/dialog_time.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 The LineageOS Project
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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">

<TimePicker
android:id="@+id/time_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingTop="8dp" />

</LinearLayout>
63 changes: 63 additions & 0 deletions res/layout/preference_charging_limit.xml
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 The LineageOS Project
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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingVertical="6dip"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />

<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:singleLine="true" />

</RelativeLayout>

<SeekBar
android:id="@+id/seekbar_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="15dip"
android:min="70"
android:max="100" />

</LinearLayout>
20 changes: 20 additions & 0 deletions res/values/custom_arrays.xml
Expand Up @@ -59,4 +59,24 @@
<item>3600</item>
</string-array>

<!-- Values for the charging control modes -->
<string-array name="charging_control_mode_entries" translatable="false">
<item>@string/charging_control_mode_auto_title</item>
<item>@string/charging_control_mode_custom_title</item>
</string-array>

<string-array name="charging_control_mode_values" translatable="false">
<item>1</item>
<item>2</item>
</string-array>

<!-- Values for the additional charging control modes if fine-grained control is supported -->
<string-array name="charging_control_mode_entries_fine_grained_control" translatable="false">
<item>@string/charging_control_mode_limit_title</item>
</string-array>

<string-array name="charging_control_mode_values_fine_grained_control" translatable="false">
<item>3</item>
</string-array>

</resources>
18 changes: 18 additions & 0 deletions res/values/custom_strings.xml
Expand Up @@ -342,4 +342,22 @@
<string name="smart_5g_title">Smart 5G</string>
<string name="smart_5g_summary">Automatically switch between 5G and 4G to reduce battery consumption</string>

<!-- Charging control settings -->
<string name="charging_control_title">Charging control</string>
<string name="charging_control_enable_title">Enable charging control</string>
<string name="charging_control_mode_title">Charging mode</string>
<string name="charging_control_mode_auto_title">Automatic schedule</string>
<string name="charging_control_mode_auto_summary">Automatically determine when to start charging based on alarms set</string>
<string name="charging_control_mode_custom_title">Custom schedule</string>
<string name="charging_control_mode_custom_summary">Set a target time to full charge</string>
<string name="charging_control_mode_limit_title">Limit charging</string>
<string name="charging_control_mode_limit_summary">Limit charging to a certain percentage</string>
<string name="charging_control_start_time_title">Start time</string>
<string name="charging_control_start_time_summary">Charging control activates when you start charging after %s</string>
<string name="charging_control_target_time_title">Target time to full charge</string>
<string name="charging_control_target_time_summary">Battery will be fully charged by %s</string>
<string name="charging_control_limit_title">Limit</string>


<string name="reset">Reset</string>
</resources>
48 changes: 48 additions & 0 deletions res/xml/charging_control_settings.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 The LineageOS Project
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:key="charging_control"
android:title="@string/charging_control_title">

<com.android.settings.custom.preference.SystemSettingMainSwitchPreference
android:key="charging_control_enabled"
android:title="@string/charging_control_enable_title" />

<com.android.settings.custom.preference.SystemSettingDropDownPreference
android:key="charging_control_mode"
android:title="@string/charging_control_mode_title"
android:entries="@array/charging_control_mode_entries"
android:entryValues="@array/charging_control_mode_values"
android:dependency="charging_control_enabled" />

<com.android.settings.lineage.health.StartTimePreference
android:key="charging_control_start_time"
android:title="@string/charging_control_start_time_title"
android:dependency="charging_control_enabled" />

<com.android.settings.lineage.health.TargetTimePreference
android:key="charging_control_target_time"
android:title="@string/charging_control_target_time_title"
android:dependency="charging_control_enabled" />

<com.android.settings.lineage.health.ChargingLimitPreference
android:key="charging_control_charging_limit"
android:title="@string/charging_control_limit_title"
android:dependency="charging_control_enabled" />

</PreferenceScreen>
7 changes: 7 additions & 0 deletions res/xml/power_usage_summary.xml
Expand Up @@ -58,6 +58,13 @@
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryManagerPreferenceController"
settings:keywords="@string/keywords_battery_adaptive_preferences" />

<!-- Charging control -->
<Preference
android:key="charging_control"
android:title="@string/charging_control_title"
android:fragment="com.android.settings.lineage.health.ChargingControlSettings"
settings:controller="com.android.settings.lineage.health.ChargingControlPreferenceController" />

<SwitchPreference
android:key="battery_percentage"
android:title="@string/battery_percentage"
Expand Down
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2022 The PixelExperience Project
* Copyright (C) 2023 The lineage Foundation
*
* 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.android.settings.lineage.health;

import android.content.Context;
import android.os.IBinder;
import android.os.ServiceManager;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;

public class ChargingControlPreferenceController extends BasePreferenceController {

public static final String KEY = "charging_control";

private Context mContext;

public ChargingControlPreferenceController(Context context, String key) {
super(context, key);

mContext = context;
}

public ChargingControlPreferenceController(Context context) {
this(context, KEY);

mContext = context;
}

private boolean isNegated(String key) {
return key != null && key.startsWith("!");
}

@Override
public int getAvailabilityStatus() {
String rService = "lineagehealth";
boolean negated = isNegated(rService);
if (negated) {
rService = rService.substring(1);
}
IBinder value = ServiceManager.getService(rService);
boolean available = value != null;
if (available == negated) {
return UNSUPPORTED_ON_DEVICE;
}
return AVAILABLE;
}

}

0 comments on commit b01f75a

Please sign in to comment.