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:ac.robinson.bettertogether.ConnectionSetupActivity.java

private boolean cameraPermissionGranted() {
    if (ContextCompat.checkSelfPermission(ConnectionSetupActivity.this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

        if (!mHasRequestedCameraPermission) {
            mHasRequestedCameraPermission = true;

            if (ActivityCompat.shouldShowRequestPermissionRationale(ConnectionSetupActivity.this,
                    Manifest.permission.CAMERA)) {
                AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
                builder.setTitle(R.string.title_camera_access);
                builder.setMessage(R.string.hint_enable_camera_access);
                builder.setPositiveButton(R.string.hint_ask_again_permissions,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(ConnectionSetupActivity.this,
                                        new String[] { Manifest.permission.CAMERA }, CAMERA_PERMISSION_RESULT);
                            }/*from   www . j  a  v  a  2  s . c om*/
                        });
                builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_camera,
                                Toast.LENGTH_LONG).show();
                        restartCaptureManager(); // reset capture UI and try again
                    }
                });
                builder.show();
            } else {
                ActivityCompat.requestPermissions(ConnectionSetupActivity.this,
                        new String[] { Manifest.permission.CAMERA }, CAMERA_PERMISSION_RESULT);
            }
        }
        return false;
    }
    return true;
}

From source file:com.phonegap.Notification.java

/**
 * Builds and shows a native Android confirm dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
 * // www .j av a2 s .  c o m
 * @param message       The message the dialog should display
 * @param title       The title of the dialog
 * @param buttonLabels    A comma separated list of button labels (Up to 3 buttons)
 * @param callbackId   The callback id
 */
public synchronized void confirm(final String message, final String title, String buttonLabels,
        final String callbackId) {

    final PhonegapActivity ctx = this.ctx;
    final Notification notification = this;
    final String[] fButtons = buttonLabels.split(",");

    Runnable runnable = new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            // First button
            if (fButtons.length > 0) {
                dlg.setPositiveButton(fButtons[0], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
                    }
                });
            }

            // Second button
            if (fButtons.length > 1) {
                dlg.setNeutralButton(fButtons[1], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
                    }
                });
            }

            // Third button
            if (fButtons.length > 2) {
                dlg.setNegativeButton(fButtons[2], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
                    }
                });
            }

            dlg.create();
            dlg.show();
        };
    };
    this.ctx.runOnUiThread(runnable);
}

From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java

private boolean locationPermissionGranted() {
    if (ContextCompat.checkSelfPermission(ConnectionSetupActivity.this,
            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(ConnectionSetupActivity.this,
                Manifest.permission.ACCESS_COARSE_LOCATION)) {

            AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
            builder.setTitle(R.string.title_coarse_location_access);
            builder.setMessage(R.string.hint_enable_coarse_location_access);
            builder.setPositiveButton(R.string.hint_ask_again_permissions,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(ConnectionSetupActivity.this,
                                    new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                                    COARSE_LOCATION_PERMISSION_RESULT);
                        }//  w w  w  . j  ava 2s .c  o  m
                    });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                            Toast.LENGTH_LONG).show();
                    restartCaptureManager(); // reset capture UI and try again
                }
            });
            builder.show();
        } else {
            ActivityCompat.requestPermissions(ConnectionSetupActivity.this,
                    new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                    COARSE_LOCATION_PERMISSION_RESULT);
        }
        return false;
    }
    return true;
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

/**
 * Called when excel export task is done.
 * /*from  w  w  w. j  a v  a 2  s  .co  m*/
 * @param filePath
 */
private void onGameSetExportedToExcelFile(String filePath) {
    // should never happen
    if (filePath == null) {
        UIHelper.showSimpleRichTextDialog(this, this.getString(R.string.msgDbExportFailed),
                this.getString(R.string.titleDbExportFailed));
    }

    else {
        this.tempExcelFilePath = filePath;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(this.getString(R.string.titleGameSetExportedToExcelFile));
        builder.setMessage(Html.fromHtml(this.getText(R.string.msgGameSetExportedToExcelFile).toString()));
        builder.setPositiveButton(this.getString(R.string.btnOk), this.exportExcelByEmailDialogClickListener);
        builder.setNegativeButton(this.getString(R.string.btnCancel),
                this.exportExcelByEmailDialogClickListener);
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.show();
    }
}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

