diff options
Diffstat (limited to 'GNexusParts/src/com/cyanogenmod')
7 files changed, 704 insertions, 0 deletions
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; + } +} |