Example usage for android.preference PreferenceFragment findPreference

List of usage examples for android.preference PreferenceFragment findPreference

Introduction

In this page you can find the example usage for android.preference PreferenceFragment findPreference.

Prototype

public Preference findPreference(CharSequence key) 

Source Link

Document

Finds a Preference based on its key.

Usage

From source file:Main.java

/**
 * Gets a preference and sets the {@link android.preference.Preference.OnPreferenceChangeListener}.
 *//*  ww w  .j  a  va 2 s .  com*/
public static Preference getPrefAndSetClickListener(PreferenceFragment prefFrag, int id,
        Preference.OnPreferenceClickListener listener) {
    Preference pref = prefFrag.findPreference(prefFrag.getString(id));
    if (pref != null)
        pref.setOnPreferenceClickListener(listener);
    return pref;
}

From source file:Main.java

/**
 * Gets a preference and sets the {@link android.preference.Preference.OnPreferenceChangeListener}.
 *//* ww  w.  ja  va2  s . c om*/
public static Preference getPrefAndSetChangeListener(PreferenceFragment prefFrag, int id,
        Preference.OnPreferenceChangeListener listener) {
    Preference pref = prefFrag.findPreference(prefFrag.getString(id));
    if (pref != null)
        pref.setOnPreferenceChangeListener(listener);
    return pref;
}

From source file:Main.java

/**
 * Removes a {@link Preference} from the {@link PreferenceCategory} with the given key.
 */// w  w w .j av a 2 s .c  o  m
public static void removePreference(PreferenceFragment prefFrag, int parentKey, int prefKey) {
    String parentName = prefFrag.getString(parentKey);
    String prefName = prefFrag.getString(prefKey);
    PreferenceGroup parent = (PreferenceGroup) prefFrag.findPreference(parentName);
    Preference child = prefFrag.findPreference(prefName);

    if (parent != null && child != null) {
        parent.removePreference(child);
    }
}

From source file:com.quarterfull.newsAndroid.SettingsActivity.java

private static void bindNotificationPreferences(PreferenceFragment prefFrag, PreferenceActivity prefAct) {
    if (prefFrag != null) {
        bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SHOW_NOTIFICATION_NEW_ARTICLES_STRING));
    } else {//  w  ww.ja  v a  2s.  c  o m
        bindPreferenceBooleanToValue(prefAct.findPreference(CB_SHOW_NOTIFICATION_NEW_ARTICLES_STRING));
    }
}

From source file:com.quarterfull.newsAndroid.SettingsActivity.java

@SuppressWarnings("deprecation")
private static void bindDisplayPreferences(PreferenceFragment prefFrag, PreferenceActivity prefAct) {
    if (prefFrag != null) {
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_APP_THEME));
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_FEED_LIST_LAYOUT));
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_TITLE_LINES_COUNT));
    } else {/*from  ww  w .j  av  a  2s.com*/
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_APP_THEME));
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_FEED_LIST_LAYOUT));
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_TITLE_LINES_COUNT));
    }
}

From source file:de.luhmer.owncloudnewsreader.SettingsActivity.java

