Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2015 The CyanogenMod 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.android.settings.cyanogenmod;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.res.Resources;
- import android.os.Bundle;
- import android.os.UserHandle;
- import android.preference.ListPreference;
- import android.preference.Preference;
- import android.preference.Preference.OnPreferenceChangeListener;
- import android.preference.PreferenceScreen;
- import android.preference.SwitchPreference;
- import android.provider.Settings;
- import android.provider.SearchIndexableResource;
- import com.android.settings.R;
- import com.android.settings.SettingsPreferenceFragment;
- import com.android.settings.cyanogenmod.qs.QSTiles;
- import com.android.settings.search.BaseSearchIndexProvider;
- import com.android.settings.search.Indexable;
- import java.util.ArrayList;
- import java.util.List;
- import com.android.internal.widget.LockPatternUtils;
- public class NotificationDrawerSettings extends SettingsPreferenceFragment implements Indexable,
- Preference.OnPreferenceChangeListener {
- private static final String QUICK_PULLDOWN = "quick_pulldown";
- private static final String PREF_BLOCK_ON_SECURE_KEYGUARD = "block_on_secure_keyguard";
- private ListPreference mQuickPulldown;
- private Preference mQSTiles;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.notification_drawer_settings);
- mQSTiles = findPreference("qs_order");
- }
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- PreferenceScreen prefSet = getPreferenceScreen();
- ContentResolver resolver = getActivity().getContentResolver();
- mQuickPulldown = (ListPreference) prefSet.findPreference(QUICK_PULLDOWN);
- mQuickPulldown.setOnPreferenceChangeListener(this);
- int quickPulldownValue = Settings.System.getIntForUser(resolver,
- Settings.System.QS_QUICK_PULLDOWN, 0, UserHandle.USER_CURRENT);
- mQuickPulldown.setValue(String.valueOf(quickPulldownValue));
- updatePulldownSummary(quickPulldownValue);
- final LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
- mBlockOnSecureKeyguard = (SwitchPreference) findPreference(PREF_BLOCK_ON_SECURE_KEYGUARD);
- if (lockPatternUtils.isSecure()) {
- mBlockOnSecureKeyguard.setChecked(Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.STATUS_BAR_LOCKED_ON_SECURE_KEYGUARD, 1) == 1);
- mBlockOnSecureKeyguard.setOnPreferenceChangeListener(this);
- } else {
- prefSet.removePreference(mBlockOnSecureKeyguard);
- }
- }
- @Override
- public void onResume() {
- super.onResume();
- int qsTileCount = QSTiles.determineTileCount(getActivity());
- mQSTiles.setSummary(getResources().getQuantityString(R.plurals.qs_tiles_summary,
- qsTileCount, qsTileCount));
- }
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- ContentResolver resolver = getContentResolver();
- if (preference == mQuickPulldown) {
- int quickPulldownValue = Integer.valueOf((String) newValue);
- Settings.System.putIntForUser(resolver, Settings.System.QS_QUICK_PULLDOWN,
- quickPulldownValue, UserHandle.USER_CURRENT);
- updatePulldownSummary(quickPulldownValue);
- return true;
- } else if (preference == mBlockOnSecureKeyguard) {
- Settings.Secure.putInt(getContentResolver(),
- Settings.Secure.STATUS_BAR_LOCKED_ON_SECURE_KEYGUARD,
- (Boolean) newValue ? 1 : 0);
- return true;
- }
- return false;
- }
- private void updatePulldownSummary(int value) {
- Resources res = getResources();
- if (value == 0) {
- // quick pulldown deactivated
- mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_off));
- } else {
- String direction = res.getString(value == 2
- ? R.string.quick_pulldown_summary_left
- : R.string.quick_pulldown_summary_right);
- mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_summary, direction));
- }
- }
- public static final Indexable.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.notification_drawer_settings;
- result.add(sir);
- return result;
- }
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- return new ArrayList<String>();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement