Example usage for android.preference ListPreference getEntries

List of usage examples for android.preference ListPreference getEntries

Introduction

In this page you can find the example usage for android.preference ListPreference getEntries.

Prototype

public CharSequence[] getEntries() 

Source Link

Document

The list of entries to be shown in the list in subsequent dialogs.

Usage

From source file:com.schoentoon.connectbot.HostEditorActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    getSupportActionBar().setSubtitle("Host editor");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    long hostId = this.getIntent().getLongExtra(Intent.EXTRA_TITLE, -1);

    // TODO: we could pass through a specific ContentProvider uri here
    //this.getPreferenceManager().setSharedPreferencesName(uri);

    this.hostdb = new HostDatabase(this);
    this.pubkeydb = new PubkeyDatabase(this);

    host = hostdb.findHostById(hostId);/*w  w  w.  ja  v a2s . c om*/

    connection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService();

            hostBridge = bound.getConnectedBridge(host);
        }

        public void onServiceDisconnected(ComponentName name) {
            hostBridge = null;
        }
    };

    this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId);
    this.pref.registerOnSharedPreferenceChangeListener(this);

    this.addPreferencesFromResource(R.xml.host_prefs);

    // add all existing pubkeys to our listpreference for user to choose from
    // TODO: may be an issue here when this activity is recycled after adding a new pubkey
    // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once
    ListPreference pubkeyPref = (ListPreference) this.findPreference(HostDatabase.FIELD_HOST_PUBKEYID);

    List<CharSequence> pubkeyNicks = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntries()));
    pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME));
    pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()]));

    List<CharSequence> pubkeyIds = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntryValues()));
    pubkeyIds.addAll(pubkeydb.allValues("_id"));
    pubkeyPref.setEntryValues(pubkeyIds.toArray(new CharSequence[pubkeyIds.size()]));

    // Populate the character set encoding list with all available
    final ListPreference charsetPref = (ListPreference) findPreference(HostDatabase.FIELD_HOST_ENCODING);

    if (CharsetHolder.isInitialized()) {
        initCharsetPref(charsetPref);
    } else {
        String[] currentCharsetPref = new String[1];
        currentCharsetPref[0] = charsetPref.getValue();
        charsetPref.setEntryValues(currentCharsetPref);
        charsetPref.setEntries(currentCharsetPref);

        new Thread(new Runnable() {
            public void run() {
                initCharsetPref(charsetPref);
            }
        }).start();
    }

    this.updateSummaries();
}

From source file:com.vonglasow.michael.satstat.ui.SettingsActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    boolean needsLocationPerm = false;
    if (key.equals(Const.KEY_PREF_NOTIFY_FIX) || key.equals(Const.KEY_PREF_NOTIFY_SEARCH)) {
        boolean notifyFix = sharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_FIX, false);
        boolean notifySearch = sharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, false);
        if (!(notifyFix || notifySearch)) {
            Intent stopServiceIntent = new Intent(this, PasvLocListenerService.class);
            this.stopService(stopServiceIntent);
        } else if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            needsLocationPerm = true;/*from ww  w  . j  av a 2s  .c o  m*/
        }
    } else if (key.equals(Const.KEY_PREF_UPDATE_FREQ)) {
        // this piece of code is necessary because Android has no way
        // of updating the preference summary automatically. I am
        // told the absence of such functionality is a feature...
        SettingsFragment sf = (SettingsFragment) getFragmentManager().findFragmentById(android.R.id.content);
        ListPreference prefUpdateFreq = (ListPreference) sf.findPreference(Const.KEY_PREF_UPDATE_FREQ);
        final String value = sharedPreferences.getString(key, key);
        final int index = prefUpdateFreq.findIndexOfValue(value);
        if (index >= 0) {
            final String summary = (String) prefUpdateFreq.getEntries()[index];
            prefUpdateFreq.setSummary(summary);
        }
    } else if (key.equals(Const.KEY_PREF_MAP_PATH)) {
        SettingsFragment sf = (SettingsFragment) getFragmentManager().findFragmentById(android.R.id.content);
        Preference prefMapPath = sf.findPreference(Const.KEY_PREF_MAP_PATH);
        prefMapPathValue = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPathValue);
        prefMapPath.setSummary(prefMapPathValue);
    } else if (key.equals(Const.KEY_PREF_UPDATE_NETWORKS)) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Set<String> updateNetworks = sharedPreferences.getStringSet(Const.KEY_PREF_UPDATE_NETWORKS,
                    new HashSet<String>());
            if (!updateNetworks.isEmpty())
                needsLocationPerm = true;
        }
    }
    if (needsLocationPerm)
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                Const.PERM_REQUEST_LOCATION_PREF);
}

