Cherish: Rework cutout force fullscreen pref

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Pranav Vashi
2022-02-11 02:00:15 +05:30
committed by Hưng Phan
parent 77180c6bd9
commit 5680e6ea30
5 changed files with 65 additions and 69 deletions

View File

@@ -34,10 +34,11 @@
<Preference <Preference
android:key="display_cutout_force_fullscreen_settings" android:key="display_cutout_force_fullscreen_settings"
android:title="@string/display_cutout_force_fullscreen_title" android:title="@string/display_cutout_force_fullscreen_title"
android:summary="@string/display_cutout_force_fullscreen_summary" android:summary="@string/display_cutout_force_fullscreen_summary">
android:fragment="com.cherish.settings.fragments.DisplayCutoutForceFullscreenSettings" <intent android:action="android.intent.action.MAIN"
settings:controller="com.cherish.settings.fragments.DisplayCutoutForceFullscreenPreferenceController" /> android:targetPackage="com.android.settings"
android:targetClass="com.cherish.settings.fragments.DisplayCutoutForceFullscreenActivity"/>
</Preference>
<com.cherish.settings.preferences.SystemSettingSwitchPreference <com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="use_photos_spoof" android:key="use_photos_spoof"

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2022 crDroid Android 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 com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
import com.android.settingslib.collapsingtoolbar.R;
public class DisplayCutoutForceFullscreenActivity extends CollapsingToolbarBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new DisplayCutoutForceFullscreenFragment())
.commit();
}
}

View File

