Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:com.klick.plugins.listviewalert.ListViewAlert.java

public void loadList(final JSONArray thelist, final CallbackContext callbackContext) {
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            List<String> list = new ArrayList<String>();
            // we start with index 1 because index 0 is the title
            for (int x = 1; x < thelist.length(); x++) {
                try {
                    list.add(thelist.getString(x));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*w ww .ja  va  2  s  .c  o m*/
            }
            CharSequence[] items = list.toArray(new CharSequence[list.size()]);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(cordova.getActivity(), android.R.style.Theme_Holo_Dialog));
            try {
                builder.setTitle(thelist.getString(0));
                // builder.setMessage( "This is a hardcoded message to try whether or not this is feasible!");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // index 0 contains the title
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.dismiss();
                    // we +1 to item because item starts from 0, but from
                    // thelist[0], that was the title...
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, item + 1));
                    //callbackContext.sendPluginResult(pluginResult)
                }
            });
            AlertDialog alert = builder.create();
            alert.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            alert.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:ch.fixme.status.Main.java

private AlertDialog createHsDialog() {
    // Construct hackerspaces list
    try {//from   ww w .java2 s.  c o  m
        JSONObject obj = new JSONObject(mResultDir);
        JSONArray arr = obj.names();
        int len = obj.length();
        String[] names = new String[len];
        final ArrayList<String> url = new ArrayList<String>(len);
        for (int i = 0; i < len; i++) {
            names[i] = arr.getString(i);
        }
        Arrays.sort(names, 0, len, String.CASE_INSENSITIVE_ORDER);
        for (int i = 0; i < len; i++) {
            url.add(i, obj.getString(names[i]));
        }

        // Create the dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
        builder.setTitle(R.string.choose_hs).setItems(names, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                setIntent(null);
                Editor edit = mPrefs.edit();
                edit.putString(PREF_API_URL, url.get(which));
                getApiTask = new GetApiTask();
                getApiTask.execute(url.get(which));
                edit.commit();
            }
        });
        return builder.create();
    } catch (Exception e) {
        e.printStackTrace();
        showError(e.getClass().getCanonicalName(), e.getLocalizedMessage() + getString(R.string.error_generic));
        return null;
    }
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void combineTrainAndPsnDetails() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();//  ww w .java 2  s  . c o  m
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    //Combine both Train & Passenger details table into a single LinearLayout and add it to FrameLayout
    LinearLayout ll = new LinearLayout(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);
    textViewPsnDtls.setText("Passenger Details");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTableLayoutTrn);
    ll.addView(textViewPsnDtls);
    ll.addView(mTableLayoutPsn);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
    if (isWaitingList && !mPNRList.contains(mPNRNumber)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Track this PNR?");
        builder.setMessage("Would you like this PNR to be tracked for status change?");
        builder.setPositiveButton("Track", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //save the pnr
                pnrDB.addPNRToTrack(mPNRNumber);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("No thanks", null);
        builder.create().show();
    }

}

From source file:com.bringcommunications.etherpay.SendActivity.java

