Search in sources :

Example 11 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project frostwire by frostwire.

the class ApplicationFragment method setupVPNRequirementOption.

private void setupVPNRequirementOption() {
    SwitchPreferenceCompat preference = findPreference(Constants.PREF_KEY_NETWORK_BITTORRENT_ON_VPN_ONLY);
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        boolean newVal = (boolean) newValue;
        if (newVal && !NetworkManager.instance().isTunnelUp()) {
            disconnect();
            setChecked(findPreference("frostwire.prefs.internal.connect_disconnect"), false, false);
            UIUtils.showShortMessage(getView(), R.string.switch_off_engine_without_vpn);
        }
        return true;
    });
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat)

Example 12 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project frostwire by frostwire.

the class ApplicationFragment method setupDataSaving.

private void setupDataSaving() {
    SwitchPreferenceCompat preference = findPreference(Constants.PREF_KEY_NETWORK_USE_WIFI_ONLY);
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        boolean newVal = (Boolean) newValue;
        if (newVal && !NetworkManager.instance().isDataWIFIUp()) {
            if (TransferManager.instance().isHttpDownloadInProgress()) {
                YesNoDialog dlg = YesNoDialog.newInstance(CONFIRM_STOP_HTTP_IN_PROGRESS_DIALOG_TAG, R.string.data_saving_kill_http_warning_title, R.string.data_saving_kill_http_warning, YesNoDialog.FLAG_DISMISS_ON_OK_BEFORE_PERFORM_DIALOG_CLICK);
                dlg.setTargetFragment(ApplicationFragment.this, 0);
                dlg.show(getFragmentManager(), CONFIRM_STOP_HTTP_IN_PROGRESS_DIALOG_TAG);
                return false;
            }
            turnOffTransfers();
        }
        return true;
    });
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) YesNoDialog(com.frostwire.android.gui.dialogs.YesNoDialog)

Example 13 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project MiMangaNu by raulhaag.

