Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();
    mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    mPreferences.registerOnSharedPreferenceChangeListener(this);
    addPreferencesFromResource(R.layout.advanced);

    sreadahead = getResources().getString(R.string.ps_read_ahead, "");

    mReadAhead = (ListPreference) findPreference(PREF_READ_AHEAD);
    mBltimeout = findPreference(PREF_BLTIMEOUT);
    mBltouch = (CheckBoxPreference) findPreference(PREF_BLTOUCH);
    mBln = (CheckBoxPreference) findPreference(PREF_BLN);
    mWifiPM = (CheckBoxPreference) findPreference("pref_wifi_pm");
    mTouchScr = findPreference("touchscr_settings");
    mViber = findPreference("pref_viber");
    mVM = findPreference("vm_settings");

    mDsync = (CheckBoxPreference) findPreference(PREF_DSYNC);

    mPFK = findPreference("pfk_settings");

    mDynamicWriteBackOn = (CheckBoxPreference) findPreference(PREF_DYNAMIC_DIRTY_WRITEBACK);
    mDynamicWriteBackActive = findPreference(PREF_DIRTY_WRITEBACK_ACTIVE);
    mDynamicWriteBackSuspend = findPreference(PREF_DIRTY_WRITEBACK_SUSPEND);

    if (!new File(DSYNC_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("dsync");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mDsync.setChecked(Helpers.readOneLine(DSYNC_PATH).equals("1"));
    }
    if (!new File(PFK_HOME_ENABLED).exists() || !new File(PFK_MENUBACK_ENABLED).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("pfk");
      getPreferenceScreen().removePreference(hideCat);
    }

    if (!new File(BL_TIMEOUT_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bltimeout");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBltimeout.setSummary(Helpers.readOneLine(BL_TIMEOUT_PATH));
    }

    if (!new File(BL_TOUCH_ON_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bltouch");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBltouch.setChecked(Helpers.readOneLine(BL_TOUCH_ON_PATH).equals("1"));
    }

    BLN_PATH = Helpers.bln_path();
    if (BLN_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("bln");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mBln.setChecked(Helpers.readOneLine(BLN_PATH).equals("1"));
    }

    if (no_touchscreen()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("touch_scr");
      getPreferenceScreen().removePreference(hideCat);
    }

    VIBE_PATH = vib.get_path();

    if (VIBE_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("viber");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mViber.setSummary(vib.get_val(VIBE_PATH));
    }

    if (!new File(DYNAMIC_DIRTY_WRITEBACK_PATH).exists()) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("cat_dynamic_write_back");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      boolean ison = Helpers.readOneLine(DYNAMIC_DIRTY_WRITEBACK_PATH).equals("1");
      mDynamicWriteBackOn.setChecked(ison);
      mDynamicWriteBackActive.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_ACTIVE_PATH));
      mDynamicWriteBackSuspend.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_SUSPEND_PATH));
    }
    WIFIPM_PATH = Helpers.wifipm_path();
    if (WIFIPM_PATH == null) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("wifi_pm");
      getPreferenceScreen().removePreference(hideCat);
    } else {
      mWifiPM.setChecked(Helpers.readOneLine(WIFIPM_PATH).equals("1"));
    }
    final String readahead = Helpers.readOneLine(READ_AHEAD_PATH);
    mReadAhead.setValue(readahead);
    mReadAhead.setSummary(getString(R.string.ps_read_ahead, readahead + "  kb"));

    setHasOptionsMenu(true);
  }
