[SQUASHED] Custom Carrier Label & Carrier Label Placement [1/2]

SuperDroidBond Edit- Port Carrier Label Font Size, Style & Color from AOSP Ex & RR Nougat
                     Use the lock clock font arrays.

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
beanstown106
2018-09-15 21:18:12 +05:30
committed by Hưng Phan
parent ba6f49f566
commit 69d6ea5f4a
5 changed files with 260 additions and 0 deletions

View File

@@ -1034,4 +1034,19 @@
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>
</string-array> </string-array>
<!-- Carrier Label -->
<string-array name="carrier_label_entries" translatable="false">
<item>@string/show_carrier_disabled</item>
<item>@string/show_carrier_keyguard</item>
<item>@string/show_carrier_statusbar</item>
<item>@string/show_carrier_enabled</item>
</string-array>
<string-array name="carrier_label_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources> </resources>

View File

@@ -976,4 +976,21 @@
<!-- Power menu on lockscreen --> <!-- Power menu on lockscreen -->
<string name="lockscreen_power_menu_disabled_title">Disable power menu on lock screen</string> <string name="lockscreen_power_menu_disabled_title">Disable power menu on lock screen</string>
<string name="lockscreen_power_menu_disabled_summary">This will only disable the power menu on secure lock screens</string> <string name="lockscreen_power_menu_disabled_summary">This will only disable the power menu on secure lock screens</string>
<!-- Custom carrier label and position -->
<string name="carrier_label_category_title">CarrierLabel Settings</string>
<string name="carrier_label_category_summary">Customize statusbar carrierlabel</string>
<string name="carrier_label_settings_title">Carrier Label</string>
<string name="carrier_label_settings_summary">Customize the carrier label</string>
<string name="custom_carrier_label_title">Custom carrier label</string>
<string name="custom_carrier_label_explain">Please enter a new label. Leave blank to revert to stock label.</string>
<string name="custom_carrier_label_notset">Custom label currently not set</string>
<string name="show_carrier_title">Carrier label</string>
<string name="show_carrier_disabled">Disabled</string>
<string name="show_carrier_keyguard">Lockscreen only</string>
<string name="show_carrier_statusbar">Statusbar only</string>
<string name="show_carrier_enabled">Lockscreen &amp; statusbar</string>
<string name="status_bar_carrier_color">Carrier label color</string>
<string name="status_bar_carrier_size">Carrier label size</string>
<string name="status_bar_carrier_font_style_title">Carrier Label Font</string>
</resources> </resources>

View File

@@ -137,5 +137,11 @@
android:summary="@string/battery_bar_summary" android:summary="@string/battery_bar_summary"
android:fragment="com.cherish.settings.fragments.BatteryBarSettings" /> android:fragment="com.cherish.settings.fragments.BatteryBarSettings" />
<Preference
android:key="carrier_label"
android:icon="@drawable/ic_carrierlabel"
android:title="@string/carrier_label_settings_title"
android:summary="@string/carrier_label_settings_summary"
android:fragment="com.cherish.settings.fragments.CustomCarrierLabel" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020 CherishOS
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="@string/carrier_label_settings_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="status_bar_show_carrier"
android:title="@string/show_carrier_title"
android:dialogTitle="@string/show_carrier_title"
android:entries="@array/carrier_label_entries"
android:entryValues="@array/carrier_label_values"
android:summary="%s"
android:defaultValue="0" />
<PreferenceScreen
android:key="custom_carrier_label"
android:title="@string/custom_carrier_label_title" />
<ListPreference
android:key="status_bar_carrier_font_style"
android:title="@string/status_bar_carrier_font_style_title"
android:dialogTitle="@string/status_bar_carrier_font_style_title"
android:entries="@array/sb_clock_fonts_entries"
android:entryValues="@array/sb_clock_fonts_values"
android:defaultValue="0" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="status_bar_carrier_color"
android:title="@string/status_bar_carrier_color"
android:defaultValue="0xffffffff" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="status_bar_carrier_font_size"
android:title="@string/status_bar_carrier_size"
android:max="23"
settings:min="8"
settings:defaultValue="14"
settings:units="dp" />
</PreferenceScreen>

View File