boolean replaySessionData(String sessionName) {
    BufferedReader logReader = null;

    // Open a file for saving data
    try {/* w w w. ja  v a2  s  .  c  om*/
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()) {
            File gpxfile = new File(root, sessionName);
            FileReader gpxreader = new FileReader(gpxfile); // open for append
            logReader = new BufferedReader(gpxreader);

            String lineToParse;
            while ((lineToParse = logReader.readLine()) != null) {
                Log.i("SensorData", lineToParse);

                if (lineToParse.contains("ECG,")) {

                    try {
                        String[] tokens = lineToParse.split(",");

                        if (tokens.length == 7) {
                            ShimmerData shimmerData = new ShimmerData(SPINEFunctionConstants.SHIMMER,
                                    SPINESensorConstants.SHIMMER_ECG_SENSOR, (byte) 0);
                            shimmerData.setFunctionCode(SPINEFunctionConstants.SHIMMER);
                            shimmerData.sensorCode = SPINESensorConstants.SHIMMER_ECG_SENSOR;
                            shimmerData.ecgLaLL = 2000 + (int) Float.parseFloat(tokens[5].trim());
                            shimmerData.ecgRaLL = 2000;
                            shimmerData.timestamp = Integer.parseInt(tokens[1].trim());
                            this.received(shimmerData);
                        }
                        if (tokens.length == 6) {
                            ShimmerData shimmerData = new ShimmerData(SPINEFunctionConstants.SHIMMER,
                                    SPINESensorConstants.SHIMMER_ECG_SENSOR, (byte) 0);
                            shimmerData.setFunctionCode(SPINEFunctionConstants.SHIMMER);
                            shimmerData.sensorCode = SPINESensorConstants.SHIMMER_ECG_SENSOR;
                            shimmerData.ecgLaLL = 2000 + Integer.parseInt(tokens[4].trim());
                            shimmerData.ecgRaLL = 2000;
                            shimmerData.timestamp = Integer.parseInt(tokens[2].trim());
                            this.received(shimmerData);
                        }
                        if (tokens.length == 5) {
                            ShimmerData shimmerData = new ShimmerData(SPINEFunctionConstants.SHIMMER,
                                    SPINESensorConstants.SHIMMER_ECG_SENSOR, (byte) 0);
                            shimmerData.setFunctionCode(SPINEFunctionConstants.SHIMMER);
                            shimmerData.sensorCode = SPINESensorConstants.SHIMMER_ECG_SENSOR;
                            shimmerData.ecgLaLL = 2000 + Integer.parseInt(tokens[3].trim());
                            shimmerData.ecgRaLL = 2000;
                            shimmerData.timestamp = Integer.parseInt(tokens[2].trim());
                            this.received(shimmerData);
                        }

                    } catch (Exception e) {
                    }
                }

            }

        } else {
            Log.e(TAG, "Could not open file ");
            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.setTitle("ERROR");
            alert.setMessage("Cannot open to file");
            alert.show();

        }
    } catch (IOException e) {
        Log.e(TAG, "Could not open file " + e.getMessage());
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("ERROR");
        alert.setMessage("Cannot write to file");
        alert.show();

    }

    try {
        logReader.close();
    } catch (IOException e) {
        Log.e(TAG, "Could not close file " + e.getMessage());
    }

    return true;
}

From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java

public void Image_Picker_Dialog() {

    AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
    myAlertDialog.setTitle("Pictures Option");
    myAlertDialog.setMessage("Select Picture Mode");

    myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            /* Utility.pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
             Utility.pictureActionIntent.setType("image*//*");
                                                          Utility.pictureActionIntent.putExtra("return-data", true);
                                                          startActivityForResult(Utility.pictureActionIntent, Utility.GALLERY_PICTURE);*/
            Intent i7 = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i7, Utility.GALLERY_PICTURE);
        }//from   ww w.j av a2  s .  c  o  m
    });

    myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            /*Utility.pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(Utility.pictureActionIntent, Utility.CAMERA_PICTURE);*/

            Intent cameraIntent1 = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent1, Utility.CAMERA_PICTURE);

        }
    });
    myAlertDialog.show();

}

