Cherish: Custom Carrier Label & Carrier Label Placement [2/2]

Credit/Thanks to @Altaf-Mahdi @beanstown106 and @martincz

Change-Id: Ia7b29f85d7a1286bd15dc4427727a683e133ab3f
This commit is contained in:
beanstown106
2019-11-23 18:54:59 +05:30
committed by Hưng Phan
parent 8fe30d8344
commit fcfa74859b
5 changed files with 173 additions and 0 deletions

View File

@@ -303,4 +303,18 @@
<item>300000</item> <item>300000</item>
<item>600000</item> <item>600000</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

@@ -306,4 +306,16 @@
<string name="adaptive_playback_timeout_5_min">5 minutes</string> <string name="adaptive_playback_timeout_5_min">5 minutes</string>
<string name="adaptive_playback_timeout_10_min">10 minutes</string> <string name="adaptive_playback_timeout_10_min">10 minutes</string>
<!-- Custom carrier label and position -->
<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">Enter a custom label. Leave blank to use your network name</string>
<string name="custom_carrier_label_notset">Custom label currently not set</string>
<string name="show_carrier_title">Carrier label location</string>
<string name="show_carrier_disabled">Disabled</string>
<string name="show_carrier_keyguard">Lockscreen</string>
<string name="show_carrier_statusbar">Statusbar</string>
<string name="show_carrier_enabled">Both</string>
</resources> </resources>

View File

@@ -15,6 +15,12 @@
android:title="@string/statusbar_title" android:title="@string/statusbar_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<Preference
android:key="carrier_label"
android:title="@string/carrier_label_settings_title"
android:summary="@string/carrier_label_settings_summary"
android:fragment="com.cherish.settings.fragments.CustomCarrierLabel" />
<PreferenceCategory <PreferenceCategory
android:key="status_bar_icons" android:key="status_bar_icons"
android:title="@string/status_bar_system_icons_title"> android:title="@string/status_bar_system_icons_title">

View File

@@ -0,0 +1,34 @@
<?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:entries="@array/carrier_label_entries"
android:entryValues="@array/carrier_label_values"
android:summary="%s"
android:defaultValue="1" />
<PreferenceScreen
android:key="custom_carrier_label"
android:title="@string/custom_carrier_label_title" />
</PreferenceScreen>

View File

@@ -0,0 +1,107 @@
/*
* 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.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 com.android.internal.logging.nano.MetricsProto;
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 PreferenceScreen mCustomCarrierLabel;
private String mCustomCarrierLabelText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentResolver resolver = getActivity().getContentResolver();
addPreferencesFromResource(R.xml.custom_carrier_label);
PreferenceScreen prefSet = getPreferenceScreen();
mCustomCarrierLabel = (PreferenceScreen) findPreference(CUSTOM_CARRIER_LABEL);
updateCustomLabelTextSummary();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return false;
}
public boolean onPreferenceTreeClick(Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
boolean value;
if (preference == mCustomCarrierLabel) {
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);
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}