androidx.preference.Preference.getKey()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中androidx.preference.Preference.getKey()方法的一些代码示例,展示了Preference.getKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preference.getKey()方法的具体详情如下:
包路径:androidx.preference.Preference
类名称:Preference
方法名:getKey

Preference.getKey介绍

暂无

代码示例

代码示例来源:origin: cSploit/android

private void startDirectoryPicker(Preference preference) {
  Intent i = new Intent(getActivity(), DirectoryPicker.class);
  i.putExtra(DirectoryPicker.AFFECTED_PREF, preference.getKey());
  startActivityForResult(i, DirectoryPicker.PICK_DIRECTORY);
}

代码示例来源:origin: cSploit/android

final String key = preference.getKey();

代码示例来源:origin: westnordost/StreetComplete

@Override
public void onDisplayPreferenceDialog(Preference preference) {
  DialogFragment fragment;
  if (preference instanceof DialogPreferenceCompat) {
    fragment = ((DialogPreferenceCompat)preference).createDialog();
    Bundle bundle = new Bundle(1);
    bundle.putString("key", preference.getKey());
    fragment.setArguments(bundle);
    fragment.setTargetFragment(this, 0);
    fragment.show(getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
  } else super.onDisplayPreferenceDialog(preference);
}

代码示例来源:origin: jaredrummler/ColorPicker

@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
  if (KEY_DEFAULT_COLOR.equals(preference.getKey())) {
   String newDefaultColor = Integer.toHexString((int) newValue);
   Log.d(TAG, "New default color is: #" + newDefaultColor);
  }
  return true;
 }
});

代码示例来源:origin: proninyaroslav/libretorrent

@Override
  public boolean onPreferenceChange(Preference preference, Object newValue)
  {
    SharedPreferences pref = SettingsManager.getPreferences(getActivity());

    if (preference.getKey().equals(getString(R.string.pref_key_streaming_hostname))) {
      pref.edit().putString(preference.getKey(), (String)newValue).apply();
      preference.setSummary((String)newValue);

    } else if (preference.getKey().equals(getString(R.string.pref_key_streaming_port))) {
      int value = SettingsManager.Default.streamingPort;
      if (!TextUtils.isEmpty((String)newValue))
        value = Integer.parseInt((String)newValue);

      pref.edit().putInt(preference.getKey(), value).apply();
      preference.setSummary(Integer.toString(value));
    }

    return true;
  }
}

代码示例来源:origin: 8enet/AppOpsX

@Override
 public void onClick(DialogInterface dialog, int which) {
  int index = selected[0];
  String language = null;
  if(index == 0){
   PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
     .remove(preference.getKey()).apply();
   language = "auto";
  }else {
   language = getResources().getStringArray(R.array.languages_key)[index];
   PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
     .putString(preference.getKey(), language).apply();
  }
  preference.setSummary(getResources().getStringArray(R.array.languages)[index]);
  switchLanguage();
 }
});

代码示例来源:origin: 8enet/AppOpsX

@Override
 public void onClick(DialogInterface dialog, int which) {
  PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
    .putInt(preference.getKey(), selected[0]).apply();
  mPrefAppSort.setSummary(getString(R.string.app_sort_type_summary,
    getResources().getStringArray(R.array.app_sort_type)[selected[0]]));
 }
});

代码示例来源:origin: michael-rapp/AndroidPreferenceActivity

@Override
public final void onRestoredDefaultValue(@NonNull final PreferenceFragment fragment,
                     @NonNull final Preference preference,
                     final Object oldValue, final Object newValue) {
  if (preference.getKey()
      .equals(getString(R.string.override_navigation_icon_preference_key))) {
    createOverrideBackButtonChangeListener().onPreferenceChange(preference, newValue);
  } else if (preference.getKey().equals(getString(R.string.hide_navigation_preference_key))) {
    createHideNavigationChangeListener().onPreferenceChange(preference, newValue);
  }
}

代码示例来源:origin: KDE/kdeconnect-android

@Override
public boolean onPreferenceTreeClick(Preference preference) {
  /*
   * There is no RingtonePreference in support library nor androidx, this is the workaround proposed here:
   * https://issuetracker.google.com/issues/37057453
   */
  if (preference.hasKey() && preference.getKey().equals(preferenceKeyRingtone)) {
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
    String existingValue = sharedPreferences.getString(preferenceKeyRingtone, null);
    if (existingValue != null) {
      intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
    } else {
      intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_RINGTONE_URI);
    }
    startActivityForResult(intent, REQUEST_CODE_SELECT_RINGTONE);
    return true;
  }
  return super.onPreferenceTreeClick(preference);
}

代码示例来源:origin: proninyaroslav/libretorrent

