Search in sources :

Example 6 with EditTextPreference

use of androidx.preference.EditTextPreference in project android_packages_apps_Settings by omnirom.

the class ApnEditorTest method setMockPreference.

private void setMockPreference(Context context) {
    mApnEditorUT.mName = new EditTextPreference(context);
    mApnEditorUT.mApn = new EditTextPreference(context);
    mApnEditorUT.mProxy = new EditTextPreference(context);
    mApnEditorUT.mPort = new EditTextPreference(context);
    mApnEditorUT.mUser = new EditTextPreference(context);
    mApnEditorUT.mServer = new EditTextPreference(context);
    mApnEditorUT.mPassword = new EditTextPreference(context);
    mApnEditorUT.mMmsc = new EditTextPreference(context);
    mApnEditorUT.mMcc = new EditTextPreference(context);
    mApnEditorUT.mMnc = new EditTextPreference(context);
    mApnEditorUT.mMmsProxy = new EditTextPreference(context);
    mApnEditorUT.mMmsPort = new EditTextPreference(context);
    mApnEditorUT.mAuthType = new ListPreference(context);
    mApnEditorUT.mApnType = new EditTextPreference(context);
    mApnEditorUT.mProtocol = new ListPreference(context);
    mApnEditorUT.mRoamingProtocol = new ListPreference(context);
    mApnEditorUT.mCarrierEnabled = new SwitchPreference(context);
    mApnEditorUT.mBearerMulti = new MultiSelectListPreference(context);
    mApnEditorUT.mMvnoType = new ListPreference(context);
    mApnEditorUT.mMvnoMatchData = new EditTextPreference(context);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) MultiSelectListPreference(androidx.preference.MultiSelectListPreference) EditTextPreference(androidx.preference.EditTextPreference) MultiSelectListPreference(androidx.preference.MultiSelectListPreference) ListPreference(androidx.preference.ListPreference)

Example 7 with EditTextPreference