the class PreferencesFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.fragment_preferences);
    ColorListDialogPref primaryColor = (ColorListDialogPref) getPreferenceManager().findPreference("primario");
    primaryColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            ((MainActivity) getActivity()).setColorToBars();
            return false;
        }
    });
    PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("account");
    ServerBase[] servers = ServerBase.getServers(getContext());
    for (final ServerBase sb : servers) {
        if (sb.needLogin()) {
            SwitchPreferenceCompat preference = new SwitchPreferenceCompat(getContext());
            preference.setTitle(sb.getServerName());
            preference.setSelectable(true);
            preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    new LoginDialog(getContext(), sb).show();
                    return false;
                }
            });
            preferenceGroup.addPreference(preference);
        }
    }
    /* Once, create necessary Data */
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    final String current_filepath = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";
    /* This enables to hide downloaded images from gallery, just a toggle */
    final SwitchPreferenceCompat cBoxPref = (SwitchPreferenceCompat) getPreferenceManager().findPreference("mostrar_en_galeria");
    // actuate the switch based on the existence of the .nomedia file
    final File noMedia = new File(current_filepath, ".nomedia");
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        cBoxPref.setChecked(noMedia.exists());
    } else {
        cBoxPref.setEnabled(false);
    }
    cBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // reject change event in case the external storage is not available
            if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
                return false;
            }
            try {
                if ((Boolean) newValue) {
                    if (!noMedia.createNewFile()) {
                        Log.w("PF", "failed to create .nomedia file");
                    }
                } else {
                    if (!noMedia.delete()) {
                        Log.w("PF", "failed to delete .nomedia file");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
    });
    /* Set summary for Reader preference + seamless chapter transitions summary */
    // true: Paged Reader; false: Continuous Reader
    Boolean readType = prefs.getBoolean("reader_type", false);
    Preference reader_type = getPreferenceManager().findPreference("reader_type");
    Preference seamlessChapterTransitionsPref = getPreferenceManager().findPreference("seamless_chapter_transitions");
    if (readType) {
        reader_type.setTitle(getString(R.string.paged_reader));
        seamlessChapterTransitionsPref.setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
    } else {
        reader_type.setTitle(getString(R.string.continuous_reader));
        seamlessChapterTransitionsPref.setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
    }
    final SwitchPreferenceCompat readerTypePref = (SwitchPreferenceCompat) getPreferenceManager().findPreference("reader_type");
    readerTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Boolean readType = prefs.getBoolean("reader_type", false);
            Preference reader_type = getPreferenceManager().findPreference("reader_type");
            Preference seamlessChapterTransitions = getPreferenceManager().findPreference("seamless_chapter_transitions");
            if (!readType) {
                reader_type.setTitle(getString(R.string.paged_reader));
                seamlessChapterTransitions.setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
            } else {
                reader_type.setTitle(getString(R.string.continuous_reader));
                seamlessChapterTransitions.setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
            }
            return true;
        }
    });
    /* enable / disable seamless_chapter_transitions_delete_read depending on the state of seamless_chapter_transitions */
    Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager().findPreference("seamless_chapter_transitions_delete_read");
    if (prefs.getBoolean("seamless_chapter_transitions", false)) {
        seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
    } else {
        seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);
    }
    final SwitchPreferenceCompat seamlessChapterTransitionsSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("seamless_chapter_transitions");
    seamlessChapterTransitionsSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager().findPreference("seamless_chapter_transitions_delete_read");
            if (!prefs.getBoolean("seamless_chapter_transitions", false)) {
                seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
            } else {
                seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);
                SharedPreferences.Editor prefEdit = prefs.edit();
                prefEdit.putBoolean("seamless_chapter_transitions_delete_read", false);
                prefEdit.apply();
            }
            return true;
        }
    });
    /* enable / disable auto_import_path depending on the state of auto_import */
    Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
    if (prefs.getBoolean("auto_import", false)) {
        autoImportPath.setEnabled(true);
    } else {
        autoImportPath.setEnabled(false);
    }
    final SwitchPreferenceCompat autoImportSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("auto_import");
    autoImportSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
            if (!prefs.getBoolean("auto_import", false)) {
                autoImportPath.setEnabled(true);
            } else {
                autoImportPath.setEnabled(false);
            }
            return true;
        }
    });
    /* This sets the download threads (parallel downloads) */
    final SeekBarCustomPreference listPreferenceDT = (SeekBarCustomPreference) getPreferenceManager().findPreference("download_threads");
    listPreferenceDT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int threads = (int) newValue;
            int antes = DownloadPoolService.SLOTS;
            DownloadPoolService.SLOTS = threads;
            if (DownloadPoolService.actual != null)
                DownloadPoolService.actual.slots += (threads - antes);
            return true;
        }
    });
    /* This sets the maximum number of errors to tolerate */
    final SeekBarCustomPreference listPrefET = (SeekBarCustomPreference) getPreferenceManager().findPreference("error_tolerancia");
    listPrefET.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ChapterDownload.MAX_ERRORS = (int) newValue;
            return true;
        }
    });
    /* This sets the number of retries to fetch images */
    SeekBarCustomPreference listPrefRT = (SeekBarCustomPreference) getPreferenceManager().findPreference("reintentos");
    listPrefRT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SingleDownload.RETRY = (int) newValue;
            return true;
        }
    });
    /* This sets the Update Interval of the mangas (i.e. once per week) */
    final ListPreference listPrefCU = (ListPreference) getPreferenceManager().findPreference("update_interval");
    listPrefCU.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            long time = Long.parseLong((String) newValue);
            JobManager.instance().cancelAllForTag(UpdateJobCreator.UPDATE_TAG);
            if (time > 0) {
                new JobRequest.Builder(UpdateJobCreator.UPDATE_TAG).setPeriodic(time, TimeUnit.MINUTES.toMillis(5)).setRequiresCharging(false).setRequiresDeviceIdle(false).setUpdateCurrent(true).build().schedule();
            }
            if (time < 0)
                MainActivity.coldStart = false;
            return true;
        }
    });
    /* This is for Custom language selection */
    final ListPreference listPrefBatotoLang = (ListPreference) getPreferenceManager().findPreference("batoto_lang_selection");
    listPrefBatotoLang.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.equals("Custom")) {
                LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View rootView = inflater.inflate(R.layout.simple_input_dialog, null);
                final EditText CustomLang = (EditText) rootView.findViewById(R.id.txtCustomLang);
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
                dialogBuilder.setTitle(getString(R.string.custom_language));
                dialogBuilder.setView(rootView);
                dialogBuilder.setPositiveButton("Ok", null);
                dialogBuilder.setNegativeButton(getString(R.string.cancel), null);
                AlertDialog dialog = dialogBuilder.create();
                dialog.setOnShowListener(new DialogInterface.OnShowListener() {

                    @Override
                    public void onShow(final DialogInterface dialog) {
                        Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                        accept.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                prefs.edit().putString("batoto_custom_lang", CustomLang.getText().toString()).apply();
                                Util.getInstance().toast(getContext(), getString(R.string.custom_language) + ": " + CustomLang.getText().toString());
                                dialog.dismiss();
                            }
                        });
                    }
                });
                dialog.show();
            }
            return true;
        }
    });
    /* This sets the Version Number, that's all */
    final Preference prefAbout = getPreferenceManager().findPreference("about_text");
    prefAbout.setSummary("v" + BuildConfig.VERSION_NAME);
    /* This will check how much storage is taken by the mangas */
    new calcStorage().execute(current_filepath);
    final Preference prefLicense = getPreferenceManager().findPreference("license_view");
    prefLicense.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((MainActivity) getActivity()).replaceFragment(new LicenseFragment(), "licence_fragment");
            return false;
        }
    });
    final SwitchPreferenceCompat onlyWifiUpdateSwitch = (SwitchPreferenceCompat) getPreferenceManager().findPreference("update_only_wifi");
    SwitchPreferenceCompat onlyWifiSwitch = (SwitchPreferenceCompat) getPreferenceManager().findPreference("only_wifi");
    onlyWifiSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            NetworkUtilsAndReceiver.ONLY_WIFI = (Boolean) o;
            NetworkUtilsAndReceiver.connectionStatus = NetworkUtilsAndReceiver.ConnectionStatus.UNCHECKED;
            onlyWifiUpdateSwitch.setEnabled(!(Boolean) o);
            return true;
        }
    });
    if (onlyWifiSwitch.isChecked()) {
        onlyWifiUpdateSwitch.setEnabled(false);
    } else {
        onlyWifiUpdateSwitch.setEnabled(true);
    }
    final SeekBarCustomPreference seekBarConnectionRetry = (SeekBarCustomPreference) getPreferenceManager().findPreference("connection_retry");
    seekBarConnectionRetry.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.connectionRetry = Integer.parseInt(prefs.getString("connection_retry", "10"));
            return true;
        }
    });
    final SeekBarCustomPreference seekBarConnectionTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("connection_timeout");
    seekBarConnectionTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.connectionTimeout = Integer.parseInt(prefs.getString("connection_timeout", "10"));
            return true;
        }
    });
    final SeekBarCustomPreference seekBarWriteTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("write_timeout");
    seekBarWriteTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.writeTimeout = Integer.parseInt(prefs.getString("write_timeout", "10"));
            return true;
        }
    });
    final SeekBarCustomPreference seekBarReadTimeout = (SeekBarCustomPreference) getPreferenceManager().findPreference("read_timeout");
    seekBarReadTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.readTimeout = Integer.parseInt(prefs.getString("read_timeout", "30"));
            return true;
        }
    });
    Preference gridColumnsPref = getPreferenceManager().findPreference("grid_columns");
    if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
        gridColumnsPref.setEnabled(false);
    } else {
        gridColumnsPref.setEnabled(true);
    }
    final SwitchPreferenceCompat gridColumnsAutomaticDetectionSPC = (SwitchPreferenceCompat) getPreferenceManager().findPreference("grid_columns_automatic_detection");
    gridColumnsAutomaticDetectionSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference gridColumns = getPreferenceManager().findPreference("grid_columns");
            if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
                gridColumns.setEnabled(true);
            } else {
                gridColumns.setEnabled(false);
            }
            return true;
        }
    });
    final Preference prefClearCache = getPreferenceManager().findPreference("clear_cache");
    prefClearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference clearCache = getPreferenceManager().findPreference("clear_cache");
            clearCache.setEnabled(false);
            Thread t0 = new Thread(new Runnable() {

                @Override
                public void run() {
                    new FileCache(getActivity()).clearCache();
                }
            });
            Thread t1 = new Thread(new Runnable() {

                @Override
                public void run() {
                    Util.getInstance().createNotificationWithProgressbar(getContext(), 69, getString(R.string.deleting_empty_directories), "");
                    Util.getInstance().deleteEmptyDirectoriesRecursive(new File(current_filepath));
                    Util.getInstance().cancelNotification(69);
                }
            });
            t0.start();
            t1.start();
            return true;
        }
    });
    final Preference prefClearSpecificCookies = getPreferenceManager().findPreference("clear_specific_cookies");
    prefClearSpecificCookies.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference clearSpecificCookies = getPreferenceManager().findPreference("clear_specific_cookies");
            clearSpecificCookies.setEnabled(false);
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rootView = inflater.inflate(R.layout.simple_input_dialog, null);
            final EditText SpecificCookiesToClear = (EditText) rootView.findViewById(R.id.txtCustomLang);
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
            dialogBuilder.setTitle("Cookies to clear contain");
            dialogBuilder.setView(rootView);
            dialogBuilder.setPositiveButton("Ok", null);
            dialogBuilder.setNegativeButton(getString(R.string.cancel), null);
            AlertDialog dialog = dialogBuilder.create();
            dialog.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(final DialogInterface dialog) {
                    Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                    accept.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            Thread t0 = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.getInstance().removeSpecificCookies(getContext(), SpecificCookiesToClear.getText().toString());
                                }
                            });
                            t0.start();
                            dialog.dismiss();
                        }
                    });
                    Button cancel = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
                    cancel.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                        }
                    });
                }
            });
            dialog.show();
            return true;
        }
    });
    final Preference prefClearAllCookies = getPreferenceManager().findPreference("clear_all_cookies");
    prefClearAllCookies.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference clearAllCookies = getPreferenceManager().findPreference("clear_all_cookies");
            clearAllCookies.setEnabled(false);
            Thread t0 = new Thread(new Runnable() {

                @Override
                public void run() {
                    Util.getInstance().removeAllCookies(getContext());
                }
            });
            t0.start();
            return true;
        }
    });
    final Preference prefResetServersToDefaults = getPreferenceManager().findPreference("reset_server_list_to_defaults");
    prefResetServersToDefaults.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference resetServerListToDefaults = getPreferenceManager().findPreference("reset_server_list_to_defaults");
            resetServerListToDefaults.setEnabled(false);
            prefs.edit().putString("unused_servers", "").apply();
            return true;
        }
    });
    final Preference prefVacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
    prefVacuumDatabase.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference vacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
            vacuumDatabase.setEnabled(false);
            Thread t0 = new Thread(new Runnable() {

                @Override
                public void run() {
                    Util.getInstance().createNotificationWithProgressbar(getContext(), 70, getString(R.string.vacuum_database_notification_text), "");
                    Database.vacuumDatabase(getContext());
                    Util.getInstance().cancelNotification(70);
                }
            });
            t0.start();
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        getPreferenceManager().findPreference("update_sound").setVisible(false);
        getPreferenceManager().findPreference("update_vibrate").setVisible(false);
        getPreferenceManager().findPreference("update_notif_options").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
                intent.putExtra(Settings.EXTRA_CHANNEL_ID, Util.channelIdNews);
                intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
                startActivity(intent);
                return true;
            }
        });
    } else {
        getPreferenceManager().findPreference("update_notif_options").setVisible(false);
    }
    setFirstRunDefaults();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ColorListDialogPref(ar.rulosoft.custompref.ColorListDialogPref) JobRequest(com.evernote.android.job.JobRequest) Button(android.widget.Button) ServerBase(ar.rulosoft.mimanganu.servers.ServerBase) EditText(android.widget.EditText) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) View(android.view.View) FileCache(com.fedorvlasov.lazylist.FileCache) SeekBarCustomPreference(ar.rulosoft.custompref.SeekBarCustomPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) LayoutInflater(android.view.LayoutInflater) PreferenceGroup(android.support.v7.preference.PreferenceGroup) LoginDialog(ar.rulosoft.mimanganu.componentes.LoginDialog) File(java.io.File) SeekBarCustomPreference(ar.rulosoft.custompref.SeekBarCustomPreference)

