Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Battery light customization [2/2]
Browse files Browse the repository at this point in the history
Original commit: ezio84/abc_packages_apps_AbcSettings@d27e134

Signed-off-by: XrTV <binder_z@mail.ru>
  • Loading branch information
XrTV committed Sep 5, 2017
1 parent b030be8 commit bf69b82
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 1 deletion.
11 changes: 11 additions & 0 deletions res/values-ru/octogen_strings.xml
Expand Up @@ -114,4 +114,15 @@
<string name="headset_connect_player_bt">Когда гарнитура BT подключена</string>
<string name="headset_connect_player_both_no_carkit">Когда проводная или BT-гарнитура (без каркита) подключена</string>
<string name="headset_connect_player_both">Когда проводная или BT-гарнитура подключена</string>

<!-- Battery light -->
<string name="octogen_leds">Индикация</string>
<string name="octogen_battery_light_settings">Настройки индикатора батареи</string>
<string name="battery_light_allow_on_dnd_title">Индикатор заряда батареи в режиме «Не беспокоить»</string>
<string name="battery_light_low_blinking_title">Мигать при низком заряде батареи</string>
<string name="battery_light_cat">Цверт зарядки батареи</string>
<string name="battery_light_low_color">Батарея разряжена</string>
<string name="battery_light_medium_color">Батарея почти заряжена</string>
<string name="battery_light_full_color">Батарея заряжена</string>

</resources>
10 changes: 10 additions & 0 deletions res/values/octogen_strings.xml
Expand Up @@ -116,4 +116,14 @@
<string name="headset_connect_player_both_no_carkit">When wired or BT headset (no carkit) is plugged in</string>
<string name="headset_connect_player_both">When wired or BT headset is plugged in</string>

<!-- Battery light -->
<string name="octogen_leds">Leds settings</string>
<string name="octogen_battery_light_settings">Battery light settings</string>
<string name="battery_light_allow_on_dnd_title">Battery light in Do Not Disturb mode</string>
<string name="battery_light_low_blinking_title">Binking light on low battery</string>
<string name="battery_light_cat">Battery light color when charging</string>
<string name="battery_light_low_color">Low battery</string>
<string name="battery_light_medium_color">Medium battery</string>
<string name="battery_light_full_color">High battery</string>

</resources>
50 changes: 50 additions & 0 deletions res/xml/octogen_battery_light_settings.xml
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 OctoDev 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"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

<com.octogen.settings.preferences.SystemSettingSwitchPreference
android:key="battery_light_allow_on_dnd"
android:title="@string/battery_light_allow_on_dnd_title"
android:defaultValue="false" />

<com.octogen.settings.preferences.SystemSettingSwitchPreference
android:key="battery_light_low_blinking"
android:title="@string/battery_light_low_blinking_title"
android:defaultValue="false" />

<PreferenceCategory
android:key="battery_light_cat"
android:title="@string/battery_light_cat">
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="battery_light_low_color"
android:title="@string/battery_light_low_color"
android:defaultValue="0xFFFF0000" />

<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="battery_light_medium_color"
android:title="@string/battery_light_medium_color"
android:defaultValue="0xFFFFFF00" />

<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="battery_light_full_color"
android:title="@string/battery_light_full_color"
android:defaultValue="0xFF00FF00" />
</PreferenceCategory>

</PreferenceScreen>
21 changes: 21 additions & 0 deletions res/xml/octogen_settings_notifications.xml
Expand Up @@ -18,4 +18,25 @@
android:title="@string/notifications_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

<com.octogen.settings.preferences.SystemSettingSwitchPreference
android:key="battery_light_allow_on_dnd"
android:title="@string/battery_light_allow_on_dnd_title"
android:defaultValue="false" />

<com.octogen.settings.preferences.SystemSettingSwitchPreference
android:key="battery_light_low_blinking"
android:title="@string/battery_light_low_blinking_title"
android:defaultValue="false" />

<PreferenceCategory
android:key="octogen_leds"
android:title="@string/octogen_leds" >

