Пример #1
0
  @Override
  public boolean onPreferenceClick(Preference pref) {
    if (pref.getKey().equals(ABOUT_VERSION)) {
      if (m_clickCounter == -1) {
        Toast.makeText(this, R.string.already_developer, Toast.LENGTH_SHORT).show();
        return true;
      }

      ++m_clickCounter;

      if (m_clickCounter == DEV_STEPS) {
        Toast.makeText(this, R.string.now_developer, Toast.LENGTH_SHORT).show();

        SharedPreferences.Editor p = MultiROMMgrApplication.getPreferences().edit();
        p.putBoolean(DEV_ENABLE, true);
        p.commit();

        addDevOptions();
      } else if (m_clickCounter >= 3) {
        String s = getString(R.string.steps_developer, DEV_STEPS - m_clickCounter);
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
      }
      return true;
    } else if (pref.getKey().equals(ABOUT_LICENSES)) {
      final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(SRC_URL));
      startActivity(intent);
      return true;
    }
    return false;
  }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference == mLockscreenOption) {
      int val = Integer.parseInt((String) newValue);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.LOCKSCREEN_LAYOUT, val);
      refreshSettings();
      return true;

    } else if (preference.getKey().startsWith("lockscreen_target")) {
      int index =
          Integer.parseInt(preference.getKey().substring(preference.getKey().lastIndexOf("_") + 1));
      Log.e("ROMAN", "lockscreen target, index: " + index);

      if (newValue.equals("**app**")) {
        mCurrentCustomActivityPreference = preference;
        mCurrentCustomActivityString = Settings.System.LOCKSCREEN_CUSTOM_APP_ACTIVITIES[index];
        mPicker.pickShortcut();
      } else {
        Settings.System.putString(
            getContentResolver(),
            Settings.System.LOCKSCREEN_CUSTOM_APP_ACTIVITIES[index],
            (String) newValue);
        refreshSettings();
      }
      return true;
    }

    return false;
  }
