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.cricketkorner.cricket.VitamioListActivity.java

private void ListFunction() {

    listView = (ListView) findViewById(R.id.listView);
    //copying array 
    for (int i = 0; i < Singleton.getInstance().getChannelList().size(); i++) {

        title.add(Singleton.getInstance().getChannelList().get(i).getChannelName());
        desc.add("Long Press This Channel To Report, Id: "
                + Singleton.getInstance().getChannelList().get(i).getChannelId());
        thumb.add(R.drawable.ic_launcher);
    }/* w  ww .j  a  va2s  .c o  m*/
    listView.setAdapter(new VersionAdapter(VitamioListActivity.this));

    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            AlertDialog.Builder alert = new AlertDialog.Builder(VitamioListActivity.this);

            alert.setTitle("Report Broken Link");
            alert.setMessage("Message: (Channel not working?)");

            // Set an EditText view to get user input 
            final EditText input = new EditText(VitamioListActivity.this);
            alert.setView(input);

            alert.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    if (isNetworkAvailable()) {
                        new ReportFeedback().execute("http://yoururl.com/LiveStreaming/reportFeedback.php",
                                value, Singleton.getInstance().getChannelList().get(position).getChannelId());
                    }
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                }
            });
            alert.show();
            return false;
        }
    });

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            int pos = arg2;

            LayoutInflater layoutInflator = getLayoutInflater();

            View layout = layoutInflator.inflate(R.layout.custom_toast,
                    (ViewGroup) findViewById(R.id.toast_layout_root));

            ImageView iv = (ImageView) layout.findViewById(R.id.toast_iv);
            TextView tv = (TextView) layout.findViewById(R.id.toast_tv);

            iv.setBackgroundResource(thumb.get(pos));
            tv.setText(title.get(pos));
            Intent intent = new Intent(VitamioListActivity.this, VideoViewDemo.class);
            intent.putExtra("path", Singleton.getInstance().getChannelList().get(pos).getChannelPath());
            startAppAd.onBackPressed();
            startActivity(intent);
        }
    });
}

From source file:jieehd.villain.updater.VillainUpdater.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;

    }/* ww w .j  a  v a2s . c om*/
    if (haveConnectedWifi == false && haveConnectedMobile == false) {
        Log.d("Network State", "false");
        AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this);
        alert.setTitle("No Data Connection!");
        alert.setMessage(
                "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates.");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                // TODO Auto-generated method stub
                final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                final ComponentName cn = new ComponentName("com.android.settings",
                        "com.android.settings.wifi.WifiSettings");
                intent.setComponent(cn);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }

        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                return;
            }
        });
        alert.show();

    } else {
        download();
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:com.mh_jmcdexample.projectblaze_mh.MainHomeFragActivity.java

public void logoutAlertdialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.mipmap.ic_matlauncher);
    builder.setTitle(R.string.logout_title);
    builder.setMessage(R.string.logout_message)
            .setPositiveButton(R.string.logout_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    session.setLogin(false);

                    db.deleteUsers();/*from  w  w  w .j ava  2 s .  com*/

                    // Launching Login activity
                    Intent intent = new Intent(MainHomeFragActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            }).setNegativeButton(R.string.logout_no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    builder.show();
}

