Search in sources :

Example 61 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen 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 62 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen 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 63 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen 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 64 with PreferenceScreen

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

the class Update method updateLinks.

private void updateLinks(boolean force) {
    Context context = getActivity().getApplicationContext();
    List<OTALink> links = LinkConfig.getInstance().getLinks(context, force);
    Drawable drawable = context.getDrawable(R.drawable.ic_web);
    TypedArray ta = context.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
    drawable.setTint(ta.getColor(0, 0));
    if (mLinksCategory == null)
        return;
    for (OTALink link : links) {
        String id = link.getId();
        if (id.equalsIgnoreCase(DOWNLOAD_TAG) || id.equalsIgnoreCase(CHANGELOG_TAG) || id.equalsIgnoreCase(GAPPS_TAG) || id.equalsIgnoreCase(FORUM_TAG) || id.equalsIgnoreCase(PAYPAL_TAG) || id.equalsIgnoreCase(TELEGRAM_TAG)) {
            continue;
        }
        PreferenceScreen linkPref = (PreferenceScreen) getPreferenceScreen().findPreference(id.toLowerCase());
        if (linkPref == null) {
            linkPref = getPreferenceManager().createPreferenceScreen(context);
            linkPref.setKey(id.toLowerCase());
            linkPref.setIcon(drawable);
            mLinksCategory.addPreference(linkPref);
        }
        if (linkPref != null) {
            String title = link.getTitle();
            linkPref.setTitle(title.isEmpty() ? id : title);
            linkPref.setSummary(link.getDescription());
        }
    }
    mLinksCategory.setTitle(mShowLinks ? context.getString(R.string.links_category) : "");
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) OTALink(com.crdroid.settings.fragments.about.update.xml.OTALink)

Example 65 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen in project android_frameworks_base by crdroidandroid.

the class DemoModeFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Context context = getContext();
    mEnabledSwitch = new SwitchPreference(context);
    mEnabledSwitch.setTitle(R.string.enable_demo_mode);
    mEnabledSwitch.setOnPreferenceChangeListener(this);
    mOnSwitch = new SwitchPreference(context);
    mOnSwitch.setTitle(R.string.show_demo_mode);
    mOnSwitch.setEnabled(false);
    mOnSwitch.setOnPreferenceChangeListener(this);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
    screen.addPreference(mEnabledSwitch);
    screen.addPreference(mOnSwitch);
    setPreferenceScreen(screen);
    updateDemoModeEnabled();
    updateDemoModeOn();
    ContentResolver contentResolver = getContext().getContentResolver();
    contentResolver.registerContentObserver(Settings.Global.getUriFor(DemoMode.DEMO_MODE_ALLOWED), false, mDemoModeObserver);
    contentResolver.registerContentObserver(Settings.Global.getUriFor(DEMO_MODE_ON), false, mDemoModeObserver);
    setHasOptionsMenu(true);
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) ContentResolver(android.content.ContentResolver)

Aggregations

PreferenceScreen (android.support.v7.preference.PreferenceScreen)115 Preference (android.support.v7.preference.Preference)42 ContentResolver (android.content.ContentResolver)35 SwitchPreference (android.support.v14.preference.SwitchPreference)21 Context (android.content.Context)19 Resources (android.content.res.Resources)16 PreferenceCategory (android.support.v7.preference.PreferenceCategory)14 Intent (android.content.Intent)12 ArrayList (java.util.ArrayList)9 ListPreference (android.support.v7.preference.ListPreference)8 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 PreferenceGroup (android.support.v7.preference.PreferenceGroup)7 PackageManager (android.content.pm.PackageManager)6 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)6 PreferenceManager (android.support.v7.preference.PreferenceManager)6 Activity (android.app.Activity)5 SharedPreferences (android.content.SharedPreferences)4 Bundle (android.os.Bundle)4 InputMethodInfo (android.view.inputmethod.InputMethodInfo)4 ComponentName (android.content.ComponentName)3