Cherish: Notch friendly carrier label [2/2]

This commit is contained in:
Alex
2019-02-21 21:16:02 +01:00
committed by Hung Phan
parent f75ead2bb6
commit 9d4cffdecb
7 changed files with 85 additions and 17 deletions

View File

@@ -0,0 +1,21 @@
<!--
Copyright (C) 2018 The Android Open Source 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="30dp"
android:width="30dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path android:fillColor="#000" android:pathData="M5.5,7A1.5,1.5 0 0,0 7,5.5A1.5,1.5 0 0,0 5.5,4A1.5,1.5 0 0,0 4,5.5A1.5,1.5 0 0,0 5.5,7M21.41,11.58C21.77,11.94 22,12.44 22,13C22,13.55 21.78,14.05 21.41,14.41L14.41,21.41C14.05,21.77 13.55,22 13,22C12.45,22 11.95,21.77 11.58,21.41L2.59,12.41C2.22,12.05 2,11.55 2,11V4C2,2.89 2.89,2 4,2H11C11.55,2 12.05,2.22 12.41,2.58L21.41,11.58M13,20L20,13L11.5,4.5L4.5,11.5L13,20M10.09,8.91L11.5,7.5L17,13L15.59,14.41L10.09,8.91M7.59,11.41L9,10L13,14L11.59,15.41L7.59,11.41Z" />
</vector>

View File

@@ -265,4 +265,16 @@
<string name="adaptive_playback_timeout_2_min">2 phút</string>
<string name="adaptive_playback_timeout_5_min">5 phút</string>
<string name="adaptive_playback_timeout_10_min">10 phút</string>
<!-- Custom carrier label and position -->
<string name="label_title">Nhãn hiệu</string>
<string name="carrier_label_settings_title">Tên nhà mạng</string>
<string name="carrier_label_settings_summary">Tùy chỉnh tên của nhà mạng</string>
<string name="custom_carrier_label_title">Tùy chỉnh tên nhà mạng</string>
<string name="custom_carrier_label_explain">Nhập nhãn tùy chỉnh. Để trống để sử dụng tên mạng của bạn</string>
<string name="custom_carrier_label_notset">Nhãn tùy chỉnh hiện không được đặt</string>
<string name="show_carrier_title">Địa chỉ tên nhà mạng</string>
<string name="show_carrier_disabled">Đã tắt</string>
<string name="show_carrier_keyguard">Màn hình khóa</string>
<string name="show_carrier_statusbar">Thanh trạng thái</string>
<string name="show_carrier_enabled">Cả hai</string>
</resources>

View File

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

View File

@@ -307,6 +307,7 @@
<string name="adaptive_playback_timeout_10_min">10 minutes</string>
<!-- Custom carrier label and position -->
<string name="label_title">Label</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>

View File

@@ -15,11 +15,18 @@
android:title="@string/statusbar_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<PreferenceCategory
android:key="label"
android:title="@string/label_title">
<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
android:key="status_bar_icons"

View File

@@ -22,9 +22,6 @@
<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

View File

@@ -20,6 +20,7 @@ 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;
@@ -34,18 +35,23 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import android.widget.LinearLayout;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.cherish.CherishUtils;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.SystemSettingListPreference;
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 KEY_CARRIER_LABEL = "status_bar_show_carrier";
private PreferenceScreen mCustomCarrierLabel;
private String mCustomCarrierLabelText;
private SystemSettingListPreference mShowCarrierLabel;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -57,13 +63,51 @@ public class CustomCarrierLabel extends SettingsPreferenceFragment
mCustomCarrierLabel = (PreferenceScreen) findPreference(CUSTOM_CARRIER_LABEL);
updateCustomLabelTextSummary();
mShowCarrierLabel = (SystemSettingListPreference) findPreference(KEY_CARRIER_LABEL);
int showCarrierLabel = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_SHOW_CARRIER, 1);
CharSequence[] NonNotchEntries = { getResources().getString(R.string.show_carrier_disabled),
getResources().getString(R.string.show_carrier_keyguard),
getResources().getString(R.string.show_carrier_statusbar), getResources().getString(
R.string.show_carrier_enabled) };
CharSequence[] NotchEntries = { getResources().getString(R.string.show_carrier_disabled),
getResources().getString(R.string.show_carrier_keyguard) };
CharSequence[] NonNotchValues = {"0", "1" , "2", "3"};
CharSequence[] NotchValues = {"0", "1"};
mShowCarrierLabel.setEntries(CherishUtils.hasNotch(getActivity()) ? NotchEntries : NonNotchEntries);
mShowCarrierLabel.setEntryValues(CherishUtils.hasNotch(getActivity()) ? NotchValues : NonNotchValues);
mShowCarrierLabel.setValue(String.valueOf(showCarrierLabel));
mShowCarrierLabel.setSummary(mShowCarrierLabel.getEntry());
mShowCarrierLabel.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mShowCarrierLabel) {
int value = Integer.parseInt((String) newValue);
updateCarrierLabelSummary(value);
return true;
}
return false;
}
private void updateCarrierLabelSummary(int value) {
Resources res = getResources();
if (value == 0) {
// Carrier Label disabled
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_disabled));
} else if (value == 1) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_keyguard));
} else if (value == 2) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_statusbar));
} else if (value == 3) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_enabled));
}
}
public boolean onPreferenceTreeClick(Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
boolean value;