Пример #3
0
 /** Handle the event that the preference is clicked. */
 public boolean onPreferenceClick(Preference preference) {
   if (preference.getKey().equals(pen_color_key)) {
     String str = getResources().getString(R.string.tip_choose_color);
     new ColorPickerDialog(this, this, Brush.getPen().getColor(), str).show();
   } else if (preference.getKey().equals(pen_width_key)) {
     showSetBrushWidthDialog();
   }
   return true;
 }
  @Override
  public boolean onPreferenceClick(Preference preference) {
    // TODO Auto-generated method stub
    Log.v("Cit ", "preference is clicked");
    Log.v("Key_Cit", preference.getKey());
    if (preference.getKey().equals("to_sdcard")) {

      Log.v(" cit ", "positive button is clicked");
      int freeSpace = 0;
      freeSpace = GetFreeSpaceOnSd();
      Log.v("cit", String.format("free Space = %d", freeSpace));

      // if free Space is small than 5 MB
      if (freeSpace > 5) {
        try {
          File fd = new File("/sdcard/LEWA/LOG/" + sf.format(cal.getTime()) + "/");
          if (!fd.exists()) {
            if (fd.mkdirs()) {
              Log.v("cit", "cit dir make on sdcard succeed");
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        isSaveToData = false;
        ShowAlert(
            String.format(
                getString(R.string.make_sure), (isSaveToData ? LOG_TO_DATA : LOG_TO_SDCARD)));
      }
    } else if (preference.getKey().equals("to_data")) {

      try {
        try {
          File fd = new File("/data/data/com.lewa.cit/LEWA/LOG/" + sf.format(cal.getTime()) + "/");
          if (!fd.exists()) {
            if (fd.mkdirs()) {
              Log.v("cit", "dir make on data succeed");
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        // Toast.makeText(this,"Saved",Toast.LENGTH_LONG).show();
      } catch (Exception e) {
        e.printStackTrace();
      }
      isSaveToData = true;
      ShowAlert(
          String.format(
              getString(R.string.make_sure), (isSaveToData ? LOG_TO_DATA : LOG_TO_SDCARD)));

    } else {

      return false;
    }
    return true;
  }
Пример #5
0
  /** @param resource if null, updates all resources */
  @Override
  public void updatePreferences(Preference preference, Object value) {
    Resources r = getResources();

    if (r.getString(R.string.p_rmd_quietStart).equals(preference.getKey())) {
      int index =
          AndroidUtilities.indexOf(
              r.getStringArray(R.array.EPr_quiet_hours_start_values), (String) value);
      Preference endPreference = findPreference(getString(R.string.p_rmd_quietEnd));
      if (index <= 0) {
        preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none));
        endPreference.setEnabled(false);
      } else {
        String setting = r.getStringArray(R.array.EPr_quiet_hours_start)[index];
        preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_start_desc, setting));
        endPreference.setEnabled(true);
      }
    } else if (r.getString(R.string.p_rmd_quietEnd).equals(preference.getKey())) {
      int index =
          AndroidUtilities.indexOf(
              r.getStringArray(R.array.EPr_quiet_hours_end_values), (String) value);
      int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
      if (index == -1 || quietHoursStart == -1)
        preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none));
      else {
        String setting = r.getStringArray(R.array.EPr_quiet_hours_end)[index];
        preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_end_desc, setting));
      }
    } else if (r.getString(R.string.p_rmd_time).equals(preference.getKey())) {
      int index =
          AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_rmd_time_values), (String) value);
      String setting = r.getStringArray(R.array.EPr_rmd_time)[index];
      preference.setSummary(r.getString(R.string.rmd_EPr_rmd_time_desc, setting));
    } else if (r.getString(R.string.p_rmd_ringtone).equals(preference.getKey())) {
      if (value == null
          || "content://settings/system/notification_sound".equals(value)) // $NON-NLS-1$
      preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_default));
      else if ("".equals(value)) // $NON-NLS-1$
      preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_silent));
      else preference.setSummary(r.getString(R.string.rmd_EPr_ringtone_desc_custom));
    } else if (r.getString(R.string.p_rmd_persistent).equals(preference.getKey())) {
      if ((Boolean) value)
        preference.setSummary(r.getString(R.string.rmd_EPr_persistent_desc_true));
      else preference.setSummary(r.getString(R.string.rmd_EPr_persistent_desc_false));
    } else if (r.getString(R.string.p_rmd_maxvolume).equals(preference.getKey())) {
      if ((Boolean) value)
        preference.setSummary(r.getString(R.string.rmd_EPr_multiple_maxvolume_desc_true));
      else preference.setSummary(r.getString(R.string.rmd_EPr_multiple_maxvolume_desc_false));
    } else if (r.getString(R.string.p_rmd_vibrate).equals(preference.getKey())) {
      if ((Boolean) value) preference.setSummary(r.getString(R.string.rmd_EPr_vibrate_desc_true));
      else preference.setSummary(r.getString(R.string.rmd_EPr_vibrate_desc_false));
    } else if (r.getString(R.string.p_rmd_nagging).equals(preference.getKey())) {
      if ((Boolean) value) preference.setSummary(r.getString(R.string.rmd_EPr_nagging_desc_true));
      else preference.setSummary(r.getString(R.string.rmd_EPr_nagging_desc_false));
    } else if (r.getString(R.string.p_rmd_snooze_dialog).equals(preference.getKey())) {
      if (value == null || ((Boolean) value) == true)
        preference.setSummary(r.getString(R.string.rmd_EPr_snooze_dialog_desc_true));
      else preference.setSummary(r.getString(R.string.rmd_EPr_snooze_dialog_desc_false));
    }
  }
Пример #6
0
 @Override
 public boolean onPreferenceClick(Preference preference) {
   if (preference.getKey().equals(getString(R.string.cache_clear_key))) {
     showDialog(R.string.cache_clear_warning);
   } else if (preference.getKey().equals(getString(R.string.security_clear_certificate_key))) {
     showDialog(R.string.security_clear_certificate_warning);
   } else if (preference.getKey().equals(getString(R.string.contacts_reset_offline_key))) {
     showDialog(R.string.contacts_reset_offline_warning);
   }
   return false;
 }