From source file:me.willowcheng.makerthings.ui.OpenHABWidgetListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d(TAG, "onActivityCreated()");
    Log.d(TAG, "isAdded = " + isAdded());
    mActivity = (OpenHABMainActivity) getActivity();
    openHABWidgetDataSource = new OpenHABWidgetDataSource();
    openHABWidgetAdapter = new OpenHABWidgetAdapter(getActivity(), R.layout.openhabwidgetlist_genericitem,
            widgetList);/* w  w w  . j a v a  2  s  .c  om*/
    getListView().setAdapter(openHABWidgetAdapter);
    openHABBaseUrl = mActivity.getOpenHABBaseUrl();
    openHABUsername = mActivity.getOpenHABUsername();
    openHABPassword = mActivity.getOpenHABPassword();
    openHABWidgetAdapter.setOpenHABUsername(openHABUsername);
    openHABWidgetAdapter.setOpenHABPassword(openHABPassword);
    openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl);
    openHABWidgetAdapter.setAsyncHttpClient(mAsyncHttpClient);
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "Widget clicked " + String.valueOf(position));
            OpenHABWidget openHABWidget = openHABWidgetAdapter.getItem(position);
            if (openHABWidget.hasLinkedPage()) {
                // Widget have a page linked to it
                String[] splitString;
                splitString = openHABWidget.getLinkedPage().getTitle().split("\\[|\\]");
                if (OpenHABWidgetListFragment.this.widgetSelectedListener != null) {
                    widgetSelectedListener.onWidgetSelectedListener(openHABWidget.getLinkedPage(),
                            OpenHABWidgetListFragment.this);
                }
                //                        navigateToPage(openHABWidget.getLinkedPage().getLink(), splitString[0]);
                mOldSelectedItem = position;
            } else {
                Log.d(TAG, String.format("Click on item with no linked page, reverting selection to item %d",
                        mOldSelectedItem));
                // If an item without a linked page is clicked this will clear the selection
                // and revert it to previously selected item (if any) when CHOICE_MODE_SINGLE
                // is switched on for widget listview in multi-column mode on tablets
                getListView().clearChoices();
                getListView().requestLayout();
                getListView().setItemChecked(mOldSelectedItem, true);
            }
        }

    });
    getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "Widget long-clicked " + String.valueOf(position));
            OpenHABWidget openHABWidget = openHABWidgetAdapter.getItem(position);
            Log.d(TAG, "Widget type = " + openHABWidget.getType());
            if (openHABWidget.getType().equals("Switch") || openHABWidget.getType().equals("Selection")
                    || openHABWidget.getType().equals("Colorpicker")) {
                selectedOpenHABWidget = openHABWidget;
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(R.string.nfc_dialog_title);
                OpenHABNFCActionList nfcActionList = new OpenHABNFCActionList(selectedOpenHABWidget);
                builder.setItems(nfcActionList.getNames(), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent writeTagIntent = new Intent(getActivity().getApplicationContext(),
                                OpenHABWriteTagActivity.class);
                        writeTagIntent.putExtra("sitemapPage", displayPageUrl);
                        writeTagIntent.putExtra("item", selectedOpenHABWidget.getItem().getName());
                        writeTagIntent.putExtra("itemType", selectedOpenHABWidget.getItem().getType());
                        OpenHABNFCActionList nfcActionList = new OpenHABNFCActionList(selectedOpenHABWidget);
                        writeTagIntent.putExtra("command", nfcActionList.getCommands()[which]);
                        startActivityForResult(writeTagIntent, 0);
                        Util.overridePendingTransition(getActivity(), false);
                        selectedOpenHABWidget = null;
                    }
                });
                builder.show();
                return true;
            }
            return true;
        }
    });
    if (getResources().getInteger(R.integer.pager_columns) > 1) {
        Log.d(TAG, "More then 1 column, setting selector on");
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
}

From source file:com.ved.musicmapapp.LoginAcitivity.java

public void showDialogRestart() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Message");
    builder.setMessage("Unable to log into app. Please try again!");
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override//from  w  w w.j ava2  s .co m
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            edt = prefs.edit();
            edt.putString("FB_ID", "");
            edt.commit();
            finish();
        }
    });
    builder.setNeutralButton("Try again", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            edt = prefs.edit();
            edt.putString("FB_ID", "");
            edt.commit();
            finish();
            Intent i = new Intent(LoginAcitivity.this, LoginAcitivity.class);
            startActivity(i);
        }
    });
    builder.show();
}

From source file:cm.aptoide.pt.ManageRepos.java

private void askAddDefaultRepo() {
    final String uri = Constants.APPS_REPO;
    AlertDialog.Builder defaultDialog = new AlertDialog.Builder(theme);
    defaultDialog.setTitle(getString(R.string.attention));
    defaultDialog.setIcon(R.drawable.ic_menu_info_details);
    defaultDialog.setMessage(getString(R.string.add_default_repo_confirm) + uri);
    defaultDialog.setPositiveButton(getText(R.string.yes), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            addDisplayRepo(new ViewRepository(uri));
            initReposList();//  w  w w  . j  a  v  a  2  s  .c  o  m
            return;
        }
    });
    defaultDialog.setNegativeButton(getText(R.string.no), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            initReposList();
            return;
        }
    });
    defaultDialog.show();
}

From source file:com.googlecode.android_scripting.ZipExtractorTask.java

private Replace showDialog(final String name) {
    final FutureResult<Replace> mResult = new FutureResult<Replace>();

    MainThread.run(mContext, new Runnable() {
        @Override//  w w w . j  ava  2s.c o m
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(String.format("Script \"%s\" already exist.", name));
            builder.setMessage(String.format("Do you want to replace script \"%s\" ?", name));

            DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Replace result = Replace.SKIPALL;
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:
                        result = Replace.YES;
                        break;
                    case DialogInterface.BUTTON_NEGATIVE:
                        result = Replace.NO;
                        break;
                    case DialogInterface.BUTTON_NEUTRAL:
                        result = Replace.YESTOALL;
                        break;
                    }
                    mResult.set(result);
                    dialog.dismiss();
                }
            };
            builder.setNegativeButton("Skip", buttonListener);
            builder.setPositiveButton("Replace", buttonListener);
            builder.setNeutralButton("Replace All", buttonListener);

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    mResult.set(Replace.SKIPALL);
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    try {
        return mResult.get();
    } catch (InterruptedException e) {
        Log.e(e);
    }
    return null;
}