From c5a2454a28e87a779873c369053078e7cc81c663 Mon Sep 17 00:00:00 2001 From: Shawn Alty Date: Tue, 27 Dec 2011 21:22:49 -0600 Subject: Mass rename of com.cyanogenmod.AriesParts to com.cyanogenmod.settings.device Needed (possibly?) for "Device Settings" to work. --- .../src/com/cyanogenmod/AriesParts/AriesParts.java | 118 -------------- .../AriesParts/ColorTuningPreference.java | 173 --------------------- .../src/com/cyanogenmod/AriesParts/Hspa.java | 48 ------ .../src/com/cyanogenmod/AriesParts/Startup.java | 16 -- .../AriesParts/TouchKeyBacklightTimeout.java | 36 ----- .../com/cyanogenmod/AriesParts/TvOutService.java | 146 ----------------- .../src/com/cyanogenmod/AriesParts/Utils.java | 47 ------ .../cyanogenmod/settings/device/AriesParts.java | 118 ++++++++++++++ .../settings/device/ColorTuningPreference.java | 173 +++++++++++++++++++++ .../src/com/cyanogenmod/settings/device/Hspa.java | 48 ++++++ .../com/cyanogenmod/settings/device/Startup.java | 16 ++ .../settings/device/TouchKeyBacklightTimeout.java | 36 +++++ .../cyanogenmod/settings/device/TvOutService.java | 146 +++++++++++++++++ .../src/com/cyanogenmod/settings/device/Utils.java | 47 ++++++ 14 files changed, 584 insertions(+), 584 deletions(-) delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/Hspa.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/Startup.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/TvOutService.java delete mode 100644 AriesParts/src/com/cyanogenmod/AriesParts/Utils.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/AriesParts.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/Hspa.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/Startup.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/TouchKeyBacklightTimeout.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/Utils.java (limited to 'AriesParts/src/com') diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java b/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java deleted file mode 100644 index 3d6a68f..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/AriesParts.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.cyanogenmod.AriesParts; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.hardware.TvOut; -import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.ListPreference; -import android.preference.Preference; -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"; - public static final String KEY_HSPA = "hspa"; - public static final String KEY_TVOUT_ENABLE = "tvout_enable"; - public static final String KEY_TVOUT_SYSTEM = "tvout_system"; - - private ColorTuningPreference mColorTuning; - private ListPreference mBacklightTimeout; - private ListPreference mHspa; - private CheckBoxPreference mTvOutEnable; - private ListPreference mTvOutSystem; - private TvOut mTvOut; - - private BroadcastReceiver mHeadsetReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - int state = intent.getIntExtra("state", 0); - updateTvOutEnable(state != 0); - } - - }; - - @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()); - - mHspa = (ListPreference) findPreference(KEY_HSPA); - mHspa.setEnabled(Hspa.isSupported()); - mHspa.setOnPreferenceChangeListener(new Hspa(this)); - - mTvOut = new TvOut(); - mTvOutEnable = (CheckBoxPreference) findPreference(KEY_TVOUT_ENABLE); - mTvOutEnable.setChecked(mTvOut._isEnabled()); - - mTvOutEnable.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - boolean enable = (Boolean) newValue; - Intent i = new Intent(AriesParts.this, TvOutService.class); - i.putExtra(TvOutService.EXTRA_COMMAND, enable ? TvOutService.COMMAND_ENABLE : TvOutService.COMMAND_DISABLE); - startService(i); - return true; - } - - }); - - mTvOutSystem = (ListPreference) findPreference(KEY_TVOUT_SYSTEM); - mTvOutSystem.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (mTvOut._isEnabled()) { - int newSystem = Integer.valueOf((String) newValue); - Intent i = new Intent(AriesParts.this, TvOutService.class); - i.putExtra(TvOutService.EXTRA_COMMAND, TvOutService.COMMAND_CHANGE_SYSTEM); - i.putExtra(TvOutService.EXTRA_SYSTEM, newSystem); - startService(i); - } - return true; - } - - }); - } - - @Override - protected void onResume() { - super.onResume(); - registerReceiver(mHeadsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); - } - - @Override - protected void onPause() { - super.onPause(); - unregisterReceiver(mHeadsetReceiver); - } - - private void updateTvOutEnable(boolean connected) { - mTvOutEnable.setEnabled(connected); - mTvOutEnable.setSummaryOff(connected ? R.string.tvout_enable_summary : R.string.tvout_enable_summary_nocable); - - if (!connected && mTvOutEnable.isChecked()) { - // Disable on unplug (UI) - mTvOutEnable.setChecked(false); - } - } - - @Override - protected void onDestroy() { - mTvOut.finalize(); - super.onDestroy(); - } - -} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java b/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java deleted file mode 100644 index edffa72..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/ColorTuningPreference.java +++ /dev/null @@ -1,173 +0,0 @@ -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/Hspa.java b/AriesParts/src/com/cyanogenmod/AriesParts/Hspa.java deleted file mode 100644 index 7c89127..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/Hspa.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.cyanogenmod.AriesParts; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.PreferenceManager; - -public class Hspa implements OnPreferenceChangeListener { - - private static final String APK_FILE = "/system/app/SamsungServiceMode.apk"; - private Context mCtx; - - public Hspa(Context context) { - mCtx = context; - } - - public static boolean isSupported() { - return Utils.fileExists(APK_FILE); - } - - /** - * Restore HSPA 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); - sendIntent(context, sharedPrefs.getString(AriesParts.KEY_HSPA, "23")); - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - sendIntent(mCtx, (String) newValue); - return true; - } - - private static void sendIntent(Context context, String value) { - Intent i = new Intent("com.cyanogenmod.SamsungServiceMode.EXECUTE"); - i.putExtra("sub_type", 20); // HSPA Setting - i.putExtra("data", value); - context.sendBroadcast(i); - } -} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java b/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java deleted file mode 100644 index 755d599..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/Startup.java +++ /dev/null @@ -1,16 +0,0 @@ -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); - Hspa.restore(context); - } - -} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java b/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java deleted file mode 100644 index 554098a..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/TouchKeyBacklightTimeout.java +++ /dev/null @@ -1,36 +0,0 @@ -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/TvOutService.java b/AriesParts/src/com/cyanogenmod/AriesParts/TvOutService.java deleted file mode 100644 index 5812ac6..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/TvOutService.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.cyanogenmod.AriesParts; - -import android.app.Service; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.hardware.TvOut; -import android.os.IBinder; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.os.SystemProperties; -import android.preference.PreferenceManager; -import android.view.Display; -import android.view.IRotationWatcher; -import android.view.IWindowManager; -import android.view.WindowManager; - -public class TvOutService extends Service { - - public static final String EXTRA_COMMAND = "command"; - public static final String EXTRA_SYSTEM = "system"; - public static final String COMMAND_ENABLE = "enable"; - public static final String COMMAND_DISABLE = "disable"; - public static final String COMMAND_CHANGE_SYSTEM = "system"; - - private TvOut mTvOut; - private SharedPreferences mPref; - private int mSystem; - private boolean mWasOn = false; // For enabling on screen on - - private BroadcastReceiver mReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (Intent.ACTION_HEADSET_PLUG.equals(action)) { - int state = intent.getIntExtra("state", 0); - if (state == 0 && mTvOut._isEnabled()) { - // Disable when cable is unplugged - mWasOn = false; - disable(); - stopSelf(); - } - } - else if (Intent.ACTION_SCREEN_ON.equals(action)) { - if (mWasOn) { - enable(); - mWasOn = false; - } - } - else if (Intent.ACTION_SCREEN_OFF.equals(action)) { - if (mTvOut._isEnabled()) { - mWasOn = true; - disable(); - } - } - } - - }; - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public void onCreate() { - mTvOut = new TvOut(); - mPref = PreferenceManager.getDefaultSharedPreferences(this); - - IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); - try { - wm.watchRotation(new IRotationWatcher.Stub() { - @Override - public void onRotationChanged(int rotation) { - TvOutService.this.onRotationChanged(rotation); - } - }); - } - catch (RemoteException e) { } - - IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); - filter.addAction(Intent.ACTION_SCREEN_OFF); - filter.addAction(Intent.ACTION_SCREEN_ON); - registerReceiver(mReceiver, filter); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (intent != null) { - String command = intent.getStringExtra("command"); - if (COMMAND_ENABLE.equals(command)) { - mSystem = Integer.parseInt(mPref.getString(AriesParts.KEY_TVOUT_SYSTEM, "2")); // Default = PAL - enable(); - } - else if (COMMAND_DISABLE.equals(command)) { - disable(); - stopSelf(); - } - else if (COMMAND_CHANGE_SYSTEM.equals(command)) { - if (mTvOut._isEnabled()) { - mSystem = intent.getIntExtra(EXTRA_SYSTEM, 2); - disable(); - enable(); - } - } - } - - return START_STICKY; - } - - @Override - public void onDestroy() { - unregisterReceiver(mReceiver); - mTvOut.finalize(); - super.onDestroy(); - } - - public void onRotationChanged(int rotation) { - mTvOut._SetOrientation(rotation); - } - - private void enable() { - mTvOut._SetTvSystem(mSystem); - mTvOut._TvOutSetImageString("TV-out not supported while application running. Phone display only"); - - Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - mTvOut._SetOrientation(display.getRotation()); - - mTvOut._EnableTvOut(); - mTvOut._setTvoutCableConnected(1); - - // Start tvouthack service used to bombard screen refresh messages - SystemProperties.set("ctl.start", "tvouthack"); - } - - private void disable() { - SystemProperties.set("ctl.stop", "tvouthack"); - - mTvOut._DisableTvOut(); - mTvOut._setTvoutCableConnected(0); - } - -} diff --git a/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java b/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java deleted file mode 100644 index 87a7fbd..0000000 --- a/AriesParts/src/com/cyanogenmod/AriesParts/Utils.java +++ /dev/null @@ -1,47 +0,0 @@ -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.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(); - } - -} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/AriesParts.java b/AriesParts/src/com/cyanogenmod/settings/device/AriesParts.java new file mode 100644 index 0000000..37660ab --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/AriesParts.java @@ -0,0 +1,118 @@ +package com.cyanogenmod.settings.device; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.TvOut; +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.ListPreference; +import android.preference.Preference; +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"; + public static final String KEY_HSPA = "hspa"; + public static final String KEY_TVOUT_ENABLE = "tvout_enable"; + public static final String KEY_TVOUT_SYSTEM = "tvout_system"; + + private ColorTuningPreference mColorTuning; + private ListPreference mBacklightTimeout; + private ListPreference mHspa; + private CheckBoxPreference mTvOutEnable; + private ListPreference mTvOutSystem; + private TvOut mTvOut; + + private BroadcastReceiver mHeadsetReceiver = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + int state = intent.getIntExtra("state", 0); + updateTvOutEnable(state != 0); + } + + }; + + @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()); + + mHspa = (ListPreference) findPreference(KEY_HSPA); + mHspa.setEnabled(Hspa.isSupported()); + mHspa.setOnPreferenceChangeListener(new Hspa(this)); + + mTvOut = new TvOut(); + mTvOutEnable = (CheckBoxPreference) findPreference(KEY_TVOUT_ENABLE); + mTvOutEnable.setChecked(mTvOut._isEnabled()); + + mTvOutEnable.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + boolean enable = (Boolean) newValue; + Intent i = new Intent(AriesParts.this, TvOutService.class); + i.putExtra(TvOutService.EXTRA_COMMAND, enable ? TvOutService.COMMAND_ENABLE : TvOutService.COMMAND_DISABLE); + startService(i); + return true; + } + + }); + + mTvOutSystem = (ListPreference) findPreference(KEY_TVOUT_SYSTEM); + mTvOutSystem.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mTvOut._isEnabled()) { + int newSystem = Integer.valueOf((String) newValue); + Intent i = new Intent(AriesParts.this, TvOutService.class); + i.putExtra(TvOutService.EXTRA_COMMAND, TvOutService.COMMAND_CHANGE_SYSTEM); + i.putExtra(TvOutService.EXTRA_SYSTEM, newSystem); + startService(i); + } + return true; + } + + }); + } + + @Override + protected void onResume() { + super.onResume(); + registerReceiver(mHeadsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); + } + + @Override + protected void onPause() { + super.onPause(); + unregisterReceiver(mHeadsetReceiver); + } + + private void updateTvOutEnable(boolean connected) { + mTvOutEnable.setEnabled(connected); + mTvOutEnable.setSummaryOff(connected ? R.string.tvout_enable_summary : R.string.tvout_enable_summary_nocable); + + if (!connected && mTvOutEnable.isChecked()) { + // Disable on unplug (UI) + mTvOutEnable.setChecked(false); + } + } + + @Override + protected void onDestroy() { + mTvOut.finalize(); + super.onDestroy(); + } + +} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java b/AriesParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java new file mode 100644 index 0000000..7ac4b31 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java @@ -0,0 +1,173 @@ +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.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/settings/device/Hspa.java b/AriesParts/src/com/cyanogenmod/settings/device/Hspa.java new file mode 100644 index 0000000..779e733 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/Hspa.java @@ -0,0 +1,48 @@ +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class Hspa implements OnPreferenceChangeListener { + + private static final String APK_FILE = "/system/app/SamsungServiceMode.apk"; + private Context mCtx; + + public Hspa(Context context) { + mCtx = context; + } + + public static boolean isSupported() { + return Utils.fileExists(APK_FILE); + } + + /** + * Restore HSPA 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); + sendIntent(context, sharedPrefs.getString(AriesParts.KEY_HSPA, "23")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + sendIntent(mCtx, (String) newValue); + return true; + } + + private static void sendIntent(Context context, String value) { + Intent i = new Intent("com.cyanogenmod.SamsungServiceMode.EXECUTE"); + i.putExtra("sub_type", 20); // HSPA Setting + i.putExtra("data", value); + context.sendBroadcast(i); + } +} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java new file mode 100644 index 0000000..bb64961 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java @@ -0,0 +1,16 @@ +package com.cyanogenmod.settings.device; + +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); + Hspa.restore(context); + } + +} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/TouchKeyBacklightTimeout.java b/AriesParts/src/com/cyanogenmod/settings/device/TouchKeyBacklightTimeout.java new file mode 100644 index 0000000..0bcb0fd --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/TouchKeyBacklightTimeout.java @@ -0,0 +1,36 @@ +package com.cyanogenmod.settings.device; + +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/settings/device/TvOutService.java b/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java new file mode 100644 index 0000000..5392669 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/TvOutService.java @@ -0,0 +1,146 @@ +package com.cyanogenmod.settings.device; + +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.hardware.TvOut; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.os.SystemProperties; +import android.preference.PreferenceManager; +import android.view.Display; +import android.view.IRotationWatcher; +import android.view.IWindowManager; +import android.view.WindowManager; + +public class TvOutService extends Service { + + public static final String EXTRA_COMMAND = "command"; + public static final String EXTRA_SYSTEM = "system"; + public static final String COMMAND_ENABLE = "enable"; + public static final String COMMAND_DISABLE = "disable"; + public static final String COMMAND_CHANGE_SYSTEM = "system"; + + private TvOut mTvOut; + private SharedPreferences mPref; + private int mSystem; + private boolean mWasOn = false; // For enabling on screen on + + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (Intent.ACTION_HEADSET_PLUG.equals(action)) { + int state = intent.getIntExtra("state", 0); + if (state == 0 && mTvOut._isEnabled()) { + // Disable when cable is unplugged + mWasOn = false; + disable(); + stopSelf(); + } + } + else if (Intent.ACTION_SCREEN_ON.equals(action)) { + if (mWasOn) { + enable(); + mWasOn = false; + } + } + else if (Intent.ACTION_SCREEN_OFF.equals(action)) { + if (mTvOut._isEnabled()) { + mWasOn = true; + disable(); + } + } + } + + }; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate() { + mTvOut = new TvOut(); + mPref = PreferenceManager.getDefaultSharedPreferences(this); + + IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); + try { + wm.watchRotation(new IRotationWatcher.Stub() { + @Override + public void onRotationChanged(int rotation) { + TvOutService.this.onRotationChanged(rotation); + } + }); + } + catch (RemoteException e) { } + + IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); + filter.addAction(Intent.ACTION_SCREEN_OFF); + filter.addAction(Intent.ACTION_SCREEN_ON); + registerReceiver(mReceiver, filter); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + if (intent != null) { + String command = intent.getStringExtra("command"); + if (COMMAND_ENABLE.equals(command)) { + mSystem = Integer.parseInt(mPref.getString(AriesParts.KEY_TVOUT_SYSTEM, "2")); // Default = PAL + enable(); + } + else if (COMMAND_DISABLE.equals(command)) { + disable(); + stopSelf(); + } + else if (COMMAND_CHANGE_SYSTEM.equals(command)) { + if (mTvOut._isEnabled()) { + mSystem = intent.getIntExtra(EXTRA_SYSTEM, 2); + disable(); + enable(); + } + } + } + + return START_STICKY; + } + + @Override + public void onDestroy() { + unregisterReceiver(mReceiver); + mTvOut.finalize(); + super.onDestroy(); + } + + public void onRotationChanged(int rotation) { + mTvOut._SetOrientation(rotation); + } + + private void enable() { + mTvOut._SetTvSystem(mSystem); + mTvOut._TvOutSetImageString("TV-out not supported while application running. Phone display only"); + + Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + mTvOut._SetOrientation(display.getRotation()); + + mTvOut._EnableTvOut(); + mTvOut._setTvoutCableConnected(1); + + // Start tvouthack service used to bombard screen refresh messages + SystemProperties.set("ctl.start", "tvouthack"); + } + + private void disable() { + SystemProperties.set("ctl.stop", "tvouthack"); + + mTvOut._DisableTvOut(); + mTvOut._setTvoutCableConnected(0); + } + +} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Utils.java b/AriesParts/src/com/cyanogenmod/settings/device/Utils.java new file mode 100644 index 0000000..f112e09 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/Utils.java @@ -0,0 +1,47 @@ +package com.cyanogenmod.settings.device; + +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.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(); + } + +} -- cgit v1.1