summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/cyanogenmod
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2015-10-29 17:42:25 -0700
committerDanesh M <daneshm90@gmail.com>2015-10-29 18:22:16 -0700
commit98f6c278df782b58a0184218241b3c8360991766 (patch)
tree46d1e1e57c70b6e3db339aee2e3c26c92c84a65f /src/com/android/settings/cyanogenmod
parent3931eaedb8f1fb20247315bb8c6547c42a8aee77 (diff)
downloadpackages_apps_Settings-98f6c278df782b58a0184218241b3c8360991766.zip
packages_apps_Settings-98f6c278df782b58a0184218241b3c8360991766.tar.gz
packages_apps_Settings-98f6c278df782b58a0184218241b3c8360991766.tar.bz2
Revert "Revert "Settings : Port forward statusbar settings""
This reverts commit 4c7e67e680997c15195b1ae96452f8baf3895779. Change-Id: Iaecfc7a36281422a58d469361cef3c6a5659c7d7
Diffstat (limited to 'src/com/android/settings/cyanogenmod')
-rw-r--r--src/com/android/settings/cyanogenmod/StatusBarSettings.java192
1 files changed, 192 insertions, 0 deletions
diff --git a/src/com/android/settings/cyanogenmod/StatusBarSettings.java b/src/com/android/settings/cyanogenmod/StatusBarSettings.java
new file mode 100644
index 0000000..a2762f4
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/StatusBarSettings.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2014-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.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.format.DateFormat;
+import android.view.View;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import cyanogenmod.providers.CMSettings;
+
+public class StatusBarSettings extends SettingsPreferenceFragment
+ implements OnPreferenceChangeListener, Indexable {
+
+ private static final String TAG = "StatusBar";
+
+ private static final String STATUS_BAR_CLOCK_STYLE = "status_bar_clock";
+ private static final String STATUS_BAR_AM_PM = "status_bar_am_pm";
+ private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
+ private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
+
+ private static final int STATUS_BAR_BATTERY_STYLE_HIDDEN = 4;
+ private static final int STATUS_BAR_BATTERY_STYLE_TEXT = 6;
+
+ private ListPreference mStatusBarClock;
+ private ListPreference mStatusBarAmPm;
+ private ListPreference mStatusBarBattery;
+ private ListPreference mStatusBarBatteryShowPercent;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.status_bar_settings);
+
+ ContentResolver resolver = getActivity().getContentResolver();
+
+ mStatusBarClock = (ListPreference) findPreference(STATUS_BAR_CLOCK_STYLE);
+ mStatusBarAmPm = (ListPreference) findPreference(STATUS_BAR_AM_PM);
+ mStatusBarBattery = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
+ mStatusBarBatteryShowPercent =
+ (ListPreference) findPreference(STATUS_BAR_SHOW_BATTERY_PERCENT);
+
+ int clockStyle = CMSettings.System.getInt(resolver,
+ CMSettings.System.STATUS_BAR_CLOCK, 1);
+ mStatusBarClock.setValue(String.valueOf(clockStyle));
+ mStatusBarClock.setSummary(mStatusBarClock.getEntry());
+ mStatusBarClock.setOnPreferenceChangeListener(this);
+
+ if (DateFormat.is24HourFormat(getActivity())) {
+ mStatusBarAmPm.setEnabled(false);
+ mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
+ } else {
+ int statusBarAmPm = CMSettings.System.getInt(resolver,
+ CMSettings.System.STATUS_BAR_AM_PM, 2);
+ mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm));
+ mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry());
+ mStatusBarAmPm.setOnPreferenceChangeListener(this);
+ }
+
+ int batteryStyle = CMSettings.System.getInt(resolver,
+ CMSettings.System.STATUS_BAR_BATTERY_STYLE, 0);
+ mStatusBarBattery.setValue(String.valueOf(batteryStyle));
+ mStatusBarBattery.setSummary(mStatusBarBattery.getEntry());
+ mStatusBarBattery.setOnPreferenceChangeListener(this);
+
+ int batteryShowPercent = CMSettings.System.getInt(resolver,
+ CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
+ mStatusBarBatteryShowPercent.setValue(String.valueOf(batteryShowPercent));
+ mStatusBarBatteryShowPercent.setSummary(mStatusBarBatteryShowPercent.getEntry());
+ enableStatusBarBatteryDependents(batteryStyle);
+ mStatusBarBatteryShowPercent.setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ protected int getMetricsCategory() {
+ // todo add a constant in MetricsLogger.java
+ return MetricsLogger.MAIN_SETTINGS;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ // Adjust clock position for RTL if necessary
+ Configuration config = getResources().getConfiguration();
+ if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
+ mStatusBarClock.setEntries(getActivity().getResources().getStringArray(
+ R.array.status_bar_clock_style_entries_rtl));
+ mStatusBarClock.setSummary(mStatusBarClock.getEntry());
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ ContentResolver resolver = getActivity().getContentResolver();
+ if (preference == mStatusBarClock) {
+ int clockStyle = Integer.parseInt((String) newValue);
+ int index = mStatusBarClock.findIndexOfValue((String) newValue);
+ CMSettings.System.putInt(
+ resolver, CMSettings.System.STATUS_BAR_CLOCK, clockStyle);
+ mStatusBarClock.setSummary(mStatusBarClock.getEntries()[index]);
+ return true;
+ } else if (preference == mStatusBarAmPm) {
+ int statusBarAmPm = Integer.valueOf((String) newValue);
+ int index = mStatusBarAmPm.findIndexOfValue((String) newValue);
+ CMSettings.System.putInt(
+ resolver, CMSettings.System.STATUS_BAR_AM_PM, statusBarAmPm);
+ mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntries()[index]);
+ return true;
+ } else if (preference == mStatusBarBattery) {
+ int batteryStyle = Integer.valueOf((String) newValue);
+ int index = mStatusBarBattery.findIndexOfValue((String) newValue);
+ CMSettings.System.putInt(
+ resolver, CMSettings.System.STATUS_BAR_BATTERY_STYLE, batteryStyle);
+ mStatusBarBattery.setSummary(mStatusBarBattery.getEntries()[index]);
+ enableStatusBarBatteryDependents(batteryStyle);
+ return true;
+ } else if (preference == mStatusBarBatteryShowPercent) {
+ int batteryShowPercent = Integer.valueOf((String) newValue);
+ int index = mStatusBarBatteryShowPercent.findIndexOfValue((String) newValue);
+ CMSettings.System.putInt(
+ resolver, CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, batteryShowPercent);
+ mStatusBarBatteryShowPercent.setSummary(
+ mStatusBarBatteryShowPercent.getEntries()[index]);
+ return true;
+ }
+ return false;
+ }
+
+ private void enableStatusBarBatteryDependents(int batteryIconStyle) {
+ if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_HIDDEN ||
+ batteryIconStyle == STATUS_BAR_BATTERY_STYLE_TEXT) {
+ mStatusBarBatteryShowPercent.setEnabled(false);
+ } else {
+ mStatusBarBatteryShowPercent.setEnabled(true);
+ }
+ }
+
+ 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.status_bar_settings;
+ result.add(sir);
+
+ return result;
+ }
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ ArrayList<String> result = new ArrayList<String>();
+ return result;
+ }
+ };
+}