From source file:com.ichi2.anki.PreferenceContext.java

public void updateNotificationPreference(ListPreference listpref) {
    CharSequence[] entries = listpref.getEntries();
    CharSequence[] values = listpref.getEntryValues();
    for (int i = 0; i < entries.length; i++) {
        int value = Integer.parseInt(values[i].toString());
        if (entries[i].toString().contains("%d")) {
            entries[i] = String.format(entries[i].toString(), value);
        }//from   www . j  av a  2 s  .c om
    }
    listpref.setEntries(entries);
    listpref.setSummary(listpref.getEntry().toString());
}

From source file:be.deadba.ampd.SettingsActivity.java

/**
 * A preference value change listener that updates the preference's summary
 * to reflect its new value./*  w w w  . j  a  v a 2  s. com*/
 */
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    String key = preference.getKey();
    Log.d(TAG, "onPreferenceChange: key: " + key + " / value: " + stringValue);

    if (preference.isPersistent()) {
        Editor editor = MPDConf.getSharedPreferences(this).edit();
        if (value instanceof Boolean)
            editor.putBoolean(key, (Boolean) value);
        else
            editor.putString(key, (String) value);
        editor.commit();
    }
    if (key.equals("run")) {
        mRunPreference = (TwoStatePreference) preference;
        mRun = stringValue.equals("true");
        onMPDStatePreferenceChange(false);
        return true;
    }
    if (key.equals("run_on_boot")) {
        mRunOnBootPreference = (TwoStatePreference) preference;
        mRunOnBoot = stringValue.equals("true");
        if (mRunOnBoot)
            mRun = true;
        onMPDStatePreferenceChange(false);
        return true;
    } else if (key.equals("wakelock")) {
        onMPDStatePreferenceChange(true);
        return true;
    } else if (key.equals("mpd_music_directory")) {
        File file = new File(stringValue);
        mDirValid = file.exists() && file.isDirectory() && file.canRead() && file.canExecute();
        onMPDStatePreferenceChange(true);
    } else if (key.equals("mpd_port")) {
        int port = 0;
        try {
            port = Integer.parseInt(stringValue);
        } catch (NumberFormatException e) {
        }
        mPortValid = port >= 1024 && port <= 65535;
        if (mPortValid)
            mPort = String.valueOf(port);
        onMPDStatePreferenceChange(true);
    } else if (key.equals("mpd_mixer")) {
        onMPDStatePreferenceChange(true);
        return true;
    } else if (key.equals("mpd_output")) {
        onMPDStatePreferenceChange(true);
    }
    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;
}

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

