summaryrefslogtreecommitdiffstats
path: root/CrespoParts
diff options
context:
space:
mode:
authorKalimochoAz <calimochoazucarado@gmail.com>2012-09-01 14:51:29 +0200
committerKalimochoAz <calimochoazucarado@gmail.com>2012-09-01 14:53:04 +0200
commitb573633abeb138af9dfea62266f19dd9250e59da (patch)
treed91fa97210c86ebc552931920c3f47bb03dfcefc /CrespoParts
parent0232757ebba61546c3bfffc4a1ea02080bd4475c (diff)
downloaddevice_samsung_crespo-b573633abeb138af9dfea62266f19dd9250e59da.zip
device_samsung_crespo-b573633abeb138af9dfea62266f19dd9250e59da.tar.gz
device_samsung_crespo-b573633abeb138af9dfea62266f19dd9250e59da.tar.bz2
Add button led timeout option into settings
Change-Id: If9ca126b52fd06da7f6e55fc59b305189acac68a
Diffstat (limited to 'CrespoParts')
-rw-r--r--CrespoParts/res/layout/preference_dialog_bld_tuning.xml35
-rw-r--r--CrespoParts/res/values/strings.xml3
-rw-r--r--CrespoParts/res/xml/general_preferences.xml4
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java1
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java9
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/Startup.java1
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/Utils.java15
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/bldTuningPreference.java218
8 files changed, 284 insertions, 2 deletions
diff --git a/CrespoParts/res/layout/preference_dialog_bld_tuning.xml b/CrespoParts/res/layout/preference_dialog_bld_tuning.xml
new file mode 100644
index 0000000..5c83b6e
--- /dev/null
+++ b/CrespoParts/res/layout/preference_dialog_bld_tuning.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_horizontal"
+ android:paddingBottom="20dip">
+
+ <TextView android:id="@+id/bld_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/bld_title"
+ android:paddingTop="10dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip" />
+ <TextView android:id="@+id/bld_value"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:paddingTop="10dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip" />
+ <SeekBar android:id="@+id/bld_seekbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/bld_text"
+ android:paddingTop="2dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip" />
+ </RelativeLayout>
+</ScrollView>
diff --git a/CrespoParts/res/values/strings.xml b/CrespoParts/res/values/strings.xml
index 661fb8d..d3531df 100644
--- a/CrespoParts/res/values/strings.xml
+++ b/CrespoParts/res/values/strings.xml
@@ -26,6 +26,9 @@
<string name="color_default_title">Default</string>
<string name="color_CM_title">CM Sett.</string>
<string name="color_dark_title">Dark Sett.</string>
+ <string name="bld_title">BLD</string>
+ <string name="bld_tuning_title_head">BLD Tuning</string>
+ <string name="bld_tuning_summary_head">Set the time to turn off keys light ( 0 means no BLD )</string>
<string name="preset1_default_title">Default.</string>
<string name="preset2_default_title">Natural</string>
diff --git a/CrespoParts/res/xml/general_preferences.xml b/CrespoParts/res/xml/general_preferences.xml
index 423f97b..7788a88 100644
--- a/CrespoParts/res/xml/general_preferences.xml
+++ b/CrespoParts/res/xml/general_preferences.xml
@@ -20,6 +20,10 @@
<CheckBoxPreference android:key="touchkey_notification"
android:title="@string/touchkey_notification_title_head"
android:summary="@string/touchkey_notification_summary_head" />
+ <com.cyanogenmod.settings.device.bldTuningPreference
+ android:key="bld_tuning"
+ android:title="@string/bld_tuning_title_head"
+ android:summary="@string/bld_tuning_summary_head" />
</PreferenceCategory>
</PreferenceScreen>
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java b/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java
index d84a78b..e868086 100644
--- a/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java
@@ -49,6 +49,7 @@ public class DeviceSettings extends Activity {
public static final String KEY_NOTIFICATION = "touchkey_notification";
public static final String KEY_CATEGORY_RADIO = "category_radio";
public static final String KEY_HSPA = "hspa";
+ public static final String KEY_BLD_TUNING = "bld_tuning";
ViewPager mViewPager;
TabsAdapter mTabsAdapter;
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java b/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java
index eb183a2..d437997 100644
--- a/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java
@@ -44,9 +44,11 @@ public class GeneralFragmentActivity extends PreferenceFragment implements OnPre
private static final String TOUCHKEY_NOTIFICATION_FILE = "/sys/class/misc/notification/enabled";
private static final String PREF_ENABLED = "1";
private static final String TAG = "CrespoParts_General";
+ private static final String BLD_FILE = "/sys/class/misc/backlightdimmer/enabled";
private CheckBoxPreference mDeepIdle;
private CheckBoxPreference mNotification;
+ private bldTuningPreference mbldTuning;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -71,9 +73,12 @@ public class GeneralFragmentActivity extends PreferenceFragment implements OnPre
}
Preference p = findPreference(DeviceSettings.KEY_DEEPIDLE_STATS);
- if(p != null) {
+ if(p != null)
p.setOnPreferenceClickListener(this);
- }
+
+ mbldTuning = (bldTuningPreference) findPreference(DeviceSettings.KEY_BLD_TUNING);
+ if(mbldTuning != null)
+ mbldTuning.setEnabled(bldTuningPreference.isSupported());
}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java b/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java
index 0728953..2799424 100644
--- a/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java
@@ -10,6 +10,7 @@ public class Startup extends BroadcastReceiver {
public void onReceive(final Context context, final Intent bootintent) {
GeneralFragmentActivity.restore(context);
ColorTuningPreference.restore(context);
+ bldTuningPreference.restore(context);
GammaTuningPreference.restore(context);
if (Hspa.isSupported()) {
Hspa.restore(context);
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java b/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java
index 6b9c0d3..a5b9ea7 100644
--- a/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java
@@ -119,6 +119,21 @@ public class Utils {
}
/**
+ * Write the "color value" to the specified file. The value is scaled from
+ * seconds to miliseconds multiplying by 1000.
+ *
+ * @param filename The filename
+ * @param value The value of time
+ */
+ public static void writebld(String filename, int value) {
+ writeValue(filename, String.valueOf(value * 1000));
+ if(value > 0)
+ writeValue("/sys/class/misc/backlightdimmer/enabled", "1");
+ else
+ writeValue("/sys/class/misc/backlightdimmer/enabled", "0");
+ }
+
+ /**
* Check if the specified file exists.
*
* @param filename The filename
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/bldTuningPreference.java b/CrespoParts/src/com/cyanogenmod/settings/device/bldTuningPreference.java
new file mode 100644
index 0000000..edad9ba
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/bldTuningPreference.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2011 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.cyanogenmod.settings.device;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.preference.DialogPreference;
+import android.preference.PreferenceManager;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.SeekBar;
+import android.widget.TextView;
+import android.util.Log;
+import android.widget.Button;
+
+/**
+ * Special preference type that allows configuration of both the ring volume and
+ * notification volume.
+ */
+public class bldTuningPreference extends DialogPreference {
+
+ private static final String TAG = "BLD...";
+
+ private static final int[] SEEKBAR_ID = new int[] {
+ R.id.bld_seekbar
+ };
+
+ private static final int[] VALUE_DISPLAY_ID = new int[] {
+ R.id.bld_value
+ };
+
+ private static final String[] FILE_PATH = new String[] {
+ "/sys/class/misc/backlightdimmer/delay",
+ };
+
+
+ private bldSeekBar mSeekBars[] = new bldSeekBar[1];
+
+ // Align MAX_VALUE with Voodoo Control settings
+ private static final int MAX_VALUE = 30;
+
+ // Track instances to know when to restore original bld
+ // (when the orientation changes, a new dialog is created before the old one
+ // is destroyed)
+ private static int sInstances = 0;
+
+ public bldTuningPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ setDialogLayoutResource(R.layout.preference_dialog_bld_tuning);
+ }
+
+ @Override
+ protected void onBindDialogView(View view) {
+ super.onBindDialogView(view);
+
+ sInstances++;
+
+ for (int i = 0; i < SEEKBAR_ID.length; i++) {
+ SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID[i]);
+ TextView valueDisplay = (TextView) view.findViewById(VALUE_DISPLAY_ID[i]);
+ mSeekBars[i] = new bldSeekBar(seekBar, valueDisplay, FILE_PATH[i]);
+ }
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+
+ sInstances--;
+
+ if (positiveResult) {
+ for (bldSeekBar csb : mSeekBars) {
+ csb.save();
+ }
+ } else if (sInstances == 0) {
+ for (bldSeekBar csb : mSeekBars) {
+ csb.reset();
+ }
+ }
+ }
+
+ /**
+ * Restore screen bld tuning from SharedPreferences. (Write to kernel.)
+ *
+ * @param context The context to read the SharedPreferences from
+ */
+ public static void restore(Context context) {
+ int iValue, iValue2;
+ if (!isSupported()) {
+ return;
+ }
+
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ for (String filePath : FILE_PATH) {
+ String sDefaultValue = Utils.readOneLine(filePath);
+ Log.d(TAG,"INIT: " + sDefaultValue);
+ try {
+ iValue2 = Integer.parseInt(sDefaultValue) - 1000;
+ } catch (NumberFormatException e) {
+ iValue2 = 0;
+ }
+ try {
+ iValue = sharedPrefs.getInt(filePath, iValue2);
+ Log.d(TAG, "restore: iValue: " + iValue + " File: " + filePath);
+ } catch (NumberFormatException e) {
+ iValue = iValue2;
+ Log.e(TAG, "restore ERROR: iValue: " + iValue + " File: " + filePath);
+ }
+ Utils.writebld(filePath, (int) iValue);
+ }
+ }
+
+ /**
+ * Check whether the running kernel supports bld tuning or not.
+ *
+ * @return Whether bld tuning is supported or not
+ */
+ public static boolean isSupported() {
+ boolean supported = true;
+ for (String filePath : FILE_PATH) {
+ if (!Utils.fileExists(filePath)) {
+ supported = false;
+ }
+ }
+
+ return supported;
+ }
+
+ class bldSeekBar implements SeekBar.OnSeekBarChangeListener {
+
+ private String mFilePath;
+
+ private int mOriginal;
+
+ private SeekBar mSeekBar;
+
+ private TextView mValueDisplay;
+
+ public bldSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath) {
+ int iValue;
+
+ mSeekBar = seekBar;
+ mValueDisplay = valueDisplay;
+ mFilePath = filePath;
+
+ SharedPreferences sharedPreferences = getSharedPreferences();
+
+ // Read original value
+ if (Utils.fileExists(mFilePath)) {
+ String sDefaultValue = Utils.readOneLine(mFilePath);
+ iValue = (int) (Long.valueOf(sDefaultValue) / 1000);
+ } else {
+ iValue = sharedPreferences.getInt(mFilePath, MAX_VALUE);
+ }
+ mOriginal = iValue;
+
+ mSeekBar.setMax(MAX_VALUE);
+ reset();
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ public void reset() {
+ mSeekBar.setProgress(mOriginal);
+ updateValue(mOriginal);
+ }
+
+ public void save() {
+ Editor editor = getEditor();
+ editor.putInt(mFilePath, mSeekBar.getProgress());
+ editor.commit();
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ Utils.writebld(mFilePath, progress);
+ updateValue(progress);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+
+ private void updateValue(int progress) {
+ mValueDisplay.setText(String.format("%d", progress));
+ }
+
+ public void SetNewValue(int iValue) {
+ mOriginal = iValue;
+ reset();
+ }
+
+ }
+
+}