Search in sources :

Example 1 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project Xposed-Tinted-Status-Bar by MohammadAG.

the class SettingsActivity method onPostCreate.

@SuppressWarnings({ "deprecation" })
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
    addPreferencesFromResource(R.xml.pref_general);
    Preference copyrightPreference = findPreference("copyright_key");
    copyrightPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this);
            builder.setTitle("").setItems(R.array.my_apps, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    Uri uri = null;
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    switch(which) {
                        case 0:
                            uri = Uri.parse(URL_MY_APPS);
                            intent.setPackage("com.android.vending");
                            break;
                        case 1:
                            uri = Uri.parse(URL_MY_MODULES);
                            break;
                        case 2:
                            uri = Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KGGZ5C3AVC8ZU");
                            break;
                    }
                    startActivity(intent.setData(uri));
                }
            });
            builder.create().show();
            return false;
        }
    });
    Preference donatePreference = findPreference("donate_key");
    donatePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(URL_DONATION_PACKAGE));
            intent.setPackage("com.android.vending");
            startActivity(intent);
            return false;
        }
    });
    if (Utils.isDonateVersionInstalled(getApplicationContext())) {
        copyrightPreference.setTitle(R.string.app_name_donate_version);
        donatePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Toast.makeText(SettingsActivity.this, R.string.thank_you, Toast.LENGTH_SHORT).show();
                return false;
            }
        });
        donatePreference.setTitle(R.string.thank_you);
        donatePreference.setSummary(R.string.thank_you_summary);
    }
    String[] colorKeys = { SettingsKeys.DEFAULT_STATUS_BAR_TINT, SettingsKeys.DEFAULT_STATUS_BAR_ICON_TINT, SettingsKeys.DEFAULT_STATUS_BAR_INVERTED_ICON_TINT, SettingsKeys.DEFAULT_NAV_BAR_TINT, SettingsKeys.DEFAULT_NAV_BAR_ICON_TINT, SettingsKeys.DEFAULT_NAV_BAR_IM_TINT, SettingsKeys.DEFAULT_NAV_BAR_ICON_IM_TINT };
    intializeColorPreferences(colorKeys);
    findPreference(SettingsKeys.LINK_PANEL_VIEW_COLORS).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            sendBroadcast(new Intent(Common.INTENT_SETTINGS_UPDATED));
            return true;
        }
    });
    ListPreference overlayTypePreference = (ListPreference) findPreference("pref_overlay_type");
    final Preference overlayTransparencyPreference = findPreference("pref_semi_transparent_overlay_opacity");
    if (overlayTypePreference.getValue().equals("semi_transparent"))
        overlayTransparencyPreference.setEnabled(true);
    overlayTypePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.equals("semi_transparent"))
                overlayTransparencyPreference.setEnabled(true);
            else
                overlayTransparencyPreference.setEnabled(false);
            return true;
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) ListPreference(android.preference.ListPreference) Uri(android.net.Uri) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) ColorPreference(com.mohammadag.colouredstatusbar.preferences.ColorPreference) Preference(android.preference.Preference)

Example 2 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project KeepScore by nolanlawson.

the class SettingsActivity method setUpPreferences.