@SuppressWarnings("deprecation")
private static void bindDataSyncPreferences(PreferenceFragment prefFrag, PreferenceActivity prefAct) {
    String[] authorities = { "de.luhmer.owncloudnewsreader" };
    Intent intentSyncSettings = new Intent(Settings.ACTION_SYNC_SETTINGS);
    intentSyncSettings.putExtra(Settings.EXTRA_AUTHORITIES, authorities);

    if (prefFrag != null) {
        prefFrag.findPreference(PREF_SYNC_SETTINGS).setIntent(intentSyncSettings);
        //bindPreferenceSummaryToValue(prefFrag.findPreference(SP_MAX_ITEMS_SYNC));
        clearCachePref = (EditTextPreference) prefFrag.findPreference(EDT_CLEAR_CACHE);
        bindPreferenceSummaryToValue(prefFrag.findPreference(LV_CACHE_IMAGES_OFFLINE_STRING));
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_MAX_CACHE_SIZE));
    } else {//from w  ww .j  a  va 2  s  .  co  m
        prefAct.findPreference(PREF_SYNC_SETTINGS).setIntent(intentSyncSettings);
        //bindPreferenceSummaryToValue(prefAct.findPreference(SP_MAX_ITEMS_SYNC));
        clearCachePref = (EditTextPreference) prefAct.findPreference(EDT_CLEAR_CACHE);
        bindPreferenceSummaryToValue(prefAct.findPreference(LV_CACHE_IMAGES_OFFLINE_STRING));
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_MAX_CACHE_SIZE));

    }

    clearCachePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {

            ((EditTextPreference) preference).getDialog().dismiss();

            checkForUnsycedChangesInDatabaseAndResetDatabase(_mActivity);
            return false;
        }
    });
}

From source file:com.quarterfull.newsAndroid.SettingsActivity.java

@SuppressWarnings("deprecation")
private static void bindDataSyncPreferences(PreferenceFragment prefFrag, PreferenceActivity prefAct) {
    String[] authorities = { "com.quarterfull.newsAndroid" };
    Intent intentSyncSettings = new Intent(Settings.ACTION_SYNC_SETTINGS);
    intentSyncSettings.putExtra(Settings.EXTRA_AUTHORITIES, authorities);

    if (prefFrag != null) {
        prefFrag.findPreference(PREF_SYNC_SETTINGS).setIntent(intentSyncSettings);
        //bindPreferenceSummaryToValue(prefFrag.findPreference(SP_MAX_ITEMS_SYNC));
        clearCachePref = (EditTextPreference) prefFrag.findPreference(EDT_CLEAR_CACHE);
        bindPreferenceSummaryToValue(prefFrag.findPreference(LV_CACHE_IMAGES_OFFLINE_STRING));
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_MAX_CACHE_SIZE));
    } else {/*from ww w.  ja v  a2  s  .co m*/
        prefAct.findPreference(PREF_SYNC_SETTINGS).setIntent(intentSyncSettings);
        //bindPreferenceSummaryToValue(prefAct.findPreference(SP_MAX_ITEMS_SYNC));
        clearCachePref = (EditTextPreference) prefAct.findPreference(EDT_CLEAR_CACHE);
        bindPreferenceSummaryToValue(prefAct.findPreference(LV_CACHE_IMAGES_OFFLINE_STRING));
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_MAX_CACHE_SIZE));

    }

    clearCachePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {

            ((EditTextPreference) preference).getDialog().dismiss();

            checkForUnsycedChangesInDatabaseAndResetDatabase(_mActivity);
            return false;
        }
    });
}

From source file:com.quarterfull.newsAndroid.SettingsActivity.java

