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


Java Preference類代碼示例

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


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

示例1: setPreferenceSummary

import android.support.v7.preference.Preference; //導入依賴的package包/類
private void setPreferenceSummary(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 (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);
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:17,代碼來源:SettingsFragment.java

示例2: onCreatePreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    // Add 'general' preferences, defined in the XML file
    addPreferencesFromResource(R.xml.pref_general);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:17,代碼來源:SettingsFragment.java

示例3: onCreatePreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    /* Add 'general' preferences, defined in the XML file */
    addPreferencesFromResource(R.xml.pref_general);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:17,代碼來源:SettingsFragment.java

示例4: onSharedPreferenceChanged

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
        // we've changed the location
        // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
        SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
        // units have changed. update lists of weather entries accordingly
        activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
        if (!(preference instanceof CheckBoxPreference)) {
            setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
        }
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:20,代碼來源:SettingsFragment.java

示例5: onDisplayPreferenceDialog

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (callback != null) {
        callback.onSettingChanged();
    }

    DialogFragment dialogFragment = null;
    if (preference instanceof StylePreference) {
        dialogFragment
                = StylePreferenceDialogFragment
                .newInstance(preference);
    } else if (preference instanceof ColumnCountPreference) {
        dialogFragment
                = ColumnCountPreferenceDialogFragment
                .newInstance(preference);
    }

    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(this, 0);
        dialogFragment.show(this.getFragmentManager(), DIALOG_FRAGMENT_TAG);
        return;
    }

    super.onDisplayPreferenceDialog(preference);
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:26,代碼來源:SettingsActivity.java

示例6: initPrefsSummary

import android.support.v7.preference.Preference; //導入依賴的package包/類
/**
 * Init single Preference
 */
protected void initPrefsSummary(SharedPreferences sharedPreferences,
                                Preference p) {
    if (p instanceof PreferenceCategory) {
        PreferenceCategory pCat = (PreferenceCategory) p;
        int pcCatCount = pCat.getPreferenceCount();
        for (int i = 0; i < pcCatCount; i++) {
            initPrefsSummary(sharedPreferences, pCat.getPreference(i));
        }
    } else {
        updatePrefsSummary(sharedPreferences, p);
        if (p instanceof RingtonePreference) {
            p.setOnPreferenceChangeListener(new RingToneOnPreferenceChangeListener());
            mRingtonePreference = (RingtonePreference) p;
        }
    }
}
 
開發者ID:davideas,項目名稱:AndroidBlueprints,代碼行數:20,代碼來源:PreferencesFragmentSummary.java

示例7: onSharedPreferenceChanged

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
        // we've changed the location
        // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
        SunshinePreferences.resetLocationCoordinates(activity);
        SunshineSyncUtils.startImmediateSync(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
        // units have changed. update lists of weather entries accordingly
        activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
        if (!(preference instanceof CheckBoxPreference)) {
            setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
        }
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:21,代碼來源:SettingsFragment.java

示例8: onCreatePreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();


    // Go through all of the preferences, and set up their preference summary.
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        //don't need to set up preference summaries for checkbox preferences because
        // they are already set up in xml using summaryOff and summary On
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }

    }
}
 
開發者ID:Existentio,項目名稱:OddLauncher,代碼行數:22,代碼來源:SettingsFragment.java

示例9: onPreferenceChange

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    NotificationManager manager = new NotificationManager(getContext());
    ListPreference delay = (ListPreference)findPreference("delayNotifications");
    CheckBoxPreference display = (CheckBoxPreference)findPreference("displaySilNotification");
    app.savePublicPreference(Common.GLOBAL_SETTING_ISNOTIFON, (boolean)newValue);
    if ((boolean)newValue) {
        delay.setEnabled(true);
        display.setEnabled(true);
        display.setChecked(app.getPublicPreferenceB(Common.GLOBAL_SETTING_NOTIFICATIONDISPLAY));
        manager.setRecurrentService();
    } else {
        delay.setEnabled(false);
        display.setEnabled(false);
        display.setChecked(false);
        manager.deactivateRecurrentService();
    }
    return true;
}
 
開發者ID:Onelio,項目名稱:ConnectU,代碼行數:20,代碼來源:NotificationsFragment.java

