Search in sources :

Example 91 with Preference

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

the class SettingsActivity method setDynamicListPreferenceSummary.

private void setDynamicListPreferenceSummary(ListPreference preference) {
    // set the summary to be whatever the value is, and change it if
    // necessary
    CharSequence entryValue = preference.getValue();
    int idx = Arrays.asList(preference.getEntryValues()).indexOf(entryValue);
    CharSequence entry = preference.getEntries()[idx];
    preference.setSummary(entry);
    preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            CharSequence entryValue = (CharSequence) newValue;
            int idx = Arrays.asList(((ListPreference) preference).getEntryValues()).indexOf(entryValue);
            CharSequence entry = ((ListPreference) preference).getEntries()[idx];
            preference.setSummary(entry);
            PreferenceHelper.resetCache();
            return true;
        }
    });
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) ListPreference(android.preference.ListPreference)

Example 92 with Preference

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

the class SettingsActivity method getPreferenceCategoryPosition.

@SuppressWarnings("deprecation")
private int getPreferenceCategoryPosition(int titleId) {
    PreferenceScreen screen = getPreferenceScreen();
    String titleToFind = getString(titleId);
    for (int i = 0; i < screen.getPreferenceCount(); i++) {
        Preference preference = screen.getPreference(i);
        if (!(preference instanceof PreferenceCategory)) {
            continue;
        }
        if (titleToFind.equals(((PreferenceCategory) preference).getTitle())) {
            return i;
        }
    }
    return -1;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory)

Example 93 with Preference

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

the class SettingsActivity method setDynamicSummary.

private void setDynamicSummary(EditTextPreference editTextPreference) {
    // set the summary to be whatever the value is, and change it if
    // necessary
    editTextPreference.setSummary(editTextPreference.getText());
    editTextPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!IntegerUtil.validInt(newValue.toString()) || Integer.parseInt(newValue.toString()) == 0) {
                ToastHelper.showLong(SettingsActivity.this, R.string.toast_no_zeroes);
                return false;
            }
            preference.setSummary((CharSequence) newValue);
            PreferenceHelper.resetCache();
            return true;
        }
    });
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 94 with Preference

use of android.preference.Preference in project Pokemap by omkarmoghe.

the class SettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    // Create Theme button to link to Theme Fragment
    Preference button = (Preference) getPreferenceManager().findPreference(getString(R.string.pref_theme_button_key));
    if (button != null) {
        button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(getActivity(), ThemeActivity.class);
                startActivity(intent);
                return true;
            }
        });
    }
}
Also used : Preference(android.preference.Preference) Intent(android.content.Intent)

Example 95 with Preference

use of android.preference.Preference in project android by owncloud.

