Search in sources :

Example 36 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project android by nextcloud.

the class Preferences method setupHelpPreference.

private void setupHelpPreference(PreferenceCategory preferenceCategoryMore) {
    boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
    Preference pHelp = findPreference("help");
    if (pHelp != null) {
        if (helpEnabled) {
            pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String helpWeb = getString(R.string.url_help);
                    if (helpWeb != null && helpWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(helpWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pHelp);
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) Intent(android.content.Intent) Uri(android.net.Uri)

Example 37 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project android by nextcloud.

the class Preferences method loadExternalSettingLinks.

private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
        for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) {
            // only add if it does not exist, in case activity is re-used
            if (findPreference(link.id.toString()) == null) {
                Preference p = new Preference(this);
                p.setTitle(link.name);
                p.setKey(link.id.toString());
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.name);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.url);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.id);
                        startActivity(externalWebViewIntent);
                        return true;
                    }
                });
                preferenceCategory.addPreference(p);
            }
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) ExternalLinksProvider(com.owncloud.android.datamodel.ExternalLinksProvider) Intent(android.content.Intent) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 38 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project android by nextcloud.

the class Preferences method setupRecommendPreference.

private void setupRecommendPreference(PreferenceCategory preferenceCategoryMore) {
    boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
    Preference pRecommend = findPreference("recommend");
    if (pRecommend != null) {
        if (recommendEnabled) {
            pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    String appName = getString(R.string.app_name);
                    String downloadUrlGooglePlayStore = getString(R.string.url_app_download);
                    String downloadUrlFDroid = getString(R.string.fdroid_link);
                    String downloadUrls = String.format(getString(R.string.recommend_urls), downloadUrlGooglePlayStore, downloadUrlFDroid);
                    String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
                    String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrls);
                    intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, recommendText);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pRecommend);
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) Intent(android.content.Intent)

Example 39 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project Osmand by osmandapp.

the class SettingsOsmEditingActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    ((OsmandApplication) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    getToolbar().setTitle(R.string.osm_settings);
    @SuppressWarnings("deprecation") PreferenceScreen grp = getPreferenceScreen();
    DialogPreference loginDialogPreference = new OsmLoginDataDialogPreference(this, null);
    grp.addPreference(loginDialogPreference);
    CheckBoxPreference poiEdit = createCheckBoxPreference(settings.OFFLINE_EDITION, R.string.offline_edition, R.string.offline_edition_descr);
    grp.addPreference(poiEdit);
    Preference pref = new Preference(this);
    pref.setTitle(R.string.local_openstreetmap_settings);
    pref.setSummary(R.string.local_openstreetmap_settings_descr);
    pref.setKey("local_openstreetmap_points");
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
            final Intent favorites = new Intent(SettingsOsmEditingActivity.this, appCustomization.getFavoritesActivity());
            favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            getMyApplication().getSettings().FAVORITES_TAB.set(R.string.osm_edits);
            startActivity(favorites);
            return true;
        }
    });
    grp.addPreference(pref);
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) PreferenceScreen(android.preference.PreferenceScreen) DialogPreference(android.preference.DialogPreference) CheckBoxPreference(android.preference.CheckBoxPreference) CheckBoxPreference(android.preference.CheckBoxPreference) DialogPreference(android.preference.DialogPreference) Preference(android.preference.Preference) OsmAndAppCustomization(net.osmand.plus.OsmAndAppCustomization) Intent(android.content.Intent)

Example 40 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project sentinel-android by Samourai-Wallet.

the class SettingsActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.app_name);
    addPreferencesFromResource(R.xml.settings);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    Preference aboutPref = (Preference) findPreference("about");
    aboutPref.setSummary("Sentinel," + " " + getResources().getString(R.string.version_name));
    aboutPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            new AlertDialog.Builder(SettingsActivity.this).setIcon(R.drawable.ic_launcher).setTitle(R.string.app_name).setMessage("Sentinel," + " " + getResources().getString(R.string.version_name)).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    ;
                }
            }).show();
            return true;
        }
    });
    Preference explorersPref = (Preference) findPreference("explorer");
    explorersPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            getBlockExplorer();
            return true;
        }
    });
    Preference fiatPref = (Preference) findPreference("fiat");
    fiatPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            getExchange();
            return true;
        }
    });
    final CheckBoxPreference cbPref1 = (CheckBoxPreference) findPreference("pin");
    final CheckBoxPreference cbPref2 = (CheckBoxPreference) findPreference("scramblePin");
    final CheckBoxPreference cbPref3 = (CheckBoxPreference) findPreference("haptic");
    if (!cbPref1.isChecked()) {
        cbPref2.setChecked(false);
        cbPref2.setEnabled(false);
        cbPref3.setChecked(false);
        cbPref3.setEnabled(false);
    }
    cbPref1.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (cbPref1.isChecked()) {
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.PIN_HASH, "");
                cbPref2.setChecked(false);
                cbPref2.setEnabled(false);
                cbPref3.setChecked(false);
                cbPref3.setEnabled(false);
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, false);
            } else {
                cbPref2.setEnabled(true);
                cbPref3.setEnabled(true);
                Intent intent = new Intent(SettingsActivity.this, PinEntryActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("create", true);
                startActivity(intent);
            }
            return true;
        }
    });
    cbPref2.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (cbPref2.isChecked()) {
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, false);
            } else {
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
            }
            return true;
        }
    });
    cbPref3.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (cbPref3.isChecked()) {
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.HAPTIC_PIN, false);
            } else {
                PrefsUtil.getInstance(SettingsActivity.this).setValue(PrefsUtil.HAPTIC_PIN, true);
            }
            return true;
        }
    });
    Preference exportPref = (Preference) findPreference("export");
    exportPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            AppUtil.getInstance(SettingsActivity.this).doBackup();
            return true;
        }
    });
    Preference restorePref = (Preference) findPreference("restore");
    restorePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            AppUtil.getInstance(SettingsActivity.this).doRestore();
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) AlertDialog(android.app.AlertDialog) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) DialogInterface(android.content.DialogInterface) CheckBoxPreference(android.preference.CheckBoxPreference) Intent(android.content.Intent)

Aggregations

OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)51 Preference (android.preference.Preference)50 Intent (android.content.Intent)26 ListPreference (android.preference.ListPreference)21 CheckBoxPreference (android.preference.CheckBoxPreference)15 SwitchPreference (android.preference.SwitchPreference)15 DialogInterface (android.content.DialogInterface)8 SharedPreferences (android.content.SharedPreferences)8 PreferenceCategory (android.preference.PreferenceCategory)8 PreferenceScreen (android.preference.PreferenceScreen)8 EditTextPreference (android.preference.EditTextPreference)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)7 AlertDialog (android.app.AlertDialog)6 Bundle (android.os.Bundle)6 Uri (android.net.Uri)5 View (android.view.View)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 TextView (android.widget.TextView)4 Activity (android.app.Activity)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3