Search in sources :

Example 81 with Preference

use of android.support.v7.preference.Preference in project NetGuard by M66B.

the class ActivityLog method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("log".equals(name)) {
        // Get enabled
        boolean log = prefs.getBoolean(name, false);
        // Display disabled warning
        TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
        tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
        // Check switch state
        SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
        if (swEnabled.isChecked() != log)
            swEnabled.setChecked(log);
        ServiceSinkhole.reload("changed " + name, ActivityLog.this);
    }
}
Also used : TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 82 with Preference

use of android.support.v7.preference.Preference in project Rashr by DsLNeXuS.

the class InformationFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getContext());
    ArrayList<InformationItem> items = new ArrayList<>();
    items.add(new InformationItem("Device Name", App.Device.getName()));
    items.add(new InformationItem("Manufacture", App.Device.getManufacture()));
    String recoveryType = "";
    boolean recoveryWithPath = false;
    boolean recoveryWithBS = false;
    switch(App.Device.getRecoveryType()) {
        case Device.PARTITION_TYPE_DD:
            recoveryType = "DD";
            recoveryWithPath = true;
            recoveryWithBS = App.Device.getRecoveryBlocksize() > 0;
            break;
        case Device.PARTITION_TYPE_MTD:
            recoveryType = "MTD";
            break;
        case Device.PARTITION_TYPE_RECOVERY:
            recoveryType = "Flash over current Recovery";
            break;
        case Device.PARTITION_TYPE_NOT_SUPPORTED:
            recoveryType = "Not supported";
            break;
    }
    String kernelType = "";
    boolean kernelWithPath = false;
    boolean kernelWithBS = false;
    switch(App.Device.getKernelType()) {
        case Device.PARTITION_TYPE_DD:
            kernelType = "DD";
            kernelWithPath = true;
            kernelWithBS = App.Device.getKernelBlocksize() > 0;
            break;
        case Device.PARTITION_TYPE_MTD:
            kernelType = "MTD";
            break;
        case Device.PARTITION_TYPE_RECOVERY:
            kernelType = "Flash over current Recovery";
            break;
        case Device.PARTITION_TYPE_NOT_SUPPORTED:
            kernelType = "Not supported";
    }
    items.add(new InformationItem(getString(R.string.recovery_type), recoveryType));
    if (recoveryWithPath)
        items.add(new InformationItem("Recovery Path", App.Device.getRecoveryPath()));
    if (recoveryWithBS)
        items.add(new InformationItem("Recovery Blocksize", String.valueOf(App.Device.getRecoveryBlocksize())));
    items.add(new InformationItem("Kernel Partition Type", kernelType));
    if (kernelWithPath)
        items.add(new InformationItem("Kernel Path", App.Device.getKernelPath()));
    if (kernelWithBS)
        items.add(new InformationItem("Kernel Blocksize", String.valueOf(App.Device.getKernelBlocksize())));
    int total = 0;
    if (App.Device.isCwmRecoverySupported()) {
        int tmp = App.Device.getCwmRecoveryVersions().size();
        items.add(new InformationItem(getString(R.string.sCWM), String.valueOf(tmp)));
        total += tmp;
    }
    if (App.Device.isTwrpRecoverySupported()) {
        int tmp = App.Device.getTwrpRecoveryVersions().size();
        items.add(new InformationItem(getString(R.string.sTWRP), String.valueOf(tmp)));
        total += tmp;
    }
    if (App.Device.isPhilzRecoverySupported()) {
        int tmp = App.Device.getPhilzRecoveryVersions().size();
        items.add(new InformationItem(getString(R.string.sPhilz), String.valueOf(tmp)));
        total += tmp;
    }
    if (App.Device.isXZDualRecoverySupported()) {
        int tmp = App.Device.getXZDualRecoveryVersions().size();
        items.add(new InformationItem(getString(R.string.xzdualrecovery), String.valueOf(tmp)));
        total += tmp;
    }
    if (App.Device.isStockRecoverySupported()) {
        int tmp = App.Device.getStockRecoveryVersions().size();
        items.add(new InformationItem(getString(R.string.stock_recovery), String.valueOf(tmp)));
        total += tmp;
    }
    if (App.Device.isStockKernelSupported()) {
        int tmp = App.Device.getStockKernelVersions().size();
        items.add(new InformationItem(getString(R.string.stock_kernel), String.valueOf(tmp)));
        total += tmp;
    }
    items.add(new InformationItem(getString(R.string.total_images), String.valueOf(total)));
    for (String err : App.ERRORS) {
        items.add(new InformationItem("Error:", err));
    }
    for (InformationItem item : items) {
        Preference pref = new Preference(getContext());
        pref.setTitle(item.id);
        pref.setSummary(item.content);
        pref.setOnPreferenceClickListener(this);
        screen.addPreference(pref);
    }
    setPreferenceScreen(screen);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) InformationItem(de.mkrtchyan.recoverytools.InformationItem)

Example 83 with Preference

use of android.support.v7.preference.Preference in project twicalico by moko256.