@@ -1,6 +1,5 @@
/* /*
* Copyright (C) 2018 The LineageOS Project * Copyright (C) 2022 crDroid Android Project
* Copyright (C) 2019 PixelExperience
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -37,11 +36,11 @@ import android.widget.SectionIndexer;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import androidx.preference.PreferenceFragment;
import com.android.internal.util.cherish.cutout.CutoutFullscreenController; import com.android.internal.util.cherish.cutout.CutoutFullscreenController;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState;
import java.util.ArrayList; import java.util.ArrayList;
@@ -50,7 +49,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class DisplayCutoutForceFullscreenSettings extends SettingsPreferenceFragment public class DisplayCutoutForceFullscreenFragment extends PreferenceFragment
implements ApplicationsState.Callbacks { implements ApplicationsState.Callbacks {
private ActivityManager mActivityManager; private ActivityManager mActivityManager;
@@ -87,6 +86,11 @@ public class DisplayCutoutForceFullscreenSettings extends SettingsPreferenceFrag
return inflater.inflate(R.layout.cutout_force_fullscreen_layout, container, false); return inflater.inflate(R.layout.cutout_force_fullscreen_layout, container, false);
} }
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
@@ -152,7 +156,7 @@ public class DisplayCutoutForceFullscreenSettings extends SettingsPreferenceFrag
private void handleAppEntries(List<ApplicationsState.AppEntry> entries) { private void handleAppEntries(List<ApplicationsState.AppEntry> entries) {
final ArrayList<String> sections = new ArrayList<String>(); final ArrayList<String> sections = new ArrayList<String>();
final ArrayList<Integer> positions = new ArrayList<Integer>(); final ArrayList<Integer> positions = new ArrayList<Integer>();
final PackageManager pm = getPackageManager(); final PackageManager pm = getActivity().getPackageManager();
String lastSectionIndex = null; String lastSectionIndex = null;
int offset = 0; int offset = 0;
@@ -349,28 +353,15 @@ public class DisplayCutoutForceFullscreenSettings extends SettingsPreferenceFrag
@Override @Override
public void init() {} public void init() {}
private final String[] hideApps = {"com.android.settings", "com.android.documentsui",
"com.android.fmradio", "com.caf.fmradio", "com.android.stk",
"com.google.android.calculator", "com.google.android.calendar",
"com.google.android.deskclock", "com.google.android.contacts",
"com.google.android.apps.messaging", "com.google.android.googlequicksearchbox",
"com.android.vending", "com.google.android.dialer",
"com.google.android.apps.wallpaper", "com.google.android.as"};
@Override @Override
public boolean filterApp(ApplicationsState.AppEntry entry) { public boolean filterApp(ApplicationsState.AppEntry entry) {
boolean show = !mAllPackagesAdapter.mEntries.contains(entry.info.packageName); boolean show = !mAllPackagesAdapter.mEntries.contains(entry.info.packageName);
if (show) { if (show) {
synchronized (mLauncherResolveInfoList) { synchronized (mLauncherResolveInfoList) {
show = mLauncherResolveInfoList.contains(entry.info.packageName) && !Arrays.asList(hideApps).contains(entry.info.packageName); show = mLauncherResolveInfoList.contains(entry.info.packageName) && !entry.info.isSystemApp();
} }
} }
return show; return show;
} }
} }
}
@Override
public int getMetricsCategory() {
return MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -45,12 +45,14 @@ import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MiscSettings extends SettingsPreferenceFragment implements public class MiscSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener { OnPreferenceChangeListener {
private static final String KEY_FORCE_FULL_SCREEN = "display_cutout_force_fullscreen_settings";
private static final String KEY_PHOTOS_SPOOF = "use_photos_spoof"; private static final String KEY_PHOTOS_SPOOF = "use_photos_spoof";
private static final String KEY_STREAM_SPOOF = "use_stream_spoof"; private static final String KEY_STREAM_SPOOF = "use_stream_spoof";
private static final String SYS_PHOTOS_SPOOF = "persist.sys.photo"; private static final String SYS_PHOTOS_SPOOF = "persist.sys.photo";
private static final String SYS_STREAM_SPOOF = "persist.sys.stream"; private static final String SYS_STREAM_SPOOF = "persist.sys.stream";
private Preference mShowCutoutForce;
private SwitchPreference mPhotosSpoof; private SwitchPreference mPhotosSpoof;
private SwitchPreference mStreamSpoof; private SwitchPreference mStreamSpoof;
@@ -62,6 +64,14 @@ public class MiscSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_misc); addPreferencesFromResource(R.xml.cherish_settings_misc);
final PreferenceScreen prefSet = getPreferenceScreen(); final PreferenceScreen prefSet = getPreferenceScreen();
Context mContext = getActivity().getApplicationContext();
final String displayCutout =
mContext.getResources().getString(com.android.internal.R.string.config_mainBuiltInDisplayCutout);
mShowCutoutForce = (Preference) findPreference(KEY_FORCE_FULL_SCREEN);
if (TextUtils.isEmpty(displayCutout)) {
prefSet.removePreference(mShowCutoutForce);
}
final String usePhotosSpoof = SystemProperties.get(SYS_PHOTOS_SPOOF, "1"); final String usePhotosSpoof = SystemProperties.get(SYS_PHOTOS_SPOOF, "1");
mPhotosSpoof = (SwitchPreference) findPreference(KEY_PHOTOS_SPOOF); mPhotosSpoof = (SwitchPreference) findPreference(KEY_PHOTOS_SPOOF);
@@ -136,6 +146,12 @@ public class MiscSettings extends SettingsPreferenceFragment implements
@Override @Override
public List<String> getNonIndexableKeys(Context context) { public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context); List<String> keys = super.getNonIndexableKeys(context);
final String displayCutout =
context.getResources().getString(com.android.internal.R.string.config_mainBuiltInDisplayCutout);
if (TextUtils.isEmpty(displayCutout)) {
keys.add(KEY_FORCE_FULL_SCREEN);
}
return keys; return keys;
} }
}; };

View File

@@ -1,43 +0,0 @@
/*
* Copyright (C) 2019 The PixelExperience 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.content.Context;
import android.provider.Settings;
import android.os.Handler;
import android.os.UserHandle;
import com.android.internal.util.cherish.cutout.CutoutFullscreenController;
import com.android.settings.core.BasePreferenceController;
public class DisplayCutoutForceFullscreenPreferenceController extends BasePreferenceController {
private static final String PREF_KEY = "display_cutout_force_fullscreen_settings";
private CutoutFullscreenController mCutoutForceFullscreenSettings;
public DisplayCutoutForceFullscreenPreferenceController(Context context) {
super(context, PREF_KEY);
mCutoutForceFullscreenSettings = new CutoutFullscreenController(new Handler(), context);
}
@Override
public int getAvailabilityStatus() {
return mCutoutForceFullscreenSettings.isSupported() ?
AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
}