use of androidx.preference.EditTextPreference in project twicalico by moko256.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    setPreferencesFromResource(R.xml.settings, rootKey);
    if (rootKey == null) {
        AccountsModel accountsModel = GlobalApplicationKt.getAccountsModel(requireActivity());
        List<AccessToken> accessTokens = accountsModel.getAccessTokens();
        CharSequence[] entriesAccountList = new CharSequence[accessTokens.size() + 1];
        CharSequence[] entryValues = new CharSequence[accessTokens.size() + 1];
        for (int i = 0; i < accessTokens.size(); i++) {
            AccessToken accessToken = accessTokens.get(i);
            entriesAccountList[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entryValues[i] = accessToken.getKeyString();
        }
        entriesAccountList[entriesAccountList.length - 1] = getString(R.string.login_with_another_account);
        entryValues[entryValues.length - 1] = "-1";
        ListPreference nowAccountList = findPreference(KEY_ACCOUNT_KEY);
        nowAccountList.setEntries(entriesAccountList);
        nowAccountList.setEntryValues(entryValues);
        nowAccountList.setDefaultValue(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1"));
        nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
            if (newValue.equals("-1")) {
                startActivityForResult(new Intent(getContext(), OAuthActivity.class), REQUEST_OAUTH_OR_CANCEL);
                return false;
            } else {
                AccessToken accessToken = GlobalApplicationKt.getAccountsModel(requireActivity()).get((String) newValue);
                ((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
                startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                return true;
            }
        });
        List<AccessToken> accessTokensTwitter = accountsModel.getAccessTokensByType(CLIENT_TYPE_TWITTER);
        CharSequence[] entriesLinkOpen = new CharSequence[accessTokensTwitter.size() + 1];
        CharSequence[] entriesLinkOpenValue = new CharSequence[accessTokensTwitter.size() + 1];
        for (int i = 0; i < accessTokensTwitter.size(); i++) {
            AccessToken accessToken = accessTokensTwitter.get(i);
            entriesLinkOpen[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entriesLinkOpenValue[i] = accessToken.getKeyString();
        }
        entriesLinkOpen[entriesLinkOpen.length - 1] = getString(R.string.not_set);
        entriesLinkOpenValue[entriesLinkOpenValue.length - 1] = "-1";
        ListPreference linkOpenAccountList = findPreference(KEY_ACCOUNT_KEY_LINK_OPEN);
        linkOpenAccountList.setEntries(entriesLinkOpen);
        linkOpenAccountList.setEntryValues(entriesLinkOpenValue);
        linkOpenAccountList.setDefaultValue("-1");
        findPreference("logout").setOnPreferenceClickListener(preference -> {
            new AlertDialog.Builder(requireContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
                accountsModel.delete(accountsModel.get(GlobalApplicationKt.preferenceRepository.getString(KEY_ACCOUNT_KEY, "-1")));
                int point = accountsModel.size() - 1;
                if (point != -1) {
                    AccessToken accessToken = accountsModel.getAccessTokens().get(point);
                    GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, accessToken.getKeyString());
                    ((GlobalApplication) requireActivity().getApplication()).initCurrentClient(accessToken);
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    GlobalApplicationKt.preferenceRepository.putString(KEY_ACCOUNT_KEY, "-1");
                    ((GlobalApplication) requireActivity().getApplication()).clearCurrentClient();
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
            return false;
        });
        ListPreference nowThemeMode = findPreference(KEY_NIGHT_MODE);
        nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
            AppCompatDelegate.setDefaultNightMode(ThemePreferenceConverterKt.convertToAppCompatNightThemeMode(String.valueOf(newValue)));
            ((AppCompatActivity) requireActivity()).getDelegate().applyDayNight();
            return true;
        });
        Preference licenseThisApp = findPreference("license_at_this_app");
        licenseThisApp.setOnPreferenceClickListener(preference -> {
            requireContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twitlatte"));
            return true;
        });
        Preference sourceCodeLink = findPreference("source_code_link");
        sourceCodeLink.setOnPreferenceClickListener(preference -> {
            AppCustomTabsKt.launchChromeCustomTabs(requireContext(), "https://github.com/moko256/twitlatte", false);
            return true;
        });
        Preference version = findPreference("app_version");
        version.setSummary(BuildConfig.VERSION_NAME);
        version.setOnPreferenceClickListener(preference -> {
            eggCount--;
            if (eggCount <= 0) {
                startActivity(new Intent(getActivity(), AboutActivity.class));
                eggCount = 3;
            }
            return true;
        });
    } else if (rootKey.equals("regexMute")) {
        PreferenceScreen regexMute = getPreferenceScreen();
        for (int i = 0, length = regexMute.getPreferenceCount(); i < length; i++) {
            Preference name = regexMute.getPreference(i);
            if (name instanceof EditTextPreference) {
                name.setOnPreferenceChangeListener((preference, newValue) -> {
                    try {
                        GlobalApplicationKt.preferenceRepository.updateRegex(preference.getKey(), (String) newValue);
                    } catch (PatternSyntaxException e) {
                        e.printStackTrace();
                        Toast.makeText(requireContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                    return true;
                });
            }
        }
    } else if (rootKey.equals("license")) {
        PreferenceScreen license = getPreferenceScreen();
        for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
            license.getPreference(i).setOnPreferenceClickListener(preference -> {
                startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
                preference.getKey().substring(12)));
                return true;
            });
        }
    } else if (rootKey.equals("contributors")) {
        PreferenceScreen contributorCategory = getPreferenceScreen();
        for (int c = 0, length = contributorCategory.getPreferenceCount(); c < length; c++) {
            PreferenceCategory contributor = (PreferenceCategory) contributorCategory.getPreference(c);
            for (int i = 0, l = contributor.getPreferenceCount(); i < l; i++) {
                Preference name = contributor.getPreference(i);
                String uri = "https://github.com/" + name.getKey();
                name.setSummary(uri);
                name.setOnPreferenceClickListener(preference -> {
                    AppCustomTabsKt.launchChromeCustomTabs(requireContext(), uri, false);
                    return true;
                });
            }
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ThemePreferenceConverterKt(com.github.moko256.twitlatte.text.ThemePreferenceConverterKt) KEY_ACCOUNT_KEY_LINK_OPEN(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_ACCOUNT_KEY_LINK_OPEN) RESULT_OK(android.app.Activity.RESULT_OK) PreferenceCategory(androidx.preference.PreferenceCategory) AccountsModel(com.github.moko256.twitlatte.model.AccountsModel) Intent(android.content.Intent) CLIENT_TYPE_TWITTER(com.github.moko256.latte.client.twitter.TwitterApiClientImplKt.CLIENT_TYPE_TWITTER) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) AppCustomTabsKt(com.github.moko256.twitlatte.intent.AppCustomTabsKt) TwitterStringUtils(com.github.moko256.twitlatte.text.TwitterStringUtils) Toast(android.widget.Toast) EditTextPreference(androidx.preference.EditTextPreference) PreferenceScreen(androidx.preference.PreferenceScreen) PatternSyntaxException(java.util.regex.PatternSyntaxException) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) KEY_ACCOUNT_KEY(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_ACCOUNT_KEY) Preference(androidx.preference.Preference) AccessToken(com.github.moko256.latte.client.base.entity.AccessToken) List(java.util.List) KEY_NIGHT_MODE(com.github.moko256.twitlatte.repository.PreferenceRepositoryKt.KEY_NIGHT_MODE) Nullable(androidx.annotation.Nullable) ListPreference(androidx.preference.ListPreference) PreferenceScreen(androidx.preference.PreferenceScreen) AccountsModel(com.github.moko256.twitlatte.model.AccountsModel) Intent(android.content.Intent) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory) AccessToken(com.github.moko256.latte.client.base.entity.AccessToken) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 8 with EditTextPreference

