Permalink
Browse files

Modifications to CMSettings

Added Backlight
Added SettingFragment class as a bse for Fragments
Added start of easier process to add Inline switches
Added switch for Expanded View Widget
  • Loading branch information...
1 parent 8d7048d commit 67609133ea930c17918a5fea9430b813053fbb0f @Pedlar committed Dec 3, 2011
View
@@ -34,6 +34,7 @@
android:taskAffinity="com.cyanogenmod.settings">
</activity>
+ <!-- Notification Widget -->
<activity android:name="Settings$PowerWidgetActivity"
android:label="@string/title_widget_buttons"
android:configChanges="orientation|keyboardHidden|screenSize"
@@ -63,7 +64,6 @@
android:resource="@id/power_widget_settings" />
<meta-data android:name="com.cyanogenmod.settings.PARENT_FRAGMENT_TITLE"
android:value="@string/title_widget_buttons" />
-
<meta-data android:name="com.cyanogenmod.settings.PARENT_FRAGMENT_CLASS"
android:value="com.cyanogenmod.settings.Settings$PowerWidgetActivity" />
</activity>
@@ -82,10 +82,33 @@
android:resource="@id/power_widget_settings" />
<meta-data android:name="com.cyanogenmod.settings.PARENT_FRAGMENT_TITLE"
android:value="@string/title_widget_buttons" />
-
<meta-data android:name="com.cyanogenmod.settings.PARENT_FRAGMENT_CLASS"
android:value="com.cyanogenmod.settings.Settings$PowerWidgetActivity" />
</activity>
+ <!--- End Notification Widget -->
+ <!--- Backlight -->
+ <activity android:name="Settings$BackLightActivity"
+ android:label="@string/backlight_title"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:clearTaskOnLaunch="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <action android:name="android.cyanogenmod.BACKLIGHT_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.cyanogenmod.settings.FRAGMENT_CLASS"
+ android:value="com.cyanogenmod.settings.activities.Backlight" />
+ <meta-data android:name="com.cyanogenmod.settings.TOP_LEVEL_HEADER_ID"
+ android:resource="@id/backlight_settings" />
+ </activity>
+
+ <activity android:name=".activities.LightLevelsActivity"
+ android:configChanges="keyboard|keyboardHidden|orientation">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <!--- End Backlight -->
</application>
- <activity android:name=".activities.PowerWidget$PowerWidgetOrder" android:label="@string/title_widget_order"> </activity>
</manifest>
View
@@ -4,3 +4,4 @@
-keep class com.cyanogenmod.settings.*
-keep class com.cyanogenmod.settings.utils.*
-keep class com.cyanogenmod.settings.widget.*
+-keep class com.cyanogenmod.settings.switches.*
@@ -59,8 +59,8 @@
android:title="@string/light_levels_editor_title"
android:dependency="light_levels_enabled">
<intent android:action="android.intent.action.MAIN"
- android:targetPackage="com.cyanogenmod.cmparts"
- android:targetClass="com.cyanogenmod.cmparts.activities.LightLevelsActivity" />
+ android:targetPackage="com.cyanogenmod.settings"
+ android:targetClass="com.cyanogenmod.settings.activities.LightLevelsActivity" />
</PreferenceScreen>
<!-- Allow screen brightness to decrease -->
@@ -78,4 +78,4 @@
android:entryValues="@array/values_light_decrease_hysteresis"
android:dependency="light_decrease_enabled" android:persistent="false" />
</PreferenceCategory>
-</PreferenceScreen>
+</PreferenceScreen>
View
@@ -1,11 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <!-- Application Settings -->
+ <header android:title="@string/application_settings_title_head" />
+
+ <!-- Display Settings -->
+ <header android:title="@string/display_settings_title_head" />
+
+ <!-- Input Settings -->
+ <header android:title="@string/input_settings_title_head" />
+
+ <!-- Interface Settings -->
<header android:title="@string/interface_settings_title_head" />
-
<header
android:id="@+id/power_widget_settings"
android:fragment="com.cyanogenmod.settings.activities.PowerWidget"
android:title="@string/title_widget_buttons"
/>
+ <header
+ android:id="@+id/backlight_settings"
+ android:fragment="com.cyanogenmod.settings.activities.Backlight"
+ android:title="@string/backlight_title"
+ />
+
+ <!-- Performance settings -->
+ <header android:title="@string/performance_settings_title_head" />
+
+ <!-- Sound settings -->
+ <header android:title="@string/sound_settings_title_head" />
+
+ <!-- System Settings -->
+ <header android:title="@string/system_settings_title_head" />
+
+ <!-- Tablet Tweaks -->
+ <header android:title="@string/tablet_tweaks_title_head" />
+
</preference-headers>
@@ -29,6 +29,8 @@
import com.cyanogenmod.settings.R;
+import com.cyanogenmod.settings.switches.PowerWidgetEnabler;
+
public class Settings extends PreferenceActivity {
private static final String LOG_TAG = "Settings";
@@ -288,6 +290,7 @@ public Intent getIntent() {
static final int HEADER_TYPE_SWITCH = 2;
private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1;
+ private final PowerWidgetEnabler mWidgetEnabler;
private static class HeaderViewHolder {
ImageView icon;
@@ -301,9 +304,9 @@ public Intent getIntent() {
static int getHeaderType(Header header) {
if (header.fragment == null && header.intent == null) {
return HEADER_TYPE_CATEGORY;
- } /*else if (header.id == R.id.power_widget_settings) {
+ } else if (header.id == R.id.power_widget_settings) {
return HEADER_TYPE_SWITCH;
- }*/ else {
+ } else {
return HEADER_TYPE_NORMAL;
}
}
@@ -344,6 +347,7 @@ public HeaderAdapter(Context context, List<Header> objects) {
mWifiEnabler = new WifiEnabler(context, new Switch(context));
mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
*/
+ mWidgetEnabler = new PowerWidgetEnabler(context, new Switch(context));
}
@Override
@@ -394,6 +398,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
break;
case HEADER_TYPE_SWITCH:
+ if (header.id == R.id.power_widget_settings) {
+ mWidgetEnabler.setSwitch(holder.switch_);
+ }
//$FALL-THROUGH$
case HEADER_TYPE_NORMAL:
holder.icon.setImageResource(header.iconRes);
@@ -412,9 +419,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
public void resume() {
+ mWidgetEnabler.resume();
}
public void pause() {
+ mWidgetEnabler.pause();
}
}
@@ -440,4 +449,5 @@ public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference p
public static class PowerWidgetActivity extends Settings { /* */ }
public static class PowerWidgetChooserActivity extends Settings { /* */ }
public static class PowerWidgetOrderActivity extends Settings { /* */ }
+ public static class BackLightActivity extends Settings { /* */ }
}
@@ -0,0 +1,26 @@
+package com.cyanogenmod.settings;
+
+import android.app.Fragment;
+import android.content.ContentResolver;
+import android.content.pm.PackageManager;
+import android.content.Context;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
+
+public class SettingsFragment extends PreferenceFragment {
+
+ @Override
+ public void onActivityCreated(Bundle icicle) {
+ super.onActivityCreated(icicle);
+ }
+
+ public ContentResolver getContentResolver() {
+ return getActivity().getContentResolver();
+ }
+
+ public Context getContext() {
+ return getActivity().getApplicationContext();
+ }
+}
+
@@ -0,0 +1,144 @@
+package com.cyanogenmod.settings.activities;
+
+import com.cyanogenmod.settings.R;
+
+import android.content.ContentResolver;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.provider.Settings;
+
+import com.cyanogenmod.settings.SettingsFragment;
+
+public class Backlight extends SettingsFragment implements
+ OnPreferenceChangeListener {
+
+ private static final String FILTER_ENABLED = "light_filter_enabled";
+ private static final String FILTER_WINDOW = "light_filter_window";
+ private static final String FILTER_RESET = "light_filter_reset";
+ private static final String FILTER_INTERVAL = "light_filter_interval";
+ private static final String LEVELS_ENABLED = "light_levels_enabled";
+ private static final String SCREEN_DIM = "light_levels_dim";
+ private static final String DECREASE_ENABLED = "light_decrease_enabled";
+ private static final String DECREASE_HYSTERESIS = "light_decrease_hysteresis";
+
+ private CheckBoxPreference mFilterEnabled;
+ private ListPreference mFilterWindow;
+ private ListPreference mFilterReset;
+ private ListPreference mFilterInterval;
+ private CheckBoxPreference mLevelsEnabled;
+ private ListPreference mScreenDim;
+ private CheckBoxPreference mDecreaseEnabled;
+ private ListPreference mDecreaseHysteresis;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.backlight_settings);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+ ContentResolver cr = getContentResolver();
+
+ mFilterEnabled = (CheckBoxPreference) prefSet.findPreference(FILTER_ENABLED);
+ mFilterEnabled.setChecked(Settings.System.getInt(cr,
+ Settings.System.LIGHT_FILTER, 0) != 0);
+ mFilterEnabled.setOnPreferenceChangeListener(this);
+
+ mFilterReset = (ListPreference) prefSet.findPreference(FILTER_RESET);
+ mFilterReset.setValue(String.valueOf(Settings.System.getInt(cr,
+ Settings.System.LIGHT_FILTER_RESET, -1)));
+ mFilterReset.setOnPreferenceChangeListener(this);
+
+ mFilterWindow = (ListPreference) prefSet.findPreference(FILTER_WINDOW);
+ mFilterWindow.setValue(String.valueOf(Settings.System.getInt(cr,
+ Settings.System.LIGHT_FILTER_WINDOW, 30000)));
+ mFilterWindow.setOnPreferenceChangeListener(this);
+
+ mFilterInterval = (ListPreference) prefSet.findPreference(FILTER_INTERVAL);
+ mFilterInterval.setValue(String.valueOf(Settings.System.getInt(cr,
+ Settings.System.LIGHT_FILTER_INTERVAL, 1000)));
+ mFilterInterval.setOnPreferenceChangeListener(this);
+
+ mLevelsEnabled = (CheckBoxPreference) prefSet.findPreference(LEVELS_ENABLED);
+ mLevelsEnabled.setChecked(Settings.System.getInt(cr,
+ Settings.System.LIGHT_SENSOR_CUSTOM, 0) != 0);
+ mLevelsEnabled.setOnPreferenceChangeListener(this);
+
+ mScreenDim = (ListPreference) prefSet.findPreference(SCREEN_DIM);
+ mScreenDim.setValue(String.valueOf(Settings.System.getInt(cr,
+ Settings.System.LIGHT_SCREEN_DIM,
+ android.os.Power.BRIGHTNESS_DIM)));
+ mScreenDim.setOnPreferenceChangeListener(this);
+
+ mDecreaseEnabled = (CheckBoxPreference) prefSet.findPreference(DECREASE_ENABLED);
+ mDecreaseEnabled.setChecked(Settings.System.getInt(cr,
+ Settings.System.LIGHT_DECREASE, 0) != 0);
+ mDecreaseEnabled.setOnPreferenceChangeListener(this);
+
+ mDecreaseHysteresis = (ListPreference) prefSet.findPreference(DECREASE_HYSTERESIS);
+ mDecreaseHysteresis.setValue(String.valueOf(Settings.System.getInt(cr,
+ Settings.System.LIGHT_HYSTERESIS, 50)));
+ mDecreaseHysteresis.setOnPreferenceChangeListener(this);
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ boolean handled = false;
+
+ if (preference == mFilterEnabled) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_FILTER, getBoolean(newValue) ? 1 : 0);
+ handled = true;
+ } else if (preference == mFilterWindow) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_FILTER_WINDOW, getInt(newValue));
+ handled = true;
+ } else if (preference == mFilterReset) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_FILTER_RESET, getInt(newValue));
+ handled = true;
+ } else if (preference == mFilterInterval) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_FILTER_INTERVAL, getInt(newValue));
+ handled = true;
+ } else if (preference == mScreenDim) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_SCREEN_DIM, getInt(newValue));
+ handled = true;
+ } else if (preference == mLevelsEnabled) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_SENSOR_CUSTOM, getBoolean(newValue) ? 1 : 0);
+ handled = true;
+ } else if (preference == mDecreaseEnabled) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_DECREASE, getBoolean(newValue) ? 1 : 0);
+ handled = true;
+ } else if (preference == mDecreaseHysteresis) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.LIGHT_HYSTERESIS, getInt(newValue));
+ handled = true;
+ }
+
+ // Force the system to reload settings and reinit
+ if (handled) {
+ long tag = Settings.System.getLong(getContentResolver(),
+ Settings.System.LIGHTS_CHANGED, 0) + 1;
+ Settings.System.putLong(getContentResolver(), Settings.System.LIGHTS_CHANGED, tag);
+ }
+
+ return handled;
+ }
+
+ private boolean getBoolean(Object o) {
+ return Boolean.valueOf(o.toString());
+ }
+
+ private int getInt(Object o) {
+ return Integer.valueOf(o.toString());
+ }
+}
Oops, something went wrong.

0 comments on commit 6760913

Please sign in to comment.