@Override
  public boolean onPreferenceChange(Preference preference, Object newValue)
  {
    SharedPreferences pref = SettingsManager.getPreferences(getActivity());

    if (preference instanceof ColorPreference) {
      ColorPreference ledIndicatorColor = (ColorPreference)preference;
      ledIndicatorColor.forceSetValue((int)newValue);
    } else if (preference.getKey().equals(getString(R.string.pref_key_theme))) {
      int type = Integer.parseInt((String) newValue);
      pref.edit().putInt(preference.getKey(), type).apply();
      String typesName[] = getResources().getStringArray(R.array.pref_theme_entries);
      preference.setSummary(typesName[type]);

      Toast.makeText(getActivity().getApplicationContext(),
          R.string.theme_settings_apply_after_reboot,
          Toast.LENGTH_SHORT)
          .show();
    } else if (preference.getKey().equals(getString(R.string.pref_key_foreground_notify_func_button))) {
      int type = Integer.parseInt((String) newValue);
      pref.edit().putInt(preference.getKey(), type).apply();
      String typesName[] = getResources().getStringArray(R.array.pref_function_button_entries);
      preference.setSummary(typesName[type]);
    }

    return true;
  }
}

代码示例来源:origin: andstatus/andstatus

@Override
public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
  final Bundle args = pref.getExtras();
  args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey());
  MySettingsFragment fragment = new MySettingsFragment();
  fragment.setArguments(args);
  fragment.setTargetFragment(caller, 0);
  getSupportFragmentManager().beginTransaction()
      .replace(R.id.settings_container, fragment, pref.getKey())
      .addToBackStack(pref.getKey())
      .commit();
  return true;
}

代码示例来源:origin: proninyaroslav/libretorrent

@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
  SharedPreferences pref = SettingsManager.getPreferences(getActivity());
  if (preference.getKey().equals(getString(R.string.pref_key_port))) {
    int value = TorrentEngine.Settings.DEFAULT_PORT;
    if (!TextUtils.isEmpty((String) newValue))
      value = Integer.parseInt((String) newValue);
    pref.edit().putInt(preference.getKey(), value).apply();
    preference.setSummary(Integer.toString(value));
  } else if (preference.getKey().equals(getString(R.string.pref_key_enc_mode))) {
    int type = Integer.parseInt((String) newValue);
    pref.edit().putInt(preference.getKey(), type).apply();
    String typesName[] = getResources().getStringArray(R.array.pref_enc_mode_entries);
    preference.setSummary(typesName[type]);
    boolean enableAdvancedEncryptSettings = type != Integer.parseInt(getString(R.string.pref_enc_mode_disable_value));
    String keyEncryptInConnections = getString(R.string.pref_key_enc_in_connections);
    SwitchPreferenceCompat encryptInConnections =
        (SwitchPreferenceCompat) findPreference(keyEncryptInConnections);
    encryptInConnections.setEnabled(enableAdvancedEncryptSettings);
    encryptInConnections.setChecked(enableAdvancedEncryptSettings);
    String keyEncryptOutConnections = getString(R.string.pref_key_enc_out_connections);
    SwitchPreferenceCompat encryptOutConnections =
        (SwitchPreferenceCompat) findPreference(keyEncryptOutConnections);
    encryptOutConnections.setEnabled(enableAdvancedEncryptSettings);
    encryptOutConnections.setChecked(enableAdvancedEncryptSettings);
  }
  return true;
}

代码示例来源:origin: TUM-Dev/Campus-Android

/**
 * Handle all clicks on 'button'-preferences
 *
 * @param preference Preference that has been clicked
 * @return True, if handled
 */
@Override
public boolean onPreferenceClick(Preference preference) {
  final String key = preference.getKey();
  switch (key) {
    case SETUP_EDUROAM:
      startActivity(new Intent(getContext(), SetupEduroamActivity.class));
      break;
    case BUTTON_LOGOUT:
      showLogoutDialog();
      break;
    default:
      return false;
  }
  return true;
}

代码示例来源:origin: 8enet/AppOpsX

@Override
 public boolean onPreferenceClick(Preference preference) {
  String key = preference.getKey();
  if ("opensource_licenses".equals(key)) {
   Intent intent = new Intent(getContext(), HtmlActionActivity.class);
   intent.putExtra(Intent.EXTRA_TITLE, preference.getTitle());
   intent.putExtra(HtmlActionActivity.EXTRA_URL, "file:///android_res/raw/licenses.html");
   getActivity().startActivity(intent);
  } else if ("help".equals(key)) {
   Intent intent = new Intent(getContext(), HtmlActionActivity.class);
   intent.putExtra(Intent.EXTRA_TITLE, preference.getTitle());
   intent.putExtra(HtmlActionActivity.EXTRA_URL, "file:///android_res/raw/help.html");
   getActivity().startActivity(intent);
  } else if ("pref_app_language".equals(key)) {
   showLanguageDialog(preference);
  } else if ("shell_start".equals(key)){
   showShellStart();
  }
  return false;
 }
}

代码示例来源:origin: bfabiszewski/ulogger-android

