當前位置: 首頁>>代碼示例>>Java>>正文


Java Preference類代碼示例

本文整理匯總了Java中android.preference.Preference的典型用法代碼示例。如果您正苦於以下問題:Java Preference類的具體用法?Java Preference怎麽用?Java Preference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Preference類屬於android.preference包,在下文中一共展示了Preference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onPreferenceChange

import android.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
開發者ID:ekumenlabs,項目名稱:tangobot,代碼行數:20,代碼來源:MasterChooserSettingsActivity.java

示例2: onPreferenceClick

import android.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceClick(Preference preference) {
    switch (preference.getKey()) {

        case CACHE_MAX:
            break;
        case CLEAR_CACHE:
            Toast.makeText(getActivity(), "clear cache", Toast.LENGTH_SHORT).show();
            break;
        case CHECK_UPDATE:
            Toast.makeText(getActivity(), "check update", Toast.LENGTH_SHORT).show();
            break;
        case VERSION_INFO:
            startActivity(new Intent(getActivity(), VersionInfoAct.class));
            break;

        default:
            return false;
    }
    return true;
}
 
開發者ID:xhd-Git,項目名稱:3DPrint-Controller,代碼行數:22,代碼來源:SettingFragment.java

示例3: onPreferenceChange

import android.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
開發者ID:dandanes7,項目名稱:lurkerhn,代碼行數:23,代碼來源:SettingsActivity.java

示例4: setChildrenStarted

import android.preference.Preference; //導入依賴的package包/類
private void setChildrenStarted(PreferenceGroup group, boolean started) {
    final int count = group.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference pref = group.getPreference(i);
        if (pref instanceof ApplicationLightPreference) {
            ApplicationLightPreference ap = (ApplicationLightPreference) pref;
            if (started) {
                ap.onStart();
            } else {
                ap.onStop();
            }
        } else if (pref instanceof PreferenceGroup) {
            setChildrenStarted((PreferenceGroup) pref, started);
        }
    }
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:17,代碼來源:NotificationLightSettings.java

示例5: onPreferenceChange

import android.preference.Preference; //導入依賴的package包/類
public boolean onPreferenceChange(final Preference p, Object newValue) {
  // Asynchronously save the alarm since this method is called _before_
  // the value of the preference has changed.
  final String ktekstomalnova = ("" + mKanaloPref.getEntry()).trim();
  sHandler.post(new Runnable() {
    public void run() {
      // Editing any preference (except enable) enables the alarm.
      if (p != mEnabledPref) {
        mEnabledPref.setChecked(true);
      }
      if (p == mKanaloPref) {

        String kteksto = ("" + mKanaloPref.getEntry()).trim();
        mKanaloPref.setSummary(kteksto);

        String lteksto = mLabel.getText().toString().trim();
        if (lteksto.length() == 0 || lteksto.equals(ktekstomalnova)) {
          mLabel.setText(kteksto);
        }
      }
      saveAlarm(null);
    }
  });
  return true;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:26,代碼來源:SetAlarm_akt.java

示例6: bindPreferenceSummaryToValue

import android.preference.Preference; //導入依賴的package包/類
/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference' current value.
    if (preference instanceof ListPreference
            || preference instanceof EditTextPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } else if (preference instanceof SwitchPreference
            || preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getBoolean(preference.getKey(),true));
    }
}
 
開發者ID:an-garcia,項目名稱:MovieGuide,代碼行數:29,代碼來源:SettingsActivity.java

示例7: onCreate

import android.preference.Preference; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().setTitle(R.string.prefs_about_chrome);
    addPreferencesFromResource(R.xml.about_chrome_preferences);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        ChromeBasePreference deprecationWarning = new ChromeBasePreference(
                new ContextThemeWrapper(getActivity(),
                        R.style.DeprecationWarningPreferenceTheme));
        deprecationWarning.setOrder(-1);
        deprecationWarning.setTitle(R.string.deprecation_warning);
        deprecationWarning.setIcon(R.drawable.exclamation_triangle);
        getPreferenceScreen().addPreference(deprecationWarning);
    }

    PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
    AboutVersionStrings versionStrings = prefServiceBridge.getAboutVersionStrings();
    Preference p = findPreference(PREF_APPLICATION_VERSION);
    p.setSummary(getApplicationVersion(getActivity(), versionStrings.getApplicationVersion()));
    p = findPreference(PREF_OS_VERSION);
    p.setSummary(versionStrings.getOSVersion());
    p = findPreference(PREF_LEGAL_INFORMATION);
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    p.setSummary(getString(R.string.legal_information_summary, currentYear));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:27,代碼來源:AboutChromePreferences.java

示例8: onPreferenceChange