示例10: createPreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
protected void createPreferences(PreferenceScreen screen)
{
    switch (mAction) {
        case SettingsConstantsUI.ACTION_PREFS_GENERAL:
            addPreferencesFromResource(R.xml.preferences_general);

            final ListPreference theme =
                    (ListPreference) findPreference(SettingsConstantsUI.KEY_PREF_THEME);
            initializeTheme(getActivity(), theme);
            final Preference reset =
                    findPreference(SettingsConstantsUI.KEY_PREF_RESET_SETTINGS);
            initializeReset(getActivity(), reset);
            break;

        case SettingsConstantsUI.ACTION_PREFS_UPDATE:
            ApkDownloader.check(getActivity(), true);
            break;
    }
}
 
開發者ID:nextgis,項目名稱:android_nextgis_mobile,代碼行數:21,代碼來源:SettingsFragment.java

示例11: initializeTheme

import android.support.v7.preference.Preference; //導入依賴的package包/類
public static void initializeTheme(
        final Activity activity,
        final ListPreference theme)
{
    if (null != theme) {
        theme.setSummary(theme.getEntry());

        theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
        {
            @Override
            public boolean onPreferenceChange(
                    Preference preference,
                    Object newValue)
            {
                activity.startActivity(activity.getIntent());
                activity.finish();
                return true;
            }
        });
    }
}
 
開發者ID:nextgis,項目名稱:android_nextgis_mobile,代碼行數:22,代碼來源:SettingsFragment.java

示例12: onCreatePreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s) {

    // Add visualizer preferences, defined in the XML file in res->xml->pref_visualizer
    addPreferencesFromResource(R.xml.pref_visualizer);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();

    // Go through all of the preferences, and set up their preference summary.
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        // You don't need to set up preference summaries for checkbox preferences because
        // they are already set up in xml using summaryOff and summary On
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }
    // COMPLETED (3) Add the OnPreferenceChangeListener specifically to the EditTextPreference
    Preference preference = findPreference(getString(R.string.pref_size_key));
    preference.setOnPreferenceChangeListener(this);
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:25,代碼來源:SettingsFragment.java

示例13: bindPreferenceSummaryToValue

import android.support.v7.preference.Preference; //導入依賴的package包/類
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    final String key = preference.getKey();
    if (preference instanceof MultiSelectListPreference) {
        Set<String> summary = SharedPreferencesCompat.getStringSet(
                PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
                key, new HashSet<String>());
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
    } else if (preference instanceof SeekBarPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
    } else {
        String value = PreferenceManager
                .getDefaultSharedPreferences(preference.getContext())
                .getString(key, "");
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
    }
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:22,代碼來源:NotifPreferenceFragment.java

示例14: onPreferenceChange

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    Toast error = Toast.makeText(getContext(), "Please select a number between 0.1 and 3", Toast.LENGTH_SHORT);

    String sizeKey = getString(R.string.pref_size_key);
    if (preference.getKey().equals(sizeKey)) {
        String stringSize = ((String) newValue).trim();

        try {
            float size = Float.parseFloat(stringSize);
            if (size > 3 || size <= 0.1) {
                error.show();
                return false;
            }
        } catch (NumberFormatException nfe) {
            error.show();
            return false;
        }
    }
    return true;
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:22,代碼來源:SettingsFragment.java

示例15: onCreatePreferences

import android.support.v7.preference.Preference; //導入依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s) {

    // Add visualizer preferences, defined in the XML file in res->xml->pref_visualizer
    addPreferencesFromResource(R.xml.pref_visualizer);

    // COMPLETED (3) Get the preference screen, get the number of preferences and iterate through
    // all of the preferences if it is not a checkbox preference, call the setSummary method
    // passing in a preference and the value of the preference
    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    int count = preferenceScreen.getPreferenceCount();

    for (int i = 0; i < count; i++) {
        Preference pref = preferenceScreen.getPreference(i);

        if (!(pref instanceof CheckBoxPreference)) {
            setPreferenceSummary(pref, sharedPreferences.getString(pref.getKey(), ""));
        }
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:22,代碼來源:SettingsFragment.java


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