the class SettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    String preferenceRoot = getArguments() != null ? getArguments().getString(ARG_PREFERENCE_ROOT, null) : null;
    if (preferenceRoot == null) {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(getContext());
        AccessToken[] accessTokens = helper.getAccessTokens();
        CharSequence[] entries = new CharSequence[accessTokens.length + 1];
        CharSequence[] entryValues = new CharSequence[accessTokens.length + 1];
        for (int i = 0; i < accessTokens.length; i++) {
            AccessToken accessToken = accessTokens[i];
            entries[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entryValues[i] = accessToken.getKeyString();
        }
        entries[entries.length - 1] = getString(R.string.add_account);
        entryValues[entryValues.length - 1] = "-1";
        ListPreference nowAccountList = (ListPreference) findPreference("AccountKey");
        nowAccountList.setEntries(entries);
        nowAccountList.setEntryValues(entryValues);
        nowAccountList.setDefaultValue(defaultSharedPreferences.getString("AccountKey", "-1"));
        nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
            if (newValue.equals("-1")) {
                GlobalApplication.twitter = null;
                startActivity(new Intent(getContext(), OAuthActivity.class));
            } else {
                TokenSQLiteOpenHelper tokenOpenHelper = new TokenSQLiteOpenHelper(this.getContext());
                AccessToken accessToken = tokenOpenHelper.getAccessToken((String) newValue);
                tokenOpenHelper.close();
                ((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
                startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
            }
            return true;
        });
        findPreference("logout").setOnPreferenceClickListener(preference -> {
            new AlertDialog.Builder(getContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
                helper.deleteAccessToken(helper.getAccessToken(defaultSharedPreferences.getString("AccountKey", "-1")));
                int point = helper.getSize() - 1;
                if (point != -1) {
                    AccessToken accessToken = helper.getAccessTokens()[point];
                    defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
                    ((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    defaultSharedPreferences.edit().putString("AccountKey", "-1").apply();
                    GlobalApplication.twitter = null;
                    startActivity(new Intent(getContext(), OAuthActivity.class));
                }
            }).setNeutralButton(R.string.back, (dialog, i) -> dialog.cancel()).show();
            return false;
        });
        ListPreference nowThemeMode = (ListPreference) findPreference("nightModeType");
        nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
            switch(String.valueOf(newValue)) {
                case "mode_night_no":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    break;
                case "mode_night_auto":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
                    break;
                case "mode_night_follow_system":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                    break;
                case "mode_night_yes":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    break;
                default:
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            }
            return true;
        });
        Preference causeError = findPreference("cause_error");
        causeError.setOnPreferenceClickListener(preference -> {
            getActivity().finish();
            throw new NullPointerException();
        });
        Preference licenseThisApp = findPreference("license_at_this_app");
        licenseThisApp.setOnPreferenceClickListener(preference -> {
            getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twicalico"));
            return true;
        });
        Preference sourceCodeLink = findPreference("source_code_link");
        sourceCodeLink.setOnPreferenceClickListener(preference -> {
            AppCustomTabsKt.launchChromeCustomTabs(getContext(), "https://github.com/moko256/twicalico");
            return false;
        });
        Preference version = findPreference("app_version");
        version.setSummary(BuildConfig.VERSION_NAME);
        version.setOnPreferenceClickListener(preference -> {
            Date birthday = new Date(1446956982000L);
            Toast.makeText(getContext(), getString(R.string.birthday_of_this_app_is, birthday) + "\n\n" + getString(R.string.age_of_this_app_is, (int) Math.floor((new Date().getTime() - birthday.getTime()) / (31557600000L))), Toast.LENGTH_LONG).show();
            return false;
        });
    } else if (preferenceRoot.equals("license")) {
        PreferenceScreen license = getPreferenceScreen();
        for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
            license.getPreference(i).setOnPreferenceClickListener(preference -> {
                getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
                preference.getKey().substring(12)));
                return true;
            });
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) AccessToken(com.github.moko256.twicalico.entity.AccessToken) PreferenceFragmentCompat(android.support.v7.preference.PreferenceFragmentCompat) Date(java.util.Date) ListPreference(android.support.v7.preference.ListPreference) Intent(android.content.Intent) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) AppCompatDelegate(android.support.v7.app.AppCompatDelegate) Preference(android.support.v7.preference.Preference) PreferenceManager(android.support.v7.preference.PreferenceManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) AppCustomTabsKt(com.github.moko256.twicalico.intent.AppCustomTabsKt) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Toast(android.widget.Toast) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) Date(java.util.Date) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) AccessToken(com.github.moko256.twicalico.entity.AccessToken) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)

Example 84 with Preference

use of android.support.v7.preference.Preference in project aware-client by denzilferreira.

the class Aware_Client method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, final Preference preference) {
    if (preference instanceof PreferenceScreen) {
        Dialog subpref = ((PreferenceScreen) preference).getDialog();
        ViewGroup root = (ViewGroup) subpref.findViewById(android.R.id.content).getParent();
        Toolbar toolbar = new Toolbar(this);
        toolbar.setBackgroundColor(ContextCompat.getColor(preferenceScreen.getContext(), R.color.primary));
        toolbar.setTitleTextColor(ContextCompat.getColor(preferenceScreen.getContext(), android.R.color.white));
        toolbar.setTitle(preference.getTitle());
        // add to the top
        root.addView(toolbar, 0);
        subpref.setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                new SettingsSync().execute(preference);
            }
        });
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) ViewGroup(android.view.ViewGroup) Toolbar(android.support.v7.widget.Toolbar)

Example 85 with Preference

use of android.support.v7.preference.Preference in project android_packages_apps_crDroidSettings by crdroidandroid.

the class SlimRecentsBlacklist method refreshCustomApplicationPrefs.

private void refreshCustomApplicationPrefs() {
    if (!parsePackageList()) {
        return;
    }
    // Add the Application Preferences
    if (mBlacklistPrefList != null) {
        mBlacklistPrefList.removeAll();
        for (Package pkg : mBlacklistPackages.values()) {
            try {
                Preference pref = createPreferenceFromInfo(pkg);
                mBlacklistPrefList.addPreference(pref);
            } catch (PackageManager.NameNotFoundException e) {
            // Do nothing
            }
        }
    }
    // Keep these at the top
    mAddBlacklistPref.setOrder(0);
    // Add 'add' options
    mBlacklistPrefList.addPreference(mAddBlacklistPref);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7