Search in sources :

Example 61 with PreferenceCategory

use of android.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class ChooseLockGeneric method disableUnusablePreferences.

/**
 * Disables preferences that are less secure than required quality.
 *
 * @param quality the requested quality.
 */
private void disableUnusablePreferences(final int quality) {
    final Preference picker = getPreferenceScreen().findPreference("security_picker_category");
    final PreferenceCategory cat = (PreferenceCategory) picker;
    final int preferenceCount = cat.getPreferenceCount();
    for (int i = 0; i < preferenceCount; i++) {
        Preference pref = cat.getPreference(i);
        if (pref instanceof PreferenceScreen) {
            final String key = ((PreferenceScreen) pref).getKey();
            boolean enabled = true;
            if (KEY_UNLOCK_SET_NONE.equals(key)) {
                enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
            } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) {
                enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
            } else if (KEY_UNLOCK_SET_PIN.equals(key)) {
                enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
            } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) {
                enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
            }
            if (!enabled) {
                pref.setSummary(R.string.unlock_set_unlock_disabled_summary);
                pref.setEnabled(false);
            }
        }
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory)

Example 62 with PreferenceCategory

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

the class ContributorsActivity method onPostCreate.

@SuppressWarnings("deprecation")
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.contributors_prefs);
    PreferenceCategory coders = (PreferenceCategory) findPreference("coders");
    PreferenceCategory designers = (PreferenceCategory) findPreference("designers");
    PreferenceCategory libraries = (PreferenceCategory) findPreference("libraries");
    PreferenceCategory translators = (PreferenceCategory) findPreference("translators");
    Field[] fields = R.array.class.getFields();
    Resources res = getResources();
    for (Field f : fields) {
        String fName = f.getName();
        if (fName.startsWith("contributor_") || fName.startsWith("translator_") || fName.startsWith("library_") || fName.startsWith("designer_")) {
            try {
                int arrayId = (Integer) f.get(null);
                String[] contributor = res.getStringArray(arrayId);
                if (contributor.length != 3)
                    continue;
                String name = contributor[0];
                String type = contributor[1];
                String link = contributor[2];
                Preference preference = new Preference(this);
                preference.setTitle(name);
                preference.setSummary(getSummaryHelpfulText(type, link));
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(link));
                preference.setIntent(intent);
                if ("CODER".equals(type)) {
                    coders.addPreference(preference);
                } else if ("TRANSLATOR".equals(type)) {
                    translators.addPreference(preference);
                } else if ("LIBRARY".equals(type)) {
                    libraries.addPreference(preference);
                } else if ("DESIGNER".equals(type)) {
                    designers.addPreference(preference);
                } else if ("BITCHING".equals(preference)) {
                    throw new RuntimeException("GermainZ asked for this");
                }
            } catch (IndexOutOfBoundsException e) {
            // Doesn't deserve to be added
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Intent(android.content.Intent) Field(java.lang.reflect.Field) R(com.mohammadag.colouredstatusbar.R) PreferenceCategory(android.preference.PreferenceCategory) Preference(android.preference.Preference) Resources(android.content.res.Resources)

Example 63 with PreferenceCategory

use of android.preference.PreferenceCategory in project Conversations by siacs.

the class SettingsActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    changeOmemoSettingSummary();
    if (QuickConversationsService.isQuicksy()) {
        final PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
        final PreferenceCategory groupChats = (PreferenceCategory) mSettingsFragment.findPreference("group_chats");
        final Preference channelDiscoveryMethod = mSettingsFragment.findPreference("channel_discovery_method");
        PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
        if (connectionOptions != null) {
            expert.removePreference(connectionOptions);
        }
        if (groupChats != null && channelDiscoveryMethod != null) {
            groupChats.removePreference(channelDiscoveryMethod);
        }
    }
    PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
    PreferenceCategory attachmentsCategory = (PreferenceCategory) mSettingsFragment.findPreference("attachments");
    CheckBoxPreference locationPlugin = (CheckBoxPreference) mSettingsFragment.findPreference("use_share_location_plugin");
    if (attachmentsCategory != null && locationPlugin != null) {
        if (!GeoHelper.isLocationPluginInstalled(this)) {
            attachmentsCategory.removePreference(locationPlugin);
        }
    }
    // this feature is only available on Huawei Android 6.
    PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
    if (huaweiPreferenceScreen != null) {
        Intent intent = huaweiPreferenceScreen.getIntent();
        // remove when Api version is above M (Version 6.0) or if the intent is not callable
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
            PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
            generalCategory.removePreference(huaweiPreferenceScreen);
            if (generalCategory.getPreferenceCount() == 0) {
                if (mainPreferenceScreen != null) {
                    mainPreferenceScreen.removePreference(generalCategory);
                }
            }
        }
    }
    ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
    if (automaticMessageDeletionList != null) {
        final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values);
        CharSequence[] entries = new CharSequence[choices.length];
        CharSequence[] entryValues = new CharSequence[choices.length];
        for (int i = 0; i < choices.length; ++i) {
            entryValues[i] = String.valueOf(choices[i]);
            if (choices[i] == 0) {
                entries[i] = getString(R.string.never);
            } else {
                entries[i] = TimeFrameUtils.resolve(this, 1000L * choices[i]);
            }
        }
        automaticMessageDeletionList.setEntries(entries);
        automaticMessageDeletionList.setEntryValues(entryValues);
    }
    boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null;
    boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null;
    ListPreference quickAction = (ListPreference) mSettingsFragment.findPreference("quick_action");
    if (quickAction != null && (removeLocation || removeVoice)) {
        ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(quickAction.getEntries()));
        ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(quickAction.getEntryValues()));
        int index = entryValues.indexOf("location");
        if (index > 0 && removeLocation) {
            entries.remove(index);
            entryValues.remove(index);
        }
        index = entryValues.indexOf("voice");
        if (index > 0 && removeVoice) {
            entries.remove(index);
            entryValues.remove(index);
        }
        quickAction.setEntries(entries.toArray(new CharSequence[entries.size()]));
        quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
    }
    final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
    if (removeCertsPreference != null) {
        removeCertsPreference.setOnPreferenceClickListener(preference -> {
            final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
            final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
            if (aliases.size() == 0) {
                displayToast(getString(R.string.toast_no_trusted_certs));
                return true;
            }
            final ArrayList<Integer> selectedItems = new ArrayList<>();
            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
            dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
            dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, (dialog, indexSelected, isChecked) -> {
                if (isChecked) {
                    selectedItems.add(indexSelected);
                } else if (selectedItems.contains(indexSelected)) {
                    selectedItems.remove(Integer.valueOf(indexSelected));
                }
                ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(selectedItems.size() > 0);
            });
            dialogBuilder.setPositiveButton(getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> {
                int count = selectedItems.size();
                if (count > 0) {
                    for (int i = 0; i < count; i++) {
                        try {
                            Integer item = Integer.valueOf(selectedItems.get(i).toString());
                            String alias = aliases.get(item);
                            mtm.deleteCertificate(alias);
                        } catch (KeyStoreException e) {
                            e.printStackTrace();
                            displayToast("Error: " + e.getLocalizedMessage());
                        }
                    }
                    if (xmppConnectionServiceBound) {
                        reconnectAccounts();
                    }
                    displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
                }
            });
            dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
            AlertDialog removeCertsDialog = dialogBuilder.create();
            removeCertsDialog.show();
            removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            return true;
        });
    }
    final Preference createBackupPreference = mSettingsFragment.findPreference("create_backup");
    if (createBackupPreference != null) {
        createBackupPreference.setSummary(getString(R.string.pref_create_backup_summary, FileBackend.getBackupDirectory(this)));
        createBackupPreference.setOnPreferenceClickListener(preference -> {
            if (hasStoragePermission(REQUEST_CREATE_BACKUP)) {
                createBackup();
            }
            return true;
        });
    }
    if (Config.ONLY_INTERNAL_STORAGE) {
        final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
        if (cleanCachePreference != null) {
            cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
        }
        final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
        if (cleanPrivateStoragePreference != null) {
            cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage());
        }
    }
    final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
    if (deleteOmemoPreference != null) {
        deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities());
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) KeyStoreException(java.security.KeyStoreException) MemorizingTrustManager(eu.siacs.conversations.services.MemorizingTrustManager) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Example 64 with PreferenceCategory