import android.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
        int          value        = Integer.parseInt((String) newValue);
  final VibrateState vibrateState = VibrateState.fromId(value);

  recipients.setVibrate(vibrateState);

  new AsyncTask<Void, Void, Void>() {
    @Override
    protected Void doInBackground(Void... params) {
      DatabaseFactory.getRecipientPreferenceDatabase(getActivity())
                     .setVibrate(recipients, vibrateState);
      return null;
    }
  }.execute();

  return false;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:19,代碼來源:RecipientPreferenceActivity.java

示例9: initSettings

import android.preference.Preference; //導入依賴的package包/類
private void initSettings() {
	initTunnelSettings();
	initAudioSettings();
	initVideoSettings();
	initCallSettings();
	initChatSettings();
	initNetworkSettings();
	initAdvancedSettings();

	findPreference(getString(R.string.pref_add_account_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(Preference preference) {
			int nbAccounts = mPrefs.getAccountCount();
			LinphoneActivity.instance().displayAccountSettings(nbAccounts);
			return true;
		}
	});
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:19,代碼來源:SettingsFragment.java

示例10: createUserDictionaryPreference

import android.preference.Preference; //導入依賴的package包/類
/**
 * Create a single User Dictionary Preference object, with its parameters set.
 * @param localeString The locale for which this user dictionary is for.
 * @return The corresponding preference.
 */
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
    final Preference newPref = new Preference(getActivity());
    final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
    if (null == localeString) {
        newPref.setTitle(Locale.getDefault().getDisplayName());
    } else {
        if (localeString.isEmpty()) {
            newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
        } else {
            newPref.setTitle(
                    LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
        }
        intent.putExtra("locale", localeString);
        newPref.getExtras().putString("locale", localeString);
    }
    newPref.setIntent(intent);
    newPref.setFragment(UserDictionarySettings.class.getName());
    return newPref;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:25,代碼來源:UserDictionaryList.java

示例11: setPreferenceSummaryByValue

import android.preference.Preference; //導入依賴的package包/類
/**
 * Sets the summary of the preference according to its value
 *
 * @param preference
 * @param value
 */
private static void setPreferenceSummaryByValue(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    }
    else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
}
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:28,代碼來源:PreferenceActivity.java

示例12: onCreate

import android.preference.Preference; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    if(Build.VERSION.SDK_INT>=21)
        setTheme(R.style.Material);
    else if (Build.VERSION.SDK_INT>=11)
        setTheme(R.style.Holo);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_settings);
    findPreference("disable_qq").setOnPreferenceChangeListener(new disabler("QQActivity"));
    findPreference("disable_wechat").setOnPreferenceChangeListener(new disabler("WechatActivity"));
    findPreference("disable_generic").setOnPreferenceChangeListener(new disabler("GenericActivity"));
    findPreference("disable_this").setOnPreferenceChangeListener(new disabler("JumpActivity"));
    findPreference("show_help").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(SettingsActivity.this, GuideActivity.class));
            return true;
        }
    });
}
 
開發者ID:CwithW,項目名稱:PretendSharing,代碼行數:21,代碼來源:SettingsActivity.java

示例13: onCreate

import android.preference.Preference; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);

    ChromeSwitchPreference doNotTrackSwitch =
            (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);

    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);

    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:21,代碼來源:DoNotTrackPreference.java

示例14: updateDebugHwOverdraw

import android.preference.Preference; //導入依賴的package包/類
private void updateDebugHwOverdraw() {
    final CharSequence[] entries = mDebugHwOverdrawPref.getEntries();
    String value = SystemProperties.get(Constants.THREADED_RENDERER_DEBUG_OVERDRAW_PROPERTY);
    int idxOfValue = mDebugHwOverdrawPref.findIndexOfValue(value);
    if (idxOfValue != -1) {
        mDebugHwOverdrawPref.setValueIndex(idxOfValue);
        mDebugHwOverdrawPref.setSummary(entries[idxOfValue]);
    }

    mDebugHwOverdrawPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY
            String command = String.format("setprop %s %s",
                    Constants.THREADED_RENDERER_DEBUG_OVERDRAW_PROPERTY,
                    newValue.toString());
            ShellUtils.execCommand(command, true);
            new SystemPropPoker().execute();

            int indexOfValue = mDebugHwOverdrawPref.findIndexOfValue(newValue.toString());
            preference.setSummary(entries[indexOfValue]);

            return true;
        }
    });
}
 
開發者ID:XuDaojie,項目名稱:DeveloperSettings,代碼行數:27,代碼來源:DevelopmentSettingsActivity.java

示例15: onPreferenceChange

import android.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
	String value = newValue.toString();
	try {
		int intValue = Integer.parseInt(value);
		if ((intValue < 1) || (intValue > 5)) {
			return false;
		}
	} catch (NumberFormatException nfe) { }
	if (isNewAccount) {
		//TODO
	} else {
		mPrefs.setAvpfRRInterval(n, value);
	}
	preference.setSummary(value);
	return true;
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:18,代碼來源:AccountPreferencesFragment.java


注:本文中的android.preference.Preference類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。