diff options
Diffstat (limited to 'CrespoParts/src/com/cyanogenmod')
9 files changed, 767 insertions, 0 deletions
diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/ColorTuningPreference.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/ColorTuningPreference.java new file mode 100644 index 0000000..4eb5f88 --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/ColorTuningPreference.java @@ -0,0 +1,173 @@ +package com.cyanogenmod.CrespoParts; + +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/class/misc/voodoo_color/red_multiplier", + "/sys/class/misc/voodoo_color/green_multiplier", + "/sys/class/misc/voodoo_color/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("%.10f", (double) progress / MAX_VALUE)); + } + + } + +} diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/CrespoParts.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/CrespoParts.java new file mode 100644 index 0000000..c8ce364 --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/CrespoParts.java @@ -0,0 +1,59 @@ +package com.cyanogenmod.CrespoParts; + +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceCategory; +import android.preference.PreferenceScreen; + +public class CrespoParts extends PreferenceActivity { + + public static final String KEY_COLOR_TUNING = "color_tuning"; + public static final String KEY_GAMMA_TUNING = "gamma_tuning"; + public static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout"; + public static final String KEY_BLINK_TIMEOUT = "blink_timeout"; + public static final String KEY_CATEGORY_RADIO = "category_radio"; + public static final String KEY_HSPA = "hspa"; + + private ColorTuningPreference mColorTuning; + private GammaTuningPreference mGammaTuning; + private ListPreference mBacklightTimeout; + private ListPreference mBlinkTimeout; + private ListPreference mHspa; + private PreferenceCategory mHsapCategory; + private PreferenceScreen mPreferenceScreen; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.main); + + mColorTuning = (ColorTuningPreference) findPreference(KEY_COLOR_TUNING); + mColorTuning.setEnabled(ColorTuningPreference.isSupported()); + + mGammaTuning = (GammaTuningPreference) findPreference(KEY_GAMMA_TUNING); + mGammaTuning.setEnabled(ColorTuningPreference.isSupported()); + + mBacklightTimeout = (ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT); + mBacklightTimeout.setEnabled(TouchKeyBacklightTimeout.isSupported()); + mBacklightTimeout.setOnPreferenceChangeListener(new TouchKeyBacklightTimeout()); + + mBlinkTimeout = (ListPreference) findPreference(KEY_BLINK_TIMEOUT); + mBlinkTimeout.setEnabled(TouchKeyBacklightTimeout.isSupported()); + mBlinkTimeout.setOnPreferenceChangeListener(new TouchKeyBlinkTimeout()); + + mHspa = (ListPreference) findPreference(KEY_HSPA); + + if (Hspa.isSupported()) { + mHspa.setEnabled(true); + mHspa.setOnPreferenceChangeListener(new Hspa(this)); + } else { + mHsapCategory = (PreferenceCategory) findPreference(KEY_CATEGORY_RADIO); + mPreferenceScreen = getPreferenceScreen(); + + mHspa.setEnabled(false); + mHsapCategory.removePreference(mHspa); + mPreferenceScreen.removePreference(mHsapCategory); + } + } +} diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/GammaTuningPreference.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/GammaTuningPreference.java new file mode 100644 index 0000000..28edb8f --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/GammaTuningPreference.java @@ -0,0 +1,186 @@ +package com.cyanogenmod.CrespoParts; + +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 GammaTuningPreference extends DialogPreference { + + private static final String TAG = "GAMMA..."; + + enum Colors { + RED, + GREEN, + BLUE + }; + + private static final int[] SEEKBAR_ID = new int[] { + R.id.gamma_red_seekbar, + R.id.gamma_green_seekbar, + R.id.gamma_blue_seekbar + }; + + private static final int[] VALUE_DISPLAY_ID = new int[] { + R.id.gamma_red_value, + R.id.gamma_green_value, + R.id.gamma_blue_value + }; + + private static final String[] FILE_PATH = new String[] { + "/sys/class/misc/voodoo_color/red_v1_offset", + "/sys/class/misc/voodoo_color/green_v1_offset", + "/sys/class/misc/voodoo_color/blue_v1_offset" + }; + + private GammaSeekBar mSeekBars[] = new GammaSeekBar[3]; + + private static final int MAX_VALUE = 80; + + // 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 GammaTuningPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_dialog_gamma_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 GammaSeekBar(seekBar, valueDisplay, FILE_PATH[i]); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + if (positiveResult) { + for (GammaSeekBar csb : mSeekBars) { + csb.save(); + } + } else if (sInstances == 0) { + for (GammaSeekBar 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) { + String sDefaultValue = Utils.readOneLine(filePath); + int iValue = sharedPrefs.getInt(filePath, Integer.valueOf(sDefaultValue)); + Utils.writeValue(filePath, String.valueOf((long) iValue)); + } + } + + /** + * 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 GammaSeekBar implements SeekBar.OnSeekBarChangeListener { + + private String mFilePath; + private int mOriginal; + private SeekBar mSeekBar; + private TextView mValueDisplay; + + public GammaSeekBar(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() { + int iValue; + + iValue = mOriginal+60; + mSeekBar.setProgress(iValue); + updateValue(mOriginal); + } + + public void save() { + int iValue; + + iValue = mSeekBar.getProgress()-60; + Editor editor = getEditor(); + editor.putInt(mFilePath, iValue); + editor.commit(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, + boolean fromUser) { + int iValue; + + iValue = progress-60; + Utils.writeValue(mFilePath, String.valueOf((long) iValue)); + updateValue(iValue); + } + + @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",(int) progress )); + } + + } + +} diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/Hspa.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/Hspa.java new file mode 100644 index 0000000..5f85302 --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/Hspa.java @@ -0,0 +1,57 @@ +package com.cyanogenmod.CrespoParts; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.SystemProperties; +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 static final String HSPA_PROP = "ro.crespoparts.rild.hspa"; + private static final String HSPA_PROP_ENABLED = "1"; + + private Context mCtx; + + public Hspa(Context context) { + mCtx = context; + } + + public static boolean isSupported() { + String mHspa = SystemProperties.get(HSPA_PROP,"0"); + if (mHspa.equals(HSPA_PROP_ENABLED)) { + return true; + } else { + return false; + } + } + + /** + * 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(CrespoParts.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/CrespoParts/src/com/cyanogenmod/CrespoParts/Startup.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/Startup.java new file mode 100644 index 0000000..5cb715a --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/Startup.java @@ -0,0 +1,19 @@ +package com.cyanogenmod.CrespoParts; + +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); + GammaTuningPreference.restore(context); + TouchKeyBacklightTimeout.restore(context); + WM8994ControlActivity.restore(context); + if (Hspa.isSupported()) { + Hspa.restore(context); + } + } +} diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBacklightTimeout.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBacklightTimeout.java new file mode 100644 index 0000000..c07f042 --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBacklightTimeout.java @@ -0,0 +1,36 @@ +package com.cyanogenmod.CrespoParts; + +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(CrespoParts.KEY_BACKLIGHT_TIMEOUT, "5")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +}
\ No newline at end of file diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBlinkTimeout.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBlinkTimeout.java new file mode 100644 index 0000000..3fdcf4d --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/TouchKeyBlinkTimeout.java @@ -0,0 +1,36 @@ +package com.cyanogenmod.CrespoParts; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class TouchKeyBlinkTimeout implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/misc/notification/blinktimeout"; + + 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(CrespoParts.KEY_BLINK_TIMEOUT, "5")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +}
\ No newline at end of file diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/Utils.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/Utils.java new file mode 100644 index 0000000..eb7dc57 --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/Utils.java @@ -0,0 +1,94 @@ +package com.cyanogenmod.CrespoParts; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; + +import android.util.Log; + +public class Utils { + private static final String TAG = "CrespoParts_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 a string value to the specified file. + * @param filename The filename + * @param value The value + */ + public static void writeValue(String filename, Boolean value) { + try { + String sEnvia; + FileOutputStream fos = new FileOutputStream(new File(filename)); + if(value) + sEnvia = "1"; + else + sEnvia = "0"; + fos.write(sEnvia.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(); + } + + // Read value from sysfs interface + public static String readOneLine(String sFile) { + BufferedReader brBuffer; + String sLine = null; + + try { + brBuffer = new BufferedReader(new FileReader(sFile), 512); + try { + sLine = brBuffer.readLine(); + } finally { + brBuffer.close(); + } + } catch (Exception e) { + Log.e(TAG, "IO Exception when reading /sys/ file", e); + } + return sLine; + } +} diff --git a/CrespoParts/src/com/cyanogenmod/CrespoParts/WM8994ControlActivity.java b/CrespoParts/src/com/cyanogenmod/CrespoParts/WM8994ControlActivity.java new file mode 100644 index 0000000..cde224c --- /dev/null +++ b/CrespoParts/src/com/cyanogenmod/CrespoParts/WM8994ControlActivity.java @@ -0,0 +1,107 @@ +/* + * 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.CrespoParts; + +import com.cyanogenmod.CrespoParts.R; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.util.Log; + +// WM8994 sound control stuff +public class WM8994ControlActivity extends PreferenceActivity /*implements + Preference.OnPreferenceChangeListener */{ + + public static final String aOptionControl[][] = { + {"/sys/class/misc/voodoo_sound_control/enable","pref_wm8994_control_enable"}, + {"/sys/class/misc/voodoo_sound/speaker_tuning","pref_wm8994_speaker_tuning"}, + {"/sys/class/misc/voodoo_sound/mono_downmix","pref_wm8994_mono_downmix"}, + {"/sys/class/misc/voodoo_sound/stereo_expansion","pref_wm8994_stereo_expansion"}, + {"/sys/class/misc/voodoo_sound/dac_direct","pref_wm8994_dac_direct"}, + {"/sys/class/misc/voodoo_sound/dac_osr128","pref_wm8994_dac_osr128"}, + {"/sys/class/misc/voodoo_sound/adc_osr128","pref_wm8994_adc_osr128"}, + {"/sys/class/misc/voodoo_sound/fll_tuning","pref_wm8994_fll_tuning"} + }; + private static final Integer iTotalOptions = aOptionControl.length; + private CheckBoxPreference cbpStatus[] = new CheckBoxPreference[iTotalOptions]; + + // Misc + private static final String PREF_ENABLED = "1"; + private static final String TAG = "CrespoParts_WM8994ControlSound"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setTitle(R.string.wm8994_settings_title_subhead); + addPreferencesFromResource(R.xml.wm8994_settings); + + PreferenceScreen prefSet = getPreferenceScreen(); + + // Set status value for all options created + Integer iPosition; + for(iPosition=0;iPosition<iTotalOptions;iPosition++) { + if (isSupported(aOptionControl[iPosition][0])) { + cbpStatus[iPosition] = (CheckBoxPreference) prefSet.findPreference(aOptionControl[iPosition][1]); + cbpStatus[iPosition].setChecked(PREF_ENABLED.equals(Utils.readOneLine(aOptionControl[iPosition][0]))); + } + } + } + + // Preference change action for check boxes + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + + Integer iPosition; + String boxValue; + for(iPosition=0;iPosition<iTotalOptions;iPosition++) { + if (preference == cbpStatus[iPosition]) { + Log.d(TAG,"Procesando Salida: " + aOptionControl[iPosition][1] + " .. " + aOptionControl[iPosition][0]); + boxValue = cbpStatus[iPosition].isChecked() ? "1" : "0"; + Utils.writeValue(aOptionControl[iPosition][0], boxValue); + } + } + + return true; + } + + public static boolean isSupported(String FILE) { + return Utils.fileExists(FILE); + } + + /** + * Restore Voodoo Sound options setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + + // Restore all + Integer iPosition; + for(iPosition=0;iPosition<iTotalOptions;iPosition++) { + if (isSupported(aOptionControl[iPosition][0])) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(aOptionControl[iPosition][0], sharedPrefs.getBoolean(aOptionControl[iPosition][1], true)); + } + } + } +} |