private void setUpPreferences() {
    plusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_plus_button);
    minusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_minus_button);
    button1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_1);
    button2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_2);
    button3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_3);
    button4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_4);
    twoPlayerButton1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_1);
    twoPlayerButton2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_2);
    twoPlayerButton3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_3);
    twoPlayerButton4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_4);
    greenTextPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_green_text);
    showRoundTotalsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_round_totals);
    showInitialMessagePref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_initial_message);
    disableHighlightTagPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_disable_highlight_tag);
    showColorsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_colors);
    updateDelayPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_update_delay);
    initialScorePref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_initial_score);
    resetPref = findPreferenceById(R.string.CONSTANT_pref_reset);
    aboutPref = findPreferenceById(R.string.CONSTANT_pref_about);
    colorSchemePref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_color_scheme);
    orientationPref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_orientation);
    loadSettingsPref = findPreferenceById(R.string.CONSTANT_pref_load_settings);
    saveSettingsPref = findPreferenceById(R.string.CONSTANT_pref_save_settings);
    // changed
    for (EditTextPreference pref : new EditTextPreference[] { button1Pref, button2Pref, button3Pref, button4Pref, twoPlayerButton1Pref, twoPlayerButton2Pref, twoPlayerButton3Pref, twoPlayerButton4Pref, plusButtonPref, minusButtonPref }) {
        setDynamicSummary(pref);
    }
    // do a special check for the update delay value
    updateDelayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!IntegerUtil.validInt(newValue.toString()) || Integer.parseInt(newValue.toString()) < 1 || Integer.parseInt(newValue.toString()) > 600) {
                ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_update_delay_values);
                return false;
            }
            PreferenceHelper.resetCache();
            return true;
        }
    });
    // do another special check for the initial score value
    initialScorePref.setSummary(initialScorePref.getText());
    initialScorePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!IntegerUtil.validInt(newValue.toString())) {
                ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_initial_score);
                return false;
            }
            preference.setSummary(newValue.toString());
            return true;
        }
    });
    // show the version number in the "about" summary text
    String version = String.format(getString(R.string.text_version_number), PackageHelper.getVersionName(this));
    aboutPref.setSummary(version);
    // do a special popup for the reset preference
    resetPref.setOnPreferenceClickListener(this);
    loadSettingsPref.setOnPreferenceClickListener(this);
    saveSettingsPref.setOnPreferenceClickListener(this);
    setDynamicListPreferenceSummary(colorSchemePref);
    setDynamicListPreferenceSummary(orientationPref);
    // go to the about activity if the about pref is pressed
    aboutPref.setOnPreferenceClickListener(this);
    greenTextPref.setOnPreferenceChangeListener(this);
    showRoundTotalsPref.setOnPreferenceChangeListener(this);
    disableHighlightTagPref.setOnPreferenceChangeListener(this);
    showInitialMessagePref.setOnPreferenceChangeListener(this);
    showColorsPref.setOnPreferenceChangeListener(this);
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) EditTextPreference(android.preference.EditTextPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 3 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project android-sms-relay by nyaruka.

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View title = getWindow().findViewById(android.R.id.title);
    title.setPadding(5, 0, 0, 0);
    addPreferencesFromResource(R.xml.preferences);
    // Add a listener for relay password
    Preference relayPassword = (Preference) findPreference("relay_password");
    relayPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String password = newValue.toString();
            Log.d(TAG, "New password " + password);
            return true;
        }
    });
    Preference prefNetwork = (Preference) findPreference("pref_net");
    prefNetwork.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.d(TAG, "Your preferred network has been changed to: " + newValue);
            return true;
        }
    });
    // Add a listener for our clear button, with a confirmation
    Preference clearMessages = (Preference) findPreference("clear_messages");
    clearMessages.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            // show a confirmation dialog
            new AlertDialog.Builder(SettingsActivity.this).setTitle("WARNING").setMessage("This will remove all messages, including ones not yet sent to the server or mobile phones.\n\nThis operation cannot be undone.").setPositiveButton("Reset", new OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    AndroidRelay.clearMessages(SettingsActivity.this);
                    Toast.makeText(SettingsActivity.this, "Messages cleared", Toast.LENGTH_LONG).show();
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
            return true;
        }
    });
    Preference sendLog = (Preference) findPreference("send_log");
    sendLog.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            RelayService.doSendLog = true;
            WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(1), getApplicationContext());
            Toast.makeText(SettingsActivity.this, "Log will be sent shortly.", Toast.LENGTH_LONG).show();
            return true;
        }
    });
    Preference updateInterval = (Preference) findPreference("update_interval");
    updateInterval.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(Long.parseLong(newValue.toString())), SettingsActivity.this);
            Log.d(TAG, "Rescheduling alarms based on new update_interval value: " + newValue);
            return true;
        }
    });
    Preference setRapidHost = (Preference) findPreference("router_hostname");
    setRapidHost.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String hostname = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String backend = prefs.getString("router_backend", "android");
            String password = prefs.getString("router_password", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
    Preference setRapidBackend = (Preference) findPreference("router_backend");
    setRapidBackend.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String backend = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String hostname = prefs.getString("router_hostname", null);
            String password = prefs.getString("router_password", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
    Preference setRapidPassword = (Preference) findPreference("router_password");
    setRapidPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String password = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String backend = prefs.getString("router_backend", "android");
            String hostname = prefs.getString("router_hostname", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference) DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) OnClickListener(android.content.DialogInterface.OnClickListener) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View)

Example 4 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project android-garage-opener by bradfitz.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(Preferences.NAME);
    addPreferencesFromResource(R.xml.preferences);
    ssidPref = (EditTextPreference) findPreference(Preferences.KEY_SSID);
    urlPref = (EditTextPreference) findPreference(Preferences.KEY_URL);
    secretPref = (EditTextPreference) findPreference(Preferences.KEY_SECRET);
    OnPreferenceChangeListener onChange = new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String key = preference.getKey();
            Log.v(TAG, "preference change for: " + key);
            // yes, persist it.
            return true;
        }
    };
//ssidPref.setOnPreferenceChangeListener(onChange);
//urlPref.setOnPreferenceChangeListener(onChange);
//secretPref.setOnPreferenceChangeListener(onChange);
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 5 with OnPreferenceChangeListener

use of android.preference.Preference.OnPreferenceChangeListener in project AndroidSDK-RecipeBook by gabu.

the class MyPreferenceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref);
    mContext = this;
    Resources r = getResources();
    mInputPasswordKey = r.getString(R.string.input_password_key);
    mRealPasswordKey = r.getString(R.string.real_password_key);
    // パスワード入力用のプリファレンスを取得
    Preference password = findPreference(mInputPasswordKey);
    // 変更を検知するリスナーをセット
    password.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // 本来のパスワードには空文字をセット
            ((EditTextPreference) preference).setText("");
            // SharedPreferencesを取得
            SharedPreferences sp;
            sp = PreferenceManager.getDefaultSharedPreferences(mContext);
            // 編集のためEditorを取得
            Editor editor = sp.edit();
            // key: real_password_key
            // value: SHA-1値
            // newValueに入力された値が入っています。
            editor.putString(mRealPasswordKey, sha256(newValue.toString()));
            // 保存
            editor.commit();
            return false;
        }
    });
}
Also used : EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) SharedPreferences(android.content.SharedPreferences) Resources(android.content.res.Resources) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Editor(android.content.SharedPreferences.Editor)

Aggregations

Preference (android.preference.Preference)23 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)10 CheckBoxPreference (android.preference.CheckBoxPreference)7 EditTextPreference (android.preference.EditTextPreference)7 SharedPreferences (android.content.SharedPreferences)6 ListPreference (android.preference.ListPreference)6 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)6 ManagedPreferenceDelegate (org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate)6 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 AlertDialog (android.app.AlertDialog)2 Intent (android.content.Intent)2 Editor (android.content.SharedPreferences.Editor)2 Resources (android.content.res.Resources)2 Uri (android.net.Uri)2 Map (java.util.Map)2 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)2 ChromeBaseCheckBoxPreference (org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference)2 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)2