PixelParts: Remove battery info and fast charge
We ship unmodified prebuilt kernel therefore we can't ship fast charge. The ROM now includes a battery information panel. Rename charge control to percentage-based charge control. Signed-off-by: AnierinB <anierin@evolution-x.org>
This commit is contained in:
@@ -78,34 +78,6 @@
|
||||
android:value="true" />
|
||||
</service>
|
||||
|
||||
<!-- Battery info activity -->
|
||||
<activity
|
||||
android:name=".batteryinfo.BatteryInfoActivity"
|
||||
android:label="@string/battery_info_title"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.IA_SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.battery" />
|
||||
<meta-data
|
||||
android:name="com.android.settings.summary"
|
||||
android:resource="@string/battery_info_summary" />
|
||||
</activity>
|
||||
|
||||
<!-- Battery info tile service -->
|
||||
<service
|
||||
android:name=".batteryinfo.BatteryInfoTileService"
|
||||
android:label="@string/battery_info_title"
|
||||
android:icon="@drawable/ic_battery_info_tile"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- Charge control activity -->
|
||||
<activity
|
||||
android:name=".chargecontrol.ChargeControlActivity"
|
||||
@@ -193,36 +165,5 @@
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- Fast charge activity-->
|
||||
<activity
|
||||
android:name=".fastcharge.FastChargeActivity"
|
||||
android:label="@string/fast_charge_title"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.IA_SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.battery" />
|
||||
<meta-data
|
||||
android:name="com.android.settings.summary"
|
||||
android:resource="@string/fast_charge_summary" />
|
||||
</activity>
|
||||
|
||||
<!-- Fast charge tile service -->
|
||||
<service
|
||||
android:name=".fastcharge.FastChargeTileService"
|
||||
android:label="@string/fast_charge_title"
|
||||
android:icon="@drawable/ic_fast_charge_tile"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
||||
android:value="true" />
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
16
README.md
16
README.md
@@ -1,28 +1,16 @@
|
||||

|
||||
|
||||
## About the app
|
||||
|
||||
PixelParts began as a simple High Brightness Mode (HBM) tool. Since then, it has evolved to include a detailed battery information panel, a display saturation level adjuster, charging limiter and more. The app now offers a wide range of features, transitioning from its original function as an HBM tool to a hub for device tweaks and stats on customs, with a lot more planned going forward.
|
||||