the class Preferences method onCreate.

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.actionbar_settings);
    // For adding content description tag to a title field in the action bar
    int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
    if (actionBarTitleView != null) {
        // it's null in Android 2.x
        getWindow().getDecorView().findViewById(actionBarTitleId).setContentDescription(getString(R.string.actionbar_settings));
    }
    // Load package info
    String temp;
    try {
        PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
        temp = pkg.versionName;
    } catch (NameNotFoundException e) {
        temp = "";
        Log_OC.e(TAG, "Error while showing about dialog", e);
    }
    final String appVersion = temp;
    // Register context menu for list of preferences.
    registerForContextMenu(getListView());
    pCode = (CheckBoxPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
    if (pCode != null) {
        pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
                Boolean incoming = (Boolean) newValue;
                i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : PassCodeActivity.ACTION_CHECK_WITH_RESULT);
                startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);
                // Don't update just yet, we will decide on it in onActivityResult
                return false;
            }
        });
    }
    PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
    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 = (String) getText(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 {
            preferenceCategory.removePreference(pHelp);
        }
    }
    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_SENDTO);
                    intent.setType("text/plain");
                    intent.setData(Uri.parse(getString(R.string.mail_recommend)));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    String appName = getString(R.string.app_name);
                    String downloadUrl = getString(R.string.url_app_download);
                    String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
                    String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl);
                    intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, recommendText);
                    startActivity(intent);
                    return (true);
                }
            });
        } else {
            preferenceCategory.removePreference(pRecommend);
        }
    }
    boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
    Preference pFeedback = findPreference("feedback");
    if (pFeedback != null) {
        if (feedbackEnabled) {
            pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String feedbackMail = (String) getText(R.string.mail_feedback);
                    String feedback = (String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
                    intent.setData(Uri.parse(feedbackMail));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pFeedback);
        }
    }
    boolean privacyPolicyEnabled = getResources().getBoolean(R.bool.privacy_policy_enabled);
    Preference pPrivacyPolicy = findPreference("privacyPolicy");
    if (pPrivacyPolicy != null) {
        if (privacyPolicyEnabled) {
            pPrivacyPolicy.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent privacyPolicyIntent = new Intent(getApplicationContext(), PrivacyPolicyActivity.class);
                    startActivity(privacyPolicyIntent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pPrivacyPolicy);
        }
    }
    boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG;
    Preference pLogger = findPreference("logger");
    if (pLogger != null) {
        if (loggerEnabled) {
            pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
                    startActivity(loggerIntent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pLogger);
        }
    }
    boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
    Preference pImprint = findPreference("imprint");
    if (pImprint != null) {
        if (imprintEnabled) {
            pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String imprintWeb = (String) getText(R.string.url_imprint);
                    if (imprintWeb != null && imprintWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(imprintWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pImprint);
        }
    }
    mPrefInstantUploadPath = findPreference("instant_upload_path");
    if (mPrefInstantUploadPath != null) {
        mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
                    mUploadPath += OCFile.PATH_SEPARATOR;
                }
                Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
                startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
                return true;
            }
        });
    }
    mPrefInstantUploadCategory = (PreferenceCategory) findPreference("instant_uploading_category");
    mPrefInstantUploadWiFi = findPreference("instant_upload_on_wifi");
    mPrefInstantUpload = findPreference("instant_uploading");
    toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
    mPrefInstantUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean enableInstantPicture = (Boolean) newValue;
            toggleInstantPictureOptions(enableInstantPicture);
            toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), enableInstantPicture);
            return true;
        }
    });
    mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
    if (mPrefInstantVideoUploadPath != null) {
        mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
                    mUploadVideoPath += OCFile.PATH_SEPARATOR;
                }
                Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
                startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
                return true;
            }
        });
    }
    mPrefInstantVideoUploadWiFi = findPreference("instant_video_upload_on_wifi");
    mPrefInstantVideoUpload = findPreference("instant_video_uploading");
    toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
    mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            toggleInstantVideoOptions((Boolean) newValue);
            toggleInstantUploadCommonOptions((Boolean) newValue, ((CheckBoxPreference) mPrefInstantUpload).isChecked());
            return true;
        }
    });
    mPrefInstantUploadSourcePath = findPreference("instant_upload_source_path");
    if (mPrefInstantUploadSourcePath != null) {
        mPrefInstantUploadSourcePath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mSourcePath.endsWith(File.separator)) {
                    mSourcePath += File.separator;
                }
                LocalFolderPickerActivity.startLocalFolderPickerActivityForResult(Preferences.this, mSourcePath, ACTION_SELECT_SOURCE_PATH);
                return true;
            }
        });
    } else {
        Log_OC.e(TAG, "Lost preference instant_upload_source_path");
    }
    mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour");
    toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), ((CheckBoxPreference) mPrefInstantUpload).isChecked());
    /* About App */
    pAboutApp = (Preference) findPreference("about_app");
    if (pAboutApp != null) {
        pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
        pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
    }
    loadInstantUploadPath();
    loadInstantUploadVideoPath();
    loadInstantUploadSourcePath();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) CheckBoxPreference(android.preference.CheckBoxPreference) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View) Uri(android.net.Uri) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ActionBar(android.support.v7.app.ActionBar)

Aggregations

Preference (android.preference.Preference)173 CheckBoxPreference (android.preference.CheckBoxPreference)50 ListPreference (android.preference.ListPreference)49 PreferenceScreen (android.preference.PreferenceScreen)36 Intent (android.content.Intent)32 EditTextPreference (android.preference.EditTextPreference)26 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 PreferenceCategory (android.preference.PreferenceCategory)23 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)21 SharedPreferences (android.content.SharedPreferences)19 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)16 Test (org.junit.Test)15 PreferenceGroup (android.preference.PreferenceGroup)13 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 SwitchPreference (android.preference.SwitchPreference)10 View (android.view.View)10 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)10