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:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * Adds the pickup location to the map route.
 *//*  www  .  j  av a 2 s  . co m*/
private void setPickupLocation() {
    // Defines the AutoCompleteTextView pickupText
    acPickup = (AutoCompleteTextView) findViewById(R.id.pickupText);
    // Controls if the user has entered an address
    if (!acPickup.getText().toString().equals("")) {
        // Gets the GeoPoint of the written address
        GeoPoint pickupGeo = GeoHelper.getGeoPoint(acPickup.getText().toString());
        // Gets the MapLocation of the GeoPoint
        MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(pickupGeo);
        // Finds the pickup location on the route closest to the given address
        Location temp = findClosestLocationOnRoute(mapLocation);

        //Controls if the user has entered a NEW address
        if (pickupPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayPickupThumb != null) {
                mapView.getOverlays().remove(overlayPickupThumb);
                overlayPickupThumb = null;
            }
            mapView.invalidate();

            // If no dropoff point is specified, we add the pickup point to the map.
            if (dropoffPoint == null) {
                pickupPoint = temp;
                overlayPickupThumb = drawThumb(pickupPoint, true);
            } else { // If a dropoff point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the pickup point is before the dropoff point.
                if (l.indexOf(temp) < l.indexOf(dropoffPoint)) {
                    //makeToast("The pickup point has to be before the dropoff point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The pickup point has to be before the dropoff point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the pickup point to the map by drawing a cross
                    pickupPoint = temp;
                    overlayPickupThumb = drawThumb(pickupPoint, true);
                }
            }
        }
    } else {
        //makeToast("Please add a pickup address");
        AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
        ad.setMessage("Please add a pickup address");
        ad.setTitle("Unable to send request");
        ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

            }
        });
        ad.show();
    }
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * Adds the dropoff location to the map route.
 *//*from   www.  j av a  2  s. co m*/
private void setDropOffLocation() {
    // Defines the AutoCompleteTextView with the dropoff address
    acDropoff = (AutoCompleteTextView) findViewById(R.id.dropoffText);
    //Controls if the user has entered an address
    if (!acDropoff.getText().toString().equals("")) {
        // Gets the GeoPoint of the given address
        GeoPoint dropoffGeo = GeoHelper.getGeoPoint(acDropoff.getText().toString());
        // Gets the MapLocation from the given GeoPoint
        MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(dropoffGeo);
        // Finds the dropoff location on the route closest to the given address
        Location temp = findClosestLocationOnRoute(mapLocation);

        // Controls if the user has entered a NEW address
        if (dropoffPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayDropoffThumb != null) {
                mapView.getOverlays().remove(overlayDropoffThumb);
                overlayDropoffThumb = null;
            }
            mapView.invalidate();

            // If no pickup point is specified, we add the dropoff point to the map.
            if (pickupPoint == null) {
                dropoffPoint = temp;
                overlayDropoffThumb = drawThumb(dropoffPoint, false);
            } else { // If a pickup point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the dropoff point is after the pickup point.
                if (l.indexOf(temp) > l.indexOf(pickupPoint)) {
                    //makeToast("The droppoff point has to be after the pickup point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The droppoff point has to be after the pickup point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the dropoff point to the map by drawing a cross
                    dropoffPoint = temp;
                    overlayDropoffThumb = drawThumb(dropoffPoint, false);
                }
            }
        }
    } else {
        //makeToast("Please add a dropoff address");
        AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
        ad.setMessage("Please add a dropoff address");
        ad.setTitle("Unable to send request");
        ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

            }
        });
        ad.show();
    }
}

From source file:com.andybotting.tubechaser.activity.StationDetail.java

/**
 * Show line select dialog/*  w  ww.j a  va  2  s. com*/
 */
private void showLineSelect(final List<Line> lines) {

    ListAdapter adapter = new LinesListAdapter(mContext, -1, lines);

    final AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setTitle("Select Line");

    ad.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            mLine = lines.get(which);
            dialog.dismiss();
            displayStation();
        }
    });

    ad.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            // Just end our activity if no line is selected
            StationDetail.this.finish();
        }
    });

    ad.create();
    ad.show();
}

From source file:net.evecom.android.log.DailyLogAddActivity.java

/**
 * fh//  www. ja va2s .c  o  m
 * 
 * @param v
 */
public void logfh(View v) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(DailyLogAddActivity.this);
    builder.setTitle("");
    builder.setIcon(R.drawable.qq_dialog_default_icon);// 
    builder.setMessage("");
    builder.setPositiveButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
            DailyLogAddActivity.this.finish();
            Intent intent = new Intent(getApplicationContext(), DailyLogListActivity.class);
            startActivity(intent);

        }
    });
    builder.setNegativeButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.show();

}

