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

    mResidualFiles = findPreference(RESIDUAL_FILES);
    mOptimDB = findPreference(PREF_OPTIM_DB);

    long mStartTime = mPreferences.getLong(RESIDUAL_FILES, 0);
    mResidualFiles.setSummary("");
    if (mStartTime > 0) mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));

    mStartTime = mPreferences.getLong(PREF_OPTIM_DB, 0);
    mOptimDB.setSummary("");
    if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));

    if (Helpers.binExist("dd").equals(NOT_FOUND) || NO_FLASH) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_flash_img");
      getPreferenceScreen().removePreference(hideCat);
    }
    if (Helpers.binExist("pm").equals(NOT_FOUND)) {
      PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_freezer");
      getPreferenceScreen().removePreference(hideCat);
    }
    setRetainInstance(true);
    setHasOptionsMenu(true);
  }
 /**
  * onCreateView
  *
  * <p>handles the special case of the serverport entry which is an int....
  */
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
   // prefs.registerOnSharedPreferenceChangeListener(this);
   for (String key : prefs.getAll().keySet()) {
     Preference pref = findPreference(key);
     if (pref == null) continue;
     if (key.equals("serverport")) pref.setSummary("" + prefs.getInt(key, 0));
     else pref.setSummary(prefs.getString(key, key));
   }
   return super.onCreateView(inflater, container, savedInstanceState);
 }
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(RESIDUAL_FILES)) {
      mResidualFiles.setSummary("");
      final long mStartTime = sharedPreferences.getLong(key, 0);
      if (mStartTime > 0)
        mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));

    } else if (key.equals(PREF_OPTIM_DB)) {
      mOptimDB.setSummary("");
      final long mStartTime = sharedPreferences.getLong(key, 0);
      if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime));
    }
  }
  /**
   * onSharedPreferenceChanged not needed in my code, but still in case i have one listpreference,
   * its takes the selected entry to create the summary (planned when/if i add background images to
   * the buttons...
   */
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key) {
    Preference pref = findPreference(key);
    // Log.d(TAG, "preference change for " + key + " " + pref.getTitle());

    // pref.getTitle();
    if (pref instanceof ListPreference) {
      ListPreference listPref = (ListPreference) pref;
      pref.setSummary(listPref.getEntry());
    } else pref.setSummary(sharedPref.getString(key, key));

    // MainActivity mainAct = (MainActivity) getContext();
    // if(mainAct != null) mainAct.onSharedPreferenceChanged(sharedPref,key);
  }
Beispiel #5
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);
  }
Beispiel #6
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();
     }
   }
 }