Example 14 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project Signal-Android by signalapp.

the class RegistrationLockDialog method showRegistrationUnlockPrompt.

@SuppressLint("StaticFieldLeak")
public static void showRegistrationUnlockPrompt(@NonNull Context context, @NonNull SwitchPreferenceCompat preference, @NonNull SignalServiceAccountManager accountManager) {
    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(R.string.RegistrationLockDialog_disable_registration_lock_pin).setView(R.layout.registration_unlock_dialog_view).setPositiveButton(R.string.RegistrationLockDialog_disable, null).setNegativeButton(android.R.string.cancel, null).create();
    dialog.setOnShowListener(created -> {
        Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(v -> {
            ProgressBar progressBar = dialog.findViewById(R.id.progress);
            assert progressBar != null;
            new AsyncTask<Void, Void, Boolean>() {

                @Override
                protected void onPreExecute() {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setIndeterminate(true);
                    button.setEnabled(false);
                }

                @Override
                protected Boolean doInBackground(Void... voids) {
                    try {
                        accountManager.setPin(Optional.absent());
                        return true;
                    } catch (IOException e) {
                        Log.w(TAG, e);
                        return false;
                    }
                }

                @Override
                protected void onPostExecute(Boolean result) {
                    progressBar.setVisibility(View.GONE);
                    button.setEnabled(true);
                    if (result) {
                        preference.setChecked(false);
                        created.dismiss();
                    } else {
                        Toast.makeText(context, R.string.RegistrationLockDialog_error_connecting_to_the_service, Toast.LENGTH_LONG).show();
                    }
                }
            }.execute();
        });
    });
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Button(android.widget.Button) IOException(java.io.IOException) ProgressBar(android.widget.ProgressBar) SuppressLint(android.annotation.SuppressLint)

Example 15 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project Signal-Android by signalapp.

the class BackupDialog method showEnableBackupDialog.

public static void showEnableBackupDialog(@NonNull Context context, @NonNull SwitchPreferenceCompat preference) {
    String[] password = BackupUtil.generateBackupPassphrase();
    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(R.string.BackupDialog_enable_local_backups).setView(R.layout.backup_enable_dialog).setPositiveButton(R.string.BackupDialog_enable_backups, null).setNegativeButton(android.R.string.cancel, null).create();
    dialog.setOnShowListener(created -> {
        Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(v -> {
            CheckBox confirmationCheckBox = dialog.findViewById(R.id.confirmation_check);
            if (confirmationCheckBox.isChecked()) {
                TextSecurePreferences.setBackupPassphrase(context, Util.join(password, " "));
                TextSecurePreferences.setBackupEnabled(context, true);
                LocalBackupListener.schedule(context);
                preference.setChecked(true);
                created.dismiss();
            } else {
                Toast.makeText(context, R.string.BackupDialog_please_acknowledge_your_understanding_by_marking_the_confirmation_check_box, Toast.LENGTH_LONG).show();
            }
        });
    });
    dialog.show();
    CheckBox checkBox = dialog.findViewById(R.id.confirmation_check);
    TextView textView = dialog.findViewById(R.id.confirmation_text);
    ((TextView) dialog.findViewById(R.id.code_first)).setText(password[0]);
    ((TextView) dialog.findViewById(R.id.code_second)).setText(password[1]);
    ((TextView) dialog.findViewById(R.id.code_third)).setText(password[2]);
    ((TextView) dialog.findViewById(R.id.code_fourth)).setText(password[3]);
    ((TextView) dialog.findViewById(R.id.code_fifth)).setText(password[4]);
    ((TextView) dialog.findViewById(R.id.code_sixth)).setText(password[5]);
    textView.setOnClickListener(v -> checkBox.toggle());
    dialog.findViewById(R.id.number_table).setOnClickListener(v -> {
        ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("text", Util.join(password, " ")));
        Toast.makeText(context, R.string.BackupDialog_copied_to_clipboard, Toast.LENGTH_LONG).show();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ClipboardManager(android.content.ClipboardManager) Button(android.widget.Button) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView)

Aggregations

SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)15 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)5 Preference (android.support.v7.preference.Preference)5 ListPreference (android.support.v7.preference.ListPreference)4 Button (android.widget.Button)4 AlertDialog (android.support.v7.app.AlertDialog)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 EditTextPreference (android.support.v7.preference.EditTextPreference)2 TwoStatePreference (android.support.v7.preference.TwoStatePreference)2 EditText (android.widget.EditText)2 ProgressBar (android.widget.ProgressBar)2 Engine (com.frostwire.android.gui.services.Engine)2 File (java.io.File)2 IOException (java.io.IOException)2 AlertDialog (android.app.AlertDialog)1 ClipboardManager (android.content.ClipboardManager)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1