From source file:fr.pasteque.client.Configure.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_EXPORT_ID:
        export();//  ww w .  j a va  2  s  . co  m
        break;
    case MENU_IMPORT_ID:
        // Get properties file
        // TODO: check external storage state and access
        File path = Environment.getExternalStorageDirectory();
        path = new File(path, "pasteque");
        File file = new File(path, "pasteque.properties");
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_file_not_found, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        Properties props = new Properties();
        try {
            props.load(fis);
        } catch (IOException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_read_error, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        // Load props
        String host = props.getProperty("host", DEMO_HOST);
        String machineName = props.getProperty("machine_name", null);
        String ticketsMode = props.getProperty("tickets_mode", "simple");
        String user = props.getProperty("user", null);
        String password = props.getProperty("password", null);
        String location = props.getProperty("stock_location", "");
        String printDrv = props.getProperty("printer_driver", "None");
        String printModel = props.getProperty("printer_model", "");
        String printAddr = props.getProperty("printer_address", "");
        String printCtxTry = String.valueOf(getPref("printer_connect_try", DEFAULT_PRINTER_CONNECT_TRY));
        // Save
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString("host", host);
        edit.putString("machine_name", machineName);
        // Set tickets mode, simple by default
        switch (ticketsMode) {
        case "restaurant":
            edit.putString("tickets_mode", String.valueOf(RESTAURANT_MODE));
            break;
        case "standard":
            edit.putString("tickets_mode", String.valueOf(STANDARD_MODE));
            break;
        default:
            edit.putString("tickets_mode", String.valueOf(SIMPLE_MODE));
            break;
        }
        edit.putString("user", user);
        edit.putString("password", password);
        edit.putString("stock_location", location);
        edit.putString("printer_driver", printDrv);
        edit.putString("printer_model", printModel);
        edit.putString("printer_address", printAddr);
        edit.putString("printer_connect_try", printCtxTry);
        edit.apply();
        Toast t = Toast.makeText(this, R.string.cfg_import_done, Toast.LENGTH_SHORT);
        t.show();
        // Reset activity to reload values
        this.finish();
        Intent i = new Intent(this, Configure.class);
        this.startActivity(i);
        break;
    case MENU_DEBUG_ID:
        AlertDialog.Builder b = new AlertDialog.Builder(this);
        b.setTitle(R.string.cfg_debug_alert_title);
        b.setMessage(R.string.cfg_debug_alert_message);
        b.setIcon(android.R.drawable.ic_dialog_alert);
        b.setNegativeButton(android.R.string.cancel, null);
        b.setPositiveButton(R.string.cfg_debug_alert_continue, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent i = new Intent(Configure.this, Debug.class);
                Configure.this.startActivity(i);
            }
        });
        b.show();
        break;
    }
    return true;
}

From source file:com.zira.registration.VehicleInformationActivity.java

public void onBackPressed() {

    AlertDialog.Builder alert = new AlertDialog.Builder(VehicleInformationActivity.this);
    alert.setTitle("Please confirm");
    alert.setMessage("Are you sure you don't want to save any changes?");
    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override/*from  w w w.ja  va 2 s .c om*/
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            for (int i = 0; i < regActivities.size(); i++) {
                regActivities.get(i).finish();
            }
        }
    });
    alert.setNegativeButton("Dismiss", null);
    alert.show();
    /*Intent intent = new Intent(VehicleInformationActivity.this,GetProfile.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);*/

}

From source file:com.googlecode.CallerLookup.Main.java

public void doSave() {
    final Context context = this;
    final EditText input = new EditText(context);
    input.setHint(R.string.Name);

    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle(R.string.SaveTitle);//  w  w w .ja  v  a  2 s  . c o m
    alert.setMessage(R.string.SaveMessage);
    alert.setView(input);

    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String name = SAVED_PREFIX + input.getText().toString().trim();
            if (name.length() <= SAVED_PREFIX.length()) {
                AlertDialog.Builder error = new AlertDialog.Builder(context);
                error.setTitle(R.string.NameMissingTitle);
                error.setMessage(R.string.NameMissingMessage);
                error.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        doSave();
                    }
                });
                error.show();
                return;
            }
            if (mLookupEntries.containsKey(name)) {
                AlertDialog.Builder confirm = new AlertDialog.Builder(context);
                confirm.setTitle(R.string.NameConfirmTitle);
                confirm.setMessage(R.string.NameConfirmMessage);
                confirm.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mLookupEntries.remove(name);
                        mUserLookupEntries.remove(name);
                        addUserLookupEntry(name);

                        int count = mLookup.getCount();
                        for (int i = 1; i < count; i++) {
                            if (mLookup.getItemAtPosition(i).toString().equals(name)) {
                                mLookup.setSelection(i);
                                break;
                            }
                        }
                    }
                });
                confirm.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        doSave();
                    }
                });
                confirm.show();
                return;
            }

            addUserLookupEntry(name);

            ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter();
            adapter.add(name);
            mLookup.setSelection(mLookup.getCount() - 1);
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    alert.show();
}

From source file:com.cricketkorner.cricket.VitamioListActivity.java

