Search in sources :

Example 91 with AlertDialog

use of android.support.v7.app.AlertDialog in project Pix-Art-Messenger by kriztan.

the class XmppActivity method quickEdit.

@SuppressLint("InflateParams")
private void quickEdit(final String previousValue, final OnValueEdited callback, final int hint, boolean password) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View view = getLayoutInflater().inflate(R.layout.quickedit, null);
    final EditText editor = view.findViewById(R.id.editor);
    if (password) {
        editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        builder.setPositiveButton(R.string.accept, null);
    } else {
        builder.setPositiveButton(R.string.ok, null);
    }
    if (hint != 0) {
        editor.setHint(hint);
    }
    editor.requestFocus();
    editor.setText("");
    if (previousValue != null) {
        editor.getText().append(previousValue);
    }
    builder.setView(view);
    builder.setNegativeButton(R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    View.OnClickListener clickListener = v -> {
        String value = editor.getText().toString();
        if (!value.equals(previousValue) && value.trim().length() > 0) {
            String error = callback.onValueEdited(value);
            if (error != null) {
                editor.setError(error);
                return;
            }
        }
        dialog.dismiss();
    };
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) Builder(android.app.AlertDialog.Builder) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) ImageView(android.widget.ImageView) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) Account(de.pixart.messenger.entities.Account) IBinder(android.os.IBinder) Manifest(android.Manifest) PowerManager(android.os.PowerManager) SessionID(net.java.otr4j.session.SessionID) Jid(de.pixart.messenger.xmpp.jid.Jid) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Handler(android.os.Handler) Map(java.util.Map) ClipboardManager(android.content.ClipboardManager) ServiceConnection(android.content.ServiceConnection) View(android.view.View) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) TargetApi(android.annotation.TargetApi) Log(android.util.Log) XmppConnectionBinder(de.pixart.messenger.services.XmppConnectionService.XmppConnectionBinder) ConnectivityManager(android.net.ConnectivityManager) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) AsyncTask(android.os.AsyncTask) ContextCompat(android.support.v4.content.ContextCompat) InputType(android.text.InputType) BarcodeProvider(de.pixart.messenger.services.BarcodeProvider) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AppCompatActivity(android.support.v7.app.AppCompatActivity) DisplayMetrics(android.util.DisplayMetrics) FileNotFoundException(java.io.FileNotFoundException) Presences(de.pixart.messenger.entities.Presences) List(java.util.List) Contact(de.pixart.messenger.entities.Contact) ActivityNotFoundException(android.content.ActivityNotFoundException) PgpEngine(de.pixart.messenger.crypto.PgpEngine) CryptoHelper(de.pixart.messenger.utils.CryptoHelper) AvatarService(de.pixart.messenger.services.AvatarService) Context(android.content.Context) OnKeyStatusUpdated(de.pixart.messenger.xmpp.OnKeyStatusUpdated) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Pair(android.util.Pair) Intent(android.content.Intent) SystemClock(android.os.SystemClock) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Conversation(de.pixart.messenger.entities.Conversation) R(de.pixart.messenger.R) Toast(android.widget.Toast) Settings(android.provider.Settings) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) Config(de.pixart.messenger.Config) ActionBar(android.support.v7.app.ActionBar) DialogInterface(android.content.DialogInterface) Message(de.pixart.messenger.entities.Message) ExceptionHelper(de.pixart.messenger.utils.ExceptionHelper) ComponentName(android.content.ComponentName) OnUpdateBlocklist(de.pixart.messenger.xmpp.OnUpdateBlocklist) Point(android.graphics.Point) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) Collections(java.util.Collections) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) EditText(android.widget.EditText) Resources(android.content.res.Resources) Builder(android.app.AlertDialog.Builder) Builder(android.app.AlertDialog.Builder) ImageView(android.widget.ImageView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 92 with AlertDialog

use of android.support.v7.app.AlertDialog in project Pix-Art-Messenger by kriztan.

the class StartUI method onPermissionsDenied.

@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
    Log.d(Config.LOGTAG, "Permissions denied:" + requestCode);
    AlertDialog dialog = new AlertDialog.Builder(this).setMessage(getString(R.string.request_permissions_message_again)).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package", getPackageName(), null);
            intent.setData(uri);
            startActivity(intent);
        }
    }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    }).create();
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) Uri(android.net.Uri)

Example 93 with AlertDialog

use of android.support.v7.app.AlertDialog in project Pix-Art-Messenger by kriztan.

