diff options
Diffstat (limited to 'GNexusParts/src')
10 files changed, 1455 insertions, 0 deletions
diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java b/GNexusParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java new file mode 100644 index 0000000..94a638d --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java @@ -0,0 +1,224 @@ +/* + * 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.TextView; +import android.widget.Button; +import android.util.Log; + +/** + * Special preference type that allows configuration of both the ring volume and + * notification volume. + */ +public class ColorHackPresets extends DialogPreference implements OnClickListener { + + private static final String TAG = "PRESETS..."; + + private static final String[] FILE_PATH_GAMMA = new String[] { + "/sys/class/misc/samoled_color/red_v1_offset", + "/sys/class/misc/samoled_color/green_v1_offset", + "/sys/class/misc/samoled_color/blue_v1_offset", + "/sys/devices/platform/omapdss/manager0/gamma" + }; + + private static final String[] FILE_PATH_MULTI = new String[] { + "/sys/class/misc/samoled_color/red_multiplier", + "/sys/class/misc/samoled_color/green_multiplier", + "/sys/class/misc/samoled_color/blue_multiplier" + }; + + // 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; + + // Align MAX_VALUE with Voodoo Control settings + private static final int MAX_VALUE = 2000000000; + + public ColorHackPresets(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_colorgamma_presets); + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + sInstances++; + + SetupButtonClickListeners(view); + } + + private void SetupButtonClickListeners(View view) { + Button[] mPresets = new Button[6]; + + mPresets[0] = (Button)view.findViewById(R.id.btnPreset1); + mPresets[1] = (Button)view.findViewById(R.id.btnPreset2); + mPresets[2] = (Button)view.findViewById(R.id.btnPreset3); + mPresets[3] = (Button)view.findViewById(R.id.btnPreset4); + mPresets[4] = (Button)view.findViewById(R.id.btnPreset5); + mPresets[5] = (Button)view.findViewById(R.id.btnPreset6); + for (int i = 0; i < 6; i++) { + mPresets[i].setOnClickListener(this); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + } + + /** + * 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; + } + + } + + /** + * 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_MULTI) { + if (!Utils.fileExists(filePath)) { + supported = false; + } + } + for (String filePath : FILE_PATH_GAMMA) { + if (!Utils.fileExists(filePath)) { + supported = false; + } + } + + return supported; + } + + public void onClick(View v) { + switch(v.getId()){ + case R.id.btnPreset1: + Preset1(); + break; + case R.id.btnPreset2: + Preset2(); + break; + case R.id.btnPreset3: + Preset3(); + break; + case R.id.btnPreset4: + Preset4(); + break; + case R.id.btnPreset5: + Preset5(); + break; + case R.id.btnPreset6: + Preset6(); + break; + } + } + + private void WriteMultiplier(Double fValue , int iPos) { + int iValue = (int) ((double) MAX_VALUE * fValue); + Utils.writeColor(FILE_PATH_MULTI[iPos], iValue); + Log.i(TAG,"KalimAz: Multiplier: " + iPos+ " Value " + iValue ); + } + + private void WriteGamma(int iValue , int iPos) { + Utils.writeValue(FILE_PATH_GAMMA[iPos], String.valueOf((long) iValue)); + Log.i(TAG,"KalimAz: Gamma: " + iPos+ " Value " + iValue ); + } + + private void Preset1() { + WriteMultiplier(0.5, 0); + WriteMultiplier(0.5, 1); + WriteMultiplier(0.5, 2); + WriteGamma(0, 0); + WriteGamma(0, 1); + WriteGamma(0, 2); + WriteGamma(0, 3); + } + + private void Preset2() { + WriteMultiplier(1.0, 0); + WriteMultiplier(1.0, 1); + WriteMultiplier(1.0, 2); + WriteGamma(0, 0); + WriteGamma(0, 1); + WriteGamma(0, 2); + WriteGamma(0, 3); + } + + private void Preset3() { + WriteMultiplier(0.35, 0); + WriteMultiplier(0.38, 1); + WriteMultiplier(0.5, 2); + WriteGamma(0, 0); + WriteGamma(0, 1); + WriteGamma(0, 2); + WriteGamma(0, 3); + } + + private void Preset4() { + WriteMultiplier(0.7231, 0); + WriteMultiplier(0.7016, 1); + WriteMultiplier(0.6532, 2); + WriteGamma(-31, 0); + WriteGamma(-30, 1); + WriteGamma(-14, 2); + WriteGamma(0, 3); + } + + private void Preset5() { + WriteMultiplier(0.6666, 0); + WriteMultiplier(0.6666, 1); + WriteMultiplier(0.8333, 2); + WriteGamma(-44, 0); + WriteGamma(-44, 1); + WriteGamma(-7, 2); + WriteGamma(0, 3); + } + + private void Preset6() { + WriteMultiplier(0.45, 0); + WriteMultiplier(0.48, 1); + WriteMultiplier(0.5, 2); + WriteGamma(-4, 0); + WriteGamma(0, 1); + WriteGamma(5, 2); + WriteGamma(0, 3); + } + +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java b/GNexusParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java new file mode 100644 index 0000000..25cbeb7 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java @@ -0,0 +1,264 @@ +/* + * 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 ColorTuningPreference extends DialogPreference implements OnClickListener { + + private static final String TAG = "COLOR..."; + + 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/samoled_color/red_multiplier", + "/sys/class/misc/samoled_color/green_multiplier", + "/sys/class/misc/samoled_color/blue_multiplier" + }; + + private ColorSeekBar mSeekBars[] = new ColorSeekBar[3]; + + // Align MAX_VALUE with Voodoo Control settings + private static final int MAX_VALUE = 2000000000; + + // 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]); + } + SetupButtonClickListeners(view); + } + + private void SetupButtonClickListeners(View view) { + Button mButton1 = (Button)view.findViewById(R.id.btnColor1); + Button mButton2 = (Button)view.findViewById(R.id.btnColor2); + Button mButton3 = (Button)view.findViewById(R.id.btnColor3); + mButton1.setOnClickListener(this); + mButton2.setOnClickListener(this); + mButton3.setOnClickListener(this); + } + + @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; + } + + int iValue, iValue2; + 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); + } catch (NumberFormatException e) { + iValue2 = MAX_VALUE; + } + 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.writeColor(filePath, (int) 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 ColorSeekBar implements SeekBar.OnSeekBarChangeListener { + + private String mFilePath; + + private int mOriginal; + + private SeekBar mSeekBar; + + private TextView mValueDisplay; + + public ColorSeekBar(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) / 2); + } 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.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("%d", (int) progress / 5000000)); + } + + public void SetNewValue(int iValue) { + mOriginal = iValue; + reset(); + } + + } + + public void onClick(View v) { + switch(v.getId()){ + case R.id.btnColor1: + SetSettings1(); + break; + case R.id.btnColor2: + SetSettings2(); + break; + case R.id.btnColor3: + SetSettings3(); + break; + } + } + + private void SetSettings1() { + mSeekBars[0].SetNewValue(1000000000); + mSeekBars[1].SetNewValue(1000000000); + mSeekBars[2].SetNewValue(1000000000); + } + + private void SetSettings2() { + mSeekBars[0].SetNewValue(1750000000); + mSeekBars[1].SetNewValue(1750000000); + mSeekBars[2].SetNewValue(1750000000); + } + + private void SetSettings3() { + mSeekBars[0].SetNewValue(900000000); + mSeekBars[1].SetNewValue(960000000); + mSeekBars[2].SetNewValue(1000000000); + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/DevicePreferenceActivity.java b/GNexusParts/src/com/cyanogenmod/settings/device/DevicePreferenceActivity.java new file mode 100644 index 0000000..957883b --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/DevicePreferenceActivity.java @@ -0,0 +1,88 @@ +/* + * 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.app.ActionBar; +import android.app.ActionBar.Tab; +import android.app.ActionBar.TabListener; +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.preference.ListPreference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; +import android.support.v13.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentActivity; +import android.support.v4.view.ViewPager; +import android.view.MenuItem; + +import com.cyanogenmod.settings.device.R; + +import java.util.ArrayList; + +public class DevicePreferenceActivity extends PreferenceFragment { + + public static final String SHARED_PREFERENCES_BASENAME = "com.cyanogenmod.settings.device"; + public static final String ACTION_UPDATE_PREFERENCES = "com.cyanogenmod.settings.device.UPDATE"; + public static final String KEY_COLOR_TUNING = "color_tuning"; + public static final String KEY_GAMMA_TUNING = "gamma_tuning"; + public static final String KEY_COLORGAMMA_PRESETS = "colorgamma_presets"; + public static final String KEY_VIBRATOR_TUNING = "vibrator_tuning"; + public static final String KEY_CATEGORY_RADIO = "category_radio"; + public static final String KEY_HSPA = "hspa"; + public static final String KEY_GPU_OVERCLOCK = "gpu_overclock"; + + private ColorTuningPreference mColorTuning; + private GammaTuningPreference mGammaTuning; + private ColorHackPresets mColorHackPresets; + private VibratorTuningPreference mVibratorTuning; + private ListPreference mGpuOverclock; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.preferences); + + mColorTuning = (ColorTuningPreference) findPreference(KEY_COLOR_TUNING); + mColorTuning.setEnabled(ColorTuningPreference.isSupported()); + + mGammaTuning = (GammaTuningPreference) findPreference(KEY_GAMMA_TUNING); + mGammaTuning.setEnabled(GammaTuningPreference.isSupported()); + + mColorHackPresets = (ColorHackPresets) findPreference(KEY_COLORGAMMA_PRESETS); + mColorHackPresets.setEnabled(ColorHackPresets.isSupported()); + + mVibratorTuning = (VibratorTuningPreference) findPreference(KEY_VIBRATOR_TUNING); + mVibratorTuning.setEnabled(VibratorTuningPreference.isSupported()); + + PreferenceScreen prefSet = getPreferenceScreen(); + + mGpuOverclock = (ListPreference) findPreference(KEY_GPU_OVERCLOCK); + mGpuOverclock.setEnabled(GpuOverclock.isSupported()); + mGpuOverclock.setOnPreferenceChangeListener(new GpuOverclock()); + GpuOverclock.updateSummary(mGpuOverclock, Integer.parseInt(mGpuOverclock.getValue())); + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/DeviceSettings.java b/GNexusParts/src/com/cyanogenmod/settings/device/DeviceSettings.java new file mode 100644 index 0000000..772e557 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -0,0 +1,30 @@ +package com.cyanogenmod.settings.device; + +import android.app.ActionBar; +import android.app.Activity; +import android.os.Bundle; +import android.view.MenuItem; + +public class DeviceSettings extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + ActionBar actionBar = getActionBar(); + actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); + actionBar.setDisplayHomeAsUpEnabled(true); + + getFragmentManager().beginTransaction().replace(android.R.id.content, + new DevicePreferenceActivity()).commit(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + DeviceSettings.this.onBackPressed(); + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java b/GNexusParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java new file mode 100644 index 0000000..3c5aef0 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java @@ -0,0 +1,286 @@ +/* + * 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.widget.Button; +import android.util.Log; + +/** + * Special preference type that allows configuration of both the ring volume and + * notification volume. + */ +public class GammaTuningPreference extends DialogPreference implements OnClickListener { + + 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, R.id.gamma_dss_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, R.id.gamma_dss_value + }; + + private static final String[] FILE_PATH = new String[] { + "/sys/class/misc/samoled_color/red_v1_offset", + "/sys/class/misc/samoled_color/green_v1_offset", + "/sys/class/misc/samoled_color/blue_v1_offset", + "/sys/devices/platform/omapdss/manager0/gamma" + }; + + private GammaSeekBar mSeekBars[] = new GammaSeekBar[4]; + + private static final int MAX_VALUE = 200; + + private static final int OFFSET_VALUE = 100; + + // 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]); + if (i < 3) + mSeekBars[i] = new GammaSeekBar(seekBar, valueDisplay, FILE_PATH[i], OFFSET_VALUE, MAX_VALUE); + else + mSeekBars[i] = new GammaSeekBar(seekBar, valueDisplay, FILE_PATH[i], 0, 10); + } + SetupButtonClickListeners(view); + } + + private void SetupButtonClickListeners(View view) { + Button mButton1 = (Button)view.findViewById(R.id.btnGamma1); + Button mButton2 = (Button)view.findViewById(R.id.btnGamma2); + Button mButton3 = (Button)view.findViewById(R.id.btnGamma3); + mButton1.setOnClickListener(this); + mButton2.setOnClickListener(this); + mButton3.setOnClickListener(this); + } + + @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; + } + + int iValue; + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + + Boolean bFirstTime = sharedPrefs.getBoolean("FirstTimeGamma", true); + for (String filePath : FILE_PATH) { + String sDefaultValue = Utils.readOneLine(filePath); + iValue = sharedPrefs.getInt(filePath, Integer.valueOf(sDefaultValue)); + if (bFirstTime) + Utils.writeValue(filePath, "0"); + else + Utils.writeValue(filePath, String.valueOf((long) iValue)); + } + if (bFirstTime) + { + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putBoolean("FirstTimeGamma", false); + editor.commit(); + } + } + + /** + * 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; + + private int iOffset; + + private int iMax; + + public GammaSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath, Integer offsetValue, Integer maxValue) { + int iValue; + + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + iOffset = offsetValue; + iMax = maxValue; + + SharedPreferences sharedPreferences = getSharedPreferences(); + + // Read original value + if (Utils.fileExists(mFilePath)) { + String sDefaultValue = Utils.readOneLine(mFilePath); + iValue = Integer.valueOf(sDefaultValue); + } else { + iValue = iMax - iOffset; + } + mOriginal = iValue; + + mSeekBar.setMax(iMax); + + reset(); + mSeekBar.setOnSeekBarChangeListener(this); + } + + public void reset() { + int iValue; + + iValue = mOriginal + iOffset; + mSeekBar.setProgress(iValue); + updateValue(mOriginal); + } + + public void save() { + int iValue; + + iValue = mSeekBar.getProgress() - iOffset; + Editor editor = getEditor(); + editor.putInt(mFilePath, iValue); + editor.commit(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + int iValue; + + iValue = progress - iOffset; + 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)); + } + + public void SetNewValue(int iValue) { + mOriginal = iValue; + reset(); + } + + } + + public void onClick(View v) { + switch(v.getId()){ + case R.id.btnGamma1: + SetSettings1(); + break; + case R.id.btnGamma2: + SetSettings2(); + break; + case R.id.btnGamma3: + SetSettings3(); + break; + } + } + + private void SetSettings1() { + mSeekBars[0].SetNewValue(0); + mSeekBars[1].SetNewValue(0); + mSeekBars[2].SetNewValue(0); + mSeekBars[3].SetNewValue(0); + } + + private void SetSettings2() { + mSeekBars[0].SetNewValue(2); + mSeekBars[1].SetNewValue(15); + mSeekBars[2].SetNewValue(5); + mSeekBars[3].SetNewValue(8); + } + + private void SetSettings3() { + mSeekBars[0].SetNewValue(-4); + mSeekBars[1].SetNewValue(0); + mSeekBars[2].SetNewValue(5); + mSeekBars[3].SetNewValue(0); + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/GpuOverclock.java b/GNexusParts/src/com/cyanogenmod/settings/device/GpuOverclock.java new file mode 100644 index 0000000..9dba113 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/GpuOverclock.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 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.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class GpuOverclock implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/devices/system/cpu/cpu0/cpufreq/gpu_oc"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(DevicePreferenceActivity.KEY_GPU_OVERCLOCK, "0")); + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + updateSummary((ListPreference) preference, Integer.parseInt(newValue.toString())); + return true; + } + + public static void updateSummary(ListPreference preference, int value) { + final CharSequence[] entries = preference.getEntries(); + final CharSequence[] values = preference.getEntryValues(); + int best = 0; + for (int i = 0; i < values.length; i++) { + int summaryValue = Integer.parseInt(values[i].toString()); + if (value >= summaryValue) { + best = i; + } + } + preference.setSummary(entries[best].toString()); + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/Hspa.java b/GNexusParts/src/com/cyanogenmod/settings/device/Hspa.java new file mode 100644 index 0000000..d2cf641 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/Hspa.java @@ -0,0 +1,57 @@ +package com.cyanogenmod.settings.device; + +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.gnexusparts.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(DevicePreferenceActivity.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/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java b/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java new file mode 100644 index 0000000..f1cd2ad --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java @@ -0,0 +1,19 @@ +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); + GammaTuningPreference.restore(context); + VibratorTuningPreference.restore(context); + GpuOverclock.restore(context); + if (Hspa.isSupported()) { + Hspa.restore(context); + } + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/Utils.java b/GNexusParts/src/com/cyanogenmod/settings/device/Utils.java new file mode 100644 index 0000000..dbf2947 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/Utils.java @@ -0,0 +1,149 @@ +/* + * 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.util.Log; + +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 java.io.SyncFailedException; + +public class Utils { + private static final String TAG = "GNexusParts_Utils"; + private static final String TAG_READ = "GNexusParts_Utils_Read"; + private static final String TAG_WRITE = "GNexusParts_Utils_Write"; + + /** + * Write a string value to the specified file. + * + * @param filename The filename + * @param value The value + */ + public static void writeValue(String filename, String value) { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(new File(filename), false); + fos.write(value.getBytes()); + fos.flush(); + // fos.getFD().sync(); + } catch (FileNotFoundException ex) { + Log.w(TAG, "file " + filename + " not found: " + ex); + } catch (SyncFailedException ex) { + Log.w(TAG, "file " + filename + " sync failed: " + ex); + } catch (IOException ex) { + Log.w(TAG, "IOException trying to sync " + filename + ": " + ex); + } catch (RuntimeException ex) { + Log.w(TAG, "exception while syncing file: ", ex); + } finally { + if (fos != null) { + try { + Log.w(TAG_WRITE, "file " + filename + ": " + value); + fos.close(); + } catch (IOException ex) { + Log.w(TAG, "IOException while closing synced file: ", ex); + } catch (RuntimeException ex) { + Log.w(TAG, "exception while closing file: ", ex); + } + } + } + + } + + /** + * Write a string value to the specified file. + * + * @param filename The filename + * @param value The value + */ + public static void writeValue(String filename, Boolean value) { + FileOutputStream fos = null; + String sEnvia; + try { + fos = new FileOutputStream(new File(filename), false); + if (value) + sEnvia = "1"; + else + sEnvia = "0"; + fos.write(sEnvia.getBytes()); + fos.flush(); + // fos.getFD().sync(); + } catch (FileNotFoundException ex) { + Log.w(TAG, "file " + filename + " not found: " + ex); + } catch (SyncFailedException ex) { + Log.w(TAG, "file " + filename + " sync failed: " + ex); + } catch (IOException ex) { + Log.w(TAG, "IOException trying to sync " + filename + ": " + ex); + } catch (RuntimeException ex) { + Log.w(TAG, "exception while syncing file: ", ex); + } finally { + if (fos != null) { + try { + Log.w(TAG_WRITE, "file " + filename + ": " + value); + fos.close(); + } catch (IOException ex) { + Log.w(TAG, "IOException while closing synced file: ", ex); + } catch (RuntimeException ex) { + Log.w(TAG, "exception while closing file: ", ex); + } + } + } + } + + /** + * 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 { + Log.w(TAG_READ, "file " + sFile + ": " + sLine); + brBuffer.close(); + } + } catch (Exception e) { + Log.e(TAG_READ, "IO Exception when reading /sys/ file", e); + } + return sLine; + } +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/VibratorTuningPreference.java b/GNexusParts/src/com/cyanogenmod/settings/device/VibratorTuningPreference.java new file mode 100644 index 0000000..f8aec17 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/VibratorTuningPreference.java @@ -0,0 +1,277 @@ +/* + * 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.widget.Button; +import android.util.Log; +import android.os.Vibrator; + +/** + * Special preference type that allows configuration of both the ring volume and + * notification volume. + */ +public class VibratorTuningPreference extends DialogPreference implements OnClickListener { + + private static final String TAG = "vibrator..."; + + private static final int[] SEEKBAR_ID = new int[] { + R.id.vibrator_seekbar + }; + + private static final int[] VALUE_DISPLAY_ID = new int[] { + R.id.vibrator_value + }; + + private static final String[] FILE_PATH = new String[] { + "/sys/vibrator/pwmvalue", + }; + + private vibratorSeekBar mSeekBars[] = new vibratorSeekBar[1]; + + private static final int MAX_VALUE = 100; + + private static final int OFFSET_VALUE = 0; + + // 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 VibratorTuningPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_dialog_vibrator_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]); + if (i < 3) + mSeekBars[i] = new vibratorSeekBar(seekBar, valueDisplay, FILE_PATH[i], OFFSET_VALUE, MAX_VALUE); + else + mSeekBars[i] = new vibratorSeekBar(seekBar, valueDisplay, FILE_PATH[i], 0, 10); + } + SetupButtonClickListeners(view); + } + + private void SetupButtonClickListeners(View view) { + Button mDefaultButton = (Button)view.findViewById(R.id.btnvibratorDefault); + mDefaultButton.setOnClickListener(this); + + Button mTestButton = (Button)view.findViewById(R.id.btnvibratorTest); + mTestButton.setOnClickListener(this); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + if (positiveResult) { + for (vibratorSeekBar csb : mSeekBars) { + csb.save(); + } + } else if (sInstances == 0) { + for (vibratorSeekBar 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); + + Boolean bFirstTime = sharedPrefs.getBoolean("FirstTimevibrator", true); + for (String filePath : FILE_PATH) { + String sDefaultValue = Utils.readOneLine(filePath); + int iValue = sharedPrefs.getInt(filePath, Integer.valueOf(sDefaultValue)); + if (bFirstTime) + Utils.writeValue(filePath, "100"); + else + Utils.writeValue(filePath, String.valueOf((long) iValue)); + } + if (bFirstTime) + { + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putBoolean("FirstTimevibrator", false); + editor.commit(); + } + } + + /** + * 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 vibratorSeekBar implements SeekBar.OnSeekBarChangeListener { + + private String mFilePath; + + private int mOriginal; + + private SeekBar mSeekBar; + + private TextView mValueDisplay; + + private int iOffset; + + private int iMax; + + public vibratorSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath, Integer offsetValue, Integer maxValue) { + int iValue; + + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + iOffset = offsetValue; + iMax = maxValue; + + SharedPreferences sharedPreferences = getSharedPreferences(); + + // Read original value + if (Utils.fileExists(mFilePath)) { + String sDefaultValue = Utils.readOneLine(mFilePath); + iValue = convertVibratorToAverage(Integer.valueOf(sDefaultValue)); + } else { + iValue = iMax - iOffset; + } + mOriginal = iValue; + + mSeekBar.setMax(iMax); + + reset(); + mSeekBar.setOnSeekBarChangeListener(this); + } + + public void reset() { + int iValue; + + iValue = mOriginal + iOffset; + mSeekBar.setProgress(iValue); + updateValue(mOriginal); + } + + public void save() { + int iValue; + + iValue = mSeekBar.getProgress() - iOffset; + Editor editor = getEditor(); + editor.putInt(mFilePath, convertAverageToVibrator(iValue)); + editor.commit(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + int iValue; + + iValue = progress - iOffset; + Utils.writeValue(mFilePath, String.valueOf((long) convertAverageToVibrator(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)); + } + + public void setNewValue(int iValue) { + mOriginal = iValue; + reset(); + } + + private int convertAverageToVibrator(int averageValue) { + int resultVibrator; + + resultVibrator = (averageValue * 127) / 100; + return resultVibrator; + } + + private int convertVibratorToAverage(int resultVibrator) { + int averageValue; + + averageValue = (resultVibrator * 100) / 127; + return averageValue; + } + + } + + public void onClick(View v) { + switch(v.getId()){ + case R.id.btnvibratorDefault: + setDefaultSettings(); + break; + case R.id.btnvibratorTest: + testVibration(); + break; + } + } + + private void setDefaultSettings() { + mSeekBars[0].setNewValue(100); + } + + private void testVibration() { + Vibrator vib = (Vibrator) this.getContext().getSystemService(Context.VIBRATOR_SERVICE); + vib.vibrate(1000); + } +} |