@SuppressWarnings("deprecation")
private static void bindGeneralPreferences(PreferenceFragment prefFrag, final PreferenceActivity prefAct) {
    if (prefFrag != null) {
        /*// www  . j  av  a2  s . c  o m
        bindPreferenceSummaryToValue(prefFrag.findPreference(EDT_USERNAME_STRING));
        bindPreferenceSummaryToValue(prefFrag.findPreference(EDT_PASSWORD_STRING));
        bindPreferenceSummaryToValue(prefFrag.findPreference(EDT_OWNCLOUDROOTPATH_STRING));
         */
        //bindPreferenceBooleanToValue(prefFrag.findPreference(CB_ALLOWALLSSLCERTIFICATES_STRING));
        bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SYNCONSTARTUP_STRING));
        bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SHOWONLYUNREAD_STRING));
        bindPreferenceBooleanToValue(prefFrag.findPreference(CB_NAVIGATE_WITH_VOLUME_BUTTONS_STRING));
        bindPreferenceBooleanToValue(prefFrag.findPreference(CB_MARK_AS_READ_WHILE_SCROLLING_STRING));
        bindPreferenceBooleanToValue(
                prefFrag.findPreference(CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING));
        bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SORT_ORDER));
    } else {
        /*
        bindPreferenceSummaryToValue(prefAct.findPreference(EDT_USERNAME_STRING));
        bindPreferenceSummaryToValue(prefAct.findPreference(EDT_PASSWORD_STRING));
        bindPreferenceSummaryToValue(prefAct.findPreference(EDT_OWNCLOUDROOTPATH_STRING));
        */
        //bindPreferenceBooleanToValue(prefAct.findPreference(CB_ALLOWALLSSLCERTIFICATES_STRING));
        bindPreferenceBooleanToValue(prefAct.findPreference(CB_SYNCONSTARTUP_STRING));
        bindPreferenceBooleanToValue(prefAct.findPreference(CB_SHOWONLYUNREAD_STRING));
        bindPreferenceBooleanToValue(prefAct.findPreference(CB_NAVIGATE_WITH_VOLUME_BUTTONS_STRING));
        bindPreferenceBooleanToValue(prefAct.findPreference(CB_MARK_AS_READ_WHILE_SCROLLING_STRING));
        bindPreferenceBooleanToValue(
                prefAct.findPreference(CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING));
        bindPreferenceSummaryToValue(prefAct.findPreference(SP_SORT_ORDER));
    }
}

From source file:com.almalence.opencam.PluginManager.java