Пример #7
0
 public void setMVNOPreferenceState(Preference preference) {
   if ("mvno_type".equals(preference.getKey())) {
     preference.setEnabled(false);
     Log.d(TAG, "disable MVNO type preference");
   } else if ("mvno_match_data".equals(preference.getKey())) {
     preference.setEnabled(false);
     Log.d(TAG, "disable MVNO match data preference");
   } else {
     Log.d(TAG, "nothing to do at present");
   }
 }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    SharedPreferences sharedPreferences =
        getSharedPreferences(getPackageName(), Activity.MODE_PRIVATE);
    Editor edit = sharedPreferences.edit();

    if (preference.getKey().equals(org.fosdem.schedules.Preferences.PREF_SORT)) {
      edit.putString(preference.getKey(), (String) newValue);
    }
    edit.commit();
    return true;
  }
Пример #9
0
  @Override
  public boolean onPreferenceClick(Preference preference) {

    if (preference.getKey().equals(PREFERENCES_ABOUT)) {
      Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(Constants.GITGUB_PROJECT));
      startActivity(intent);
    } else if (preference.getKey().equals(PREFERENCE_VERSION)) {
      showDialog();
    }

    return false;
  }
Пример #10
0
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   if (preference.getKey().equals(LUNCH_RINGTON_KEY)
       || preference.getKey().equals(DAY_RINGTON_KEY)) {
     updateRingtoneSummary((RingtonePreference) preference, (String) newValue);
     if (preference.getKey().equals(LUNCH_RINGTON_KEY)) {
       updateNotificationSummury(new KeyMeneger(KeyMeneger.LUNCH_MODE));
     } else {
       updateNotificationSummury(new KeyMeneger(KeyMeneger.DAY_MODE));
     }
   }
   return true;
 }
Пример #11
0
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   Log.i(TAG, "onPreferenceTreeClick");
   if (preference.getKey().equals(KEY_RESET_TO_DEFAULT)) {
     // TODO 恢复默认设置,清空sharedPreference
     PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().clear().commit();
     getActivity().finish();
     return true;
   } else if (preference.getKey().equals(KEY_LYRIC_SAVE_PATH)) {
     startActivity(new Intent(getActivity(), FolderChooseActivity.class));
   }
   return super.onPreferenceTreeClick(preferenceScreen, preference);
 }
