Search in sources :

Example 61 with Builder

use of android.app.AlertDialog.Builder in project Conversations by siacs.

the class XmppActivity method showInstallPgpDialog.

public void showInstallPgpDialog() {
    Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.openkeychain_required));
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setMessage(getText(R.string.openkeychain_required_long));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setNeutralButton(getString(R.string.restart), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (xmppConnectionServiceBound) {
                unbindService(mConnection);
                xmppConnectionServiceBound = false;
            }
            stopService(new Intent(XmppActivity.this, XmppConnectionService.class));
            finish();
        }
    });
    builder.setPositiveButton(getString(R.string.install), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Uri uri = Uri.parse("market://details?id=org.sufficientlysecure.keychain");
            Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri);
            PackageManager manager = getApplicationContext().getPackageManager();
            List<ResolveInfo> infos = manager.queryIntentActivities(marketIntent, 0);
            if (infos.size() > 0) {
                startActivity(marketIntent);
            } else {
                uri = Uri.parse("http://www.openkeychain.org/");
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(browserIntent);
            }
            finish();
        }
    });
    builder.create().show();
}
Also used : PackageManager(android.content.pm.PackageManager) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) OnClickListener(android.content.DialogInterface.OnClickListener) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) List(java.util.List) ArrayList(java.util.ArrayList) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 62 with Builder

use of android.app.AlertDialog.Builder in project Conversations by siacs.

the class XmppActivity method showPresenceSelectionDialog.

private void showPresenceSelectionDialog(Presences presences, final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.choose_presence));
    final String[] resourceArray = presences.toResourceArray();
    Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
    final Map<String, String> resourceTypeMap = typeAndName.first;
    final Map<String, String> resourceNameMap = typeAndName.second;
    final String[] readableIdentities = new String[resourceArray.length];
    final AtomicInteger selectedResource = new AtomicInteger(0);
    for (int i = 0; i < resourceArray.length; ++i) {
        String resource = resourceArray[i];
        if (resource.equals(contact.getLastResource())) {
            selectedResource.set(i);
        }
        String type = resourceTypeMap.get(resource);
        String name = resourceNameMap.get(resource);
        if (type != null) {
            if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
                readableIdentities[i] = UIHelper.tranlasteType(this, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            selectedResource.set(which);
        }
    });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]);
                conversation.setNextCounterpart(next);
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) Jid(eu.siacs.conversations.xmpp.jid.Jid) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(eu.siacs.conversations.entities.Contact) OnClickListener(android.content.DialogInterface.OnClickListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OnClickListener(android.content.DialogInterface.OnClickListener) Map(java.util.Map)

Example 63 with Builder

use of android.app.AlertDialog.Builder in project Conversations by siacs.

the class EditAccountActivity method onPreferencesFetched.

@Override
public void onPreferencesFetched(final Element prefs) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (mFetchingMamPrefsToast != null) {
                mFetchingMamPrefsToast.cancel();
            }
            AlertDialog.Builder builder = new Builder(EditAccountActivity.this);
            builder.setTitle(R.string.server_side_mam_prefs);
            String defaultAttr = prefs.getAttribute("default");
            final List<String> defaults = Arrays.asList("never", "roster", "always");
            final AtomicInteger choice = new AtomicInteger(Math.max(0, defaults.indexOf(defaultAttr)));
            builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    choice.set(which);
                }
            });
            builder.setNegativeButton(R.string.cancel, null);
            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    prefs.setAttribute("default", defaults.get(choice.get()));
                    xmppConnectionService.pushMamPreferences(mAccount, prefs);
                }
            });
            builder.create().show();
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) OnClickListener(android.view.View.OnClickListener) List(java.util.List)

Example 64 with Builder

use of android.app.AlertDialog.Builder in project Conversations by siacs.

the class EditAccountActivity method onCaptchaRequested.

@Override
public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
                mCaptchaDialog.dismiss();
            }
            final AlertDialog.Builder builder = new AlertDialog.Builder(EditAccountActivity.this);
            final View view = getLayoutInflater().inflate(R.layout.captcha, null);
            final ImageView imageView = (ImageView) view.findViewById(R.id.captcha);
            final EditText input = (EditText) view.findViewById(R.id.input);
            imageView.setImageBitmap(captcha);
            builder.setTitle(getString(R.string.captcha_required));
            builder.setView(view);
            builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String rc = input.getText().toString();
                    data.put("username", account.getUsername());
                    data.put("password", account.getPassword());
                    data.put("ocr", rc);
                    data.submit();
                    if (xmppConnectionServiceBound) {
                        xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, id, data);
                    }
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (xmppConnectionService != null) {
                        xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
                    }
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    if (xmppConnectionService != null) {
                        xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
                    }
                }
            });
            mCaptchaDialog = builder.create();
            mCaptchaDialog.show();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) Builder(android.app.AlertDialog.Builder) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 65 with Builder

use of android.app.AlertDialog.Builder in project Conversations by siacs.

the class EditAccountActivity method showWipePepDialog.

public void showWipePepDialog() {
    Builder builder = new Builder(this);
    builder.setTitle(getString(R.string.clear_other_devices));
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setMessage(getString(R.string.clear_other_devices_desc));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setPositiveButton(getString(R.string.accept), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mAccount.getAxolotlService().wipeOtherPepDevices();
        }
    });
    builder.create().show();
}
Also used : DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder)

Aggregations

Builder (android.app.AlertDialog.Builder)112 DialogInterface (android.content.DialogInterface)64 AlertDialog (android.app.AlertDialog)42 Intent (android.content.Intent)29 View (android.view.View)28 TextView (android.widget.TextView)25 OnClickListener (android.content.DialogInterface.OnClickListener)21 SuppressLint (android.annotation.SuppressLint)16 ArrayList (java.util.ArrayList)15 OnClickListener (android.view.View.OnClickListener)13 ImageView (android.widget.ImageView)13 Context (android.content.Context)12 AlertDialog (android.support.v7.app.AlertDialog)12 List (java.util.List)12 Bundle (android.os.Bundle)11 RelativeLayout (android.widget.RelativeLayout)10 Point (android.graphics.Point)9 ExpandableListView (android.widget.ExpandableListView)9 ImageButton (android.widget.ImageButton)7 EditText (android.widget.EditText)6