@@ -0,0 +1,169 @@
/*
* Copyright (C) 2020 CherishOS
*
* 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.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.Spannable;
import android.text.TextUtils;
import android.widget.EditText;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.ListPreference;
import com.android.internal.logging.nano.MetricsProto;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class CustomCarrierLabel extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
public static final String TAG = "CarrierLabel";
private static final String CUSTOM_CARRIER_LABEL = "custom_carrier_label";
private static final String STATUS_BAR_CARRIER_COLOR = "status_bar_carrier_color";
private static final String STATUS_BAR_CARRIER_FONT_SIZE = "status_bar_carrier_font_size";
private static final String CARRIER_FONT_STYLE = "status_bar_carrier_font_style";
static final int DEFAULT_STATUS_CARRIER_COLOR = 0xffffffff;
private PreferenceScreen mCustomCarrierLabel;
private String mCustomCarrierLabelText;
private ColorPickerPreference mCarrierColorPicker;
private CustomSeekBarPreference mStatusBarCarrierSize;
private ListPreference mCarrierFontStyle;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.custom_carrier_label);
PreferenceScreen prefSet = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
int intColor;
String hexColor;
// custom carrier label
mCustomCarrierLabel = (PreferenceScreen) findPreference(CUSTOM_CARRIER_LABEL);
updateCustomLabelTextSummary();
mCarrierColorPicker = (ColorPickerPreference) findPreference(STATUS_BAR_CARRIER_COLOR);
mCarrierColorPicker.setOnPreferenceChangeListener(this);
intColor = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CARRIER_COLOR, DEFAULT_STATUS_CARRIER_COLOR);
hexColor = String.format("#%08x", (0xffffffff & intColor));
mCarrierColorPicker.setSummary(hexColor);
mCarrierColorPicker.setNewPreviewColor(intColor);
mStatusBarCarrierSize = (CustomSeekBarPreference) findPreference(STATUS_BAR_CARRIER_FONT_SIZE);
int StatusBarCarrierSize = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CARRIER_FONT_SIZE, 14);
mStatusBarCarrierSize.setValue(StatusBarCarrierSize / 1);
mStatusBarCarrierSize.setOnPreferenceChangeListener(this);
mCarrierFontStyle = (ListPreference) findPreference(CARRIER_FONT_STYLE);
int showCarrierFont = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CARRIER_FONT_STYLE, 0);
mCarrierFontStyle.setValue(String.valueOf(showCarrierFont));
mCarrierFontStyle.setOnPreferenceChangeListener(this);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public void onResume() {
super.onResume();
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mCarrierColorPicker) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CARRIER_COLOR, intHex);
return true;
} else if (preference == mStatusBarCarrierSize) {
int width = ((Integer)newValue).intValue();
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CARRIER_FONT_SIZE, width);
return true;
} else if (preference == mCarrierFontStyle) {
int showCarrierFont = Integer.valueOf((String) newValue);
int index = mCarrierFontStyle.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver, Settings.System.
STATUS_BAR_CARRIER_FONT_STYLE, showCarrierFont);
mCarrierFontStyle.setSummary(mCarrierFontStyle.getEntries()[index]);
return true;
}
return false;
}
public boolean onPreferenceTreeClick(Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
boolean value;
if (preference.getKey().equals(CUSTOM_CARRIER_LABEL)) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.custom_carrier_label_title);
alert.setMessage(R.string.custom_carrier_label_explain);
// Set an EditText view to get user input
final EditText input = new EditText(getActivity());
input.setText(TextUtils.isEmpty(mCustomCarrierLabelText) ? "" : mCustomCarrierLabelText);
input.setSelection(input.getText().length());
alert.setView(input);
alert.setPositiveButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = ((Spannable) input.getText()).toString().trim();
Settings.System.putString(resolver, Settings.System.CUSTOM_CARRIER_LABEL, value);
updateCustomLabelTextSummary();
Intent i = new Intent();
i.setAction(Intent.ACTION_CUSTOM_CARRIER_LABEL_CHANGED);
getActivity().sendBroadcast(i);
}
});
alert.setNegativeButton(getString(android.R.string.cancel), null);
alert.show();
return true;
}
return false;
}
private void updateCustomLabelTextSummary() {
mCustomCarrierLabelText = Settings.System.getString(
getContentResolver(), Settings.System.CUSTOM_CARRIER_LABEL);
if (TextUtils.isEmpty(mCustomCarrierLabelText)) {
mCustomCarrierLabel.setSummary(R.string.custom_carrier_label_notset);
} else {
mCustomCarrierLabel.setSummary(mCustomCarrierLabelText);
}
}
}