the class SettingsActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    multiAccountPreference = mSettingsFragment.findPreference("enable_multi_accounts");
    if (multiAccountPreference != null) {
        isMultiAccountChecked = ((CheckBoxPreference) multiAccountPreference).isChecked();
    }
    if (Config.FORCE_ORBOT) {
        PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
        PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
        if (connectionOptions != null) {
            expert.removePreference(connectionOptions);
        }
    }
    PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
    // 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) {
            Log.d(Config.LOGTAG, "resolving choice " + choices[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);
    }
    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 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));
                }
                if (selectedItems.size() > 0)
                    ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
                else {
                    ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
                }
            });
            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 exportLogsPreference = mSettingsFragment.findPreference("export_logs");
    if (exportLogsPreference != null) {
        exportLogsPreference.setOnPreferenceClickListener(preference -> {
            if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
                startExport();
            }
            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());
    }
    final Preference enableMultiAccountsPreference = mSettingsFragment.findPreference("enable_multi_accounts");
    if (enableMultiAccountsPreference != null) {
        Log.d(Config.LOGTAG, "Multi account checkbox checked: " + isMultiAccountChecked);
        if (isMultiAccountChecked) {
            enableMultiAccountsPreference.setEnabled(false);
        /*
            if (xmppConnectionServiceBound) { // todo doesn't work --> it seems the service is never bound
                final List<Account> accounts = xmppConnectionService.getAccounts();
                Log.d(Config.LOGTAG, "Disabled multi account: Number of accounts " + accounts.size());
                if (accounts.size() > 1) {
                    Log.d(Config.LOGTAG, "Disabled multi account not possible because you have more than one account");
                    enableMultiAccountsPreference.setEnabled(false);
                } else {
                    Log.d(Config.LOGTAG, "Disabled multi account possible because you have one account");
                    enableMultiAccountsPreference.setEnabled(true);
                }
            } else {
                enableMultiAccountsPreference.setEnabled(false);
            }
            */
        } else {
            enableMultiAccountsPreference.setEnabled(true);
            enableMultiAccountsPreference.setOnPreferenceClickListener(preference -> {
                enableMultiAccounts();
                return true;
            });
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PreferenceScreen(android.preference.PreferenceScreen) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) KeyStoreException(java.security.KeyStoreException) MemorizingTrustManager(de.pixart.messenger.services.MemorizingTrustManager) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Example 94 with AlertDialog

use of android.support.v7.app.AlertDialog in project Pix-Art-Messenger by kriztan.

the class SettingsActivity method deleteOmemoIdentities.

private boolean deleteOmemoIdentities() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.pref_delete_omemo_identities);
    final List<CharSequence> accounts = new ArrayList<>();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.isEnabled()) {
            accounts.add(account.getJid().toBareJid().toString());
        }
    }
    final boolean[] checkedItems = new boolean[accounts.size()];
    builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, isChecked) -> {
        checkedItems[which] = isChecked;
        final AlertDialog alertDialog = (AlertDialog) dialog;
        for (boolean item : checkedItems) {
            if (item) {
                alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
                return;
            }
        }
        alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
    });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.delete_selected_keys, (dialog, which) -> {
        for (int i = 0; i < checkedItems.length; ++i) {
            if (checkedItems[i]) {
                try {
                    Jid jid = Jid.fromString(accounts.get(i).toString());
                    Account account = xmppConnectionService.findAccountByJid(jid);
                    if (account != null) {
                        account.getAxolotlService().regenerateKeys(true);
                    }
                } catch (InvalidJidException e) {
                // 
                }
            }
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) ArrayList(java.util.ArrayList)

Example 95 with AlertDialog

use of android.support.v7.app.AlertDialog in project ForPDA by RadiationX.

the class PaginationHelper method selectPageDialog.

public void selectPageDialog() {
    if (context == null)
        context = App.getActivity();
    final int[] pages = new int[pagination.getAll()];
    for (int i = 0; i < pagination.getAll(); i++) pages[i] = i + 1;
    final ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setFastScrollEnabled(true);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setAdapter(new PaginationAdapter(context, pages));
    listView.setItemChecked(pagination.getCurrent() - 1, true);
    listView.setSelection(pagination.getCurrent() - 1);
    AlertDialog dialog = new AlertDialog.Builder(context).setView(listView).show();
    if (dialog.getWindow() != null)
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    listView.setOnItemClickListener((adapterView, view1, i2, l) -> {
        if (listView.getTag() != null && !((Boolean) listView.getTag())) {
            return;
        }
        selectPage(i2 * pagination.getPerPage());
        dialog.cancel();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ListView(android.widget.ListView)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)410 DialogInterface (android.content.DialogInterface)274 View (android.view.View)219 TextView (android.widget.TextView)165 Intent (android.content.Intent)117 EditText (android.widget.EditText)86 ImageView (android.widget.ImageView)69 Button (android.widget.Button)68 LayoutInflater (android.view.LayoutInflater)59 RecyclerView (android.support.v7.widget.RecyclerView)54 NonNull (android.support.annotation.NonNull)52 AdapterView (android.widget.AdapterView)51 SuppressLint (android.annotation.SuppressLint)50 ArrayList (java.util.ArrayList)49 Bundle (android.os.Bundle)47 ListView (android.widget.ListView)42 Context (android.content.Context)35 SharedPreferences (android.content.SharedPreferences)35 Uri (android.net.Uri)32 LinearLayout (android.widget.LinearLayout)30