use of androidx.preference.EditTextPreference in project kcanotify by antest1.

the class MainPreferenceFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    isActivitySet = true;
    Activity activity = getActivity();
    if (activity instanceof Callback)
        mCallback = (Callback) activity;
    Map<String, ?> allEntries = sharedPref.getAll();
    for (String key : allEntries.keySet()) {
        Preference preference = findPreference(key);
        if (preference == null)
            continue;
        if (preference instanceof ListPreference) {
            ListPreference etp = (ListPreference) preference;
            preference.setSummary(etp.getEntry());
        } else if (preference instanceof EditTextPreference) {
            EditTextPreference etp = (EditTextPreference) preference;
            preference.setSummary(getEditTextSummary(key, etp.getText()));
        } else if (PREF_KCA_NOTI_RINGTONE.equals(preference.getKey())) {
            String uri = sharedPref.getString(PREF_KCA_NOTI_RINGTONE, "");
            Uri ringtoneUri = Uri.parse(uri);
            String ringtoneTitle = getStringWithLocale(R.string.settings_string_silent);
            if (uri.length() > 0) {
                ringtoneTitle = getRingtoneTitle(ringtoneUri);
            }
            preference.setSummary(ringtoneTitle);
        }
        preference.setOnPreferenceChangeListener(this);
    }
}
Also used : EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Activity(android.app.Activity) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference) Uri(android.net.Uri)

Example 9 with EditTextPreference

use of androidx.preference.EditTextPreference in project kcanotify by antest1.

the class NestedPreferenceFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Map<String, ?> allEntries = getPreferenceManager().getSharedPreferences().getAll();
    // SharedPreferences prefs = this.getActivity().getSharedPreferences("pref", MODE_PRIVATE);
    for (String key : allEntries.keySet()) {
        Preference pref = findPreference(key);
        if (pref == null)
            continue;
        pref.setOnPreferenceChangeListener(this);
        if (pref instanceof ListPreference) {
            ListPreference etp = (ListPreference) pref;
            pref.setSummary(etp.getEntry());
        } else if (pref instanceof EditTextPreference) {
            EditTextPreference etp = (EditTextPreference) pref;
            pref.setSummary(etp.getText());
        }
    }
}
Also used : Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference)

Example 10 with EditTextPreference

use of androidx.preference.EditTextPreference in project kcanotify by antest1.

the class NestedPreferenceFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    if (pref instanceof ListPreference) {
        ListPreference etp = (ListPreference) pref;
        pref.setSummary(etp.getEntry());
    } else if (pref instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) pref;
        pref.setSummary(etp.getText());
    }
}
Also used : Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference) ListPreference(androidx.preference.ListPreference) EditTextPreference(androidx.preference.EditTextPreference)

Aggregations

EditTextPreference (androidx.preference.EditTextPreference)13 ListPreference (androidx.preference.ListPreference)10 Preference (androidx.preference.Preference)8 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 MultiSelectListPreference (androidx.preference.MultiSelectListPreference)2 PreferenceScreen (androidx.preference.PreferenceScreen)2 SwitchPreference (androidx.preference.SwitchPreference)2 SwitchPreferenceCompat (androidx.preference.SwitchPreferenceCompat)2 ControlCharacterFilter (org.odk.collect.android.preferences.filters.ControlCharacterFilter)2 Activity (android.app.Activity)1 RESULT_OK (android.app.Activity.RESULT_OK)1 Context (android.content.Context)1 Uri (android.net.Uri)1 Message (android.os.Message)1 InputFilter (android.text.InputFilter)1 Toast (android.widget.Toast)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1