private void initExportName(Preference preference, Object newValue) {
    EditTextPreference prefix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue));
    String prefixValue = "";
    if (prefix != null) {
        if (preference != null && prefix.getKey().equals(preference.getKey())) {
            prefixValue = newValue.toString();
        } else {// w ww .ja  va2s . c o m
            prefixValue = prefix.getText();
        }

        if (!prefixValue.equals("")) {
            prefixValue = prefixValue + "_";
        }
    }

    EditTextPreference postfix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue));
    String postfixValue = "";
    if (postfix != null) {
        if (preference != null && postfix.getKey().equals(preference.getKey())) {
            postfixValue = newValue.toString();
        } else {
            postfixValue = postfix.getText();
        }

        if (!postfixValue.equals("")) {
            postfixValue = "_" + postfixValue;
        }
    }

    ListPreference exportNameList = (ListPreference) this
            .findPreference(getResources().getString(R.string.Preference_ExportNameValue));
    if (exportNameList != null) {
        String[] names = MainScreen.getAppResources().getStringArray(R.array.exportNameArray);
        CharSequence[] newNames = new CharSequence[names.length];
        int i = 0;
        for (String name : names) {
            newNames[i] = prefixValue + name + postfixValue;
            i++;
        }
        exportNameList.setEntries(newNames);
        exportNameList.setSummary(exportNameList.getEntries()[Integer.parseInt(exportNameList.getValue()) - 1]);
    }
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    thiz = this;//from   w w  w.  ja v  a  2  s.c  o m

    String settings = getArguments().getString("type");

    ApplicationScreen.getPluginManager().loadHeaderContent(settings, this);

    if (null == getPreferenceScreen())
        return;
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        initSummary(getPreferenceScreen().getPreference(i));
    }

    Preference nightPreference = findPreference("night");
    if (nightPreference != null) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (prefs.getBoolean("useCamera2Pref", false)) {
            getPreferenceScreen().removePreference(nightPreference);
        } else {
            Preference superPreference = findPreference("super");
            getPreferenceScreen().removePreference(superPreference);
        }
    }

    final SeekBarPreference brightnessPref = (SeekBarPreference) this.findPreference("brightnessPref");
    if (brightnessPref != null) {
        // Set seekbar summary :
        float gamma = PreferenceManager.getDefaultSharedPreferences(getActivity()).getFloat("gammaPref", 0.5f);
        brightnessPref.setSummary(
                this.getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma));
        brightnessPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            private final Map<Integer, Float> gamma_map = new HashMap<Integer, Float>() {
                {
                    put(0, 0.5f);
                    put(1, 0.55f);
                    put(2, 0.6f);
                    put(3, 0.65f);
                    put(4, 0.7f);
                }
            };

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                int radius = (Integer) newValue;
                float gamma = gamma_map.get(radius);
                PreferenceManager
                        .getDefaultSharedPreferences(Fragment.thiz.getActivity().getApplicationContext()).edit()
                        .putFloat("gammaPref", gamma).commit();
                brightnessPref.setSummary(getActivity()
                        .getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma));
                return true;
            }
        });
    }

    final CheckBoxPreference upscalePref = (CheckBoxPreference) this.findPreference("upscaleResult");
    if (upscalePref != null) {
        Size size = CameraController.getMaxCameraImageSize(CameraController.YUV);
        long resMpx = 0;
        float mpix = 0.0f;
        if (size != null) {
            resMpx = (long) ((long) size.getWidth() * (long) size.getHeight() * 2.25);
            mpix = (float) resMpx / 1000000.f;
        }

        String name = String.format("%3.1f Mpix ", mpix);

        upscalePref.setSummary(
                getActivity().getString(R.string.Pref_Super_SummaryUpscale).replace("$1", "" + name));
    }

    Preference cameraParameters = findPreference("camera_parameters");
    if (cameraParameters != null) {
        cameraParameters.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                try {
                    showCameraParameters();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                return true;
            }
        });
    }

    CheckBoxPreference helpPref = (CheckBoxPreference) findPreference("showHelpPrefCommon");
    if (helpPref != null)
        helpPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (((CheckBoxPreference) preference).isChecked()) {
                    SharedPreferences prefs = PreferenceManager
                            .getDefaultSharedPreferences(MainScreen.getMainContext());
                    Editor prefsEditor = prefs.edit();
                    prefsEditor.putBoolean("droShowHelp", true);
                    prefsEditor.putBoolean("sequenceRemovalShowHelp", true);
                    prefsEditor.putBoolean("panoramaShowHelp", true);
                    prefsEditor.putBoolean("superShowHelp", true);
                    prefsEditor.putBoolean("groupshotRemovalShowHelp", true);
                    prefsEditor.putBoolean("objectRemovalShowHelp", true);
                    prefsEditor.putBoolean("bestShotShowHelp", true);
                    prefsEditor.commit();
                }

                return true;
            }
        });

    EditTextPreference prefix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue));
    EditTextPreference postfix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue));
    initExportName(null, null);

    if (prefix != null) {
        prefix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                initExportName(preference, newValue);
                return true;
            }
        });
    }

    if (postfix != null) {
        postfix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                initExportName(preference, newValue);
                return true;
            }
        });
    }

    Preference sonyPreference = findPreference(MainScreen.sSonyCamerasPref);
    if (sonyPreference != null) {
        sonyPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean sonyCamerasAvailable = (Boolean) newValue;
                if (sonyCamerasAvailable) {
                    Toast.makeText(getActivity(),
                            getActivity().getString(R.string.pref_general_more_sonyCamera_available),
                            Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });
    }

    ListPreference saveToPreference = (ListPreference) this
            .findPreference(getResources().getString(R.string.Preference_SaveToValue));

    // if android 5+, then remove "save to SD card" option. Because it's
    // equals to "save to custom folder" option.
    if (saveToPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CharSequence[] entries = saveToPreference.getEntries();
        CharSequence[] entriyValues = saveToPreference.getEntryValues();

        CharSequence[] newEntries = new String[2];
        CharSequence[] newEntriyValues = new String[2];

        newEntries[0] = entries[0];
        newEntries[1] = entries[2];
        newEntriyValues[0] = entriyValues[0];
        newEntriyValues[1] = entriyValues[2];

        saveToPreference.setEntries(newEntries);
        saveToPreference.setEntryValues(newEntriyValues);
    }
    if (saveToPreference != null) {

        saveToPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                int v = -1;

                int v_old = 0;

                try {
                    v = Integer.parseInt(newValue.toString());
                    v_old = Integer.parseInt(((ListPreference) preference).getValue());
                } catch (NumberFormatException e) {

                }

                if ((v == 2 || v == 1) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                        Toast.makeText(MainScreen.getInstance(),
                                MainScreen.getAppResources()
                                        .getString(R.string.pref_advanced_saving_saveToPref_CantSaveToSD),
                                Toast.LENGTH_LONG).show();

                        if (isDeviceRooted()) {
                            Intent intent = new Intent(Preferences.thiz, FolderPicker.class);

                            intent.putExtra(MainScreen.sSavePathPref, v_old);

                            Preferences.thiz.startActivity(intent);

                            return true;
                        } else
                            return false;
                    }
                }

                if (v == 2 || v == 1) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                        startActivityForResult(intent, CHOOSE_FOLDER_CODE);
                    } else if (v != 1) {
                        Intent intent = new Intent(Preferences.thiz, FolderPicker.class);

                        intent.putExtra(MainScreen.sSavePathPref, v_old);

                        Preferences.thiz.startActivity(intent);
                    }
                }

                return true;
            }
        });
    }

    PreferenceCategory cat = (PreferenceCategory) this.findPreference("Pref_VFCommon_Preference_Category");
    if (cat != null) {
        CheckBoxPreference cp = (CheckBoxPreference) cat.findPreference("maxScreenBrightnessPref");
        if (cp != null) {
            cp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean value = Boolean.parseBoolean(newValue.toString());
                    setScreenBrightness(value);
                    return true;
                }
            });
        }
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    boolean MaxScreenBrightnessPreference = prefs.getBoolean("maxScreenBrightnessPref", false);
    setScreenBrightness(MaxScreenBrightnessPreference);
}