Example #2
0
 @Override
 public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, String key) {
   final SharedPreferences.Editor editor = sharedPreferences.edit();
   if (key.equals(PREF_READ_AHEAD)) {
     final String values = mReadAhead.getValue();
     if (!values.equals(Helpers.readOneLine(READ_AHEAD_PATH))) {
       for (byte i = 0; i < 2; i++) {
         if (new File(READ_AHEAD_PATH.replace("mmcblk0", "mmcblk" + i)).exists())
           new CMDProcessor()
               .su.runWaitFor(
                   "busybox echo "
                       + values
                       + " > "
                       + READ_AHEAD_PATH.replace("mmcblk0", "mmcblk" + i));
       }
     }
     mReadAhead.setSummary(sreadahead + values + " kb");
   } else if (key.equals(PREF_BLTIMEOUT)) {
     mBltimeout.setSummary(Helpers.readOneLine(BL_TIMEOUT_PATH));
   } else if (key.equals(BLX_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH))).apply();
     } else {
       editor.remove(PREF_BLX).apply();
     }
   } else if (key.equals(BLTIMEOUT_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       editor
           .putInt(PREF_BLTIMEOUT, Integer.parseInt(Helpers.readOneLine(BL_TIMEOUT_PATH)))
           .apply();
     } else {
       editor.remove(PREF_BLTIMEOUT).apply();
     }
   } else if (key.equals(PFK_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       if (Helpers.readOneLine(PFK_HOME_ENABLED).equals("1")) {
         editor.putBoolean(PFK_HOME_ON, true);
       } else {
         editor.putBoolean(PFK_HOME_ON, false);
       }
       editor
           .putInt(
               PREF_HOME_ALLOWED_IRQ, Integer.parseInt(Helpers.readOneLine(PFK_HOME_ALLOWED_IRQ)))
           .putInt(
               PREF_HOME_REPORT_WAIT, Integer.parseInt(Helpers.readOneLine(PFK_HOME_REPORT_WAIT)));
       if (Helpers.readOneLine(PFK_MENUBACK_ENABLED).equals("1")) {
         editor.putBoolean(PFK_MENUBACK_ON, true);
       } else {
         editor.putBoolean(PFK_MENUBACK_ON, false);
       }
       editor
           .putInt(
               PREF_MENUBACK_INTERRUPT_CHECKS,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_INTERRUPT_CHECKS)))
           .putInt(
               PREF_MENUBACK_FIRST_ERR_WAIT,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_FIRST_ERR_WAIT)))
           .putInt(
               PREF_MENUBACK_LAST_ERR_WAIT,
               Integer.parseInt(Helpers.readOneLine(PFK_MENUBACK_LAST_ERR_WAIT)))
           .apply();
     } else {
       editor
           .remove(PFK_HOME_ON)
           .remove(PREF_HOME_ALLOWED_IRQ)
           .remove(PREF_HOME_REPORT_WAIT)
           .remove(PFK_MENUBACK_ON)
           .remove(PREF_MENUBACK_INTERRUPT_CHECKS)
           .remove(PREF_MENUBACK_FIRST_ERR_WAIT)
           .remove(PREF_MENUBACK_LAST_ERR_WAIT)
           .apply();
     }
   } else if (key.equals(DYNAMIC_DIRTY_WRITEBACK_SOB)) {
     if (sharedPreferences.getBoolean(key, false)) {
       if (Helpers.readOneLine(DYNAMIC_DIRTY_WRITEBACK_PATH).equals("1")) {
         editor.putBoolean(PREF_DYNAMIC_DIRTY_WRITEBACK, true);
       } else {
         editor.putBoolean(PREF_DYNAMIC_DIRTY_WRITEBACK, false);
       }
       editor
           .putInt(
               PREF_DIRTY_WRITEBACK_ACTIVE,
               Integer.parseInt(Helpers.readOneLine(DIRTY_WRITEBACK_ACTIVE_PATH)))
           .putInt(
               PREF_DIRTY_WRITEBACK_SUSPEND,
               Integer.parseInt(Helpers.readOneLine(DIRTY_WRITEBACK_SUSPEND_PATH)))
           .apply();
     } else {
       editor
           .remove(PREF_DYNAMIC_DIRTY_WRITEBACK)
           .remove(PREF_DIRTY_WRITEBACK_ACTIVE)
           .remove(PREF_DIRTY_WRITEBACK_SUSPEND)
           .apply();
     }
   }
 }