Advertisement
Nico_60

Untitled

Mar 2nd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2015 The CyanogenMod Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.android.settings.cyanogenmod;
  17.  
  18. import android.content.ContentResolver;
  19. import android.content.Context;
  20. import android.content.res.Resources;
  21. import android.os.Bundle;
  22. import android.os.UserHandle;
  23. import android.preference.ListPreference;
  24. import android.preference.Preference;
  25. import android.preference.Preference.OnPreferenceChangeListener;
  26. import android.preference.PreferenceScreen;
  27. import android.preference.SwitchPreference;
  28. import android.provider.Settings;
  29.  
  30. import android.provider.SearchIndexableResource;
  31. import com.android.settings.R;
  32. import com.android.settings.SettingsPreferenceFragment;
  33. import com.android.settings.cyanogenmod.qs.QSTiles;
  34. import com.android.settings.search.BaseSearchIndexProvider;
  35. import com.android.settings.search.Indexable;
  36.  
  37. import java.util.ArrayList;
  38. import java.util.List;
  39.  
  40. import com.android.internal.widget.LockPatternUtils;
  41.  
  42. public class NotificationDrawerSettings extends SettingsPreferenceFragment implements Indexable,
  43. Preference.OnPreferenceChangeListener {
  44. private static final String QUICK_PULLDOWN = "quick_pulldown";
  45. private static final String PREF_BLOCK_ON_SECURE_KEYGUARD = "block_on_secure_keyguard";
  46.  
  47. private ListPreference mQuickPulldown;
  48. private Preference mQSTiles;
  49.  
  50. @Override
  51. public void onCreate(Bundle savedInstanceState) {
  52. super.onCreate(savedInstanceState);
  53. addPreferencesFromResource(R.xml.notification_drawer_settings);
  54.  
  55. mQSTiles = findPreference("qs_order");
  56. }
  57.  
  58. @Override
  59. public void onActivityCreated(Bundle savedInstanceState) {
  60. super.onActivityCreated(savedInstanceState);
  61.  
  62. PreferenceScreen prefSet = getPreferenceScreen();
  63. ContentResolver resolver = getActivity().getContentResolver();
  64. mQuickPulldown = (ListPreference) prefSet.findPreference(QUICK_PULLDOWN);
  65.  
  66. mQuickPulldown.setOnPreferenceChangeListener(this);
  67. int quickPulldownValue = Settings.System.getIntForUser(resolver,
  68. Settings.System.QS_QUICK_PULLDOWN, 0, UserHandle.USER_CURRENT);
  69. mQuickPulldown.setValue(String.valueOf(quickPulldownValue));
  70. updatePulldownSummary(quickPulldownValue);
  71.  
  72. final LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
  73. mBlockOnSecureKeyguard = (SwitchPreference) findPreference(PREF_BLOCK_ON_SECURE_KEYGUARD);
  74. if (lockPatternUtils.isSecure()) {
  75. mBlockOnSecureKeyguard.setChecked(Settings.Secure.getInt(getContentResolver(),
  76. Settings.Secure.STATUS_BAR_LOCKED_ON_SECURE_KEYGUARD, 1) == 1);
  77. mBlockOnSecureKeyguard.setOnPreferenceChangeListener(this);
  78. } else {
  79. prefSet.removePreference(mBlockOnSecureKeyguard);
  80. }
  81. }
  82.  
  83. @Override
  84. public void onResume() {
  85. super.onResume();
  86.  
  87. int qsTileCount = QSTiles.determineTileCount(getActivity());
  88. mQSTiles.setSummary(getResources().getQuantityString(R.plurals.qs_tiles_summary,
  89. qsTileCount, qsTileCount));
  90. }
  91.  
  92. @Override
  93. public boolean onPreferenceChange(Preference preference, Object newValue) {
  94. ContentResolver resolver = getContentResolver();
  95. if (preference == mQuickPulldown) {
  96. int quickPulldownValue = Integer.valueOf((String) newValue);
  97. Settings.System.putIntForUser(resolver, Settings.System.QS_QUICK_PULLDOWN,
  98. quickPulldownValue, UserHandle.USER_CURRENT);
  99. updatePulldownSummary(quickPulldownValue);
  100. return true;
  101. } else if (preference == mBlockOnSecureKeyguard) {
  102. Settings.Secure.putInt(getContentResolver(),
  103. Settings.Secure.STATUS_BAR_LOCKED_ON_SECURE_KEYGUARD,
  104. (Boolean) newValue ? 1 : 0);
  105. return true;
  106. }
  107. return false;
  108. }
  109.  
  110. private void updatePulldownSummary(int value) {
  111. Resources res = getResources();
  112.  
  113. if (value == 0) {
  114. // quick pulldown deactivated
  115. mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_off));
  116. } else {
  117. String direction = res.getString(value == 2
  118. ? R.string.quick_pulldown_summary_left
  119. : R.string.quick_pulldown_summary_right);
  120. mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_summary, direction));
  121. }
  122. }
  123.  
  124. public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
  125. new BaseSearchIndexProvider() {
  126. @Override
  127. public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
  128. boolean enabled) {
  129. ArrayList<SearchIndexableResource> result =
  130. new ArrayList<SearchIndexableResource>();
  131.  
  132. SearchIndexableResource sir = new SearchIndexableResource(context);
  133. sir.xmlResId = R.xml.notification_drawer_settings;
  134. result.add(sir);
  135.  
  136. return result;
  137. }
  138.  
  139. @Override
  140. public List<String> getNonIndexableKeys(Context context) {
  141. return new ArrayList<String>();
  142. }
  143. };
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement