This repository has been archived on 2025-09-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
android_packages_apps_Cherish/src/com/cherish/settings/fragments/LockScreenSettings.java
2021-07-09 11:47:38 +07:00

230 lines
9.7 KiB
Java

/*
* Copyright (C) 2015 The OmniROM Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cherish.settings.fragments;
import com.android.internal.logging.nano.MetricsProto;
import android.app.Activity;
import android.content.Context;
import android.content.ContentResolver;
import android.app.WallpaperManager;
import android.content.Intent;
import android.content.res.Resources;
import android.hardware.fingerprint.FingerprintManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import androidx.preference.SwitchPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import android.os.SystemProperties;
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.SystemSettingSeekBarPreference;
import com.cherish.settings.utils.Utils;
import com.cherish.settings.preferences.SystemSettingListPreference;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.cherish.settings.preferences.SecureSettingListPreference;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
import com.cherish.settings.preferences.SystemSettingListPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import android.provider.SearchIndexableResource;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class LockScreenSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String CUSTOM_TEXT_CLOCK_FONTS = "custom_text_clock_fonts";
private static final String CLOCK_FONT_SIZE = "lockclock_font_size";
private static final String CUSTOM_TEXT_CLOCK_FONT_SIZE = "custom_text_clock_font_size";
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 FOD_ANIMATION_CATEGORY = "fod_animations";
private static final String FOD_ICON_PICKER_CATEGORY = "fod_icon_picker";
private static final String KEY_LOCKSCREEN_BLUR = "lockscreen_blur";
private ContentResolver mResolver;
private Preference FODSettings;
static final int MODE_DISABLED = 0;
static final int MODE_NIGHT = 1;
static final int MODE_TIME = 2;
static final int MODE_MIXED_SUNSET = 3;
static final int MODE_MIXED_SUNRISE = 4;
private SystemSettingSeekBarPreference mLockscreenBlur;
private CustomSeekBarPreference mClockFontSize;
private CustomSeekBarPreference mDateFontSize;
private CustomSeekBarPreference mOwnerInfoFontSize;
private CustomSeekBarPreference mCustomTextClockFontSize;
private PreferenceCategory mFODIconPickerCategory;
private Preference mAODPref;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.cherish_settings_lockscreen);
Context mContext = getContext();
ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefScreen = getPreferenceScreen();
Resources resources = getResources();
WallpaperManager manager = WallpaperManager.getInstance(mContext);
ParcelFileDescriptor pfd = manager.getWallpaperFile(WallpaperManager.FLAG_LOCK);
mLockscreenBlur = (SystemSettingSeekBarPreference) findPreference(KEY_LOCKSCREEN_BLUR);
if (!Utils.isBlurSupported() || pfd != null) {
prefScreen.removePreference(mLockscreenBlur);
}
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
mClockFontSize = (CustomSeekBarPreference) findPreference(CLOCK_FONT_SIZE);
mClockFontSize.setValue(Settings.System.getInt(getContentResolver(),
Settings.System.LOCKCLOCK_FONT_SIZE, 78));
mClockFontSize.setOnPreferenceChangeListener(this);
// Lock Date Size
mDateFontSize = (CustomSeekBarPreference) findPreference(DATE_FONT_SIZE);
mDateFontSize.setValue(Settings.System.getInt(getContentResolver(),
Settings.System.LOCKDATE_FONT_SIZE, 18));
mDateFontSize.setOnPreferenceChangeListener(this);
// Lockscren OwnerInfo Size
mOwnerInfoFontSize = (CustomSeekBarPreference) findPreference(LOCKOWNER_FONT_SIZE);
mOwnerInfoFontSize.setValue(Settings.System.getInt(getContentResolver(),
Settings.System.LOCKOWNER_FONT_SIZE,21));
mOwnerInfoFontSize.setOnPreferenceChangeListener(this);
// Custom Text Clock Size
mCustomTextClockFontSize = (CustomSeekBarPreference) findPreference(CUSTOM_TEXT_CLOCK_FONT_SIZE);
mCustomTextClockFontSize.setValue(Settings.System.getInt(getContentResolver(),
Settings.System.CUSTOM_TEXT_CLOCK_FONT_SIZE, 40));
mCustomTextClockFontSize.setOnPreferenceChangeListener(this);
mAODPref = findPreference(AOD_SCHEDULE_KEY);
updateAlwaysOnSummary();
}
@Override
public void onResume() {
super.onResume();
updateAlwaysOnSummary();
}
private void updateAlwaysOnSummary() {
if (mAODPref == null) return;
int mode = Settings.Secure.getIntForUser(getActivity().getContentResolver(),
Settings.Secure.DOZE_ALWAYS_ON_AUTO_MODE, MODE_DISABLED, UserHandle.USER_CURRENT);
switch (mode) {
default:
case MODE_DISABLED:
mAODPref.setSummary(R.string.disabled);
break;
case MODE_NIGHT:
mAODPref.setSummary(R.string.night_display_auto_mode_twilight);
break;
case MODE_TIME:
mAODPref.setSummary(R.string.night_display_auto_mode_custom);
break;
case MODE_MIXED_SUNSET:
mAODPref.setSummary(R.string.always_on_display_schedule_mixed_sunset);
break;
case MODE_MIXED_SUNRISE:
mAODPref.setSummary(R.string.always_on_display_schedule_mixed_sunrise);
break;
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mClockFontSize) {
int top = (Integer) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.LOCKCLOCK_FONT_SIZE, top*1);
return true;
} else if (preference == mCustomTextClockFontSize) {
int top = (Integer) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.CUSTOM_TEXT_CLOCK_FONT_SIZE, top*1);
return true;
} else if (preference == mDateFontSize) {
int top = (Integer) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.LOCKDATE_FONT_SIZE, top*1);
return true;
}
return false;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
ArrayList<SearchIndexableResource> result =
new ArrayList<SearchIndexableResource>();
SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.cherish_settings_lockscreen;
result.add(sir);
return result;
}
@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;
}
};
}