From source file:com.speed.traquer.app.Feedback_rate_taxi.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (actv_comp_taxi.length() != 0 || inputTaxi.length() != 0) {
            final AlertDialog.Builder alertBox = new AlertDialog.Builder(Feedback_rate_taxi.this);
            alertBox.setIcon(R.drawable.info_icon);
            alertBox.setCancelable(false);
            alertBox.setTitle("Do you want to cancel feedback?");
            alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // finish used for destroyed activity
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (Yes)",
                            "Feedback taxi event", null).build());
                    finish();//from   w  w w.j a  v  a 2s. c  o  m
                    Intent intent = new Intent(Feedback_rate_taxi.this, Speedometer.class);
                    Feedback_rate_taxi.this.startActivity(intent);
                }
            });

            alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (No)",
                            "Feedback taxi event", null).build());
                    dialog.cancel();
                }
            });

            alertBox.show();
        } else {
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.kncwallet.wallet.ui.WalletActivity.java

private void exportPrivateKeys(@Nonnull final String password) {
    try {//from   w  w  w .j a v  a  2  s.  com
        Constants.EXTERNAL_WALLET_BACKUP_DIR.mkdirs();
        final DateFormat dateFormat = Iso8601Format.newDateFormat();
        dateFormat.setTimeZone(TimeZone.getDefault());
        final File file = new File(Constants.EXTERNAL_WALLET_BACKUP_DIR,
                Constants.EXTERNAL_WALLET_KEY_BACKUP + "-" + dateFormat.format(new Date()));

        final List<ECKey> keys = new LinkedList<ECKey>();
        for (final ECKey key : wallet.getKeys())
            if (!wallet.isKeyRotating(key))
                keys.add(key);

        final StringWriter plainOut = new StringWriter();
        WalletUtils.writeKeys(plainOut, keys);
        plainOut.close();
        final String plainText = plainOut.toString();

        final String cipherText = Crypto.encrypt(plainText, password.toCharArray());

        final Writer cipherOut = new OutputStreamWriter(new FileOutputStream(file), Constants.UTF_8);
        cipherOut.write(cipherText);
        cipherOut.close();

        final AlertDialog.Builder dialog = new KnCDialog.Builder(this).setInverseBackgroundForced(true)
                .setMessage(getString(R.string.export_keys_dialog_success, file));
        dialog.setPositiveButton(R.string.export_keys_dialog_button_archive, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                mailPrivateKeys(file);
            }
        });
        dialog.setNegativeButton(R.string.button_dismiss, null);
        dialog.show();

        log.info("exported " + keys.size() + " private keys to " + file);
    } catch (final IOException x) {
        new KnCDialog.Builder(this).setInverseBackgroundForced(true).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.import_export_keys_dialog_failure_title)
                .setMessage(getString(R.string.export_keys_dialog_failure, x.getMessage()))
                .setNeutralButton(R.string.button_dismiss, null).show();

        log.error("problem writing private keys", x);
    }
}

From source file:arc.noaa.weather.activities.MainActivity.java

private void searchCities() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(this.getString(R.string.search_title));
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setMaxLines(1);/*from ww  w  .  ja va2s.co m*/
    input.setSingleLine(true);
    alert.setView(input, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String result = input.getText().toString();
            if (!result.isEmpty()) {
                saveLocation(result);
            }
        }
    });
    alert.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Cancelled
        }
    });
    alert.show();
}

From source file:net.evecom.android.PublicOpinionLookActivity.java

/**
 * /*from w  w  w .  j a va 2s .  com*/
 * 
 * @param errorMsg
 */
private void DialogToast(String errorMsg) {
    AlertDialog.Builder builder1 = new AlertDialog.Builder(PublicOpinionLookActivity.this);
    builder1.setTitle("");
    builder1.setIcon(R.drawable.qq_dialog_default_icon);// 
    builder1.setMessage("" + errorMsg);
    builder1.setPositiveButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    builder1.show();
}

From source file:at.jclehner.appopsxposed.SettingsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (Util.isSystemApp(this)) {
        menu.add(R.string.uninstall).setIcon(android.R.drawable.ic_menu_delete)
                .setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override/*w  ww .  j a  v a  2  s  .c o m*/
                    public boolean onMenuItemClick(MenuItem item) {
                        final AlertDialog.Builder ab = new AlertDialog.Builder(SettingsActivity.this);
                        ab.setMessage(getString(R.string.uninstall) + "? " + getString(R.string.will_reboot));
                        ab.setNegativeButton(android.R.string.cancel, null);
                        ab.setPositiveButton(android.R.string.ok, new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (!SU.available()) {
                                    Toast.makeText(SettingsActivity.this, R.string.toast_needs_root,
                                            Toast.LENGTH_SHORT).show();
                                } else {
                                    final String[] commands = { "mount -o remount,rw /system",
                                            "rm " + LauncherActivity.SYSTEM_APK, "mount -o remount,ro /system",
                                            "sync", "reboot", };

                                    Toast.makeText(SettingsActivity.this, R.string.will_reboot,
                                            Toast.LENGTH_LONG).show();
                                    Util.runAsSu(commands);
                                }
                            }
                        });

                        ab.show();

                        return true;
                    }
                }).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    return true;
}

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

public void AskFileName() {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.AskFileName);

    final EditText input = new EditText(context);
    input.setInputType(InputType.TYPE_CLASS_TEXT);

    int pos = curFileName.lastIndexOf(File.separator) + 1;
    String filename = "";
    if (pos > 0)
        filename = curFileName.substring(pos);
    pos = filename.lastIndexOf(extension);
    if (pos > 1)
        input.setText(filename.substring(0, pos - 1));
    else/*from w w w .j  a v  a  2  s  . co  m*/
        input.setText(defFileName);

    Utilities.LogDebug("Asking user the filename to use for export of settings");

    builder.setView(input);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String str = input.getText().toString();
            String fname = "";
            if (str.length() > 0)
                fname = str.replaceAll(filter, "");
            if (fname.length() != 0) {
                curFileName = defPath + File.separator + fname + "." + extension;
                ExportFile();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}