Example usage for android.app AlertDialog.Builder show

List of usage examples for android.app AlertDialog.Builder show

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder show.

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.chaosinmotion.securechat.fragments.OnboardingLoginAccount.java

@Override
public void doNext() {
    String uname = username.getText().toString();
    String pwd = password.getText().toString();
    final SCNetworkCredentials creds = new SCNetworkCredentials(uname);
    creds.setPasswordFromClearText(pwd);

    SCNetwork.get().doLogin(creds, new SCNetwork.LoginCallback() {
        @Override//from  w  w w  .jav  a 2 s.co m
        public void loginResult(int reason) {
            if (reason == SCNetwork.LOGIN_SUCCESS) {
                /*
                 *  Login success. Register device
                 */

                SCRSAManager.shared().setCredentials(creds.getUsername(), creds.getPassword());
                SCRSAManager.shared().encodeSecureData(getActivity());

                try {
                    /*
                     *  Register device
                     */
                    JSONObject d = new JSONObject();
                    d.put("deviceid", SCRSAManager.shared().getDeviceUUID());
                    d.put("pubkey", SCRSAManager.shared().getPublicKey());

                    SCNetwork.get().request("device/adddevice", d, this, new SCNetwork.ResponseInterface() {
                        @Override
                        public void responseResult(SCNetwork.Response response) {
                            if (response.isSuccess()) {
                                SCMessageQueue.get().startQueue(getActivity());
                                wizardInterface.transitionToFragment(new OnboardingFinished());
                            }
                        }
                    });
                } catch (JSONException ex) {
                }
            } else if (reason == SCNetwork.LOGIN_FAILURE) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage(R.string.login_error_message);
                builder.setTitle(R.string.login_error_title);
                builder.setNegativeButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Ignore
                    }
                });
                builder.show();
            }
        }
    });
}

From source file:com.mendhak.gpslogger.common.PrefsIO.java

private void ReAskFileName() {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.FileExists);
    builder.setMessage(R.string.AskAnotherFile);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override/* ww w  .j  av a2 s . c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            AskFileName();
        }
    });
    builder.show();
}

From source file:in.shick.diode.common.Common.java

/**
 * Helper function to display a list of URLs.
 * @param theContext The current application context.
 * @param settings The settings to use regarding the browser component.
 * @param theItem The ThingInfo item to get URLs from.
 *//*  w  w  w  .  j a va 2  s .com*/
public static void showLinksDialog(final Context theContext, final RedditSettings settings,
        final ThingInfo theItem) {
    assert (theContext != null);
    assert (theItem != null);
    assert (settings != null);
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = theItem.getUrls();
    for (MarkdownURL vtUrl : vtUrls) {
        urls.add(vtUrl.url);
    }
    ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext,
            android.R.layout.select_dialog_item, vtUrls) {
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv;
            if (convertView == null) {
                tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                        .inflate(android.R.layout.select_dialog_item, null);
            } else {
                tv = (TextView) convertView;
            }

            String url = getItem(position).url;
            String anchorText = getItem(position).anchorText;
            //                        if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText);

            Drawable d = null;
            try {
                d = theContext.getPackageManager()
                        .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            } catch (PackageManager.NameNotFoundException ignore) {
            }
            if (d != null) {
                d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                tv.setCompoundDrawablePadding(10);
                tv.setCompoundDrawables(d, null, null, null);
            }

            final String telPrefix = "tel:";
            if (url.startsWith(telPrefix)) {
                url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
            }

            if (anchorText != null)
                tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
            else
                tv.setText(Html.fromHtml(url));

            return tv;
        }
    };

    AlertDialog.Builder b = new AlertDialog.Builder(
            new ContextThemeWrapper(theContext, settings.getDialogTheme()));

    DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            if (which >= 0) {
                Common.launchBrowser(settings, theContext, urls.get(which),
                        Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(),
                        settings.isSaveHistory());
            }
        }
    };

    b.setTitle(R.string.select_link_title);
    b.setCancelable(true);
    b.setAdapter(adapter, click);

    b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    b.show();
}

From source file:de.ub0r.android.lib.DonationHelper.java

/**
 * Show "donate" dialog.//from   w w w . j a v a  2  s. c  o m
 * 
 * @param context
 *            {@link Context}
 * @param title
 *            title
 * @param btnDonate
 *            button text for donate
 * @param btnNoads
 *            button text for "i did a donation"
 * @param messages
 *            messages for dialog body
 */
public static void showDonationDialog(final Activity context, final String title, final String btnDonate,
        final String btnNoads, final String[] messages) {
    final Intent marketIntent = Market.getInstallAppIntent(context, DONATOR_PACKAGE, null);

    String btnTitle = String.format(btnDonate, "Play Store");

    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String m : messages) {
        sb.append(m);
        sb.append("\n");
    }
    sb.delete(sb.length() - 1, sb.length());
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            try {
                context.startActivity(marketIntent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show();
            }
        }
    });
    b.setNeutralButton(btnNoads, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                        "http://code.google.com/p/ub0rapps/downloads/list?" + "can=3&q=Product%3DDonator")));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show();
            }
        }
    });
    b.show();
}

From source file:org.cocos2dx.lib.CCUtils.java

