diff --git a/res/drawable/ic_cutout.xml b/res/drawable/ic_cutout.xml new file mode 100644 index 0000000..8d1b239 --- /dev/null +++ b/res/drawable/ic_cutout.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 80cb192..c5a45fb 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -1242,4 +1242,16 @@ 0 1 + + + @string/display_cutout_style_normal + @string/display_cutout_style_immerse + @string/display_cutout_style_hide + + + + 0 + 1 + 2 + diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index ce4041b..5320323 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -1158,4 +1158,14 @@ Status bar lyric Show lyric in status bar (need App support) + + + Display Cutout + They really cut corners with this one + Cutout style + Normal + Immerse + Hide + Stock statusbar height + Use default statusbar height in Hide diff --git a/res/xml/cherish_settings_statusbar.xml b/res/xml/cherish_settings_statusbar.xml index 0875687..44bcc56 100644 --- a/res/xml/cherish_settings_statusbar.xml +++ b/res/xml/cherish_settings_statusbar.xml @@ -83,6 +83,12 @@ android:summary="@string/carrier_label_settings_summary" android:fragment="com.cherish.settings.fragments.CustomCarrierLabel" /> + + + + + + + + + + + diff --git a/src/com/cherish/settings/fragments/StatusBarSettings.java b/src/com/cherish/settings/fragments/StatusBarSettings.java index 23a3a34..cb4fc06 100644 --- a/src/com/cherish/settings/fragments/StatusBarSettings.java +++ b/src/com/cherish/settings/fragments/StatusBarSettings.java @@ -46,6 +46,8 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements private SystemSettingMasterSwitchPreference mStatusBarLogo; + private static final String PREF_KEY_CUTOUT = "cutout_settings"; + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -61,6 +63,7 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements Settings.System.STATUS_BAR_LOGO, 0) == 1)); mStatusBarLogo.setOnPreferenceChangeListener(this); + Preference mCutoutPref = (Preference) findPreference(PREF_KEY_CUTOUT); } @Override diff --git a/src/com/cherish/settings/preferences/fragments/CutoutFragment.java b/src/com/cherish/settings/preferences/fragments/CutoutFragment.java new file mode 100644 index 0000000..1ab2ddc --- /dev/null +++ b/src/com/cherish/settings/preferences/fragments/CutoutFragment.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2018 The Potato Open Sauce 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.cherish.settings.fragments; + +import android.os.Bundle; +import android.content.Context; +import android.preference.Preference.OnPreferenceChangeListener; +import android.provider.SearchIndexableResource; +import android.provider.Settings; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceScreen; +import androidx.preference.PreferenceFragment; + +import com.android.settings.R; +import com.android.internal.logging.nano.MetricsProto; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settingslib.search.Indexable; +import com.android.settings.SettingsPreferenceFragment; + +import java.util.ArrayList; +import java.util.List; + +public class CutoutFragment extends SettingsPreferenceFragment + implements Preference.OnPreferenceChangeListener, Indexable { + + private static final String KEY_DISPLAY_CUTOUT_STYLE = "display_cutout_style"; + private ListPreference mCutoutStyle; + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference == mCutoutStyle) { + String value = (String) newValue; + Settings.System.putInt(getContentResolver(), Settings.System.DISPLAY_CUTOUT_MODE, Integer.valueOf(value)); + int valueIndex = mCutoutStyle.findIndexOfValue(value); + mCutoutStyle.setValueIndex(valueIndex >= 0 ? valueIndex : 0); + mCutoutStyle.setSummary(mCutoutStyle.getEntries()[valueIndex]); + } + return false; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.cutout); + mCutoutStyle = (ListPreference) findPreference(KEY_DISPLAY_CUTOUT_STYLE); + int cutoutStyle = Settings.System.getInt(getContentResolver(), + Settings.System.DISPLAY_CUTOUT_MODE, 0); + int valueIndex = mCutoutStyle.findIndexOfValue(String.valueOf(cutoutStyle)); + mCutoutStyle.setValueIndex(valueIndex >= 0 ? valueIndex : 0); + mCutoutStyle.setSummary(mCutoutStyle.getEntry()); + mCutoutStyle.setOnPreferenceChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { + + @Override + public List getXmlResourcesToIndex(Context context, boolean enabled) { + List indexables = new ArrayList<>(); + SearchIndexableResource indexable = new SearchIndexableResource(context); + indexable.xmlResId = R.xml.cutout; + indexables.add(indexable); + return indexables; + } + + @Override + public List getNonIndexableKeys(Context context) { + List keys = super.getNonIndexableKeys(context); + return keys; + } + }; + + @Override + public int getMetricsCategory() { + return MetricsProto.MetricsEvent.CHERISH_SETTINGS; + } +}