summaryrefslogtreecommitdiffstats
path: root/CrespoParts/src/com/cyanogenmod/settings/device
diff options
context:
space:
mode:
Diffstat (limited to 'CrespoParts/src/com/cyanogenmod/settings/device')
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java212
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java264
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java163
-rwxr-xr-xCrespoParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java54
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java272
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java159
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/Hspa.java57
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/Startup.java18
-rw-r--r--CrespoParts/src/com/cyanogenmod/settings/device/Utils.java149
9 files changed, 1348 insertions, 0 deletions
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java b/CrespoParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java
new file mode 100644
index 0000000..f110d4f
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/ColorHackPresets.java
@@ -0,0 +1,212 @@
+/*
+ * 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"
+ };
+
+ 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 = Integer.MAX_VALUE - 2;
+
+ 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_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(1.0, 0);
+ WriteMultiplier(1.0, 1);
+ WriteMultiplier(1.0, 2);
+ WriteGamma(0, 0);
+ WriteGamma(0, 1);
+ WriteGamma(0, 2);
+ }
+
+ private void Preset2() {
+ WriteMultiplier(0.8575, 0);
+ WriteMultiplier(0.8575, 1);
+ WriteMultiplier(0.8575, 2);
+ WriteGamma(-50, 0);
+ WriteGamma(-50, 1);
+ WriteGamma(-40, 2);
+ }
+
+ private void Preset3() {
+ WriteMultiplier(0.658602179, 0);
+ WriteMultiplier(0.7311828147, 1);
+ WriteMultiplier(1.0, 2);
+ WriteGamma(-41, 0);
+ WriteGamma(-46, 1);
+ WriteGamma(-31, 2);
+ }
+
+ private void Preset4() {
+ WriteMultiplier(0.7231, 0);
+ WriteMultiplier(0.7016, 1);
+ WriteMultiplier(0.6532, 2);
+ WriteGamma(-35, 0);
+ WriteGamma(-55, 1);
+ WriteGamma(-48, 2);
+ }
+
+ private void Preset5() {
+ WriteMultiplier(0.6666, 0);
+ WriteMultiplier(0.6666, 1);
+ WriteMultiplier(0.8333, 2);
+ WriteGamma(-44, 0);
+ WriteGamma(-44, 1);
+ WriteGamma(-22, 2);
+ }
+
+ private void Preset6() {
+ WriteMultiplier(1.0, 0);
+ WriteMultiplier(0.7688, 1);
+ WriteMultiplier(0.2473, 2);
+ WriteGamma(-57, 0);
+ WriteGamma(-39, 1);
+ WriteGamma(45, 2);
+ }
+
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java b/CrespoParts/src/com/cyanogenmod/settings/device/ColorTuningPreference.java
new file mode 100644
index 0000000..0ca7ae2
--- /dev/null
+++ b/CrespoParts/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 = Integer.MAX_VALUE - 2;
+
+ // 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 mDefaultButton = (Button)view.findViewById(R.id.btnColorDefault);
+ Button mCMButton = (Button)view.findViewById(R.id.btnColorCM);
+ Button mDarkButton = (Button)view.findViewById(R.id.btnColorDark);
+ mDefaultButton.setOnClickListener(this);
+ mCMButton.setOnClickListener(this);
+ mDarkButton.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) {
+ int iValue, iValue2;
+ if (!isSupported()) {
+ return;
+ }
+
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ for (String filePath : FILE_PATH) {
+ String sDefaultValue = Utils.readOneLine(filePath);
+ Log.d(TAG,"INIT: " + sDefaultValue);
+ try {
+ iValue2 = Integer.parseInt(sDefaultValue);
+ } 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("%.10f", (double) progress / MAX_VALUE));
+ }
+
+ public void SetNewValue(int iValue) {
+ mOriginal = iValue;
+ reset();
+ }
+
+ }
+
+ public void onClick(View v) {
+ switch(v.getId()){
+ case R.id.btnColorDefault:
+ SetDefaultSettings();
+ break;
+ case R.id.btnColorCM:
+ SetCMSettings();
+ break;
+ case R.id.btnColorDark:
+ SetDarkSettings();
+ break;
+ }
+ }
+
+ private void SetCMSettings() {
+ mSeekBars[0].SetNewValue(1766478464);
+ mSeekBars[1].SetNewValue(1766478464);
+ mSeekBars[2].SetNewValue(1766478464);
+ }
+
+ private void SetDarkSettings() {
+ mSeekBars[0].SetNewValue(877466432);
+ mSeekBars[1].SetNewValue(877466432);
+ mSeekBars[2].SetNewValue(877466432);
+ }
+
+ private void SetDefaultSettings() {
+ mSeekBars[0].SetNewValue(MAX_VALUE);
+ mSeekBars[1].SetNewValue(MAX_VALUE);
+ mSeekBars[2].SetNewValue(MAX_VALUE);
+ }
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java b/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java
new file mode 100644
index 0000000..d84a78b
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/DeviceSettings.java
@@ -0,0 +1,163 @@
+/*
+ * 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.support.v13.app.FragmentPagerAdapter;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.view.ViewPager;
+
+import com.cyanogenmod.settings.device.R;
+
+import java.util.ArrayList;
+
+public class DeviceSettings extends Activity {
+
+ 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_COLOR_PRESET = "color_presets";
+ public static final String KEY_DEEPIDLE = "deepidle";
+ public static final String KEY_DEEPIDLE_STATS = "deepidle_stats";
+ public static final String KEY_NOTIFICATION = "touchkey_notification";
+ public static final String KEY_CATEGORY_RADIO = "category_radio";
+ public static final String KEY_HSPA = "hspa";
+
+ ViewPager mViewPager;
+ TabsAdapter mTabsAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mViewPager = new ViewPager(this);
+ mViewPager.setId(R.id.viewPager);
+ setContentView(mViewPager);
+
+ final ActionBar bar = getActionBar();
+ bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
+ bar.setTitle(R.string.app_name);
+
+ mTabsAdapter = new TabsAdapter(this, mViewPager);
+ mTabsAdapter.addTab(bar.newTab().setText(R.string.general_title),
+ GeneralFragmentActivity.class, null);
+ mTabsAdapter.addTab(bar.newTab().setText(R.string.display_title),
+ DisplayFragmentActivity.class, null);
+
+ if (savedInstanceState != null) {
+ bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
+ }
+
+ public static class TabsAdapter extends FragmentPagerAdapter
+ implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
+ private final Context mContext;
+ private final ActionBar mActionBar;
+ private final ViewPager mViewPager;
+ private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
+
+ static final class TabInfo {
+ private final Class<?> clss;
+ private final Bundle args;
+
+ TabInfo(Class<?> _class, Bundle _args) {
+ clss = _class;
+ args = _args;
+ }
+ }
+
+ public TabsAdapter(Activity activity, ViewPager pager) {
+ super(activity.getFragmentManager());
+ mContext = activity;
+ mActionBar = activity.getActionBar();
+ mViewPager = pager;
+ mViewPager.setAdapter(this);
+ mViewPager.setOnPageChangeListener(this);
+ }
+
+ public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
+ TabInfo info = new TabInfo(clss, args);
+ tab.setTag(info);
+ tab.setTabListener(this);
+ mTabs.add(info);
+ mActionBar.addTab(tab);
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getCount() {
+ return mTabs.size();
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ TabInfo info = mTabs.get(position);
+ return Fragment.instantiate(mContext, info.clss.getName(), info.args);
+ }
+
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ mActionBar.setSelectedNavigationItem(position);
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ }
+
+ @Override
+ public void onTabSelected(Tab tab, FragmentTransaction ft) {
+ Object tag = tab.getTag();
+ for (int i=0; i<mTabs.size(); i++) {
+ if (mTabs.get(i) == tag) {
+ mViewPager.setCurrentItem(i);
+ }
+ }
+ }
+
+ @Override
+ public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+ }
+
+ @Override
+ public void onTabReselected(Tab tab, FragmentTransaction ft) {
+ }
+ }
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java b/CrespoParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java
new file mode 100755
index 0000000..d719b73
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java
@@ -0,0 +1,54 @@
+/*
+ * 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.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+
+import com.cyanogenmod.settings.device.R;
+
+public class DisplayFragmentActivity extends PreferenceFragment {
+
+ private ColorTuningPreference mColorTuning;
+ private GammaTuningPreference mGammaTuning;
+ private ColorHackPresets mColorPreset;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.display_preferences);
+
+ mColorTuning = (ColorTuningPreference) findPreference(DeviceSettings.KEY_COLOR_TUNING);
+ mColorTuning.setEnabled(ColorTuningPreference.isSupported());
+
+ mGammaTuning = (GammaTuningPreference) findPreference(DeviceSettings.KEY_GAMMA_TUNING);
+ mGammaTuning.setEnabled(GammaTuningPreference.isSupported());
+
+ mColorPreset = (ColorHackPresets) findPreference(DeviceSettings.KEY_COLOR_PRESET);
+ mColorPreset.setEnabled(ColorHackPresets.isSupported());
+ }
+
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java b/CrespoParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java
new file mode 100644
index 0000000..73a66ad
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java
@@ -0,0 +1,272 @@
+/*
+ * 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
+ };
+
+ 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/samoled_color/red_v1_offset",
+ "/sys/class/misc/samoled_color/green_v1_offset",
+ "/sys/class/misc/samoled_color/blue_v1_offset"
+ };
+
+ private GammaSeekBar mSeekBars[] = new GammaSeekBar[3];
+
+ 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]);
+ mSeekBars[i] = new GammaSeekBar(seekBar, valueDisplay, FILE_PATH[i]);
+ }
+ SetupButtonClickListeners(view);
+ }
+
+ private void SetupButtonClickListeners(View view) {
+ Button mDefaultButton = (Button)view.findViewById(R.id.btnGammaDefault);
+ Button mCMButton = (Button)view.findViewById(R.id.btnGammaCM);
+ Button mBrightButton = (Button)view.findViewById(R.id.btnGammaBright);
+ mDefaultButton.setOnClickListener(this);
+ mCMButton.setOnClickListener(this);
+ mBrightButton.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;
+ }
+
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ Boolean bFirstTime = sharedPrefs.getBoolean("FirstTimeGamma", true);
+ for (String filePath : FILE_PATH) {
+ String sDefaultValue = Utils.readOneLine(filePath);
+ int 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;
+
+ public GammaSeekBar(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 = Integer.valueOf(sDefaultValue);
+ } else {
+ iValue = MAX_VALUE - OFFSET_VALUE;
+ }
+ mOriginal = iValue;
+
+ mSeekBar.setMax(MAX_VALUE);
+ reset();
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ public void reset() {
+ int iValue;
+
+ iValue = mOriginal + OFFSET_VALUE;
+ mSeekBar.setProgress(iValue);
+ updateValue(mOriginal);
+ }
+
+ public void save() {
+ int iValue;
+
+ iValue = mSeekBar.getProgress() - OFFSET_VALUE;
+ Editor editor = getEditor();
+ editor.putInt(mFilePath, iValue);
+ editor.commit();
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ int iValue;
+
+ iValue = progress - OFFSET_VALUE;
+ 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.btnGammaDefault:
+ SetDefaultSettings();
+ break;
+ case R.id.btnGammaCM:
+ SetCMSettings();
+ break;
+ case R.id.btnGammaBright:
+ SetSBrightSettings();
+ break;
+ }
+ }
+
+ private void SetCMSettings() {
+ mSeekBars[0].SetNewValue(-63);
+ mSeekBars[1].SetNewValue(-59);
+ mSeekBars[2].SetNewValue(-61);
+ }
+
+ private void SetSBrightSettings() {
+ mSeekBars[0].SetNewValue(70);
+ mSeekBars[1].SetNewValue(68);
+ mSeekBars[2].SetNewValue(61);
+ }
+
+ private void SetDefaultSettings() {
+ mSeekBars[0].SetNewValue(0);
+ mSeekBars[1].SetNewValue(0);
+ mSeekBars[2].SetNewValue(0);
+ }
+
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java b/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java
new file mode 100644
index 0000000..eb183a2
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java
@@ -0,0 +1,159 @@
+/*
+ * 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.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import android.view.View;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.widget.TextView;
+
+import com.cyanogenmod.settings.device.R;
+
+public class GeneralFragmentActivity extends PreferenceFragment implements OnPreferenceClickListener {
+
+ private static final String CPU_DEEPIDLE_FILE = "/sys/class/misc/deepidle/enabled";
+ private static final String CPU_DEEPIDLE_STATS = "/sys/class/misc/deepidle/idle_stats_list";
+ private static final String CPU_DEEPIDLE_RESET = "/sys/class/misc/deepidle/reset_stats";
+ private static final String TOUCHKEY_NOTIFICATION_FILE = "/sys/class/misc/notification/enabled";
+ private static final String PREF_ENABLED = "1";
+ private static final String TAG = "CrespoParts_General";
+
+ private CheckBoxPreference mDeepIdle;
+ private CheckBoxPreference mNotification;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.general_preferences);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+ mDeepIdle = (CheckBoxPreference) findPreference(DeviceSettings.KEY_DEEPIDLE);
+ mNotification = (CheckBoxPreference) findPreference(DeviceSettings.KEY_NOTIFICATION);
+
+ if (isSupported(CPU_DEEPIDLE_FILE)) {
+ mDeepIdle.setChecked(PREF_ENABLED.equals(Utils.readOneLine(CPU_DEEPIDLE_FILE)));
+ } else {
+ mDeepIdle.setEnabled(false);
+ }
+
+ if (isSupported(TOUCHKEY_NOTIFICATION_FILE)) {
+ mNotification.setChecked(PREF_ENABLED.equals(Utils.readOneLine(TOUCHKEY_NOTIFICATION_FILE)));
+ } else {
+ mNotification.setEnabled(false);
+ }
+
+ Preference p = findPreference(DeviceSettings.KEY_DEEPIDLE_STATS);
+ if(p != null) {
+ p.setOnPreferenceClickListener(this);
+ }
+
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+
+ String boxValue;
+ String key = preference.getKey();
+
+ Log.w(TAG, "key: " + key);
+ if (key.equals(DeviceSettings.KEY_DEEPIDLE)) {
+ final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
+ boxValue = chkPref.isChecked() ? "1" : "0";
+ Utils.writeValue(CPU_DEEPIDLE_FILE, boxValue);
+ } else if (key.equals(DeviceSettings.KEY_NOTIFICATION)) {
+ final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
+ boxValue = chkPref.isChecked() ? "1" : "0";
+ Utils.writeValue(TOUCHKEY_NOTIFICATION_FILE, boxValue);
+ }
+
+ return true;
+ }
+
+ public static boolean isSupported(String FILE) {
+ return Utils.fileExists(FILE);
+ }
+
+ public static void restore(Context context) {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+ if (isSupported(CPU_DEEPIDLE_FILE)) {
+ String sDefaultValue = Utils.readOneLine(CPU_DEEPIDLE_FILE);
+ Utils.writeValue(CPU_DEEPIDLE_FILE, sharedPrefs.getBoolean(DeviceSettings.KEY_DEEPIDLE,
+ PREF_ENABLED.equals(sDefaultValue)));
+ }
+ if (isSupported(TOUCHKEY_NOTIFICATION_FILE)) {
+ String sDefaultValue = Utils.readOneLine(TOUCHKEY_NOTIFICATION_FILE);
+ Utils.writeValue(TOUCHKEY_NOTIFICATION_FILE, sharedPrefs.getBoolean(DeviceSettings.KEY_NOTIFICATION,
+ PREF_ENABLED.equals(sDefaultValue)));
+ }
+ }
+
+ private void showIdleStatsDialog() {
+ // display dialog
+ final View content = getActivity().getLayoutInflater().inflate(R.layout.idle_stats_dialog, null);
+
+ String sStatsLine = Utils.readOneLine(CPU_DEEPIDLE_STATS);
+ String[] sValues = sStatsLine.split(" ");
+ ((TextView)content.findViewById(R.id.time1)).setText(sValues[0]);
+ ((TextView)content.findViewById(R.id.time2)).setText(sValues[2]);
+ ((TextView)content.findViewById(R.id.time3)).setText(sValues[4]);
+ ((TextView)content.findViewById(R.id.avg1)).setText(sValues[1]);
+ ((TextView)content.findViewById(R.id.avg2)).setText(sValues[3]);
+ ((TextView)content.findViewById(R.id.avg3)).setText(sValues[5]);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(getString(R.string.label_deepidle_stats));
+ builder.setView(content);
+ builder.setPositiveButton(getString(R.string.label_reset), new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Utils.writeValue(CPU_DEEPIDLE_RESET, "1");
+ dialog.dismiss();
+ }
+ });
+ builder.setNegativeButton(getString(R.string.label_close), new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ }
+ });
+ builder.show();
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ boolean ret = false;
+ if(preference.getKey().equals(DeviceSettings.KEY_DEEPIDLE_STATS)) {
+ showIdleStatsDialog();
+ ret = true;
+ }
+ return ret;
+ }
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/Hspa.java b/CrespoParts/src/com/cyanogenmod/settings/device/Hspa.java
new file mode 100644
index 0000000..2e68da2
--- /dev/null
+++ b/CrespoParts/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.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(DeviceSettings.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/settings/device/Startup.java b/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java
new file mode 100644
index 0000000..0728953
--- /dev/null
+++ b/CrespoParts/src/com/cyanogenmod/settings/device/Startup.java
@@ -0,0 +1,18 @@
+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) {
+ GeneralFragmentActivity.restore(context);
+ ColorTuningPreference.restore(context);
+ GammaTuningPreference.restore(context);
+ if (Hspa.isSupported()) {
+ Hspa.restore(context);
+ }
+ }
+}
diff --git a/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java b/CrespoParts/src/com/cyanogenmod/settings/device/Utils.java
new file mode 100644
index 0000000..6b9c0d3
--- /dev/null
+++ b/CrespoParts/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 = "CrespoParts_Utils";
+ private static final String TAG_READ = "CrespoParts_Utils_Read";
+ private static final String TAG_WRITE = "CrespoParts_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;
+ }
+}