diff options
Diffstat (limited to 'AriesParts')
-rw-r--r-- | AriesParts/Android.mk | 13 | ||||
-rw-r--r-- | AriesParts/AndroidManifest.xml | 18 | ||||
-rw-r--r-- | AriesParts/res/drawable/color_tuning_preview.xml | 9 | ||||
-rw-r--r-- | AriesParts/res/layout/preference_dialog_color_tuning.xml | 92 | ||||
-rw-r--r-- | AriesParts/res/values/arrays.xml | 21 | ||||
-rw-r--r-- | AriesParts/res/values/strings.xml | 15 | ||||
-rw-r--r-- | AriesParts/res/xml/main.xml | 25 | ||||
-rw-r--r-- | AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java | 28 | ||||
-rw-r--r-- | AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java | 173 | ||||
-rw-r--r-- | AriesParts/src/com/cyanogenmod/AriesParts/Startup.java | 15 | ||||
-rw-r--r-- | AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java | 36 | ||||
-rw-r--r-- | AriesParts/src/com/cyanogenmod/AriesParts/Utils.java | 48 |
12 files changed, 493 insertions, 0 deletions
diff --git a/AriesParts/Android.mk b/AriesParts/Android.mk new file mode 100644 index 0000000..29efe75 --- /dev/null +++ b/AriesParts/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := AriesParts +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/AriesParts/AndroidManifest.xml b/AriesParts/AndroidManifest.xml new file mode 100644 index 0000000..f29b17a --- /dev/null +++ b/AriesParts/AndroidManifest.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.cyanogenmod.AriesParts" android:sharedUserId="android.uid.system"> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <application android:label="@string/app_name"> + <activity android:name=".AriesParts" + android:label="@string/app_name"> + <intent-filter> + <action android:name="com.cyanogenmod.action.LAUNCH_DEVICE_SETTINGS" /> + </intent-filter> + </activity> + <receiver android:name=".Startup"> + <intent-filter android:priority="100"> + <action android:name="android.intent.action.BOOT_COMPLETED" /> + </intent-filter> + </receiver> + </application> +</manifest> diff --git a/AriesParts/res/drawable/color_tuning_preview.xml b/AriesParts/res/drawable/color_tuning_preview.xml new file mode 100644 index 0000000..2d83c10 --- /dev/null +++ b/AriesParts/res/drawable/color_tuning_preview.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape + xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <gradient + android:angle="0" + android:startColor="#000000" + android:endColor="#FFFFFF" /> +</shape>
\ No newline at end of file diff --git a/AriesParts/res/layout/preference_dialog_color_tuning.xml b/AriesParts/res/layout/preference_dialog_color_tuning.xml new file mode 100644 index 0000000..f228541 --- /dev/null +++ b/AriesParts/res/layout/preference_dialog_color_tuning.xml @@ -0,0 +1,92 @@ +<?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/color_red_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/color_red_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/color_red_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/color_red_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/color_red_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <TextView android:id="@+id/color_green_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/color_red_seekbar" + android:text="@string/color_green_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/color_green_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/color_red_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/color_green_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/color_green_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <TextView android:id="@+id/color_blue_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/color_green_seekbar" + android:text="@string/color_blue_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/color_blue_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/color_green_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/color_blue_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/color_blue_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <ImageView android:src="@drawable/color_tuning_preview" + android:layout_width="match_parent" + android:layout_height="40dip" + android:layout_below="@id/color_blue_seekbar" + android:paddingTop="20dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + </RelativeLayout> +</ScrollView>
\ No newline at end of file diff --git a/AriesParts/res/values/arrays.xml b/AriesParts/res/values/arrays.xml new file mode 100644 index 0000000..9053a71 --- /dev/null +++ b/AriesParts/res/values/arrays.xml @@ -0,0 +1,21 @@ +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string-array name="backlight_timeout_entries"> + <item>Default (1.6 seconds)</item> + <item>2 seconds</item> + <item>5 seconds</item> + <item>10 seconds</item> + <item>15 seconds</item> + <item>30 seconds</item> + <item>Never</item> + </string-array> + + <string-array name="backlight_timeout_entries_values" translatable="false"> + <item>1600</item> + <item>2000</item> + <item>5000</item> + <item>10000</item> + <item>15000</item> + <item>30000</item> + <item>-1</item> + </string-array> +</resources> diff --git a/AriesParts/res/values/strings.xml b/AriesParts/res/values/strings.xml new file mode 100644 index 0000000..d21d1a9 --- /dev/null +++ b/AriesParts/res/values/strings.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Galaxy S Settings</string> + + <string name="category_screen_title">Screen</string> + <string name="color_tuning_title_head">Color Tuning</string> + <string name="color_tuning_summary_head">Calibrate screen color</string> + <string name="color_red_title">Red</string> + <string name="color_green_title">Green</string> + <string name="color_blue_title">Blue</string> + + <string name="category_touchkey_title">Touch Keys</string> + <string name="backlight_timeout_title_head">Backlight Timeout</string> + <string name="backlight_timeout_summary_head">Adjust the delay before the touch key backlight automatically turns off</string> +</resources> diff --git a/AriesParts/res/xml/main.xml b/AriesParts/res/xml/main.xml new file mode 100644 index 0000000..68938f4 --- /dev/null +++ b/AriesParts/res/xml/main.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + + <PreferenceCategory + android:title="@string/category_screen_title"> + <!-- Color tuning --> + <com.cyanogenmod.AriesParts.ColorTuningPreference + android:key="color_tuning" + android:title="@string/color_tuning_title_head" + android:summary="@string/color_tuning_summary_head" /> + </PreferenceCategory> + + <PreferenceCategory + android:title="@string/category_touchkey_title"> + <!-- Touch key backlight timeout --> + <ListPreference + android:key="backlight_timeout" + android:title="@string/backlight_timeout_title_head" + android:summary="@string/backlight_timeout_summary_head" + android:entries="@array/backlight_timeout_entries" + android:entryValues="@array/backlight_timeout_entries_values" + android:defaultValue="1600" /> + </PreferenceCategory> + +</PreferenceScreen> diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java b/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java new file mode 100644 index 0000000..9aa3916 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java @@ -0,0 +1,28 @@ +package com.cyanogenmod.AriesParts; + +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.PreferenceActivity; + +public class AriesParts extends PreferenceActivity { + + public static final String KEY_COLOR_TUNING = "color_tuning"; + public static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout"; + + private ColorTuningPreference mColorTuning; + private ListPreference mBacklightTimeout; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.main); + + mColorTuning = (ColorTuningPreference) findPreference(KEY_COLOR_TUNING); + mColorTuning.setEnabled(ColorTuningPreference.isSupported()); + + mBacklightTimeout = (ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT); + mBacklightTimeout.setEnabled(TouchKeyBacklightTimeout.isSupported()); + mBacklightTimeout.setOnPreferenceChangeListener(new TouchKeyBacklightTimeout()); + } + +} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java b/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java new file mode 100644 index 0000000..edffa72 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java @@ -0,0 +1,173 @@ +package com.cyanogenmod.AriesParts; + +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.widget.SeekBar; +import android.widget.TextView; + +/** + * Special preference type that allows configuration of both the ring volume and + * notification volume. + */ +public class ColorTuningPreference extends DialogPreference { + + enum Colors { + RED, + GREEN, + BLUE + }; + + private static final int[] SEEKBAR_ID = new int[] { + R.id.color_red_seekbar, + R.id.color_green_seekbar, + R.id.color_blue_seekbar + }; + + private static final int[] VALUE_DISPLAY_ID = new int[] { + R.id.color_red_value, + R.id.color_green_value, + R.id.color_blue_value + }; + + private static final String[] FILE_PATH = new String[] { + "/sys/devices/virtual/misc/color_tuning/red_multiplier", + "/sys/devices/virtual/misc/color_tuning/green_multiplier", + "/sys/devices/virtual/misc/color_tuning/blue_multiplier" + }; + + private ColorSeekBar mSeekBars[] = new ColorSeekBar[3]; + + private static final int MAX_VALUE = Integer.MAX_VALUE; + + // Track instances to know when to restore original color + // (when the orientation changes, a new dialog is created before the old one is destroyed) + private static int sInstances = 0; + + public ColorTuningPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_dialog_color_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 ColorSeekBar(seekBar, valueDisplay, FILE_PATH[i]); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + if (positiveResult) { + for (ColorSeekBar csb : mSeekBars) { + csb.save(); + } + } else if (sInstances == 0) { + for (ColorSeekBar csb : mSeekBars) { + csb.reset(); + } + } + } + + /** + * Restore screen color tuning from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + for (String filePath : FILE_PATH) { + int value = sharedPrefs.getInt(filePath, MAX_VALUE); + Utils.writeColor(filePath, value); + } + } + + /** + * Check whether the running kernel supports color tuning or not. + * @return Whether color 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 ColorSeekBar implements SeekBar.OnSeekBarChangeListener { + + private String mFilePath; + private int mOriginal; + private SeekBar mSeekBar; + private TextView mValueDisplay; + + public ColorSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath) { + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + + // Read original value + SharedPreferences sharedPreferences = getSharedPreferences(); + mOriginal = sharedPreferences.getInt(mFilePath, MAX_VALUE); + + seekBar.setMax(MAX_VALUE); + reset(); + seekBar.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.writeColor(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("%.3f", (double) progress / MAX_VALUE)); + } + + } + +} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java b/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java new file mode 100644 index 0000000..540ed9b --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java @@ -0,0 +1,15 @@ +package com.cyanogenmod.AriesParts; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class Startup extends BroadcastReceiver { + + @Override + public void onReceive(final Context context, final Intent bootintent) { + ColorTuningPreference.restore(context); + TouchKeyBacklightTimeout.restore(context); + } + +} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java b/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java new file mode 100644 index 0000000..554098a --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java @@ -0,0 +1,36 @@ +package com.cyanogenmod.AriesParts; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class TouchKeyBacklightTimeout implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/misc/notification/bl_timeout"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore backlight timeout setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(AriesParts.KEY_BACKLIGHT_TIMEOUT, "1600")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java b/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java new file mode 100644 index 0000000..9c07261 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java @@ -0,0 +1,48 @@ +package com.cyanogenmod.AriesParts; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Utils { + + /** + * Write a string value to the specified file. + * @param filename The filename + * @param value The value + */ + public static void writeValue(String filename, String value) { + try { + FileOutputStream fos = new FileOutputStream(new File(filename)); + fos.write(value.getBytes()); + fos.flush(); + fos.getFD().sync(); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Write the "color value" to the specified file. The value is scaled from + * an integer to an unsigned integer by multiplying by 2. + * @param filename The filename + * @param value The value of max value Integer.MAX + */ + public static void writeColor(String filename, int value) { + writeValue(filename, String.valueOf((long) value * 2)); + } + + /** + * Check if the specified file exists. + * @param filename The filename + * @return Whether the file exists or not + */ + public static boolean fileExists(String filename) { + return new File(filename).exists(); + } + +} |