@Override
public void onDisplayPreferenceDialog(Preference preference) {
  if (preference instanceof EditTextPreference && KEY_HOST.equals(preference.getKey())) {
    final UrlPreferenceDialogFragment fragment = UrlPreferenceDialogFragment.newInstance(preference.getKey());
    fragment.setTargetFragment(this, 0);
    if (getFragmentManager() != null) {
      fragment.show(getFragmentManager(), "UrlPreferenceDialogFragment");
    }
  } else if (preference instanceof ListPreference && KEY_PROVIDER.equals(preference.getKey())) {
    final ProviderPreferenceDialogFragment fragment = ProviderPreferenceDialogFragment.newInstance(preference.getKey());
    fragment.setTargetFragment(this, 0);
    if (getFragmentManager() != null) {
      fragment.show(getFragmentManager(), "ProviderPreferenceDialogFragment");
    }
  } else if (preference instanceof ListPreference) {
    final ListPreferenceDialogWithMessageFragment fragment = ListPreferenceDialogWithMessageFragment.newInstance(preference.getKey());
    fragment.setTargetFragment(this, 0);
    if (getFragmentManager() != null) {
      fragment.show(getFragmentManager(), "ListPreferenceDialogWithMessageFragment");
    }
  } else {
    super.onDisplayPreferenceDialog(preference);
  }
}

代码示例来源:origin: Omico/CurrentActivity

@Override
public boolean onPreferenceTreeClick(Preference preference) {
  switch (preference.getKey()) {
    case RESET_SETUP_WIZARD:
      LocalBroadcastUtils.send(activity, new Intent(ACTION_FLOAT_VIEW_SERVICE_STOP));
      intentGuideActivity(PAGE_WELCOME, MODE_NONE);
      break;
    case HISTORY:
      ActivityUtils.startActivity(activity, HistoryActivity.class);
      break;
    case ABOUT:
      ActivityUtils.startActivity(activity, AboutActivity.class);
      break;
  }
  return super.onPreferenceTreeClick(preference);
}

代码示例来源:origin: proninyaroslav/libretorrent

if (preference.getKey().equals(getString(R.string.pref_key_feed_auto_refresh))) {
  if ((boolean)newValue) {
    long interval = pref.getLong(getString(R.string.pref_key_feed_refresh_interval),
} else if (preference.getKey().equals(getString(R.string.pref_key_feed_refresh_interval))) {
  ListPreference refreshPreference = (ListPreference)preference;
  long interval = Long.parseLong((String)newValue);
  SchedulerReceiver.setRefreshFeedsAlarm(getActivity(), interval);
} else if (preference.getKey().equals(getString(R.string.pref_key_feed_keep_items_time))) {
  ListPreference keepTimePreference = (ListPreference)preference;
  long keepTime = Long.parseLong((String)newValue);

代码示例来源:origin: 8enet/AppOpsX

@Override
public void onDisplayPreferenceDialog(Preference preference) {
 if (preference instanceof NumberPickerPreference) {
  DialogFragment fragment = NumberPickerPreference.
    NumberPickerPreferenceDialogFragmentCompat.newInstance(preference.getKey());
  fragment.setTargetFragment(this, 0);
  fragment.show(getFragmentManager(),
    "NumberPickerPreferenceDialogFragment");
 } else {
  super.onDisplayPreferenceDialog(preference);
 }
}

代码示例来源:origin: proninyaroslav/libretorrent

@Override
public void onDisplayPreferenceDialog(Preference preference)
{
  DialogFragment dialogFragment = null;
  if (preference instanceof TimePreference) {
    dialogFragment = TimePreferenceDialogFragmentCompat.newInstance(preference.getKey());
  }
  if (dialogFragment != null) {
    dialogFragment.setTargetFragment(this, 0);
    dialogFragment.show(this.getFragmentManager(), "android.support.v7.preference" +
        ".PreferenceFragment.DIALOG");
  } else {
    super.onDisplayPreferenceDialog(preference);
  }
}

代码示例来源:origin: 8enet/AppOpsX

private void showAppSortDialog(final Preference preference) {
 AlertDialog.Builder builder =
   new AlertDialog.Builder(getActivity());
 builder.setTitle(R.string.app_sort_type_title);
 final int[] selected = new int[1];
 selected[0] = PreferenceManager.getDefaultSharedPreferences(getActivity())
   .getInt(preference.getKey(), 0);
 builder.setSingleChoiceItems(R.array.app_sort_type, selected[0],
   new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
     selected[0] = which;
    }
   });
 builder.setNegativeButton(android.R.string.cancel, null);
 builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int which) {
   PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
     .putInt(preference.getKey(), selected[0]).apply();
   mPrefAppSort.setSummary(getString(R.string.app_sort_type_summary,
     getResources().getStringArray(R.array.app_sort_type)[selected[0]]));
  }
 });
 builder.show();
}

相关文章