@Override
public void loadHeaderContent(String settings, PreferenceFragment pf) {
    List<Plugin> activePlugins = new ArrayList<Plugin>();
    List<Plugin> inactivePlugins = new ArrayList<Plugin>();

    boolean hasInactive = false;

    loadStandardSettingsBefore(pf, settings);
    if ("general_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_more);
        ApplicationScreen.instance.onAdvancePreferenceCreate(pf);
    } else if ("general_image_size".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_image_size);
        if (CameraController.isUseCamera2()) {
            Preference pref;//from   w ww . j a v a2s .  c om
            if (null != (pref = pf.findPreference(ApplicationScreen.sImageSizeMultishotBackPref))
                    || null != (pref = pf.findPreference(ApplicationScreen.sImageSizeMultishotFrontPref))) {
                pref.setTitle(ApplicationScreen.getAppResources()
                        .getString(R.string.Pref_Comon_SmartMultishot_And_Super_ImageSize_Title));
            }
        }
        ApplicationScreen.instance.onPreferenceCreate(pf);
    } else if ("vf_settings".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_vf_common);
    } else if ("vf_more".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (activeVF.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, activePlugins, false);

        pf.addPreferencesFromResource(R.xml.preferences_vf_more);

        if (activePlugins.size() != listVF.size() && isPreferenecesAvailable(inactivePlugins, false))
            pf.addPreferencesFromResource(R.xml.preferences_vf_inactive);

        ApplicationScreen.instance.onAdvancePreferenceCreate(pf); //Some vf advance preferences may be related to entire application instead of some special vf plugin
    } else if ("vf_inactive_settings".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (!activeVF.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, false);
    } else if ("save_configuration".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_saveconfiguration);
    } else if ("export_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_export_common);
    } else if ("export_timestamp".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_export_timestamp);
    } else if ("shooting_settings".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_modes);
    } else if ("capture_expobracketing_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_expobracketing_more);
    } else if ("processing_expobracketing_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_processing_hdr_more);
    } else if ("capture_night_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_night_more);
    } else if ("processing_night_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_processing_night_more);
        if (CameraController.isUseCamera2()) {
            PreferenceScreen prefScr;
            if (null != (prefScr = (PreferenceScreen) pf.findPreference("nightProcessingMoreScreen"))) {
                Preference pref;
                if (null != (pref = pf.findPreference("keepcolorsPref"))) {
                    prefScr.removePreference(pref);
                }
            }
        }
    } else if ("capture_preshot_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_preshot_more);
    } else if ("capture_panorama_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_panoramaaugmented_more);
        Plugin panoramaPlugin = pluginList.get(activeCapture);
        panoramaPlugin.onPreferenceCreate(pf);
    } else if ("dro".equals(settings)) {
        AddModeSettings("single", pf);
    } else if ("burst".equals(settings)) {
        AddModeSettings("burstmode", pf);
    } else if ("expobracketing".equals(settings)) {
        AddModeSettings("expobracketing", pf);
    } else if ("hdr".equals(settings)) {
        AddModeSettings("hdrmode", pf);
    } else if ("night".equals(settings)) {
        AddModeSettings("nightmode", pf);
    } else if ("super".equals(settings)) {
        AddModeSettings("super", pf);
    } else if ("video".equals(settings)) {
        AddModeSettings("video", pf);
    } else if ("preshot".equals(settings)) {
        AddModeSettings("pixfix", pf);
    } else if ("multishot".equals(settings)) {
        AddModeSettings("multishot", pf);
    } else if ("panorama_augmented".equals(settings)) {
        AddModeSettings("panorama_augmented", pf);
    } else if ("bestshotmode".equals(settings)) {
        AddModeSettings("bestshotmode", pf);
    } else if ("saving_settings".equals(settings)) {
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (activeFilter.contains(pg.getID()))
        // activePlugins.add(pg);
        // else
        // inactivePlugins.add(pg);
        // }
        // if (activePlugins.size() != listFilter.size() &&
        // isPreferenecesAvailable(inactivePlugins, false))
        // hasInactive = true;
        addHeadersContent(pf, activePlugins, false);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (activeExport.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (activePlugins.size() != listExport.size() && isPreferenecesAvailable(inactivePlugins, false))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, false);

        if (hasInactive)
            pf.addPreferencesFromResource(R.xml.preferences_saving_inactive);
    } else if ("saving_inactive_settings".equals(settings)) {
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (!activeFilter.contains(pg.getID()))
        // inactivePlugins.add(pg);
        // }
        addHeadersContent(pf, inactivePlugins, false);

        activePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (!activeExport.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, false);
    } else if ("advanced".equals(settings)) {
        loadCommonAdvancedSettings(pf);

        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (activeVF.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listCapture.size(); i++) {
            Plugin pg = listCapture.get(i);
            if (activeCapture.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listProcessing.size(); i++) {
            Plugin pg = listProcessing.get(i);
            if (activeProcessing.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (activeFilter.contains(pg.getID()))
        // activePlugins.add(pg);
        // else
        // inactivePlugins.add(pg);
        // }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (activeExport.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        if (hasInactive)
            pf.addPreferencesFromResource(R.xml.preferences_advance_inactive);
    } else if ("advanced_inactive".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (!activeVF.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listCapture.size(); i++) {
            Plugin pg = listCapture.get(i);
            if (!activeCapture.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listProcessing.size(); i++) {
            Plugin pg = listProcessing.get(i);
            if (!activeProcessing.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (!activeFilter.contains(pg.getID()))
        // inactivePlugins.add(pg);
        // }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (!activeExport.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);
    } else if ("plugins_settings".equals(settings)) {
        pf.getActivity().finish();
        Preferences.closePrefs();
        MainScreen.setShowStore(true);
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

@Override
public void onPreferenceCreate(PreferenceFragment pf) {
    if (pf != null && !ApplicationScreen.getCameraController().isVideoStabilizationSupported()) {
        PreferenceCategory cat = (PreferenceCategory) pf.findPreference("Pref_VideoCapture_Category");
        CheckBoxPreference cp = (CheckBoxPreference) pf.findPreference("videoStabilizationPref");
        if (cp != null && cat != null)
            cat.removePreference(cp);/*from  w ww  .ja  v  a2 s.com*/
    }

}