use of android.preference.PreferenceCategory in project routerkeygenAndroid by routerkeygen.

the class Preferences method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    findPreference("download").setOnPreferenceClickListener(preference -> fetchDictionary());
    boolean app_installed = AdsUtils.checkDonation(this);
    final PreferenceCategory mCategory = (PreferenceCategory) findPreference("2section");
    if (!app_installed) {
        mCategory.removePreference(findPreference("analytics_enabled"));
        // If you haven't the donate app installed remove the paypal donate
        // link.
        mCategory.removePreference(findPreference("donate_paypal"));
        findPreference("donate_playstore").setOnPreferenceClickListener(preference -> {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GOOGLE_PLAY_DOWNLOADER)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + GOOGLE_PLAY_DOWNLOADER)));
            }
            Toast.makeText(getApplicationContext(), R.string.msg_donation, Toast.LENGTH_LONG).show();
            return true;
        });
    } else {
        // If you have the donate app installed no need to link to it.
        mCategory.removePreference(findPreference("donate_playstore"));
        if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) {
            // Play Store is quite restrictive nowadays
            mCategory.removePreference(findPreference("donate_paypal"));
        } else {
            findPreference("donate_paypal").setOnPreferenceClickListener(preference -> {
                final String donateLink = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V3FFBTRTTV5DN";
                Uri uri = Uri.parse(donateLink);
                startActivity(new Intent(Intent.ACTION_VIEW, uri));
                return true;
            });
        }
    }
    if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) {
        mCategory.removePreference(findPreference("update"));
    } else {
        findPreference("update").setOnPreferenceClickListener(preference -> {
            AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

                protected void onPreExecute() {
                    showDialog(DIALOG_WAIT);
                }

                protected Void doInBackground(Void... params) {
                    lastVersion = UpdateCheckerService.getLatestVersion();
                    return null;
                }

                protected void onPostExecute(Void result) {
                    removeDialog(DIALOG_WAIT);
                    if (isFinishing())
                        return;
                    if (lastVersion == null) {
                        showDialog(DIALOG_ERROR);
                        return;
                    }
                    if (!Preferences.VERSION.equals(lastVersion.version)) {
                        showDialog(DIALOG_UPDATE_NEEDED);
                    } else {
                        Toast.makeText(Preferences.this, R.string.msg_app_updated, Toast.LENGTH_SHORT).show();
                    }
                }
            };
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            // Checking for updates every week
            startService(new Intent(getApplicationContext(), UpdateCheckerService.class));
            return true;
        });
    }
    findPreference("changelog").setOnPreferenceClickListener(preference -> {
        showDialog(DIALOG_CHANGELOG);
        return true;
    });
    findPreference("about").setOnPreferenceClickListener(preference -> {
        showDialog(DIALOG_ABOUT);
        return true;
    });
    findPreference(dicLocalPref).setOnPreferenceClickListener(preference -> {
        startActivityForResult(new Intent(getApplicationContext(), FileChooserActivity.class), 0);
        return true;
    });
    final CheckBoxPreference autoScan = (CheckBoxPreference) findPreference("autoScan");
    autoScan.setOnPreferenceClickListener(preference -> {
        findPreference("autoScanInterval").setEnabled(autoScan.isChecked());
        return true;
    });
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    findPreference("autoScanInterval").setEnabled(prefs.getBoolean(Preferences.autoScanPref, getResources().getBoolean(R.bool.autoScanDefault)));
}
Also used : UpdateCheckerService(org.exobel.routerkeygen.UpdateCheckerService) CheckBoxPreference(android.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) Uri(android.net.Uri) PreferenceCategory(android.preference.PreferenceCategory) FileChooserActivity(com.ipaulpro.afilechooser.FileChooserActivity)

