Cherish:Hide FOD if devices not supported

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Hưng Phan
2021-07-04 14:14:15 +07:00
parent 02e2156ffe
commit 2a8495d42f
5 changed files with 80 additions and 188 deletions

View File

@@ -1,103 +0,0 @@
/*
* Copyright (C) 2021 The CherishOS 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.lockscreen;
import com.android.internal.logging.nano.MetricsProto;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.provider.Settings;
import com.android.settings.R;
import android.os.SystemProperties;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceCategory;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable;
import java.util.Locale;
import android.text.TextUtils;
import android.view.View;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
import com.android.settings.Utils;
import android.util.Log;
import android.hardware.fingerprint.FingerprintManager;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
@SearchIndexable
public class FODSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Indexable {
private ContentResolver mResolver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fod_settings);
PreferenceScreen prefScreen = getPreferenceScreen();
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
return false;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.fod_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
};
}

View File

@@ -39,6 +39,7 @@ import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.internal.util.cherish.FodUtils;
import com.android.internal.util.cherish.CherishUtils;
import com.cherish.settings.preferences.SystemSettingListPreference;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.cherish.settings.preferences.SecureSettingListPreference;
@@ -61,7 +62,8 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
private static final String DATE_FONT_SIZE = "lockdate_font_size";
private static final String LOCKOWNER_FONT_SIZE = "lockowner_font_size";
private static final String AOD_SCHEDULE_KEY = "always_on_display_schedule";
private static final String LOCKSCREEN_FOD_CATEGORY = "lockscreen_fod_category";
private static final String FOD_ANIMATION_CATEGORY = "fod_animations";
private static final String FOD_ICON_PICKER_CATEGORY = "fod_icon_picker";
private ContentResolver mResolver;
private Preference FODSettings;
@@ -75,6 +77,7 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
private CustomSeekBarPreference mDateFontSize;
private CustomSeekBarPreference mOwnerInfoFontSize;
private CustomSeekBarPreference mCustomTextClockFontSize;
private PreferenceCategory mFODIconPickerCategory;
private Preference mAODPref;
@Override
@@ -83,13 +86,20 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_lockscreen);
ContentResolver resolver = getActivity().getContentResolver();
final PreferenceScreen prefScreen = getPreferenceScreen();
PreferenceScreen prefScreen = getPreferenceScreen();
Resources resources = getResources();
FODSettings = (Preference) findPreference(LOCKSCREEN_FOD_CATEGORY);
if (FODSettings != null
&& !getResources().getBoolean(com.android.internal.R.bool.config_needCustomFODView)) {
prefScreen.removePreference(FODSettings);
mFODIconPickerCategory = findPreference(FOD_ICON_PICKER_CATEGORY);
if (mFODIconPickerCategory != null && !FodUtils.hasFodSupport(getContext())) {
prefScreen.removePreference(mFODIconPickerCategory);
}
final PreferenceCategory fodCat = (PreferenceCategory) prefScreen
.findPreference(FOD_ANIMATION_CATEGORY);
final boolean isFodAnimationResources = CherishUtils.isPackageInstalled(getContext(),
getResources().getString(com.android.internal.R.string.config_fodAnimationPackage));
if (!isFodAnimationResources) {
prefScreen.removePreference(fodCat);
}
// Lock Clock Size
@@ -197,6 +207,9 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
@Override
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
if (!FodUtils.hasFodSupport(context)) {
keys.add(FOD_ICON_PICKER_CATEGORY);
}
return keys;
}
};