<Preference
android:key="octogen_charging_light"
android:fragment="com.octogen.settings.BatteryLightSettings"
android:title="@string/octogen_battery_light_settings" />

</PreferenceCategory>

</PreferenceScreen>
126 changes: 126 additions & 0 deletions src/com/octogen/settings/BatteryLightSettings.java
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2017 The ABC rom
* Copyright (C) 2017 OctoDev 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.
*/
package com.octogen.settings;

import android.content.ContentResolver;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import android.provider.Settings;

import com.android.internal.logging.nano.MetricsProto;

import com.octogen.settings.preferences.SystemSettingSwitchPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;

import net.margaritov.preference.colorpicker.ColorPickerPreference;

public class BatteryLightSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {

private ColorPickerPreference mLowColor;
private ColorPickerPreference mMediumColor;
private ColorPickerPreference mFullColor;
private SystemSettingSwitchPreference mLowBatteryBlinking;

private PreferenceCategory mColorCategory;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.octogen_battery_light_settings);

PreferenceScreen prefSet = getPreferenceScreen();
mColorCategory = (PreferenceCategory) findPreference("battery_light_cat");

mLowBatteryBlinking = (SystemSettingSwitchPreference)prefSet.findPreference("battery_light_low_blinking");
if (getResources().getBoolean(
com.android.internal.R.bool.config_ledCanPulse)) {
mLowBatteryBlinking.setChecked(Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_BLINKING, 0, UserHandle.USER_CURRENT) == 1);
mLowBatteryBlinking.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(mLowBatteryBlinking);
}

if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
int color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_COLOR, 0xFFFF0000,
UserHandle.USER_CURRENT);
mLowColor = (ColorPickerPreference) findPreference("battery_light_low_color");
mLowColor.setAlphaSliderEnabled(true);
mLowColor.setNewPreviewColor(color);
mLowColor.setOnPreferenceChangeListener(this);

color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, 0xFFFFFF00,
UserHandle.USER_CURRENT);
mMediumColor = (ColorPickerPreference) findPreference("battery_light_medium_color");
mMediumColor.setAlphaSliderEnabled(true);
mMediumColor.setNewPreviewColor(color);
mMediumColor.setOnPreferenceChangeListener(this);

color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_FULL_COLOR, 0xFF00FF00,
UserHandle.USER_CURRENT);
mFullColor = (ColorPickerPreference) findPreference("battery_light_full_color");
mFullColor.setAlphaSliderEnabled(true);
mFullColor.setNewPreviewColor(color);
mFullColor.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(mColorCategory);
}
}

@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.OCTOGEN_SETTINGS;
}

public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.equals(mLowColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference.equals(mMediumColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference.equals(mFullColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_FULL_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference == mLowBatteryBlinking) {
boolean value = (Boolean) newValue;
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_BLINKING, value ? 1 : 0,
UserHandle.USER_CURRENT);
}
return false;
}
}
19 changes: 18 additions & 1 deletion src/com/octogen/settings/OctogenSettings.java
Expand Up @@ -22,19 +22,36 @@
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.view.Surface;
import android.preference.Preference;
import android.support.v7.preference.*;
import com.android.settings.R;

import com.android.settings.SettingsPreferenceFragment;

public class OctogenSettings extends SettingsPreferenceFragment {

private PreferenceCategory mLedsCategory;
private Preference mChargingLeds;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

addPreferencesFromResource(R.xml.octogen_settings);
PreferenceScreen prefSet = getPreferenceScreen();

mLedsCategory = (PreferenceCategory) findPreference("octogen_leds");
mChargingLeds = (Preference) findPreference("octogen_charging_light");
if (mChargingLeds != null
&& !getResources().getBoolean(
com.android.internal.R.bool.config_intrusiveBatteryLed)) {
mLedsCategory.removePreference(mChargingLeds);
}
if (mChargingLeds == null) {
prefSet.removePreference(mLedsCategory);
}
}

@Override
Expand Down

0 comments on commit bf69b82

Please sign in to comment.