Пример #12
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (preference.getKey() != null && preference.getKey().equals("bypassAddrs")) {
      Intent intent = new Intent(this, BypassListActivity.class);
      startActivity(intent);
    } else if (preference.getKey() != null && preference.getKey().equals("proxyedApps")) {
      Intent intent = new Intent(this, AppManager.class);
      startActivity(intent);
    }

    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   if (preference != null && preference instanceof SecurityItemPreference) {
     Xlog.d(TAG, "onPreferenceChange, select " + preference.getKey() + " active");
     Settings.Global.putString(
         getContentResolver(), Settings.Global.NFC_MULTISE_ACTIVE, preference.getKey());
     mProgressCategory.setProgress(true);
     mSwitchBar.setEnabled(false);
     for (SecurityItemPreference pref : mItemPreferences) {
       pref.setEnabled(false);
     }
     return true;
   }
   return false;
 }
 public boolean onPreferenceChange(Preference pref, Object objValue) {
   if (pref.getKey().equals("zoom_type")) {
     findPreference("zoom_percent").setEnabled(((String) objValue).equals("0"));
     return true;
   } else if (pref.getKey().equals("dpi_auto")) {
     findPreference("dpi_manual").setEnabled(!((Boolean) objValue));
     return true;
   } else if (pref.getKey().equals("tilesize_by_factor")) {
     findPreference("tilesize_x").setEnabled(!((Boolean) objValue));
     findPreference("tilesize_y").setEnabled(!((Boolean) objValue));
     findPreference("tilesize_factor").setEnabled(((Boolean) objValue));
     return true;
   }
   return false;
 }
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   if (preference.getKey().equals(Preferences.REMEMBER_USER)) {
     if (!(Boolean) newValue) {
       m_autoLogin.setChecked(false);
     }
   } else if (preference.getKey().equals(Preferences.NIGHT_THEME)) {
     if ((Boolean) newValue) {
       aSMApplication.THEME = R.style.Theme_Sherlock;
     } else {
       aSMApplication.THEME = R.style.Theme_Sherlock_Light;
     }
   }
   return true;
 }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference == menuButtonLocation) {
      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.LOCKSCREEN_ENABLE_MENU_KEY,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      return true;
    } else if (preference == mLockScreenTimeoutUserOverride) {
      Settings.Secure.putInt(
          getActivity().getContentResolver(),
          Settings.Secure.LOCK_SCREEN_LOCK_USER_OVERRIDE,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      return true;

    } else if (preference == mLockscreenBattery) {

      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.LOCKSCREEN_BATTERY,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      return true;

    } else if (preference == mVolumeWake) {

      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.VOLUME_WAKE_SCREEN,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      return true;
    } else if (preference == mVolumeMusic) {

      Settings.System.putInt(
          getActivity().getContentResolver(),
          Settings.System.VOLUME_MUSIC_CONTROLS,
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
      return true;

    } else if (keys.contains(preference.getKey())) {
      Log.e("RC_Lockscreens", "key: " + preference.getKey());
      return Settings.System.putInt(
          getActivity().getContentResolver(),
          preference.getKey(),
          ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
    }

    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
 @Override
 public boolean onPreferenceClick(Preference preference) {
   assert preference.getKey().equals(PREF_SERVER_PROFILE_EDIT_LINK);
   ((Preferences) preference.getContext())
       .showUrl(R.string.autofill_edit_profile, R.string.autofill_manage_wallet_addresses_url);
   return true;
 }
  public boolean onPreferenceChange(Preference arg0, Object arg1) {

    final String key = arg0.getKey();

    if (KEY_NETWORK_MODE_SETTING.equals(key)) {

      int oldNetworkMode =
          android.provider.Settings.Secure.getInt(
              getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);

      int newNetworkMode = Integer.valueOf((String) arg1).intValue();

      newNetworkMode = GeminiUtils.getNetworkMode(newNetworkMode);

      Settings.Secure.putInt(
          getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, newNetworkMode);

      if (newNetworkMode != oldNetworkMode) {

        Intent intent = new Intent(GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST, null);
        intent.putExtra(GeminiUtils.OLD_NETWORK_MODE, oldNetworkMode);
        intent.putExtra(GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST, newNetworkMode);
        intent.putExtra(Phone.GEMINI_SIM_ID_KEY, Phone.GEMINI_SIM_1);
        showDialog(DIALOG_NETWORK_MODE_CHANGE);
        setCancelable(false);
        getActivity().sendBroadcast(intent);
        Xlog.i(TAG, "Send broadcast of " + GeminiUtils.NETWORK_MODE_CHANGE_BROADCAST);
      }
    }
    return true;
  }
Пример #19
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (getActivity() == null) {
      // Monkeys cause bad things. This callback may be delayed if for some reason the
      // preference screen was closed really quickly - just bail then.
      return false;
    }

    final String key = preference.getKey();

    if (PreferenceKeys.REMOVAL_ACTION.equals(key)) {
      final String removalAction = newValue.toString();
      mMailPrefs.setRemovalAction(removalAction);
      updateListSwipeTitle(removalAction);
    } else if (AUTO_ADVANCE_WIDGET.equals(key)) {
      final int prefsAutoAdvanceMode =
          AUTO_ADVANCE_VALUES[mAutoAdvance.findIndexOfValue((String) newValue)];
      mMailPrefs.setAutoAdvanceMode(prefsAutoAdvanceMode);
    } else if (!PreferenceKeys.CONVERSATION_LIST_SWIPE.equals(key)
        && !PreferenceKeys.SHOW_SENDER_IMAGES.equals(key)
        && !PreferenceKeys.DEFAULT_REPLY_ALL.equals(key)
        && !PreferenceKeys.CONVERSATION_OVERVIEW_MODE.equals(key)
        && !PreferenceKeys.CONFIRM_DELETE.equals(key)
        && !PreferenceKeys.CONFIRM_ARCHIVE.equals(key)
        && !PreferenceKeys.CONFIRM_SEND.equals(key)) {
      return false;
    }

    return true;
  }
Пример #20
0
  private void onLongClick(Preference pref) {
    //
    // Dirty remove friend or like function.
    // If the entry has an icon pref, this
    // friend or like ist not linked to the
    // user but resulst from a search. In
    // this case it can be deleted.
    //

    String prefmode = pref.getKey();
    String prefname = prefmode.replace(".mode.", ".name.");
    String preficon = prefmode.replace(".mode.", ".icon.");

    Log.d(LOGTAG, "onLongClick:" + prefmode + "=" + Simple.getSharedPrefString(prefmode));
    Log.d(LOGTAG, "onLongClick:" + prefname + "=" + Simple.getSharedPrefString(prefname));
    Log.d(LOGTAG, "onLongClick:" + preficon + "=" + Simple.getSharedPrefString(preficon));

    if (Simple.getSharedPrefString(preficon) != null) {
      Simple.makeClick();

      Simple.removeSharedPref(prefmode);
      Simple.removeSharedPref(prefname);
      Simple.removeSharedPref(preficon);

      preferences.remove(pref);
      getPreferenceScreen().removePreference(pref);
    }
  }
  @SuppressWarnings("unchecked")
  private void preferenceChanged(Preference preference, Object newValue) {
    Editor editor = mPrefs.edit();
    if (newValue instanceof String) {
      editor.putString(preference.getKey(), (String) newValue);
    } else if (newValue instanceof Integer) {
      editor.putInt(preference.getKey(), (Integer) newValue);
    } else if (newValue instanceof Set<?>) {
      editor.putStringSet(preference.getKey(), (Set<String>) newValue);
    } else if (newValue instanceof Boolean) {
      editor.putBoolean(preference.getKey(), (Boolean) newValue);
    }

    editor.commit();
    emitSettingsChanged();
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    if (KEY_BT_SCAN.equals(preference.getKey())) {
      mLocalManager.startScanning(true);
      return true;
    }

    if (preference instanceof BluetoothDevicePreference) {
      BluetoothDevicePreference btPreference = (BluetoothDevicePreference) preference;
      if (mScreenType == SCREEN_TYPE_SETTINGS) {
        btPreference.getCachedDevice().onClicked();
      } else if (mScreenType == SCREEN_TYPE_DEVICEPICKER) {
        CachedBluetoothDevice device = btPreference.getCachedDevice();

        mSelectedDevice = device.getDevice();
        mLocalManager.stopScanning();
        mLocalManager.persistSelectedDeviceInPicker(mSelectedDevice.getAddress());
        if ((device.getBondState() == BluetoothDevice.BOND_BONDED) || (mNeedAuth == false)) {
          sendDevicePickedIntent(mSelectedDevice);
          finish();
        } else {
          btPreference.getCachedDevice().onClicked();
        }
      }
      return true;
    }

    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
Пример #23
0
 @Override
 public boolean onPreferenceClick(Preference preference) {
   String key = preference.getKey();
   if ("share_account".equals(key)) {
     UMSocialService controller =
         UMServiceFactory.getUMSocialService("Android", RequestType.SOCIAL);
     controller.openUserCenter(this);
   } else if ("check_update".equals(key)) {
     new Mumeng().update(this);
   } else if ("advise".equals(key)) {
     FeedbackAgent feedbackAgent = new FeedbackAgent(this);
     feedbackAgent.startFeedbackActivity();
   } else if ("about".equals(key)) {
     Intent intent = new Intent(this, WebViewActivity.class);
     intent.putExtra("title", "关于播播");
     intent.putExtra("url", "file:///android_asset/about.html");
     startActivity(intent);
   } else if ("author".equals(key)) {
     Intent intent = new Intent(this, WebViewActivity.class);
     intent.putExtra("title", "关于作者");
     intent.putExtra("url", "file:///android_asset/about_author.html");
     startActivity(intent);
   } else if ("sound_hint".equals(key)) {
     ExampleApplication.sound_hint = sound_hint.isChecked();
     settingSP.edit().putBoolean("sound_hint", sound_hint.isChecked()).commit();
   }
   return true;
 }
Пример #24
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {

    String key = preference.getKey();
    if (preference instanceof SwitchPreference) {
      boolean value = (boolean) newValue;

      if (key.equalsIgnoreCase(getString(R.string.abd_alatif_notificatin_pref_key))) {
        MyApplication.pref
            .edit()
            .putBoolean(getString(R.string.abd_alatif_notificatin_pref_key), value)
            .apply();

      } else if (key.equalsIgnoreCase(getString(R.string.wali_notification_pref_key))) {
        MyApplication.pref
            .edit()
            .putBoolean(getString(R.string.wali_notification_pref_key), value)
            .apply();

      } else if (key.equalsIgnoreCase(getString(R.string.khadim_notification_pref_key))) {
        MyApplication.pref
            .edit()
            .putBoolean(getString(R.string.khadim_notification_pref_key), value)
            .apply();

      } else if (key.equalsIgnoreCase(getString(R.string.first_notification_pref_key))) {
        MyApplication.pref
            .edit()
            .putBoolean(getString(R.string.first_notification_pref_key), value)
            .apply();
      }
      return true;
    }
    return false;
  }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();

    if (KEY_FREQUENCY_BAND.equals(key)) {
      try {
        mWifiManager.setFrequencyBand(Integer.parseInt((String) newValue), true);
      } catch (NumberFormatException e) {
        Toast.makeText(
                getActivity(), R.string.wifi_setting_frequency_band_error, Toast.LENGTH_SHORT)
            .show();
        return false;
      }
    }

    if (KEY_SLEEP_POLICY.equals(key)) {
      try {
        String stringValue = (String) newValue;
        Settings.System.putInt(
            getContentResolver(), Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(stringValue));
        updateSleepPolicySummary(preference, stringValue);
      } catch (NumberFormatException e) {
        Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error, Toast.LENGTH_SHORT)
            .show();
        return false;
      }
    }

    return true;
  }
 @Override
 public boolean onPreferenceChange(Preference pref, Object newValue) {
   if (pref.getKey().equals(KEY_LOCATION_TOGGLE)) {
     onToggleLocationAccess((Boolean) newValue);
   }
   return true;
 }
Пример #27
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    // are we starting the preference activity?
    if (!mBindingPreference) {
      if (preference.getKey().equals(getString(R.string.pref_location_key))) {
        FetchWeatherTask weatherTask = new FetchWeatherTask(this);
        String location = value.toString();
        weatherTask.execute(location);
      } else {
        // notify code that weather may be impacted
        getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
      }
    }

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list (since they have separate labels/values).
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else {
      // For other preferences, set the summary to the value's simple string representation.
      preference.setSummary(stringValue);
    }
    return true;
  }
