Java Code Examples for android.preference.Preference#getTitle()

The following examples show how to use android.preference.Preference#getTitle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyComboPreference.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Nullable
private CharSequence getTitleOfOtherActionAssociatedWith(Long extendedKeyCode) {
  /*
   * Collect all KeyComboPreferences. It's somewhat inefficient to iterate through all
   * preferences every time, but it's only done during configuration when the user presses a
   * key. Lazily-initializing a static list would assume that there's no way a preference
   * will be added after the initialization. That assumption was not true during testing,
   * which may have been specific to the testing environment but may also indicate that
   * problematic situations can arise.
   */
  PreferenceManager preferenceManager = getPreferenceManager();
  SharedPreferences prefs = SharedPreferencesUtils.getSharedPreferences(getContext());
  Map<String, ?> prefMap = prefs.getAll();
  String myKey = getKey();
  for (String key : prefMap.keySet()) {
    if (!myKey.equals(key)) {
      Preference preference = preferenceManager.findPreference(key);
      if (preference instanceof KeyComboPreference
          && KeyAssignmentUtils.getKeyCodesForPreference(getContext(), key)
              .contains(extendedKeyCode)) {
        return preference.getTitle();
      }
    }
  }
  return null;
}
 
Example 2
Source File: PreferenceMatchers.java    From android-test with Apache License 2.0 6 votes vote down vote up
public static Matcher<Preference> withTitleText(final Matcher<String> titleMatcher) {
  return new TypeSafeMatcher<Preference>() {
    @Override
    public void describeTo(Description description) {
      description.appendText(" a preference with title matching: ");
      titleMatcher.describeTo(description);
    }

    @Override
    public boolean matchesSafely(Preference pref) {
      if (pref.getTitle() == null) {
        return false;
      }
      String title = pref.getTitle().toString();
      return titleMatcher.matches(title);
    }
  };
}
 
Example 3
Source File: SettingFragment.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    String title = (String) preference.getTitle();
    if (title.equals("颜色风格")) {
        showThemeDialog();
        return true;
    } else if (title.equals("捐赠")) {
        donate();
        return true;
    }
    return false;
}
 
Example 4
Source File: KeyboardShortcutDialogPreference.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void showOverrideKeyComboDialog(final String key) {
  final Preference currentActionPreference = getPreferenceManager().findPreference(key);
  if (currentActionPreference == null) {
    return;
  }

  final Preference newActionPreference = getPreferenceManager().findPreference(getKey());
  if (newActionPreference == null) {
    return;
  }

  CharSequence currentAction = currentActionPreference.getTitle();
  CharSequence newAction = newActionPreference.getTitle();
  setKeyEventSource(KEY_EVENT_SOURCE_ACTIVITY);
  showOverrideKeyComboDialog(
      currentAction,
      newAction,
      new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
          if (which != DialogInterface.BUTTON_POSITIVE) {
            setKeyEventSource(getKeyEventSourceForCurrentKeyComboModel());
            return;
          }

          saveKeyCode();
          keyComboManager.getKeyComboModel().clearKeyComboCode(key);
          notifyListener(key, keyComboManager.getKeyComboModel().getKeyComboCodeForKey(key));
          Dialog mainDialog = getDialog();
          if (mainDialog != null) {
            mainDialog.dismiss();
          }
        }
      });
}
 
Example 5
Source File: ActivitySettings.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
private void markPro(Preference pref, String sku) {
    if (sku == null || !IAB.isPurchased(sku, this)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + pref.getTitle());
        ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        pref.setTitle(ssb);
    }
}
 
Example 6
Source File: PreferenceMatchers.java    From android-test with Apache License 2.0 5 votes vote down vote up
public static Matcher<Preference> withTitle(final int resourceId) {
  return new TypeSafeMatcher<Preference>() {
    private String resourceName = null;
    private String expectedText = null;

    @Override
    public void describeTo(Description description) {
      description.appendText(" with title string from resource id: ");
      description.appendValue(resourceId);
      if (null != resourceName) {
        description.appendText("[");
        description.appendText(resourceName);
        description.appendText("]");
      }
      if (null != expectedText) {
        description.appendText(" value: ");
        description.appendText(expectedText);
      }
    }

    @Override
    public boolean matchesSafely(Preference preference) {
      if (null == expectedText) {
        try {
          expectedText = preference.getContext().getResources().getString(resourceId);
          resourceName = preference.getContext().getResources().getResourceEntryName(resourceId);
        } catch (Resources.NotFoundException ignored) {
          /* view could be from a context unaware of the resource id. */
        }
      }
      if (null != expectedText && preference.getTitle() != null) {
        return expectedText.equals(preference.getTitle().toString());
      } else {
        return false;
      }
    }
  };
}