diff options
author | KalimochoAz <calimochoazucarado@gmail.com> | 2012-01-27 10:14:51 +0100 |
---|---|---|
committer | KalimochoAz <calimochoazucarado@gmail.com> | 2012-01-27 10:14:51 +0100 |
commit | 37cc75ac18ba5e1e7002c84e5ab56077131d4e38 (patch) | |
tree | 90b31d7c930820d24721a1563ce9d15433346646 | |
parent | 35485eb234a039b93ffba4e3067be8cf7d425c94 (diff) | |
download | device_samsung_tuna-37cc75ac18ba5e1e7002c84e5ab56077131d4e38.zip device_samsung_tuna-37cc75ac18ba5e1e7002c84e5ab56077131d4e38.tar.gz device_samsung_tuna-37cc75ac18ba5e1e7002c84e5ab56077131d4e38.tar.bz2 |
Added galaxy nexus specific settings
First addition is gamma color hack
Change-Id: I199dc40334b4219bb4d3209360faeef2d66b6da1
16 files changed, 891 insertions, 0 deletions
diff --git a/GNexusParts/Android.mk b/GNexusParts/Android.mk new file mode 100644 index 0000000..e934402 --- /dev/null +++ b/GNexusParts/Android.mk @@ -0,0 +1,15 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_STATIC_JAVA_LIBRARIES := android-support-v13 + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := GNexusParts +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/GNexusParts/AndroidManifest.xml b/GNexusParts/AndroidManifest.xml new file mode 100644 index 0000000..b736787 --- /dev/null +++ b/GNexusParts/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.cyanogenmod.settings.device" + android:sharedUserId="android.uid.system" > + + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> + + <application android:label="@string/app_name" > + <activity + android:name="com.cyanogenmod.settings.device.DeviceSettings" + android:icon="@drawable/ic_launcher_cmdevicesettings" + android:label="@string/app_name" > + <intent-filter> + <action android:name="com.cyanogenmod.action.LAUNCH_DEVICE_SETTINGS" /> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <receiver android:name=".Startup" > + <intent-filter android:priority="100" > + <action android:name="android.intent.action.BOOT_COMPLETED" /> + </intent-filter> + </receiver> + + <activity android:name=".GeneralFragmentActivity" /> + <activity android:name=".DisplayFragmentActivity" /> + <activity android:name=".SoundFragmentActivity" /> + </application> + +</manifest>
\ No newline at end of file diff --git a/GNexusParts/res/drawable/color_tuning_preview.xml b/GNexusParts/res/drawable/color_tuning_preview.xml new file mode 100644 index 0000000..2d83c10 --- /dev/null +++ b/GNexusParts/res/drawable/color_tuning_preview.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape + xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <gradient + android:angle="0" + android:startColor="#000000" + android:endColor="#FFFFFF" /> +</shape>
\ No newline at end of file diff --git a/GNexusParts/res/drawable/ic_launcher_cmdevicesettings.png b/GNexusParts/res/drawable/ic_launcher_cmdevicesettings.png Binary files differnew file mode 100755 index 0000000..66de9c3 --- /dev/null +++ b/GNexusParts/res/drawable/ic_launcher_cmdevicesettings.png diff --git a/GNexusParts/res/layout/preference_dialog_gamma_tuning.xml b/GNexusParts/res/layout/preference_dialog_gamma_tuning.xml new file mode 100644 index 0000000..3ece54b --- /dev/null +++ b/GNexusParts/res/layout/preference_dialog_gamma_tuning.xml @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="utf-8"?> + +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:paddingBottom="20dip"> + + <TextView android:id="@+id/gamma_red_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/color_red_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/gamma_red_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/gamma_red_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_red_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <TextView android:id="@+id/gamma_green_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_red_seekbar" + android:text="@string/color_green_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/gamma_green_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_red_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/gamma_green_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_green_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <TextView android:id="@+id/gamma_blue_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_green_seekbar" + android:text="@string/color_blue_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/gamma_blue_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_green_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/gamma_blue_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/gamma_blue_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <ImageView android:src="@drawable/color_tuning_preview" + android:layout_width="match_parent" + android:layout_height="40dip" + android:layout_below="@id/gamma_blue_seekbar" + android:paddingTop="20dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + </RelativeLayout> +</ScrollView>
\ No newline at end of file diff --git a/GNexusParts/res/layout/top.xml b/GNexusParts/res/layout/top.xml new file mode 100755 index 0000000..744b568 --- /dev/null +++ b/GNexusParts/res/layout/top.xml @@ -0,0 +1,5 @@ +<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/viewPager" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + diff --git a/GNexusParts/res/values/strings.xml b/GNexusParts/res/values/strings.xml new file mode 100644 index 0000000..7732661 --- /dev/null +++ b/GNexusParts/res/values/strings.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">Galaxy Nexus Settings</string> + + <!-- Page Headers --> + <string name="general_title">GENERAL</string> + <string name="display_title">DISPLAY</string> + + <string name="category_screen_title">WM8994 Settings ( voodoo )</string> + <string name="gamma_tuning_title_head">Color Gamma Tuning</string> + <string name="gamma_tuning_summary_head">Calibrate gamma color correction</string> + <string name="color_red_title">Red</string> + <string name="color_green_title">Green</string> + <string name="color_blue_title">Blue</string> + + <string name="category_radio_title">Radio</string> + <string name="hspa_title_head">HSPA</string> + <string name="hspa_summary_head">Enable HSDPA/HSUPA</string> +</resources> diff --git a/GNexusParts/res/xml/display_preferences.xml b/GNexusParts/res/xml/display_preferences.xml new file mode 100755 index 0000000..8ae5c6c --- /dev/null +++ b/GNexusParts/res/xml/display_preferences.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + android:title="@string/app_name"> + + <!-- Color tuning --> + <com.cyanogenmod.settings.device.GammaTuningPreference + android:key="gamma_tuning" + android:title="@string/gamma_tuning_title_head" + android:summary="@string/gamma_tuning_summary_head" /> + +</PreferenceScreen> diff --git a/GNexusParts/res/xml/general_preferences.xml b/GNexusParts/res/xml/general_preferences.xml new file mode 100644 index 0000000..92187f1 --- /dev/null +++ b/GNexusParts/res/xml/general_preferences.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + +</PreferenceScreen> 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..f2f9a83 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -0,0 +1,158 @@ +/* + * 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_GAMMA_TUNING = "gamma_tuning"; + 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.display_title), + DisplayFragmentActivity.class, null); + mTabsAdapter.addTab(bar.newTab().setText(R.string.general_title), + GeneralFragmentActivity.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/GNexusParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java b/GNexusParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java new file mode 100755 index 0000000..607339e --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/DisplayFragmentActivity.java @@ -0,0 +1,46 @@ +/* + * 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 GammaTuningPreference mGammaTuning; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.display_preferences); + + mGammaTuning = (GammaTuningPreference) findPreference(DeviceSettings.KEY_GAMMA_TUNING); + mGammaTuning.setEnabled(GammaTuningPreference.isSupported()); + } + +} 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..bfbc62e --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/GammaTuningPreference.java @@ -0,0 +1,211 @@ +/* + * 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.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/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 = 80; + + 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 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) { + 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)); + } + + } + +} diff --git a/GNexusParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java b/GNexusParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java new file mode 100644 index 0000000..ca1b155 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/GeneralFragmentActivity.java @@ -0,0 +1,66 @@ +/* + * 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.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 GeneralFragmentActivity extends PreferenceFragment { + + private static final String PREF_ENABLED = "1"; + private static final String TAG = "GNexusParts_General"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.general_preferences); + + PreferenceScreen prefSet = getPreferenceScreen(); + + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + + String boxValue; + String key = preference.getKey(); + + Log.w(TAG, "key: " + key); + + return true; + } + + public static boolean isSupported(String FILE) { + return Utils.fileExists(FILE); + } + + public static void restore(Context context) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + } +} 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..cc47307 --- /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(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/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java b/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java new file mode 100644 index 0000000..82d90b7 --- /dev/null +++ b/GNexusParts/src/com/cyanogenmod/settings/device/Startup.java @@ -0,0 +1,17 @@ +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) { + GammaTuningPreference.restore(context); + GeneralFragmentActivity.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; + } +} |