Пример #28
0
 @Override
 public boolean onPreferenceClick(Preference preference) {
   if (Constants.PREFERENCES.USERNAME.equals(preference.getKey())) {
     clearCredentialPreferences();
   }
   return true;
 }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
          } else {
            preference.setSummary(stringValue);
          }

          // detect errors
          if (preference.getKey().equals("sos_uri")) {
            try {
              URL url = new URL(value.toString());
              if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https"))
                throw new Exception("SOS URL must be HTTP or HTTPS");
            } catch (Exception e) {
              AlertDialog.Builder dlgAlert = new AlertDialog.Builder(preference.getContext());
              dlgAlert.setMessage("Invalid SOS URL");
              dlgAlert.setTitle(e.getMessage());
              dlgAlert.setPositiveButton("OK", null);
              dlgAlert.setCancelable(true);
              dlgAlert.create().show();
            }
          }

          return true;
        }
Пример #30
0
 public boolean onPreferenceChange(Preference preference, Object value) {
   Utilities.log(
       Constants.LOG_TITLE,
       LOG_SUBTITLE,
       "Preference '"
           + preference.getKey()
           + "' changed. New value is '"
           + value.toString()
           + "'");
   SharedPreferences.Editor editor = Constants.getPreferences(this).edit();
   if (preference.getKey().equals(Constants.MOUNT_ON_BOOT_PREFERENCE_KEY)) {
     editor.putBoolean(preference.getKey(), (Boolean) value);
   }
   editor.commit();
   return true;
 }