|
||||
|
||||
## Current features
|
||||
|
||||
| Category | Feature | Description | QS Tile | Required kernel changes |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| **Battery** | `Battery information` | View various battery information | Yes |N/A |
|
||||
| | `Charge control` | Start/stop charging at specific percentages | N/A | N/A |
|
||||
| | `Fast charge` | Enable CDP mode for faster charging on USB 2.0 ports. | Yes | [Commit 1/1](https://github.com/Evolution-X-Devices/kernel_google_gs101/commit/dcbfcd76bdc5d72e16f85fd8a48de6afa8804b61) |
|
||||
| **Display** | `Automatic high brightness mode (HBM)` | Enable peak luminance based on sunlight | Yes | N/A |
|
||||
| | `Saturation` | Control the saturation level of the display | Yes | N/A |
|
||||
| **Leds** | `Pixel torch` | Adjust the brightness of the PixelParts flashlight QS-Tile | PixelParts Flashlight QS | N/A |
|
||||
|
||||
## Including PixelParts
|
||||
|
||||
- Remove HbmSVManager:
|
||||
|
||||
[Commit 1/2 (vendor)](https://gitlab.com/EvoX/vendor_google_bluejay/-/commit/eb75035610983f92f2f7d2f245ba3aaea1664548)
|
||||
|
||||
[Commit 2/2 (device tree)](https://github.com/Evolution-X-Devices/device_google_bluejay/commit/6f905d723d22a9df8de3627958196f515b54add5)
|
||||
|
||||
- Clone this repository to packages/apps/PixelParts directory in your AOSP build tree:
|
||||
|
||||
```
|
||||
@@ -38,7 +26,7 @@ croot && git clone https://github.com/Evolution-X-Devices/packages_apps_PixelPar
|
||||
include packages/apps/PixelParts/device.mk
|
||||
```
|
||||
|
||||
This line includes the [device.mk](https://github.com/Evolution-X-Devices/packages_apps_PixelParts/blob/udc/device.mk) file from the PixelParts repository, which will add the PixelParts application, its initialization script (init.rc), and the necessary security policies (sepolicies) to your AOSP build during compilation.
|
||||
This line includes the [device.mk](https://github.com/Evolution-XYZ-Devices/packages_apps_PixelParts/blob/udc/device.mk) file from the PixelParts repository, which will add the PixelParts application, its initialization script (init.rc), and the necessary security policies (sepolicies) to your AOSP build during compilation.
|
||||
|
||||
## Testing changes
|
||||
|
||||
|
||||
@@ -12,8 +12,5 @@ PRODUCT_PACKAGES += \
|
||||
PRODUCT_PACKAGES += \
|
||||
init.pixelparts.rc
|
||||
|
||||
# PixelParts overlays
|
||||
DEVICE_PACKAGE_OVERLAYS += packages/apps/PixelParts/overlay
|
||||
|
||||
# PixelParts sepolicy
|
||||
BOARD_SEPOLICY_DIRS += packages/apps/PixelParts/sepolicy
|
||||
|
||||
@@ -9,7 +9,3 @@ on property:sys.boot_completed=1
|
||||
# HBM
|
||||
chown system system /sys/class/backlight/panel0-backlight/hbm_mode
|
||||
chmod 0666 /sys/class/backlight/panel0-backlight/hbm_mode
|
||||
|
||||
# USB 2.0 Force Fast Charge
|
||||
chown system system /sys/kernel/fast_charge/force_fast_charge
|
||||
chmod 0666 /sys/kernel/fast_charge/force_fast_charge
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2024 The Evolution X Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<bool name="config_showBatteryChargeCycles">false</bool>
|
||||
|
||||
</resources>
|
||||
@@ -1,11 +0,0 @@
|
||||
<!-- drawable/ic_battery_info_tile -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3M15,10.5V9A2,2 0 0,0 13,7H9V17H13A2,2 0 0,0 15,15V13.5C15,12.7 14.3,12 13.5,12C14.3,12 15,11.3 15,10.5M13,15H11V13H13V15M13,11H11V9H13V11Z" />
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<!-- drawable/ic_fast_charge_tile -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M23,11H20V4L15,14H18V22M12,8H4V6H12M12.67,4H11V2H5V4H3.33A1.33,1.33 0 0,0 2,5.33V20.67C2,21.4 2.6,22 3.33,22H12.67C13.4,22 14,21.4 14,20.67V5.33A1.33,1.33 0 0,0 12.67,4Z" />
|
||||
</vector>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-2024 The Evolution X Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/temperature_unit"
|
||||
android:title="@string/temperature_unit_title"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/battery_info_refresh"
|
||||
android:title="@string/battery_info_refresh_title"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/add_tile"
|
||||
android:title="@string/tile_add" />
|
||||
</menu>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2024 The Evolution X Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/add_tile"
|
||||
android:title="@string/tile_add" />
|
||||
</menu>
|
||||
@@ -18,58 +18,10 @@
|
||||
<string name="tile_off">Off</string>
|
||||
<string name="tile_camera_in_use">Camera in use</string>
|
||||
|
||||
<!-- Battery info -->
|
||||
<string name="battery_info_title">Battery information</string>
|
||||
<string name="battery_info_summary">View various information pertaining to the battery</string>
|
||||
<string name="battery_info_refresh_title">Refresh info every second</string>
|
||||
<string name="launch_battery_usage_title">Launch battery usage summary</string>
|
||||
<string name="technology_title">Technology</string>
|
||||
<string name="status_unknown">Unknown</string>
|
||||
<string name="status_charging">Charging</string>
|
||||
<string name="status_discharging">Discharging</string>
|
||||
<string name="status_not_charging">Not charging</string>
|
||||
<string name="status_full">Full</string>
|
||||
<string name="usb_type_title">USB type</string>
|
||||
<string name="usb_type_unknown_or_not_connected">Not connected or unknown</string>
|
||||
<string name="usb_type_standard_downstream_port">Standard Downstream Port (SDP)</string>
|
||||
<string name="usb_type_charging_downstream_port">Charging Downstream Port (CDP)</string>
|
||||
<string name="usb_type_dedicated_charging_port">Dedicated Charging Port (DCP)</string>
|
||||
<string name="temperature_title">Temperature</string>
|
||||
<string name="temperature_unit_title">Use °F for temperature</string>
|
||||
<string name="capacity_level_title">Capacity level</string>
|
||||
<string name="capacity_level_unknown">Unknown</string>
|
||||
<string name="capacity_level_critical">Critical</string>
|
||||
<string name="capacity_level_low">Low</string>
|
||||
<string name="capacity_level_normal">Normal</string>
|
||||
<string name="capacity_level_high">High</string>
|
||||
<string name="capacity_level_full">Full</string>
|
||||
<string name="current_title">Current</string>
|
||||
<string name="voltage_title">Voltage</string>
|
||||
<string name="wattage_title">Wattage</string>
|
||||
<string name="health_title">Health</string>
|
||||
<string name="health_unknown">Unknown</string>
|
||||
<string name="health_good">Good</string>
|
||||
<string name="health_overheat">Overheat</string>
|
||||
<string name="health_dead">Dead</string>
|
||||
<string name="health_over_voltage">Over voltage</string>
|
||||
<string name="health_unspecified_failure">Unspecified failure</string>
|
||||
<string name="health_cold">Cold</string>
|
||||
<string name="health_watchdog_timer_expire">Watchdog timer expire</string>
|
||||
<string name="health_safety_timer_expire">Safety timer expire</string>
|
||||
<string name="health_over_current">Over current</string>
|
||||
<string name="health_calibration_required">Calibration required</string>
|
||||
<string name="health_warm">Warm</string>
|
||||
<string name="health_cool">Cool</string>
|
||||
<string name="health_hot">Hot</string>
|
||||
<string name="manufacturing_date_title">Manufacture date</string>
|
||||
<string name="first_usage_date_title">Date of first use</string>
|
||||
<string name="cycle_count_title">Cycle count</string>
|
||||
<string name="battery_cycle_count_footer">Due to quality inspections before shipping, the cycle count may not be zero on first use</string>
|
||||
|
||||
<!-- Charge control -->
|
||||
<string name="charge_control_title">Charge control</string>
|
||||
<string name="charge_control_title">Percentage-based charge control</string>
|
||||
<string name="charge_control_summary">Control when the device stops and starts charging</string>
|
||||
<string name="charge_control_main_switch_title">Use Charge control</string>
|
||||
<string name="charge_control_main_switch_title">Use percentage-based charge control</string>
|
||||
<string name="stop_charging_title">Stop charging level</string>
|
||||
<string name="stop_charging_summary">Stop charging when the set percentage is reached</string>
|
||||
<string name="start_charging_title">Start charging level</string>
|
||||
@@ -107,12 +59,6 @@
|
||||
<string name="saturation_summary">Control the saturation level of the display</string>
|
||||
<string name="saturation_footer_summary">Changing the color mode in display settings will override the saturation level, requiring it to be reapplied.</string>
|
||||
|
||||
<!-- Fast charge -->
|
||||
<string name="fast_charge_title">Fast charge</string>
|
||||
<string name="fast_charge_summary">Enable CDP mode for fast charging on USB 2.0 ports</string>
|
||||
<string name="fast_charge_main_switch_title">Use Fast charge</string>
|
||||
<string name="fast_charge_footer_summary">Caution: Not all USB 2.0 ports support CDP mode. For changes to take effect, disconnect and reconnect the device after enabling or disabling this mode.</string>
|
||||
|
||||
<!-- Custom seekbar -->
|
||||
<string name="custom_seekbar_value">Value: <xliff:g id="v">%s</xliff:g></string>
|
||||
<string name="custom_seekbar_default_value">by default</string>
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-2024 The Evolution X Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.android.settingslib.widget.UsageProgressBarPreference
|
||||
android:key="capacity_status"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="technology"
|
||||
android:title="@string/technology_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="usb_type"
|
||||
android:title="@string/usb_type_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="temperature"
|
||||
android:title="@string/temperature_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="capacity_level"
|
||||
android:title="@string/capacity_level_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="current"
|
||||
android:title="@string/current_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="voltage"
|
||||
android:title="@string/voltage_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="wattage"
|
||||
android:title="@string/wattage_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="health"
|
||||
android:title="@string/health_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="manufacturing_date"
|
||||
android:title="@string/manufacturing_date_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="first_usage_date"
|
||||
android:title="@string/first_usage_date_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="cycle_count"
|
||||
android:title="@string/cycle_count_title"
|
||||
android:selectable="false" />
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="battery_info_footer"
|
||||
android:title="@string/battery_cycle_count_footer"
|
||||
android:selectable="false" />
|
||||
</PreferenceScreen>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023-2024 The Evolution X Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.android.settingslib.widget.TopIntroPreference
|
||||
android:key="fast_charge_intro"
|
||||
android:title="@string/fast_charge_summary" />
|
||||
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="fast_charge"
|
||||
android:title="@string/fast_charge_main_switch_title"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="fast_charge_footer"
|
||||
android:title="@string/fast_charge_footer_summary"
|
||||
android:selectable="false" />
|
||||
</PreferenceScreen>
|
||||
@@ -1,2 +0,0 @@
|
||||
# USB 2.0 force fast charge
|
||||
type sysfs_fastcharge, fs_type, sysfs_type;
|
||||
@@ -1 +0,0 @@
|
||||
/sys/kernel/fast_charge/force_fast_charge u:object_r:sysfs_fastcharge:s0
|
||||
@@ -31,7 +31,6 @@ allow pixelparts_app system_data_file:dir search;
|
||||
|
||||
allow pixelparts_app {
|
||||
sysfs_batteryinfo
|
||||
sysfs_fastcharge
|
||||
sysfs_leds
|
||||
}:file rw_file_perms;
|
||||
|
||||
|
||||
@@ -7,34 +7,6 @@ package org.evolution.pixelparts;
|
||||
|
||||
public class Constants {
|
||||
|
||||
// Battery info
|
||||
public static final String KEY_BATTERY_INFO_REFRESH = "battery_info_refresh";
|
||||
public static final String KEY_CAPACITY_STATUS = "capacity_status";
|
||||
public static final String KEY_TECHNOLOGY = "technology";
|
||||
public static final String KEY_USB_TYPE = "usb_type";
|
||||
public static final String KEY_TEMPERATURE = "temperature";
|
||||
public static final String KEY_TEMPERATURE_UNIT = "temperature_unit";
|
||||
public static final String KEY_CAPACITY_LEVEL = "capacity_level";
|
||||
public static final String KEY_CURRENT = "current";
|
||||
public static final String KEY_VOLTAGE = "voltage";
|
||||
public static final String KEY_WATTAGE = "wattage";
|
||||
public static final String KEY_HEALTH = "health";
|
||||
public static final String KEY_MANUFACTURING_DATE = "manufacturing_date";
|
||||
public static final String KEY_FIRST_USAGE_DATE = "first_usage_date";
|
||||
public static final String KEY_CYCLE_COUNT = "cycle_count";
|
||||
public static final String NODE_TECHNOLOGY = "/sys/class/power_supply/battery/technology";
|
||||
public static final String NODE_STATUS = "/sys/class/power_supply/battery/status";
|
||||
public static final String NODE_USB_TYPE = "/sys/class/power_supply/usb/usb_type";
|
||||
public static final String NODE_TEMPERATURE = "/sys/class/power_supply/battery/temp";
|
||||
public static final String NODE_CAPACITY = "/sys/class/power_supply/battery/capacity";
|
||||
public static final String NODE_CAPACITY_LEVEL = "/sys/class/power_supply/battery/capacity_level";
|
||||
public static final String NODE_CURRENT = "/sys/class/power_supply/battery/current_now";
|
||||
public static final String NODE_VOLTAGE = "/sys/class/power_supply/battery/voltage_now";
|
||||
public static final String NODE_HEALTH = "/sys/class/power_supply/battery/health";
|
||||
public static final String NODE_MANUFACTURING_DATE = "/sys/class/power_supply/battery/manufacturing_date";
|
||||
public static final String NODE_FIRST_USAGE_DATE = "/sys/class/power_supply/battery/first_usage_date";
|
||||
public static final String NODE_CYCLE_COUNT = "/sys/class/power_supply/battery/cycle_count";
|
||||
|
||||
// Charge control
|
||||
public static final String KEY_CHARGE_CONTROL = "charge_control";
|
||||
public static final String KEY_STOP_CHARGING = "stop_charging";
|
||||
@@ -63,8 +35,4 @@ public class Constants {
|
||||
// Saturation
|
||||
public static final String KEY_SATURATION = "saturation";
|
||||
public static final String KEY_SATURATION_PREVIEW = "saturation_preview";
|
||||
|
||||
// Fast charge
|
||||
public static final String KEY_FAST_CHARGE = "fast_charge";
|
||||
public static final String NODE_FAST_CHARGE = "/sys/kernel/fast_charge/force_fast_charge";
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ import org.evolution.pixelparts.autohbm.AutoHbmActivity;
|
||||
import org.evolution.pixelparts.autohbm.AutoHbmFragment;
|
||||
import org.evolution.pixelparts.autohbm.AutoHbmTileService;
|
||||
import org.evolution.pixelparts.chargecontrol.ChargeControlFragment;
|
||||
import org.evolution.pixelparts.fastcharge.FastChargeActivity;
|
||||
import org.evolution.pixelparts.fastcharge.FastChargeFragment;
|
||||
import org.evolution.pixelparts.fastcharge.FastChargeTileService;
|
||||
import org.evolution.pixelparts.pixeltorch.PixelTorchActivity;
|
||||
import org.evolution.pixelparts.pixeltorch.PixelTorchFragment;
|
||||
import org.evolution.pixelparts.pixeltorch.PixelTorchButtonService;
|
||||
@@ -49,21 +46,6 @@ public class Startup extends BroadcastReceiver {
|
||||
ChargeControlFragment.restoreStartChargingSetting(context);
|
||||
ChargeControlFragment.restoreStopChargingSetting(context);
|
||||
|
||||
// Fast charge
|
||||
FastChargeFragment.restoreFastChargeSetting(context);
|
||||
|
||||
ComponentUtils.toggleComponent(
|
||||
context,
|
||||
FastChargeActivity.class,
|
||||
FileUtils.fileExists(Constants.NODE_FAST_CHARGE)
|
||||
);
|
||||
|
||||
ComponentUtils.toggleComponent(
|
||||
context,
|
||||
FastChargeTileService.class,
|
||||
FileUtils.fileExists(Constants.NODE_FAST_CHARGE)
|
||||
);
|
||||
|
||||
// PixelTorch
|
||||
ComponentUtils.toggleComponent(
|
||||
context,
|
||||
|
||||
@@ -16,8 +16,6 @@ import android.util.Log;
|
||||
|
||||
import org.evolution.pixelparts.autohbm.AutoHbmActivity;
|
||||
import org.evolution.pixelparts.autohbm.AutoHbmTileService;
|
||||
import org.evolution.pixelparts.fastcharge.FastChargeActivity;
|
||||
import org.evolution.pixelparts.fastcharge.FastChargeTileService;
|
||||
import org.evolution.pixelparts.pixeltorch.PixelTorchActivity;
|
||||
import org.evolution.pixelparts.pixeltorch.PixelTorchTileService;
|
||||
|
||||
@@ -37,8 +35,6 @@ public final class TileHandlerActivity extends Activity {
|
||||
|
||||
if (qsName.equals(AutoHbmTileService.class.getName())) {
|
||||
aIntent.setClass(this, AutoHbmActivity.class);
|
||||
} else if (qsName.equals(FastChargeTileService.class.getName())) {
|
||||
aIntent.setClass(this, FastChargeActivity.class);
|
||||
} else if (qsName.equals(PixelTorchTileService.class.getName())) {
|
||||
aIntent.setClass(this, PixelTorchActivity.class);
|
||||
} else {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.batteryinfo;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
|
||||
|
||||
public class BatteryInfoActivity extends CollapsingToolbarBaseActivity {
|
||||
|
||||
private static final String TAG = "BatteryInfo";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
|
||||
new BatteryInfoFragment(), TAG).commit();
|
||||
}
|
||||
}
|
||||
@@ -1,380 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.batteryinfo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settingslib.widget.UsageProgressBarPreference;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.evolution.pixelparts.Constants;
|
||||
import org.evolution.pixelparts.R;
|
||||
import org.evolution.pixelparts.utils.FileUtils;
|
||||
import org.evolution.pixelparts.utils.TileUtils;
|
||||
|
||||
public class BatteryInfoFragment extends PreferenceFragmentCompat
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private Handler mHandler;
|
||||
private Runnable mUpdateRunnable;
|
||||
private SharedPreferences mSharedPrefs;
|
||||
|
||||
// Battery info
|
||||
private UsageProgressBarPreference mCapacityStatusPreference;
|
||||
|
||||
private Preference mTechnologyPreference;
|
||||
private Preference mUSBTypePreference;
|
||||
private Preference mTemperaturePreference;
|
||||
private Preference mCapacityLevelPreference;
|
||||
private Preference mCurrentPreference;
|
||||
private Preference mVoltagePreference;
|
||||
private Preference mWattagePreference;
|
||||
private Preference mHealthPreference;
|
||||
private Preference mManufacturingDatePreference;
|
||||
private Preference mFirstUsageDatePreference;
|
||||
private Preference mCycleCountPreference;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.battery_info, rootKey);
|
||||
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
Context context = getContext();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mHandler = new Handler();
|
||||
mUpdateRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updatePreferenceSummaries();
|
||||
mHandler.postDelayed(this,
|
||||
mSharedPrefs.getBoolean(Constants.KEY_BATTERY_INFO_REFRESH, false) ? 1000 : 5000);
|
||||
}
|
||||
};
|
||||
|
||||
mCapacityStatusPreference = findPreference(Constants.KEY_CAPACITY_STATUS);
|
||||
|
||||
mTechnologyPreference = findPreference(Constants.KEY_TECHNOLOGY);
|
||||
mUSBTypePreference = findPreference(Constants.KEY_USB_TYPE);
|
||||
mTemperaturePreference = findPreference(Constants.KEY_TEMPERATURE);
|
||||
mCapacityLevelPreference = findPreference(Constants.KEY_CAPACITY_LEVEL);
|
||||
mCurrentPreference = findPreference(Constants.KEY_CURRENT);
|
||||
mVoltagePreference = findPreference(Constants.KEY_VOLTAGE);
|
||||
mWattagePreference = findPreference(Constants.KEY_WATTAGE);
|
||||
mHealthPreference = findPreference(Constants.KEY_HEALTH);
|
||||
mManufacturingDatePreference = findPreference(Constants.KEY_MANUFACTURING_DATE);
|
||||
mFirstUsageDatePreference = findPreference(Constants.KEY_FIRST_USAGE_DATE);
|
||||
mCycleCountPreference = findPreference(Constants.KEY_CYCLE_COUNT);
|
||||
|
||||
updatePreferenceSummaries();
|
||||
mHandler.postDelayed(mUpdateRunnable,
|
||||
mSharedPrefs.getBoolean(Constants.KEY_BATTERY_INFO_REFRESH, false) ? 1000 : 5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updatePreferenceSummaries();
|
||||
mHandler.postDelayed(mUpdateRunnable,
|
||||
mSharedPrefs.getBoolean(Constants.KEY_BATTERY_INFO_REFRESH, false) ? 1000 : 5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mHandler.removeCallbacks(mUpdateRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacks(mUpdateRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.battery_info_menu, menu);
|
||||
menu.findItem(R.id.temperature_unit).setChecked(mSharedPrefs.getBoolean(Constants.KEY_TEMPERATURE_UNIT, false));
|
||||
menu.findItem(R.id.battery_info_refresh).setChecked(mSharedPrefs.getBoolean(Constants.KEY_BATTERY_INFO_REFRESH, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean isChecked = !item.isChecked();
|
||||
item.setChecked(isChecked);
|
||||
if (item.getItemId() == R.id.temperature_unit) {
|
||||
mSharedPrefs.edit().putBoolean(Constants.KEY_TEMPERATURE_UNIT, isChecked).apply();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.battery_info_refresh) {
|
||||
mSharedPrefs.edit().putBoolean(Constants.KEY_BATTERY_INFO_REFRESH, isChecked).apply();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.add_tile) {
|
||||
TileUtils.requestAddTileService(
|
||||
getContext(),
|
||||
BatteryInfoTileService.class,
|
||||
R.string.battery_info_title,
|
||||
R.drawable.ic_battery_info_tile
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferenceSummaries() {
|
||||
// Capacity & status preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_CAPACITY) && FileUtils.isFileReadable(Constants.NODE_STATUS)) {
|
||||
String capacityFileValue = FileUtils.getFileValue(Constants.NODE_CAPACITY, null);
|
||||
String statusFileValue = FileUtils.getFileValue(Constants.NODE_STATUS, null);
|
||||
int capacityFileIntValue = Integer.parseInt(capacityFileValue);
|
||||
int statusStringResourceId = getStatusStringResourceId(statusFileValue);
|
||||
mCapacityStatusPreference.setUsageSummary(capacityFileValue);
|
||||
mCapacityStatusPreference.setTotalSummary("%");
|
||||
mCapacityStatusPreference.setPercent(capacityFileIntValue, 100);
|
||||
mCapacityStatusPreference.setBottomSummary(getString(statusStringResourceId));
|
||||
} else {
|
||||
mCapacityStatusPreference.setUsageSummary("0");
|
||||
mCapacityStatusPreference.setTotalSummary("%");
|
||||
mCapacityStatusPreference.setBottomSummary(getString(R.string.kernel_node_access_error));
|
||||
}
|
||||
|
||||
// Technology preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_TECHNOLOGY)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_TECHNOLOGY, null);
|
||||
mTechnologyPreference.setSummary(fileValue);
|
||||
} else {
|
||||
mTechnologyPreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mTechnologyPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// USB type preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_USB_TYPE)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_USB_TYPE, null);
|
||||
int usbTypeStringResourceId = getUSBTypeStringResourceId(fileValue);
|
||||
mUSBTypePreference.setSummary(getString(usbTypeStringResourceId));
|
||||
} else {
|
||||
mUSBTypePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mUSBTypePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Temperature preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_TEMPERATURE)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_TEMPERATURE, null);
|
||||
int temperature = Integer.parseInt(fileValue);
|
||||
float temperatureCelsius = temperature / 10.0f;
|
||||
float temperatureFahrenheit = temperatureCelsius * 1.8f + 32;
|
||||
if (mSharedPrefs.getBoolean(Constants.KEY_TEMPERATURE_UNIT, false)) {
|
||||
float roundedTemperatureFahrenheit = Math.round(temperatureFahrenheit * 10) / 10.0f;
|
||||
mTemperaturePreference.setSummary(roundedTemperatureFahrenheit + "°F");
|
||||
} else {
|
||||
float roundedTemperatureCelsius = Math.round(temperatureCelsius * 10) / 10.0f;
|
||||
mTemperaturePreference.setSummary(roundedTemperatureCelsius + "°C");
|
||||
}
|
||||
} else {
|
||||
mTemperaturePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mTemperaturePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Capacity level preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_CAPACITY_LEVEL)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_CAPACITY_LEVEL, null);
|
||||
int capacityLevelStringResourceId = geCapacityLevelStringResourceId(fileValue);
|
||||
mCapacityLevelPreference.setSummary(getString(capacityLevelStringResourceId));
|
||||
} else {
|
||||
mCapacityLevelPreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mCapacityLevelPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Current preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_CURRENT)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_CURRENT, null);
|
||||
int chargingCurrent = Integer.parseInt(fileValue);
|
||||
int absoluteChargingCurrent = Math.abs(chargingCurrent);
|
||||
String formattedChargingCurrent = (absoluteChargingCurrent / 1000) + "mA";
|
||||
mCurrentPreference.setSummary(formattedChargingCurrent);
|
||||
} else {
|
||||
mCurrentPreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mCurrentPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Voltage preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_VOLTAGE)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_VOLTAGE, null);
|
||||
float chargingVoltage = Float.parseFloat(fileValue);
|
||||
String formattedChargingVoltage = String.format("%.1f", (chargingVoltage / 1000000)) + "V";
|
||||
mVoltagePreference.setSummary(formattedChargingVoltage);
|
||||
} else {
|
||||
mVoltagePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mVoltagePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Wattage preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_VOLTAGE) && FileUtils.isFileReadable(Constants.NODE_CURRENT)) {
|
||||
String voltageFileValue = FileUtils.getFileValue(Constants.NODE_VOLTAGE, null);
|
||||
String currentFileValue = FileUtils.getFileValue(Constants.NODE_CURRENT, null);
|
||||
float chargingCurrent = Integer.parseInt(currentFileValue) / 1000.0f;
|
||||
float chargingVoltage = Float.parseFloat(voltageFileValue) / 1000000.0f;
|
||||
float wattage = (chargingVoltage * chargingCurrent) / 1000.0f;
|
||||
float absoluteWattage = Math.abs(wattage);
|
||||
String formattedWattage = String.format("%.1f", absoluteWattage) + "W";
|
||||
mWattagePreference.setSummary(formattedWattage);
|
||||
} else {
|
||||
mWattagePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mWattagePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Health preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_HEALTH)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_HEALTH, null);
|
||||
int healthStringResourceId = getHealthStringResourceId(fileValue);
|
||||
mHealthPreference.setSummary(getString(healthStringResourceId));
|
||||
} else {
|
||||
mHealthPreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mHealthPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Manufacturing date preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_MANUFACTURING_DATE)) {
|
||||
long timestamp = Long.parseLong(FileUtils.getFileValue(Constants.NODE_MANUFACTURING_DATE, null)) * 1000L;
|
||||
Date date = new Date(timestamp);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy", Locale.getDefault());
|
||||
mManufacturingDatePreference.setSummary(sdf.format(date));
|
||||
} else {
|
||||
mManufacturingDatePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mManufacturingDatePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// First usage date preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_FIRST_USAGE_DATE)) {
|
||||
Date date = new Date(Long.parseLong(FileUtils.getFileValue(Constants.NODE_FIRST_USAGE_DATE, null)) * 1000L);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy", Locale.getDefault());
|
||||
mFirstUsageDatePreference.setSummary(sdf.format(date));
|
||||
} else {
|
||||
mFirstUsageDatePreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mFirstUsageDatePreference.setEnabled(false);
|
||||
}
|
||||
|
||||
// Cycle count preference
|
||||
if (FileUtils.isFileReadable(Constants.NODE_CYCLE_COUNT)) {
|
||||
String fileValue = FileUtils.getFileValue(Constants.NODE_CYCLE_COUNT, null);
|
||||
mCycleCountPreference.setSummary(fileValue);
|
||||
} else {
|
||||
mCycleCountPreference.setSummary(getString(R.string.kernel_node_access_error));
|
||||
mCycleCountPreference.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Status preference strings
|
||||
private int getStatusStringResourceId(String status) {
|
||||
switch (status) {
|
||||
case "Unknown":
|
||||
return R.string.status_unknown;
|
||||
case "Charging":
|
||||
return R.string.status_charging;
|
||||
case "Discharging":
|
||||
return R.string.status_discharging;
|
||||
case "Not charging":
|
||||
return R.string.status_not_charging;
|
||||
case "Full":
|
||||
return R.string.status_full;
|
||||
default:
|
||||
return R.string.kernel_node_returned_value_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
// USB type preference strings
|
||||
private int getUSBTypeStringResourceId(String usbType) {
|
||||
if (usbType.contains("[Unknown]")) {
|
||||
return R.string.usb_type_unknown_or_not_connected;
|
||||
} else if (usbType.contains("[SDP]")) {
|
||||
return R.string.usb_type_standard_downstream_port;
|
||||
} else if (usbType.contains("[CDP]")) {
|
||||
return R.string.usb_type_charging_downstream_port;
|
||||
} else if (usbType.contains("[DCP]")) {
|
||||
return R.string.usb_type_dedicated_charging_port;
|
||||
} else {
|
||||
return R.string.kernel_node_returned_value_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
// Capacity level preference strings
|
||||
private int geCapacityLevelStringResourceId(String capacitylevel) {
|
||||
switch (capacitylevel) {
|
||||
case "Unknown":
|
||||
return R.string.capacity_level_unknown;
|
||||
case "Critical":
|
||||
return R.string.capacity_level_critical;
|
||||
case "Low":
|
||||
return R.string.capacity_level_low;
|
||||
case "Normal":
|
||||
return R.string.capacity_level_normal;
|
||||
case "High":
|
||||
return R.string.capacity_level_high;
|
||||
case "Full":
|
||||
return R.string.capacity_level_full;
|
||||
default:
|
||||
return R.string.kernel_node_returned_value_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
// Health preference strings
|
||||
private int getHealthStringResourceId(String health) {
|
||||
switch (health) {
|
||||
case "Unknown":
|
||||
return R.string.health_unknown;
|
||||
case "Good":
|
||||
return R.string.health_good;
|
||||
case "Overheat":
|
||||
return R.string.health_overheat;
|
||||
case "Dead":
|
||||
return R.string.health_dead;
|
||||
case "Over voltage":
|
||||
return R.string.health_over_voltage;
|
||||
case "Unspecified failure":
|
||||
return R.string.health_unspecified_failure;
|
||||
case "Cold":
|
||||
return R.string.health_cold;
|
||||
case "Watchdog timer expire":
|
||||
return R.string.health_watchdog_timer_expire;
|
||||
case "Safety timer expire":
|
||||
return R.string.health_safety_timer_expire;
|
||||
case "Over current":
|
||||
return R.string.health_over_current;
|
||||
case "Calibration required":
|
||||
return R.string.health_calibration_required;
|
||||
case "Warm":
|
||||
return R.string.health_warm;
|
||||
case "Cool":
|
||||
return R.string.health_cool;
|
||||
case "Hot":
|
||||
return R.string.health_hot;
|
||||
default:
|
||||
return R.string.kernel_node_returned_value_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.batteryinfo;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
|
||||
public class BatteryInfoTileService extends TileService {
|
||||
|
||||
@Override
|
||||
public void onStartListening() {
|
||||
super.onStartListening();
|
||||
updateTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
super.onClick();
|
||||
Intent intent = new Intent(this, BatteryInfoActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
startActivityAndCollapse(pendingIntent);
|
||||
}
|
||||
|
||||
private void updateTile() {
|
||||
final Tile tile = getQsTile();
|
||||
tile.setState(Tile.STATE_ACTIVE);
|
||||
tile.updateTile();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.fastcharge;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
|
||||
|
||||
public class FastChargeActivity extends CollapsingToolbarBaseActivity {
|
||||
|
||||
private static final String TAG = "FastCharge";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
|
||||
new FastChargeFragment(), TAG).commit();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.fastcharge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
import org.evolution.pixelparts.Constants;
|
||||
import org.evolution.pixelparts.R;
|
||||
import org.evolution.pixelparts.utils.FileUtils;
|
||||
import org.evolution.pixelparts.utils.TileUtils;
|
||||
|
||||
public class FastChargeFragment extends PreferenceFragmentCompat
|
||||
implements OnCheckedChangeListener {
|
||||
|
||||
private MainSwitchPreference mFastChargeSwitch;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.fast_charge, rootKey);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
mFastChargeSwitch = findPreference(Constants.KEY_FAST_CHARGE);
|
||||
mFastChargeSwitch.setChecked(sharedPrefs.getBoolean(Constants.KEY_FAST_CHARGE, false));
|
||||
mFastChargeSwitch.addOnSwitchChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.fast_charge_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
SharedPreferences.Editor prefChange = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
|
||||
prefChange.putBoolean(Constants.KEY_FAST_CHARGE, isChecked).apply();
|
||||
if (FileUtils.isFileWritable(Constants.NODE_FAST_CHARGE)) {
|
||||
FileUtils.writeValue(Constants.NODE_FAST_CHARGE, isChecked ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.add_tile) {
|
||||
TileUtils.requestAddTileService(
|
||||
getContext(),
|
||||
FastChargeTileService.class,
|
||||
R.string.fast_charge_title,
|
||||
R.drawable.ic_fast_charge_tile
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreFastChargeSetting(Context context) {
|
||||
if (FileUtils.isFileWritable(Constants.NODE_FAST_CHARGE)) {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean value = sharedPrefs.getBoolean(Constants.KEY_FAST_CHARGE, false);
|
||||
FileUtils.writeValue(Constants.NODE_FAST_CHARGE, value ? "1" : "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 The Evolution X Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.evolution.pixelparts.fastcharge;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.evolution.pixelparts.Constants;
|
||||
import org.evolution.pixelparts.R;
|
||||
import org.evolution.pixelparts.utils.FileUtils;
|
||||
|
||||
public class FastChargeTileService extends TileService {
|
||||
|
||||
@Override
|
||||
public void onStartListening() {
|
||||
super.onStartListening();
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
updateTile(sharedPrefs.getBoolean(Constants.KEY_FAST_CHARGE, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopListening() {
|
||||
super.onStopListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
super.onClick();
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final boolean enabled = !(sharedPrefs.getBoolean(Constants.KEY_FAST_CHARGE, false));
|
||||
FileUtils.writeValue(Constants.NODE_FAST_CHARGE, enabled ? "1" : "0");
|
||||
sharedPrefs.edit().putBoolean(Constants.KEY_FAST_CHARGE, enabled).commit();
|
||||
updateTile(enabled);
|
||||
}
|
||||
|
||||
private void updateTile(boolean enabled) {
|
||||
final Tile tile = getQsTile();
|
||||
tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
||||
String subtitle = enabled ? getString(R.string.tile_on) : getString(R.string.tile_off);
|
||||
tile.setSubtitle(subtitle);
|
||||
tile.updateTile();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user