From source file:fr.pasteque.client.Configure.java

private void updateCardProcessorPreferences(String newValue) {
    if (newValue == null) {
        newValue = Configure.getCardProcessor(this);
    }// www.ja  v a  2  s.c om

    ListPreference card_processor = (ListPreference) this.findPreference("card_processor");

    EditTextPreference atos_address = (EditTextPreference) this.findPreference("worldline_address");
    EditTextPreference xengo_userid = (EditTextPreference) this.findPreference("xengo_userid");
    EditTextPreference xengo_password = (EditTextPreference) this.findPreference("xengo_password");
    EditTextPreference xengo_terminalid = (EditTextPreference) this.findPreference("xengo_terminalid");

    atos_address.setEnabled("atos_classic".equals(newValue));
    xengo_userid.setEnabled("atos_xengo".equals(newValue));
    xengo_password.setEnabled("atos_xengo".equals(newValue));
    xengo_terminalid.setEnabled("atos_xengo".equals(newValue));

    card_processor.setSummary(newValue);
    int i = 0;
    for (CharSequence entry : card_processor.getEntryValues()) {
        if (newValue.equals(entry)) {
            card_processor.setSummary(card_processor.getEntries()[i]);
        }
        i++;
    }
}

From source file:com.cesarsk.say_it.ui.fragments.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    // Use an activity context to get the rewarded video instance.
    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity());
    mRewardedVideoAd.setRewardedVideoAdListener(this);

    loadRewardedVideoAd();//from  ww w. j a v a 2s .c o m

    PackageInfo pInfo = null;
    try {
        pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    String version = pInfo.versionName;
    final Preference app_version = getPreferenceManager().findPreference("app_version");
    app_version.setSummary("Version: " + version + " (Click for Privacy Policy)");

    final Context context = getActivity();

    if (context instanceof Callback) {
        mCallback = (Callback) context;
    } else {
        throw new IllegalStateException("Owner must implement URLCallback interface");
    }

    // add listeners for non-default actions
    Preference preference = findPreference(KEY_1);
    preference.setOnPreferenceClickListener(this);

    Preference open_source_licenses = findPreference(KEY_2);
    open_source_licenses.setOnPreferenceClickListener(this);

    Preference rate_us = getPreferenceManager().findPreference("rate_us");
    rate_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            rateUs(getActivity());
            return false;
        }
    });

    Preference contact_us = getPreferenceManager().findPreference("contact_us");
    contact_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity());
            return false;
        }
    });

    Preference bug_report = getPreferenceManager().findPreference("bug_report");
    bug_report.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity());
            return false;
        }
    });

    Preference donate_ad = getPreferenceManager().findPreference("donation_ad");
    donate_ad.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            //Launch AD
            if (mRewardedVideoAd.isLoaded()) {
                mRewardedVideoAd.show();
            }
            return false;
        }
    });

    final Preference about_us = getPreferenceManager().findPreference("about_us");
    about_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/07/18/about-us/");
            return false;
        }
    });

    final Preference eula = getPreferenceManager().findPreference("eula");
    eula.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Utility.openURL(getActivity(),
                    "https://lucacesaranoblog.wordpress.com/2017/04/28/say-it-eula-agreement/");
            return false;
        }
    });

    /*final Preference github = getPreferenceManager().findPreference("github");
    github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        Utility.openURL(getActivity(), "https://github.com/Cesarsk/Say_it");
        return false;
    }
    });*/

    final Preference other_apps = getPreferenceManager().findPreference("other_apps");
    other_apps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Utility.openURL(getActivity(), "https://play.google.com/store/apps/developer?id=Cesarsk+Dev+Team");
            return false;
        }
    });

    final Preference voice_settings = getPreferenceManager().findPreference("tts_settings");
    voice_settings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent();
            intent.setAction("com.android.settings.TTS_SETTINGS");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return false;
        }
    });

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(getActivity(), LCSecurity.base64EncodedPublicKey);
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh no, there was a problem.
                if (MainActivity.isLoggingEnabled)
                    Log.d("Say It!", "Problem setting up In-app Billing: " + result);
            }
            // Hooray, IAB is fully set up!
            if (MainActivity.isLoggingEnabled)
                Log.d("Say It!", "Hooray. IAB is fully set up!" + result);
        }
    });

    mIabPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        @Override
        public void onIabPurchaseFinished(IabResult result, Purchase info) {
            if (result.isFailure()) {
                Toast.makeText(getActivity(), "Purchase Failed! Perhaps have you already purchased the item?",
                        Toast.LENGTH_SHORT).show();
            } else if (info.getSku().equals(PlayActivity.no_ads_in_app)) {
                UtilitySharedPrefs.loadAdsStatus(getActivity());
                UtilitySharedPrefs.savePrefs(getActivity(), true, MainActivity.NO_ADS_STATUS_KEY);
            }
        }
    };

    mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            if (result.isFailure()) {
                if (MainActivity.isLoggingEnabled)
                    Toast.makeText(getActivity(), "Query Failed!", Toast.LENGTH_SHORT).show();
                return;
            }

            //Open Purchase Dialog
            try {
                mHelper.flagEndAsync();
                mHelper.launchPurchaseFlow(getActivity(), PlayActivity.no_ads_in_app, 64000,
                        mIabPurchaseFinishedListener);
            } catch (IabHelper.IabAsyncInProgressException e) {
                e.printStackTrace();
            }
        }
    };

    final Preference remove_ads = getPreferenceManager().findPreference("remove_ads");
    if (MainActivity.NO_ADS) {
        remove_ads.setEnabled(false);
        remove_ads.setSummary("Thank you for supporting us ?");
    } else {
        remove_ads.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                //helper to remove ads
                List<String> additionalSkuList = new ArrayList<>();
                additionalSkuList.add(PlayActivity.no_ads_in_app);
                try {
                    mHelper.flagEndAsync();
                    mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
                } catch (IabHelper.IabAsyncInProgressException e) {
                    e.printStackTrace();
                }
                return false;
            }
        });
    }

    final Preference reset_tutorial = getPreferenceManager().findPreference("reset_showcase");
    reset_tutorial.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Random rand = new Random();
            int randomNum = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min
            MainActivity.id_showcase_playactivity = "" + randomNum;
            Toast.makeText(getActivity(), "Tutorial has been reset", Toast.LENGTH_SHORT).show();
            //MainActivity.id_showcase_fragments = "" + randomNum2;
            //int randomNum2 = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min //These two statements are commented because MaterialShowCase often crashes on fragments and while pressing the back button.
            return false;
        }
    });

    //setting an own Alert Dialog's title color
    final Spannable title = new SpannableString("Delete Recordings");
    title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, title.length(), 0);
    final Spannable message = new SpannableString("Are you sure you want to delete all recordings?");
    message.setSpan(new ForegroundColorSpan(Color.GRAY), 0, message.length(), 0);

    final Preference delete_recordings = getPreferenceManager().findPreference("delete_recordings");
    delete_recordings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Utility.delete_recordings(getActivity());
                            Toast.makeText(getActivity(), "Recordings deleted!", Toast.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            //do nothing
                        }
                    }).show();
            return true;
        }
    });

    final ListPreference button_vibration = (ListPreference) getPreferenceManager()
            .findPreference("button_vibration");
    button_vibration.setSummary(button_vibration.getEntry());
    final Spannable default_vibration_settings_title = new SpannableString("Vibration Settings");
    default_vibration_settings_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0,
            default_vibration_settings_title.length(), 0);
    button_vibration.setDialogTitle(default_vibration_settings_title);

    button_vibration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String new_value = newValue.toString();
            index_default_vibration = button_vibration.findIndexOfValue(new_value);
            CharSequence[] entries = button_vibration.getEntries();
            UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_VIBRATION_KEY);
            button_vibration
                    .setSummary(button_vibration.getEntries()[button_vibration.findIndexOfValue(new_value)]);
            Toast.makeText(getActivity(), String.valueOf(entries[index_default_vibration]), Toast.LENGTH_SHORT)
                    .show();
            UtilitySharedPrefs.loadSettingsPrefs(context);
            return true;
        }
    });

    final ListPreference default_accent = (ListPreference) getPreferenceManager()
            .findPreference("default_accent");
    default_accent.setSummary(default_accent.getEntry());
    final Spannable default_accent_title = new SpannableString("Default Accent");
    default_accent_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_accent_title.length(), 0);
    default_accent.setDialogTitle(default_accent_title);

    default_accent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String new_value = newValue.toString();
            index_default_accent = default_accent.findIndexOfValue(new_value);
            CharSequence[] entries = default_accent.getEntries();

            UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_ACCENT_KEY);
            default_accent.setSummary(default_accent.getEntries()[default_accent.findIndexOfValue(new_value)]);
            //Toast.makeText(getActivity(), String.valueOf(entries[index_default_accent]), Toast.LENGTH_SHORT).show();
            UtilitySharedPrefs.loadSettingsPrefs(context);
            return true;
        }
    });

    final ListPreference theme_selector = (ListPreference) getPreferenceManager()
            .findPreference("theme_selector");
    final Spannable theme_selector_title = new SpannableString("Theme");
    theme_selector_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, theme_selector_title.length(), 0);
    theme_selector.setDialogTitle(theme_selector_title);

    theme_selector.setSummary(theme_selector.getEntry());

    theme_selector.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String new_value = newValue.toString();
            index_default_theme = theme_selector.findIndexOfValue(new_value);
            CharSequence[] entries = theme_selector.getEntries();
            UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_THEME_KEY);
            theme_selector.setSummary(theme_selector.getEntries()[theme_selector.findIndexOfValue(new_value)]);
            //Toast.makeText(getActivity(), String.valueOf(entries[index_default_theme]), Toast.LENGTH_SHORT).show();
            UtilitySharedPrefs.loadSettingsPrefs(context);
            Toast.makeText(getActivity(), "Done! Reboot to see changes.", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    Preference acknowledgements = getPreferenceManager().findPreference("acknowledgements");
    acknowledgements.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            final Intent preference_intent = new Intent(getActivity(), FileTextActivity.class);
            Bundle args = new Bundle();
            args.putString(FileTextActivity.PREFERENCE, "acknowledgements");
            preference_intent.putExtras(args);
            startActivity(preference_intent,
                    ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
            return false;
        }
    });

    app_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/18/privacy-policy/");
            return false;
        }
    });
}