private void dsp_txid_and_exit() {
    /*/*from  w  w  w  .ja v  a  2  s .  c o m*/
    TextView txid_view = (TextView) findViewById(R.id.txid);
    txid_view.setText(txid);
    if (auto_pay.equals("true")) {
      String msg = txid.isEmpty() ? "transaction failed" : "your transaction was sent successfully";
      Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
      NavUtils.navigateUpFromSameTask(context);
      this.finish();
    } else
    */
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        String title = txid.isEmpty() ? "Error" : "Transaction Sent";
        String msg = txid.isEmpty()
                ? "An error occurred while attempting this transaction -- press OK to continue"
                : "your transaction was sent successfully -- press OK to continue";
        builder.setTitle(title);
        builder.setMessage(msg);
        builder.setCancelable(true);
        builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
                NavUtils.navigateUpFromSameTask(context);
                context.finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Builds and shows a native Android alert with given Strings
 * /*from   w w  w .ja va2s.co  m*/
 * @param message
 *           The message the alert should display
 * @param title
 *           The title of the alert
 * @param buttonLabel
 *           The label of the button
 * @param callbackContext
 *           The callback context
 */
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(true);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            dlg.create();
            dlg.show();
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:net.heroicefforts.viable.android.BugReporterActivity.java

/**
 * Issue already exists.  Now prompt the user whether they want to add an additional comment.
 *  /*from  w w w .  ja  va  2s.c o  m*/
 * @param issue the defect
 */
private void showSupplementDialog(Issue issue) {
    if (Config.LOGD)
        Log.d(TAG, "Prompting user to comment on existing issue '" + issue.getIssueId() + "'.");
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.bug_comment);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            comment = true;
        }
    });
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.setMessage(getString(R.string.bug_comment_prompt).replaceAll("\\{appName\\}", issue.getAppName()));
    builder.create().show();
}

From source file:com.example.zf_android.activity.MerchantEdit.java

private void show3Dialog(int type, final String uri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MerchantEdit.this);
    final String[] items = getResources().getStringArray(R.array.apply_detail_view);

    MerchantEdit.this.type = type;
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override//from  ww  w .  j  a va 2 s . c  o m
        public void onClick(DialogInterface dialog, int which) {

            switch (which) {
            case 0: {

                AlertDialog.Builder build = new AlertDialog.Builder(MerchantEdit.this);
                LayoutInflater factory = LayoutInflater.from(MerchantEdit.this);
                final View textEntryView = factory.inflate(R.layout.show_view, null);
                build.setView(textEntryView);
                final ImageView view = (ImageView) textEntryView.findViewById(R.id.imag);
                //               ImageCacheUtil.IMAGE_CACHE.get(uri, view);
                ImageLoader.getInstance().displayImage(uri, view, options);
                build.create().show();
                break;
            }

            case 1: {

                Intent intent;
                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                } else {
                    intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                }
                startActivityForResult(intent, REQUEST_UPLOAD_IMAGE);
                break;
            }
            case 2: {
                String state = Environment.getExternalStorageState();
                if (state.equals(Environment.MEDIA_MOUNTED)) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                    if (!outDir.exists()) {
                        outDir.mkdirs();
                    }
                    File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
                    photoPath = outFile.getAbsolutePath();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile));
                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                    startActivityForResult(intent, REQUEST_TAKE_PHOTO);
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_no_sdcard));
                }
                break;
            }
            }
        }
    });

    builder.show();
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java

private void showAlertDialog(String alertMessage) {
    AlertDialog.Builder builder = new AlertDialog.Builder(OpenHABWidgetListActivity.this);
    builder.setMessage(alertMessage).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }/*from w ww. j av  a  2 s . c om*/
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Select/* w ww  .  j  a  v  a2  s . co m*/
 * 
 * @param title
 * @param text
 * @return
 */
public int showAndroidSelect(final String title, final String text[]) {
    Runnable showSelect = new Runnable() {
        public void run() {
            final AlertDialog.Builder builder = new AlertDialog.Builder(LGameActivity.this);
            builder.setTitle(title);
            builder.setItems(text, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    androidSelect = item;
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    androidSelect = -1;
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    };
    runOnUiThread(showSelect);
    return androidSelect;
}

From source file:com.kii.world.MainActivity.java

public void onListItemClick(ListView l, View v, final int position, long id) {

    // build the alert
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Would you like to remove this item?").setCancelable(true)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                // if the user chooses 'yes',
                public void onClick(DialogInterface dialog, int id) {

                    // perform the delete action on the tapped
                    // object
                    MainActivity.this.performDelete(position);
                }//from   w ww.  ja  v  a  2  s . c om
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                // if the user chooses 'no'
                public void onClick(DialogInterface dialog, int id) {

                    // simply dismiss the dialog
                    dialog.cancel();
                }
            });

    // show the dialog
    builder.create().show();

}