Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 67609133ea930c17918a5fea9430b813053fbb0f 1 parent 8d7048d
@Pedlar authored
View
29 AndroidManifest.xml
@@ -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
1  proguard.flags
@@ -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.*
View
6 res/xml/backlight_settings.xml
@@ -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
30 res/xml/main.xml
@@ -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>
View
14 src/com/cyanogenmod/settings/Settings.java
@@ -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 { /* */ }
}
View
26 src/com/cyanogenmod/settings/SettingsFragment.java
@@ -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();
+ }
+}
+
View
144 src/com/cyanogenmod/settings/activities/Backlight.java
@@ -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());
+ }
+}
View
515 src/com/cyanogenmod/settings/activities/LightLevelsActivity.java
@@ -0,0 +1,515 @@
+package com.cyanogenmod.settings.activities;
+
+import com.cyanogenmod.settings.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.ContentResolver;
+import android.content.DialogInterface;
+import android.content.res.Configuration;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IPowerManager;
+import android.os.ServiceManager;
+import android.provider.Settings;
+import android.text.InputType;
+import android.view.Gravity;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.View.OnClickListener;
+import android.view.inputmethod.EditorInfo;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TableLayout;
+import android.widget.TableRow;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class LightLevelsActivity extends Activity implements OnClickListener {
+
+ // IDs used by dynamically created widgets
+ // Levels textviews 1000-1999
+ // Levels buttons 2000-2999
+ // Lcd buttons 3000-3999
+ // Buttons buttons 4000-4999
+ // Keyboard buttons 5000-5999
+
+ private static final int UPDATE_RATE = 400;
+
+ private boolean mHasKeyboard;
+ private boolean mHasChanges;
+ private Button mSave;
+ private Button mDefaults;
+ private Button mReload;
+ private Button mNumLevels;
+ private TextView mSensor;
+ private TextView mScreen;
+ private TextView mButtons;
+ private TextView mKeyboard;
+ private int[] mLevels;
+ private int[] mLcdValues;
+ private int[] mBtnValues;
+ private int[] mKbValues;
+ private AlertDialog mDialog;
+ private EditText mEditor;
+ private int mSensorRange;
+ private int mEditedId;
+
+ private Handler mHandler;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setTitle(R.string.ll_title);
+ setContentView(R.layout.lightlevels);
+
+ mSensorRange = (int) ((SensorManager) getSystemService(SENSOR_SERVICE)).getDefaultSensor(
+ Sensor.TYPE_LIGHT).getMaximumRange();
+ mHandler = new Handler();
+ mSave = (Button) findViewById(R.id.btn_save);
+ mSave.setOnClickListener(this);
+ mDefaults = (Button) findViewById(R.id.btn_default);
+ mDefaults.setOnClickListener(this);
+ mReload = (Button) findViewById(R.id.btn_reload);
+ mReload.setOnClickListener(this);
+ mSensor = (TextView) findViewById(R.id.ll_tw_lux_value);
+ mScreen = (TextView) findViewById(R.id.ll_tw_lcd_value);
+ mButtons = (TextView) findViewById(R.id.ll_tw_btn_value);
+ mKeyboard = (TextView) findViewById(R.id.ll_tw_kb_value);
+ mNumLevels = (Button) findViewById(R.id.btn_num_levels);
+ mNumLevels.setOnClickListener(this);
+
+ if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS) {
+ ((TableLayout) findViewById(R.id.ll_table_info))
+ .removeView(findViewById(R.id.table_row_kb));
+ ((TableRow) findViewById(R.id.ll_table_row_headers))
+ .removeView(findViewById(R.id.ll_tw_header_kb));
+ mHasKeyboard = false;
+ } else {
+ mHasKeyboard = true;
+ }
+
+ mEditor = new EditText(this);
+ mEditor.setInputType(InputType.TYPE_CLASS_NUMBER);
+ mEditor.setImeOptions(EditorInfo.IME_ACTION_NONE);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setPositiveButton(getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialogOk();
+ }
+ }).setNegativeButton(android.R.string.cancel,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ }).setView(mEditor);
+ mDialog = builder.create();
+ mDialog.setOwnerActivity(this);
+ mDialog.getWindow().setSoftInputMode(
+ WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
+ | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
+
+ loadData(false);
+ mHasChanges = false;
+ updateButtons();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mUpdateTask.run();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mHandler.removeCallbacks(mUpdateTask);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mSave) {
+ save();
+ } else if (v == mDefaults) {
+ loadData(true);
+ mHasChanges = true;
+ updateButtons();
+ } else if (v == mReload) {
+ loadData(false);
+ mHasChanges = false;
+ updateButtons();
+ } else if (v == mNumLevels) {
+ mDialog.setMessage(2 + " - " + mSensorRange);
+ mEditor.setText(String.valueOf(mLevels.length + 1));
+ mEditor.selectAll();
+ mEditedId = -1337;
+ mDialog.show();
+ } else {
+ int id = v.getId();
+ int value = -1;
+ int min = 0;
+ int max = 0;
+ if (id >= 2000 && id < 3000) {
+ value = mLevels[id - 2000];
+ min = 0;
+ max = mSensorRange;
+ } else if (id >= 3000 && id < 4000) {
+ value = mLcdValues[id - 3000];
+ min = Settings.System.getInt(getContentResolver(),
+ Settings.System.LIGHT_SCREEN_DIM,
+ android.os.Power.BRIGHTNESS_DIM);
+ max = android.os.Power.BRIGHTNESS_ON;
+ } else if (id >= 4000 && id < 5000) {
+ value = mBtnValues[id - 4000];
+ min = android.os.Power.BRIGHTNESS_OFF;
+ max = android.os.Power.BRIGHTNESS_ON;
+ } else if (id >= 5000 && id < 6000) {
+ value = mKbValues[id - 5000];
+ min = android.os.Power.BRIGHTNESS_OFF;
+ max = android.os.Power.BRIGHTNESS_ON;
+ } else {
+ value = -1;
+ }
+
+ if (value >= 0) {
+ mDialog.setMessage(min + " - " + max);
+ mEditor.setText(String.valueOf(value));
+ mEditor.selectAll();
+ mEditedId = id;
+ mDialog.show();
+ }
+ }
+ }
+
+ private void updateButtons() {
+ mSave.setEnabled(mHasChanges);
+ }
+
+ private void dialogOk() {
+ boolean changed = false;
+ try {
+ int value = Integer.valueOf(mEditor.getText().toString());
+ int valLimitHi = android.os.Power.BRIGHTNESS_ON;
+ if (mEditedId == -1337) {
+ if (value > 1 && value != (mLevels.length + 1)) {
+ int[] tmp = new int[value - 1];
+ System.arraycopy(mLevels, 0, tmp, 0, Math.min(tmp.length, mLevels.length));
+ mLevels = tmp;
+
+ tmp = new int[value];
+ System.arraycopy(mLcdValues, 0, tmp, 0, Math.min(tmp.length, mLcdValues.length));
+ mLcdValues = tmp;
+
+ tmp = new int[value];
+ System.arraycopy(mBtnValues, 0, tmp, 0, Math.min(tmp.length, mBtnValues.length));
+ mBtnValues = tmp;
+
+ tmp = new int[value];
+ System.arraycopy(mKbValues, 0, tmp, 0, Math.min(tmp.length, mKbValues.length));
+ mKbValues = tmp;
+
+ createEditor();
+ mHasChanges = true;
+ updateButtons();
+ }
+ } else if (mEditedId >= 2000 && mEditedId < 3000) {
+ if (value >= 0 && value <= mSensorRange) {
+ mLevels[mEditedId - 2000] = value;
+ ((Button) findViewById(mEditedId)).setText(String.valueOf(value));
+ ((TextView) findViewById(mEditedId - 1000)).setText(String.valueOf(value - 1));
+ changed = true;
+ }
+ } else if (mEditedId >= 3000 && mEditedId < 4000) {
+ if (value >= Settings.System.getInt(getContentResolver(),
+ Settings.System.LIGHT_SCREEN_DIM,
+ android.os.Power.BRIGHTNESS_DIM)
+ && value <= valLimitHi) {
+ mLcdValues[mEditedId - 3000] = value;
+ ((Button) findViewById(mEditedId)).setText(String.valueOf(value));
+ changed = true;
+ }
+ } else if (mEditedId >= 4000 && mEditedId < 5000) {
+ if (value >= android.os.Power.BRIGHTNESS_OFF
+ && value <= valLimitHi) {
+ mBtnValues[mEditedId - 4000] = value;
+ ((Button) findViewById(mEditedId)).setText(String.valueOf(value));
+ changed = true;
+ }
+ } else if (mEditedId >= 5000 && mEditedId < 6000) {
+ if (value >= android.os.Power.BRIGHTNESS_OFF
+ && value <= valLimitHi) {
+ mKbValues[mEditedId - 5000] = value;
+ ((Button) findViewById(mEditedId)).setText(String.valueOf(value));
+ changed = true;
+ }
+ }
+ } catch (NumberFormatException e) {
+ // Ignore
+ }
+ if (changed) {
+ mHasChanges = true;
+ mSave.setEnabled(mHasChanges);
+ }
+ }
+
+ private void loadData(boolean defaults) {
+ if (!defaults) {
+ try {
+ ContentResolver cr = getContentResolver();
+ mLevels = parseIntArray(Settings.System.getString(cr,
+ Settings.System.LIGHT_SENSOR_LEVELS));
+
+ mLcdValues = parseIntArray(Settings.System.getString(cr,
+ Settings.System.LIGHT_SENSOR_LCD_VALUES));
+
+ mBtnValues = parseIntArray(Settings.System.getString(cr,
+ Settings.System.LIGHT_SENSOR_BUTTON_VALUES));
+
+ mKbValues = parseIntArray(Settings.System.getString(cr,
+ Settings.System.LIGHT_SENSOR_KEYBOARD_VALUES));
+
+ // Sanity check
+ int N = mLevels.length;
+ if (N < 1 || mLcdValues.length != (N + 1) || mBtnValues.length != (N + 1)
+ || mKbValues.length != (N + 1)) {
+ throw new Exception("sanity check failed");
+ }
+ } catch (Exception e) {
+ // Use defaults since we can't trust custom values
+ defaults = true;
+ }
+ }
+
+ if (defaults) {
+ mLevels = getResources().getIntArray(
+ com.android.internal.R.array.config_autoBrightnessLevels);
+ mLcdValues = getResources().getIntArray(
+ com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
+ mBtnValues = getResources().getIntArray(
+ com.android.internal.R.array.config_autoBrightnessButtonBacklightValues);
+ mKbValues = getResources().getIntArray(
+ com.android.internal.R.array.config_autoBrightnessKeyboardBacklightValues);
+ }
+ createEditor();
+ }
+
+ private int[] parseIntArray(String intArray) {
+ int[] result;
+ if (intArray == null || intArray.length() == 0) {
+ result = new int[0];
+ } else {
+ String[] split = intArray.split(",");
+ result = new int[split.length];
+ for (int i = 0; i < split.length; i++) {
+ result[i] = Integer.parseInt(split[i]);
+ }
+ }
+ return result;
+ }
+
+ private void save() {
+ // Sanity check
+ boolean doSave = true;
+ for (int i = 1; i < mLevels.length; i++) {
+ if (mLevels[i] <= mLevels[i - 1]) {
+ Toast.makeText(this, getString(R.string.ll_bad_levels), Toast.LENGTH_SHORT).show();
+ doSave = false;
+ break;
+ }
+ }
+ if (doSave) {
+ Settings.System.putString(getContentResolver(), Settings.System.LIGHT_SENSOR_LEVELS,
+ intArrayToString(mLevels));
+ Settings.System.putString(getContentResolver(),
+ Settings.System.LIGHT_SENSOR_LCD_VALUES, intArrayToString(mLcdValues));
+ Settings.System.putString(getContentResolver(),
+ Settings.System.LIGHT_SENSOR_BUTTON_VALUES, intArrayToString(mBtnValues));
+ Settings.System.putString(getContentResolver(),
+ Settings.System.LIGHT_SENSOR_KEYBOARD_VALUES, intArrayToString(mKbValues));
+ long tag = Settings.System.getLong(getContentResolver(),
+ Settings.System.LIGHTS_CHANGED, 0) + 1;
+ Settings.System.putLong(getContentResolver(), Settings.System.LIGHTS_CHANGED, tag);
+
+ mHasChanges = false;
+ mSave.setEnabled(mHasChanges);
+ }
+ }
+
+ private String intArrayToString(int[] array) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length - 1; i++) {
+ sb.append(array[i]);
+ sb.append(",");
+ }
+ sb.append(array[array.length - 1]);
+ return sb.toString();
+ }
+
+ private Runnable mUpdateTask = new Runnable() {
+ public void run() {
+ boolean autoLcd = Settings.System.getInt(getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS_MODE, 1337) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+ boolean filterEnabled = Settings.System.getInt(getContentResolver(),
+ Settings.System.LIGHT_FILTER, 0) != 0;
+
+ try {
+ IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager
+ .getService("power"));
+ if (filterEnabled && autoLcd) {
+ mSensor.setText(String.valueOf(power.getLightSensorValue()) + " / "
+ + String.valueOf(power.getRawLightSensorValue()));
+ } else {
+ String value = String.valueOf(power.getLightSensorValue());
+ mSensor.setText(value + " / " + value);
+ }
+ if (autoLcd) {
+ mScreen.setText(String.valueOf(power.getLightSensorScreenBrightness()));
+ } else {
+ mScreen.setText(getString(R.string.ll_disabled));
+ }
+ mButtons.setText(String.valueOf(power.getLightSensorButtonBrightness()));
+ if (mHasKeyboard) {
+ mKeyboard.setText(String.valueOf(power.getLightSensorKeyboardBrightness()));
+ }
+ } catch (Exception e) {
+ // Display "-" on any error
+
+ if (autoLcd) {
+ mScreen.setText("-");
+ } else {
+ mScreen.setText(getString(R.string.ll_disabled));
+ }
+
+ mSensor.setText("- / -");
+ mButtons.setText("-");
+ mKeyboard.setText("-");
+ }
+
+ mHandler.postDelayed(mUpdateTask, UPDATE_RATE);
+ }
+ };
+
+ private void createEditor() {
+ // Assume at least one defined level (two values)
+ TableLayout table = (TableLayout) findViewById(R.id.ll_table_config);
+
+ // Clear all
+ while (table.getChildCount() > 1) {
+ table.removeViewAt(table.getChildCount() - 1);
+ }
+
+ TableRow row;
+
+ // First row
+ row = createRow();
+
+ // Lower
+ row.addView(createTextView(0, "0"));
+
+ // Upper
+ row.addView(createTextView(1000, String.valueOf(mLevels[0] - 1)));
+
+ // Screen
+ row.addView(createButton(3000, String.valueOf(mLcdValues[0])));
+
+ // Buttons
+ row.addView(createButton(4000, String.valueOf(mBtnValues[0])));
+
+ // Keyboard
+ if (mHasKeyboard) {
+ row.addView(createButton(5000, String.valueOf(mKbValues[0])));
+ }
+
+ table.addView(row, table.getChildCount());
+
+ for (int i = 0; i < mLevels.length - 1; i++) {
+ row = createRow();
+
+ // Lower
+ row.addView(createButton(2000 + i, String.valueOf(mLevels[i])));
+
+ // Upper
+ row.addView(createTextView(1000 + i + 1, String.valueOf(Math.max(0, mLevels[i + 1] - 1))));
+
+ // Screen
+ row.addView(createButton(3000 + i + 1, String.valueOf(mLcdValues[i + 1])));
+
+ // Buttons
+ row.addView(createButton(4000 + i + 1, String.valueOf(mBtnValues[i + 1])));
+
+ // Keyboard
+ if (mHasKeyboard) {
+ row.addView(createButton(5000 + i + 1, String.valueOf(mKbValues[i + 1])));
+ }
+
+ table.addView(row, table.getChildCount());
+ }
+
+ row = createRow();
+
+ // Lower
+ row.addView(createButton(2000 + mLevels.length - 1, String
+ .valueOf(mLevels[mLevels.length - 1])));
+
+ // Upper
+ row.addView(createTextView((int) 1e10, String.valueOf((char) '\u221e')));
+
+ // Screen
+ row
+ .addView(createButton(3000 + mLevels.length, String
+ .valueOf(mLcdValues[mLevels.length])));
+
+ // Buttons
+ row
+ .addView(createButton(4000 + mLevels.length, String
+ .valueOf(mBtnValues[mLevels.length])));
+
+ // Keyboard
+ if (mHasKeyboard) {
+ row.addView(createButton(5000 + mLevels.length, String
+ .valueOf(mKbValues[mLevels.length])));
+ }
+
+ table.addView(row, table.getChildCount());
+
+ table.setColumnStretchable(0, true);
+ table.setColumnStretchable(2, true);
+ table.setColumnStretchable(3, true);
+ if (mHasKeyboard) {
+ table.setColumnStretchable(4, true);
+ }
+ }
+
+ private int dp2px(int dp) {
+ return (int) getResources().getDisplayMetrics().density * dp;
+ }
+
+ private Button createButton(int id, String text) {
+ Button btn = new Button(this);
+ btn.setId(id);
+ btn.setText(text);
+ btn.setMinWidth(dp2px(50));
+ btn.setMaxWidth(dp2px(120));
+ btn.setOnClickListener(this);
+ return btn;
+ }
+
+ private TextView createTextView(int id, String text) {
+ TextView tv = new TextView(this);
+ tv.setGravity(Gravity.CENTER);
+ tv.setText(text);
+ tv.setWidth(dp2px(60));
+ tv.setId(id);
+ return tv;
+ }
+
+ private TableRow createRow() {
+ TableRow row = new TableRow(this);
+ row.setGravity(Gravity.CENTER);
+ return row;
+ }
+}
View
47 src/com/cyanogenmod/settings/switches/PowerWidgetEnabler.java
@@ -0,0 +1,47 @@
+package com.cyanogenmod.settings.switches;
+
+import android.provider.Settings;
+import android.content.Context;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+
+import com.cyanogenmod.settings.switches.SwitchWidget;
+
+public class PowerWidgetEnabler extends SwitchWidget {
+ public PowerWidgetEnabler(Context context, Switch switch_) {
+ mContext = context;
+ mSwitch = switch_;
+ }
+
+ public void resume() {
+ mSwitch.setOnCheckedChangeListener(this);
+ }
+
+ public void pause() {
+ mSwitch.setOnCheckedChangeListener(null);
+ }
+
+ public void setState(Switch switch_) {
+ int isEnabled = Settings.System.getInt(mContext.getContentResolver(), Settings.System.EXPANDED_VIEW_WIDGET, 1);
+ mSwitch.setChecked(isEnabled == 1 ? true : false);
+ return;
+ }
+
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ //Do nothing if called as a result of a state machine event
+ if (mStateMachineEvent) {
+ return;
+ }
+ Settings.System.putInt(mContext.getContentResolver(), Settings.System.EXPANDED_VIEW_WIDGET,
+ isChecked ? 1 : 0);
+ return;
+ }
+
+ private void setSwitchChecked(boolean checked) {
+ if (checked != mSwitch.isChecked()) {
+ mStateMachineEvent = true;
+ mSwitch.setChecked(checked);
+ mStateMachineEvent = false;
+ }
+ }
+}
View
66 src/com/cyanogenmod/settings/switches/SwitchWidget.java
@@ -0,0 +1,66 @@
+package com.cyanogenmod.settings.switches;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.provider.Settings;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+import android.widget.Toast;
+
+import com.cyanogenmod.settings.R;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class SwitchWidget implements CompoundButton.OnCheckedChangeListener {
+ public static Context mContext;
+ public Switch mSwitch;
+ public AtomicBoolean mConnected = new AtomicBoolean(false);
+
+ public boolean mStateMachineEvent;
+
+/* public SwitchWidget(Context context, Switch switch_) {
+ super(context, switch_);
+ mContext = context;
+ mSwitch = switch_;
+ }
+*/
+ public SwitchWidget() {
+ }
+ public void resume() {
+ mSwitch.setOnCheckedChangeListener(this);
+ }
+
+ public void pause() {
+ mSwitch.setOnCheckedChangeListener(null);
+ }
+
+ public void setSwitch(Switch switch_) {
+ /* Stub! */
+ if (mSwitch == switch_) return;
+ mSwitch.setOnCheckedChangeListener(null);
+ mSwitch = switch_;
+ mSwitch.setOnCheckedChangeListener(this);
+
+ setState(switch_);
+ }
+
+ public void setState(Switch switch_) {
+ /* Stub */
+ return;
+ }
+
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ /* Stub! */
+ return;
+ }
+
+ private void setSwitchChecked(boolean checked) {
+ if (checked != mSwitch.isChecked()) {
+ mStateMachineEvent = true;
+ mSwitch.setChecked(checked);
+ mStateMachineEvent = false;
+ }
+ }
+}

0 comments on commit 6760913

Please sign in to comment.
Something went wrong with that request. Please try again.