@Override
public void onBackPressed() {

    AlertDialog.Builder alert = new AlertDialog.Builder(VitamioListActivity.this);

    alert.setTitle("Please Rate This App.");
    alert.setMessage("We highly appreciate you to rate us.");

    alert.setPositiveButton("I will Rate. :-)", new DialogInterface.OnClickListener() {
        @Override/* ww w  .  j  av a 2  s  . c o m*/
        public void onClick(DialogInterface dialog, int whichButton) {
            String url = "https://play.google.com/store/apps/details?id=com.cricketkorner.cricket";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

    alert.setNegativeButton("No Thanks :-(", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            finish();

        }
    });
    alert.show();
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * When someone presses the map, this method is called and draws the pickup 
 * or dropoff point on the map depending on which of the {@link Button}s, 
 * {@link #btnSelectPickupPoint} or {@link #btnSelectDropoffPoint} that is pressed.
 *//*w w w  . j  av a2s . co  m*/
@Override
public synchronized boolean onSingleTapUp(MotionEvent e) {
    if (!isSelectingDropoffPoint && !isSelectingPickupPoint) {
        return false;
    }
    GeoPoint gp = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
    MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(gp);
    // If the user is selecting a pickup point
    if (isSelectingPickupPoint) {
        Location temp = findClosestLocationOnRoute(mapLocation);
        //Controls if the user has entered a NEW address
        if (pickupPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayPickupThumb != null) {
                mapView.getOverlays().remove(overlayPickupThumb);
                overlayPickupThumb = null;
            }
            mapView.invalidate();

            // If no dropoff point is specified, we add the pickup point to the map.
            if (dropoffPoint == null) {
                pickupPoint = temp;
                overlayPickupThumb = drawThumb(pickupPoint, true);
                // Set pickup TextView to the new address
                acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint))
                        .replace(",", "\n"));
            } else { // If a dropoff point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the pickup point is before the dropoff point.
                if (l.indexOf(temp) < l.indexOf(dropoffPoint)) {
                    //makeToast("The pickup point has to be before the dropoff point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The pickup point has to be before the dropoff point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the pickup point to the map by drawing a thumb
                    pickupPoint = temp;
                    overlayPickupThumb = drawThumb(pickupPoint, true);
                    // Set pickup TextView to the new address
                    acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint))
                            .replace(",", "\n"));
                }
            }
        }
        // If the user is selecting a dropoff point
    } else if (isSelectingDropoffPoint) {
        Location temp = findClosestLocationOnRoute(mapLocation);
        // Controls if the user has entered a NEW address
        if (dropoffPoint != temp) {
            // Removes old dropoff point (thumb)
            if (overlayDropoffThumb != null) {
                mapView.getOverlays().remove(overlayDropoffThumb);
                overlayDropoffThumb = null;
            }
            mapView.invalidate();

            // If no pickup point is specified, we add the dropoff point to the map.
            if (pickupPoint == null) {
                dropoffPoint = temp;
                overlayDropoffThumb = drawThumb(dropoffPoint, false);
                // Set dropoff TextView to the new address
                acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint))
                        .replace(",", "\n"));
            } else { // If a pickup point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the dropoff point is after the pickup point.
                if (l.indexOf(temp) > l.indexOf(pickupPoint)) {
                    //makeToast("The droppoff point has to be after the pickup point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The droppoff point has to be after the pickup point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the dropoff point to the map by drawing a thumb
                    dropoffPoint = temp;
                    overlayDropoffThumb = drawThumb(dropoffPoint, false);
                    // Set dropoff TextView to the new address
                    acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint))
                            .replace(",", "\n"));
                }
            }
        }
    }
    return true;
}

From source file:org.ubicompforall.cityexplorer.CityExplorer.java

/**
  * Display a dialog that user has no Internet connection
  * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html
 * @return /*from ww  w .  j  av a  2s.  com*/
  */
public static AlertDialog showNoConnectionDialog(final Context myContext, final String msg,
        final String cancelButtonStr, final Intent cancelIntent) {
    AlertDialog.Builder builder = new AlertDialog.Builder(myContext);
    builder.setCancelable(true);
    if (msg == "") {
        builder.setMessage(R.string.no_connection);
    } else {
        builder.setMessage(msg);
    }
    builder.setTitle(R.string.no_connection_title);
    builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            myContext.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
        }
    });

    String cancelText = cancelButtonStr;
    if (cancelText == "") {
        cancelText = myContext.getResources().getString(R.string.cancel);
    }
    builder.setNegativeButton(cancelText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (cancelIntent != null) {
                if (myContext instanceof Activity) {
                    ((Activity) myContext).startActivityForResult(cancelIntent, CityExplorer.REQUEST_LOCATION);
                } else {
                    debug(-1, "This is not an Activity!!");
                }
                dialog.dismiss();
            }
            return;
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            if (myContext == null) {
                debug(0, "OOOPS!");
            } else {
                Toast.makeText(myContext, "CANCELLED!", Toast.LENGTH_LONG).show();
                if (cancelIntent != null) {
                    myContext.startActivity(cancelIntent);
                }
            }
            return;
        }
    });

    DATACONNECTION_NOTIFIED = true;
    return builder.show();
}