Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 8.40 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.android.settings;
  2. import com.android.settings.R;
  3.  
  4. import android.app.Activity;
  5. import android.app.AlertDialog;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.preference.CheckBoxPreference;
  10. import android.preference.ListPreference;
  11. import android.preference.Preference;
  12. import android.preference.PreferenceActivity;
  13. import android.preference.PreferenceCategory;
  14. import android.preference.PreferenceScreen;
  15. import android.preference.Preference.OnPreferenceChangeListener;
  16. import android.provider.Settings;
  17. import android.provider.Settings.SettingNotFoundException;
  18. import android.text.Spannable;
  19. import android.widget.EditText;
  20. import android.util.Log;
  21.  
  22. import net.margaritov.preference.colorpicker.ColorPickerPreference;
  23.  
  24. public class RomCustomSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
  25.  
  26.     private static final String PREF_VOLUME_MUSIC = "volume_music_controls";
  27.     private static final String PREF_CLOCK_DISPLAY_STYLE = "clock_am_pm";
  28.     private static final String PREF_CLOCK_STYLE = "clock_style";
  29.     private static final String QUICK_PASSWORD_UNLOCK = "quick_password_unlock";
  30.     CheckBoxPreference mVolumeMusic;
  31.     CheckBoxPreference mQuickUnlock;
  32.     private ListPreference mAmPmStyle;
  33.     private ListPreference mClockStyle;
  34.  
  35.     private static final String BATTERY_STYLE = "battery_style";
  36.     private static final String BATTERY_BAR = "battery_bar";
  37.     private static final String BATTERY_BAR_COLOR = "battery_bar_color";
  38.     private ListPreference mBatteryStyle;
  39.     private CheckBoxPreference mBattBar;
  40.     private ColorPickerPreference mBattBarColor;
  41.  
  42.     private static final String PREF_VOLUME_WAKE = "volume_wake";
  43.     CheckBoxPreference mVolumeWake;
  44.  
  45.     private static final String PREF_CARRIER_TEXT = "carrier_text";
  46.     private Preference mCarrier;
  47.     String mCarrierText = null;
  48.        
  49.     @Override
  50.     public void onCreate(Bundle savedInstanceState) {
  51.         super.onCreate(savedInstanceState);
  52.         addPreferencesFromResource(R.xml.rom_custom_settings);
  53.         PreferenceScreen prefSet = getPreferenceScreen();
  54.  
  55.         mQuickUnlock = (CheckBoxPreference) prefSet.findPreference(QUICK_PASSWORD_UNLOCK);
  56.         mQuickUnlock.setChecked(Settings.System.getInt(getContentResolver(),
  57.             Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, 0) == 1); 
  58.  
  59.         mVolumeMusic = (CheckBoxPreference) prefSet.findPreference(PREF_VOLUME_MUSIC);
  60.         mVolumeMusic.setChecked(Settings.System.getInt(getActivity()
  61.             .getContentResolver(), Settings.System.VOLUME_MUSIC_CONTROLS,
  62.             0) == 1);
  63.  
  64.         mClockStyle = (ListPreference) prefSet.findPreference(PREF_CLOCK_STYLE);
  65.         mAmPmStyle = (ListPreference) prefSet.findPreference(PREF_CLOCK_DISPLAY_STYLE);
  66.  
  67.         int styleValue = Settings.System.getInt(getContentResolver(),
  68.                 Settings.System.STATUS_BAR_AM_PM, 2);
  69.         mAmPmStyle.setValueIndex(styleValue);
  70.         mAmPmStyle.setOnPreferenceChangeListener(this);
  71.  
  72.         int clockVal = Settings.System.getInt(getContentResolver(),
  73.                 Settings.System.STATUS_BAR_CLOCK, 1);
  74.         mClockStyle.setValueIndex(clockVal);
  75.         mClockStyle.setOnPreferenceChangeListener(this);
  76.  
  77.             mBatteryStyle = (ListPreference) prefSet.findPreference(BATTERY_STYLE);
  78.         int battVal = Settings.System.getInt(getContentResolver(),
  79.                 Settings.System.BATTERY_PERCENTAGES, 1);
  80.         mBatteryStyle.setValueIndex(battVal);
  81.         mBatteryStyle.setOnPreferenceChangeListener(this);
  82.  
  83.         mVolumeWake = (CheckBoxPreference) findPreference(PREF_VOLUME_WAKE);
  84.         mVolumeWake.setChecked(Settings.System.getInt(getActivity()
  85.                 .getContentResolver(), Settings.System.VOLUME_WAKE_SCREEN,     
  86.                 0) == 1);
  87.  
  88.         mBattBar = (CheckBoxPreference) prefSet.findPreference(BATTERY_BAR);
  89.         mBattBar.setChecked(Settings.System.getInt(getContentResolver(),
  90.             Settings.System.STATUSBAR_BATTERY_BAR, 0) == 1);
  91.  
  92.         mBattBarColor = (ColorPickerPreference) prefSet.findPreference(BATTERY_BAR_COLOR);
  93.         mBattBarColor.setOnPreferenceChangeListener(this);
  94.         mBattBarColor.setEnabled(mBattBar.isChecked());                        
  95.  
  96.         mCarrier = (Preference) prefSet.findPreference(PREF_CARRIER_TEXT);
  97.         updateCarrierText();
  98.     }
  99.  
  100.     private void updateBatteryBarToggle(boolean bool){
  101.         if (bool)
  102.             mBattBarColor.setEnabled(true);
  103.         else
  104.             mBattBarColor.setEnabled(false);
  105.     }
  106.  
  107.     private void updateCarrierText() {
  108.         mCarrierText = Settings.System.getString(getContentResolver(), Settings.System.CUSTOM_CARRIER_TEXT);
  109.         if (mCarrierText == null) {
  110.             mCarrier.setSummary("Upon changing you will need to data wipe to get back stock. Requires reboot.");
  111.         } else {
  112.             mCarrier.setSummary(mCarrierText);
  113.         }
  114.     }
  115.  
  116.     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
  117.         boolean value;
  118.         if (preference == mVolumeMusic) {
  119.             Settings.System.putInt(getActivity().getContentResolver(),
  120.                 Settings.System.VOLUME_MUSIC_CONTROLS,
  121.                 ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
  122.             return true;
  123.         } else if (preference == mVolumeWake) {
  124.             Settings.System.putInt(getActivity().getContentResolver(),
  125.             Settings.System.VOLUME_WAKE_SCREEN,
  126.                 ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
  127.             return true;
  128.     } else if (preference == mBattBar) {
  129.             value = mBattBar.isChecked();
  130.             Settings.System.putInt(getContentResolver(),
  131.                 Settings.System.STATUSBAR_BATTERY_BAR, value ? 1 : 0);
  132.             return true;
  133.         } else if (preference == mQuickUnlock) {
  134.             value = mQuickUnlock.isChecked();
  135.             Settings.System.putInt(getContentResolver(),
  136.                 Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, value ? 1 : 0);
  137.             return true;
  138.         } else if (preference == mCarrier) {
  139.             AlertDialog.Builder ad = new AlertDialog.Builder(getActivity());
  140.             ad.setTitle("Custom Carrier Text");
  141.             ad.setMessage("Enter new carrier text here");
  142.             final EditText text = new EditText(getActivity());
  143.             text.setText(mCarrierText != null ? mCarrierText : "");
  144.             ad.setView(text);
  145.             ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  146.                 public void onClick(DialogInterface dialog, int whichButton) {
  147.                     String value = ((Spannable) text.getText()).toString();
  148.                     Settings.System.putString(getActivity().getContentResolver(), Settings.System.CUSTOM_CARRIER_TEXT, value);
  149.                     updateCarrierText();
  150.                 }
  151.             });
  152.             ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  153.                 public void onClick(DialogInterface dialog, int whichButton) {
  154.                 }
  155.             });
  156.             ad.show();
  157.     }
  158.  
  159.     return false;
  160.     }
  161.  
  162.     @Override
  163.     public boolean onPreferenceChange(Preference preference, Object newValue) {
  164.         if (preference == mAmPmStyle) {
  165.             int statusBarAmPm = Integer.valueOf((String) newValue);
  166.             Settings.System.putInt(getContentResolver(),
  167.                 Settings.System.STATUS_BAR_AM_PM, statusBarAmPm);
  168.             return true;
  169.         } else if (preference == mClockStyle) {
  170.             int val = Integer.valueOf((String) newValue);
  171.             Settings.System.putInt(getContentResolver(),
  172.                 Settings.System.STATUS_BAR_CLOCK, val);
  173.             return true;
  174.         } else if (preference == mBatteryStyle) {
  175.             int val = Integer.valueOf((String) newValue);
  176.             Settings.System.putInt(getContentResolver(),
  177.                 Settings.System.BATTERY_PERCENTAGES, val);
  178.             return true;
  179.         } else if (preference == mBattBarColor) {
  180.             String hexColor = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
  181.             preference.setSummary(hexColor);
  182.             int color = ColorPickerPreference.convertToColorInt(hexColor);
  183.             Settings.System.putInt(getContentResolver(),
  184.                 Settings.System.STATUSBAR_BATTERY_BAR_COLOR, color);
  185.             return true;
  186.         }
  187.  
  188.         return false;
  189.     }
  190.  
  191. }