static void showConfirmDialog(final String title, final String text, final String positiveButton,
        final String negativeButton, final long okFunc, final long cancelFunc) {
    nativeRetain(okFunc);/*  w  w w.jav  a  2 s .co m*/
    nativeRetain(cancelFunc);

    final Cocos2dxActivity act = (Cocos2dxActivity) Cocos2dxActivity.getContext();
    act.runOnUiThread(new Runnable() {
        public void run() {
            AlertDialog.Builder builder = new Builder(act);
            if (title != null)
                builder.setTitle(title);
            if (text != null)
                builder.setMessage(text);
            if (positiveButton != null) {
                builder.setPositiveButton(positiveButton, new OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        act.runOnGLThread(new Runnable() {
                            @Override
                            public void run() {
                                nativeExecuteCallFunc(okFunc);
                                nativeRelease(okFunc);
                            }
                        });
                    }
                });
            }
            if (negativeButton != null) {
                builder.setNegativeButton(negativeButton, new OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        act.runOnGLThread(new Runnable() {
                            @Override
                            public void run() {
                                nativeExecuteCallFunc(cancelFunc);
                                nativeRelease(cancelFunc);
                            }
                        });
                    }
                });
            }

            builder.show();
        }
    });
}

From source file:at.jclehner.rxdroid.BackupFragment.java

private void showExceptionDialog(Exception e) {
    final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
    ab.setTitle(R.string._title_error);/* w ww.  ja v a 2  s .c o m*/
    ab.setIcon(android.R.drawable.ic_dialog_alert);
    ab.setPositiveButton(android.R.string.ok, null);
    ab.setCancelable(true);

    ab.setMessage(Html
            .fromHtml("<tt>" + e.getClass().getSimpleName() + "</tt><br/>" + Util.escapeHtml(e.getMessage())));

    //ab.show(getFragmentManager(), "create_error");
    ab.show();
}

From source file:at.jclehner.rxdroid.BackupFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!getActivity().getIntent().getBooleanExtra(BackupActivity.EXTRA_NO_BACKUP_CREATION, false)) {
        final MenuItem item = menu.add(getString(R.string._title_create_backup))
                .setIcon(R.drawable.ic_action_add_box_white)
                .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override//from ww w  .j av  a2  s  .com
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        final String storageState = Backup.getStorageState();
                        if (Backup.StorageStateListener.isWritable(storageState)) {
                            try {
                                Backup.createBackup(null, null);
                                getLoaderManager().restartLoader(0, null, BackupFragment.this);
                            } catch (ZipException e) {
                                showExceptionDialog(e);
                            }
                        } else {
                            if (mShowDialogIfNotWriteable) {
                                final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
                                ab.setPositiveButton(android.R.string.ok, null);
                                ab.setMessage(R.string._msg_external_storage_not_writeable);
                                ab.setTitle(R.string._title_error);
                                ab.setIcon(android.R.drawable.ic_dialog_alert);

                                ab.show();
                                mShowDialogIfNotWriteable = false;
                            } else {
                                Toast.makeText(getActivity(), R.string._msg_external_storage_not_writeable,
                                        Toast.LENGTH_LONG);
                            }
                        }

                        return true;
                    }
                });

        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.github.barcodeeye.scan.CaptureActivity.java

/**
 * FIXME: This should be a glass compatible view (Card)
 *///  ww  w  . j  a  v a2s  .  co m
private void displayFrameworkBugMessageAndExit() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name));
    builder.setMessage(getString(R.string.msg_camera_framework_bug));
    builder.setPositiveButton(R.string.button_ok, new FinishListener(this));
    builder.setOnCancelListener(new FinishListener(this));
    builder.show();
}

From source file:br.com.testmaster.view.activity.LeadDetailActivity.java

/**
 *Preenche as views com os dados retornados.
 *///from  w  w w. j  ava2  s .  com
void fillViews() {
    mToolbar.setTitle(mDetail.get_embedded().getUser().getName());
    mUserIconView.setBackgroundResource(R.mipmap.account_green);
    mAddressIconView.setBackgroundResource(R.mipmap.map_green);
    Address ad = mDetail.get_embedded().getAddress();
    mTitle.setText(mDetail.getTitle());
    mUser.setText(mDetail.get_embedded().getUser().getName());
    mNeighborhoodCity.setText(ad.getNeighborhood() + " - " + ad.getCity());
    mDistanceDesc.setText("a " + mDetail.getIntDistance() / 1000 + "Km de voc");
    mPhone.setText(mDetail.get_embedded().getUser().get_embedded().getPhones().get(0).getNumber());
    mEmail.setText(mDetail.get_embedded().getUser().getEmail());

    mBtnCallPhone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CallApp.dialPhone(mDetail.get_embedded().getUser().get_embedded().getPhones().get(0).getNumber(),
                    LeadDetailActivity.this);
        }
    });
    mBtnWzp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String text = mDetail.get_embedded().getUser().getName() + " "
                    + mDetail.get_embedded().getUser().get_embedded().getPhones().get(0).getNumber();

            boolean ok = CallApp.shareWithWhatsApp(text, LeadDetailActivity.this);

            if (!ok) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(LeadDetailActivity.this);
                dialog.setMessage(R.string.wzp_not_available);
                dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface di, int arg) {
                        di.dismiss();
                    }
                });
                dialog.setTitle(LeadDetailActivity.this.getResources().getString(R.string.warning));
                dialog.show();
            }

        }
    });
    mRvListInfo = (RecyclerView) findViewById(R.id.rvListInfo);
    mRvListInfo.setLayoutManager(new LinearLayoutManager(this));
    mLeaInfoAdapter = new LeadDetailInfoAdapter(mDetail);
    mRvListInfo.setAdapter(mLeaInfoAdapter);
    mRvListInfo.setItemAnimator(new DefaultItemAnimator());
}

From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java

public void displayYesNoConfirmation(String title, String msg, final Runnable yesAction,
        final Runnable noAction) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            yesAction.run();/*ww w  .  jav  a 2s  .com*/
        }
    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            noAction.run();
        }
    }).setMessage(msg).setTitle(title);
    builder.show();

}