Example 65 with PreferenceCategory

use of android.preference.PreferenceCategory in project AndroidChromium by JackyAndroid.

the class SavePasswordsPreferences method passwordListAvailable.

@Override
public void passwordListAvailable(int count) {
    resetList(PREF_CATEGORY_SAVED_PASSWORDS);
    mNoPasswords = count == 0;
    if (mNoPasswords) {
        if (mNoPasswordExceptions)
            displayEmptyScreenMessage();
        return;
    }
    displayManageAccountLink();
    PreferenceCategory profileCategory = new PreferenceCategory(getActivity());
    profileCategory.setKey(PREF_CATEGORY_SAVED_PASSWORDS);
    profileCategory.setTitle(R.string.section_saved_passwords);
    profileCategory.setOrder(ORDER_SAVED_PASSWORDS);
    getPreferenceScreen().addPreference(profileCategory);
    for (int i = 0; i < count; i++) {
        PasswordUIView.SavedPasswordEntry saved = mPasswordManagerHandler.getSavedPasswordEntry(i);
        PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
        String url = saved.getUrl();
        String name = saved.getUserName();
        screen.setTitle(url);
        screen.setOnPreferenceClickListener(this);
        screen.setSummary(name);
        Bundle args = screen.getExtras();
        args.putString(PASSWORD_LIST_NAME, name);
        args.putString(PASSWORD_LIST_URL, url);
        args.putInt(PASSWORD_LIST_ID, i);
        profileCategory.addPreference(screen);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory) Bundle(android.os.Bundle) PasswordUIView(org.chromium.chrome.browser.PasswordUIView) SpannableString(android.text.SpannableString)

Aggregations

PreferenceCategory (android.preference.PreferenceCategory)80 Preference (android.preference.Preference)49 PreferenceScreen (android.preference.PreferenceScreen)31 ListPreference (android.preference.ListPreference)30 CheckBoxPreference (android.preference.CheckBoxPreference)26 Intent (android.content.Intent)19 EditTextPreference (android.preference.EditTextPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 SwitchPreference (android.preference.SwitchPreference)8 ArrayList (java.util.ArrayList)7 Uri (android.net.Uri)6 Bundle (android.os.Bundle)5 SharedPreferences (android.content.SharedPreferences)4 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)4 View (android.view.View)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 Context (android.content.Context)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 RingtonePreference (android.preference.RingtonePreference)3 ListView (android.widget.ListView)3