Example usage for android.app AlertDialog.Builder setView

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

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:edu.missouri.niaaa.pain.activity.AdminManageActivity.java

private Dialog AdminPinSetDialog(final Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.pin_input, null);
    TextView pinText = (TextView) textEntryView.findViewById(R.id.pin_text);
    pinText.setText(R.string.admin_set_msg);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);/*from   w w  w . j a  va 2s  .c o m*/
    builder.setTitle(R.string.admin_set_title);
    builder.setView(textEntryView);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            EditText pinEdite = (EditText) textEntryView.findViewById(R.id.pin_edit);
            String pinStr = pinEdite.getText().toString();
            Util.Log_debug("Pin Dialog", "pin String is " + pinStr);

            String data = null;
            try {
                data = Util.encryption(context, Util.ADMIN_UID + "," + "1" + "," + pinStr);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            /*              check network*/

            /*              prepare params for server*/
            HttpPost request = new HttpPost(Util.VALIDATE_ADDRESS);

            List<NameValuePair> params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("data", data));

            //              //file_name
            //              params.add(new BasicNameValuePair("userID","0000"));
            //              //function
            //              params.add(new BasicNameValuePair("pre","1"));
            //              //data
            //              params.add(new BasicNameValuePair("password",pinStr));

            /*              check identity*/

            try {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

                HttpResponse response = new DefaultHttpClient().execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    String result = EntityUtils.toString(response.getEntity());
                    Log.d("~~~~~~~~~~http post result", result);

                    if (result.equals("AdminIsChecked")) {
                        //do nothing

                    } else if (result.equals("AdminPinIsInvalid")) {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_failed, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    } else {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_error, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), R.string.input_apin_return, Toast.LENGTH_SHORT)
                            .show();
                    finish();
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                Toast.makeText(getApplicationContext(), R.string.input_apin_net_error, Toast.LENGTH_SHORT)
                        .show();
                ;
                finish();
            }

        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

            finish();
        }
    });

    return builder.create();
}

From source file:com.esri.arcgisruntime.generateofflinemapoverrides.MainActivity.java

/**
 * Creates parameters dialog and handles processing of input to generateOfflineMap(...) when Start Job button is clicked.
 *//*from www  . j  ava 2 s .  c om*/
private void showParametersDialog() {

    View overrideParametersView = getLayoutInflater().inflate(R.layout.override_parameters_dialog, null);

    // min and max seek bars
    TextView currMinScaleTextView = overrideParametersView.findViewById(R.id.currMinScaleTextView);
    TextView currMaxScaleTextView = overrideParametersView.findViewById(R.id.currMaxScaleTextview);

    SeekBar minScaleSeekBar = buildSeekBar(overrideParametersView.findViewById(R.id.minScaleSeekBar),
            currMinScaleTextView, 22, 15);
    SeekBar maxScaleSeekBar = buildSeekBar(overrideParametersView.findViewById(R.id.maxScaleSeekBar),
            currMaxScaleTextView, 23, 20);
    minScaleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            currMinScaleTextView.setText(String.valueOf(progress));
            if (progress >= maxScaleSeekBar.getProgress()) {
                // set max to 1 more than min value (since max must always be greater than min)
                currMaxScaleTextView.setText(String.valueOf(progress + 1));
                maxScaleSeekBar.setProgress(progress + 1);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    maxScaleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            currMaxScaleTextView.setText(String.valueOf(progress));
            if (progress <= minScaleSeekBar.getProgress()) {
                // set min to 1 less than max value (since min must always be less than max)
                currMinScaleTextView.setText(String.valueOf(progress - 1));
                minScaleSeekBar.setProgress(progress - 1);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    // extent buffer seek bar
    SeekBar extentBufferDistanceSeekBar = buildSeekBar(
            overrideParametersView.findViewById(R.id.extentBufferDistanceSeekBar),
            overrideParametersView.findViewById(R.id.currExtentBufferDistanceTextView), 500, 300);

    // include layers checkboxes
    CheckBox systemValves = overrideParametersView.findViewById(R.id.systemValvesCheckBox);
    CheckBox serviceConnections = overrideParametersView.findViewById(R.id.serviceConnectionsCheckBox);

    // min hydrant flow rate seek bar
    SeekBar minHydrantFlowRateSeekBar = buildSeekBar(
            overrideParametersView.findViewById(R.id.minHydrantFlowRateSeekBar),
            overrideParametersView.findViewById(R.id.currMinHydrantFlowRateTextView), 2000, 500);

    // crop layer to extent checkbox
    CheckBox waterPipes = overrideParametersView.findViewById(R.id.waterPipesCheckBox);

    // setup dialog
    AlertDialog.Builder overrideParametersDialogBuilder = new AlertDialog.Builder(this);
    AlertDialog overrideParametersDialog = overrideParametersDialogBuilder.create();
    overrideParametersDialogBuilder.setView(overrideParametersView).setTitle("Override Parameters")
            .setCancelable(true)
            .setNegativeButton("Cancel", (dialog, which) -> overrideParametersDialog.dismiss())
            .setPositiveButton("Start Job", (dialog, which) -> {
                // re-create download area geometry in case user hasn't changed the Viewpoint
                mDownloadArea.setGeometry(createDownloadAreaGeometry());
                defineParameters(minScaleSeekBar.getProgress(), maxScaleSeekBar.getProgress(),
                        extentBufferDistanceSeekBar.getProgress(), systemValves.isChecked(),
                        serviceConnections.isChecked(), minHydrantFlowRateSeekBar.getProgress(),
                        waterPipes.isChecked());
            }).show();
}

From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoDeviceDetails.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("Device Details, ID: " + deviceData.deviceId);
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View detailsView = inflater.inflate(R.layout.dialog_geocache_deviceinfo, null);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(detailsView);

    // Add action buttons
    builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
        @Override/*from   w  w w  .  jav a 2s.  co m*/
        public void onClick(DialogInterface dialog, int id) {
            // sign in the user ...
        }
    });

    textView_IdString = (TextView) detailsView.findViewById(R.id.textView_IdentificationString);
    textView_PIN = (TextView) detailsView.findViewById(R.id.textView_PIN);
    textView_Latitude = (TextView) detailsView.findViewById(R.id.textView_Latitude);
    textView_Longitude = (TextView) detailsView.findViewById(R.id.textView_Longitude);
    textView_HintString = (TextView) detailsView.findViewById(R.id.textView_HintString);
    textView_LastVisit = (TextView) detailsView.findViewById(R.id.textView_LastVisitTimestamp);
    textView_NumVisits = (TextView) detailsView.findViewById(R.id.textView_NumberOfVisits);
    textView_HardwareVer = (TextView) detailsView.findViewById(R.id.textView_HardwareRevision);
    textView_ManfID = (TextView) detailsView.findViewById(R.id.textView_ManufacturerID);
    textView_ModelNum = (TextView) detailsView.findViewById(R.id.textView_ModelNumber);
    textView_SoftwareVer = (TextView) detailsView.findViewById(R.id.textView_SoftwareRevision);
    textView_SerialNum = (TextView) detailsView.findViewById(R.id.textView_SerialNumber);
    textView_BatteryVoltage = (TextView) detailsView.findViewById(R.id.textView_BatteryVoltage);
    textView_BatteryStatus = (TextView) detailsView.findViewById(R.id.textView_BatteryStatus);
    textView_OperatingTime = (TextView) detailsView.findViewById(R.id.textView_CumulativeOperatingTime);
    textView_OperatingTimeResolution = (TextView) detailsView
            .findViewById(R.id.textView_CumulativeOperatingTimeResolution);

    refreshData();

    //Set up button handlers
    Button button_ProgramDevice = (Button) detailsView.findViewById(R.id.button_ProgramDevice);
    button_ProgramDevice.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //Warn user they are going to program a device that was not originally programmed by this device
            //so they will be overwriting someone else's data
            //Note: The device based PIN is generated from the Settings.Secure.ANDROID_ID
            //and is persistent for this app on the phone it is installed on.
            if ((deviceData.programmableData.identificationString.trim().length() != 0 //If the device itself is programmed
                    && deviceData.programmableData.PIN != 0xFFFFFFFF) //and the PIN is programmed
                    && !getDeviceBasedPIN(getActivity()).equals(deviceData.programmableData.PIN)) //and the app's persistent PIN doesn't match the programmed one
            {
                //Warn the user the PINs don't match and make them accept responsibility for reprogramming someone else's geocache
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
                dialogBuilder.setTitle("Incorrect PIN");
                dialogBuilder.setMessage(
                        "Your device's PIN does not match the geocache's PIN. This means you are probably trying to overwrite someone else's geocache data. If you continue, this might make them upset and hurt their feelings");
                dialogBuilder.setPositiveButton("I don't care, do it anyway",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                showProgramDevice();
                            }
                        });
                dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //let dialog be dismissed
                    }
                });

                dialogBuilder.create().show();
            } else //else the PIN matches or it is unprogrammed so we can proceed straight to programming
            {
                showProgramDevice();
            }
        }
    });

    Button button_ReqAuthToken = (Button) detailsView.findViewById(R.id.button_RequestAuthToken);
    button_ReqAuthToken.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog_GeoRequestAuthToken reqDialog = new Dialog_GeoRequestAuthToken(geoPcc, deviceData.deviceId,
                    getDeviceBasedPIN(getActivity()));
            reqDialog.show(getFragmentManager(), "ReqAuthTokenDialog");
        }
    });

    return builder.create();
}

From source file:com.auth0.sample.ProfileActivity.java

public AlertDialog createTweet(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final EditText input = new EditText(ProfileActivity.this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(50, 50, 50, 50);/*  w  w  w .j  a  va 2 s .  com*/
    input.setLayoutParams(lp);

    builder.setView(input).setTitle("Create A Tweet")
            .setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    RequestParams params = new RequestParams();
                    params.put("author", profile.getName());
                    params.put("body", input.getText().toString());
                    client.post(shares.getString("ENDPOINT_URL", "ERROR"), params,
                            new JsonHttpResponseHandler() {
                                @Override
                                public void onSuccess(int statusCode,
                                        cz.msebera.android.httpclient.Header[] headers, JSONObject response) {
                                    Toast.makeText(ProfileActivity.this, "Created Tweet Successfully",
                                            Toast.LENGTH_SHORT).show();
                                }

                                @Override
                                public void onFailure(int statusCode,
                                        cz.msebera.android.httpclient.Header[] headers, Throwable throwable,
                                        JSONObject errorResponse) {
                                    Toast.makeText(ProfileActivity.this, "Failed to Create Tweet",
                                            Toast.LENGTH_SHORT).show();
                                }
                            });
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    return builder.show();
}

From source file:ca.ualberta.app.activity.CreateAnswerActivity.java

/**
 * the dialog allow user to type in the city manually
 *///ww w  . j  a va 2  s  .  c  o m
private void showSelectedDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Set Location Manually");
    alert.setMessage("Enter the closest city");

    final EditText input = new EditText(this);
    alert.setView(input);

    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String userLocation = input.getEditableText().toString();
            double[] coord = GeoCoder.toLatLong(userLocation.toString());
            if (coord[0] == 0.0 && coord[1] == 0.0) {
                showToast();
            } else {
                cacheController.saveUserCoordinates(coord);
                cacheController.saveUserLocation(GeoCoder.toAddress(coord[0], coord[1]));
                locationName = cacheController.getUserLocation();
                locationCoordinates = cacheController.getUserCoordinates();
                locationText.setText(locationName);
            }
        }

    });
    alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            GPSButton.setChecked(false);
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alert.create();
    alertDialog.show();
}

From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java

public void handleError(Throwable error, final Uri uri) {
    Log.e("OpenDocument Reader", "Error opening file at " + uri.toString(), error);

    final Uri cacheUri = AndroidFileCache.getCacheFileUri();

    for (LoadingListener listener : loadingListeners) {
        listener.onError(error, uri);// w ww .  jav a2 s.  co  m

        // TODO: return here, but only if the listener was registered by a
        // JUnit test
    }

    int errorDescription;
    if (error == null) {
        return;
    } else if (error instanceof EncryptedDocumentException) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.toast_error_password_protected);

        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        builder.setView(input);

        builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                loadUri(cacheUri, input.getText().toString());

                dialog.dismiss();
            }
        });
        builder.setNegativeButton(getString(android.R.string.cancel), null);
        builder.show();

        return;
    } else if (error instanceof IllegalMimeTypeException || error instanceof ZipException
            || error instanceof ZipEntryNotFoundException || error instanceof UnsupportedMimeTypeException) {
        /*AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.toast_error_illegal_file);
        builder.setMessage(R.string.dialog_upload_file);
        builder.setPositiveButton(getString(android.R.string.ok),
              new DialogInterface.OnClickListener() {
                
          @Override
          public void onClick(DialogInterface dialog,
                int whichButton) {
             uploadUri(cacheUri);
                
             dialog.dismiss();
          }
              });
        builder.setNegativeButton(getString(android.R.string.cancel), null);
        builder.show();*/

        return;
    } else if (error instanceof FileNotFoundException) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)
                || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            errorDescription = R.string.toast_error_find_file;
        } else {
            errorDescription = R.string.toast_error_storage;
        }
    } else if (error instanceof IllegalArgumentException) {
        errorDescription = R.string.toast_error_illegal_file;
    } else if (error instanceof OutOfMemoryError) {
        errorDescription = R.string.toast_error_out_of_memory;
    } else {
        errorDescription = R.string.toast_error_generic;
    }

    showCrouton(errorDescription, null, AppMsg.STYLE_ALERT);

}

From source file:kr.co.cashqc.MainActivity.java

@Override
protected Dialog onCreateDialog(int i) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

    LayoutInflater inflater = MainActivity.this.getLayoutInflater();

    final View view = inflater.inflate(R.layout.dialog_custom_login, null);

    builder.setView(view);
    builder.setPositiveButton("login", new DialogInterface.OnClickListener() {
        @Override/*  www .j a v a  2s . c  o m*/
        public void onClick(DialogInterface dialog, int which) {
            EditText passwordEditText = (EditText) view.findViewById(R.id.password);
            // EditText distanceEditText = (EditText)
            // view.findViewById(R.id.distance);

            if (passwordEditText.getText().toString().equals("1599")) {
                adminFlag = true;
                Toast.makeText(mContext, "?", Toast.LENGTH_SHORT).show();
                // try {
                // mDistance =
                // Integer.parseInt(distanceEditText.getText().toString());
                // } catch (NumberFormatException e) {
                // e.printStackTrace();
                // mDistance = 3;
                // }
                mManualTextView.setVisibility(View.VISIBLE);
            } else {
                adminFlag = false;
                mDistance = 3;
                // mManualTextView.setVisibility(View.GONE);
            }

        }
    });

    return builder.create();
}

From source file:ca.mudar.mtlaucasou.BaseMapActivity.java

/**
 * Show dialog to type postal code for Geocode search.
 *//*www.j av  a2  s  .co m*/
private void showPostalCodeDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.dialog_postal_code_title);
    alert.setMessage(R.string.dialog_postal_code_summary);

    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setHint(R.string.input_hint_postal_code);
    alert.setView(input);

    alert.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            /**
             * Store value and show processing dialog. Geocode search will
             * be done in a thread.
             */
            postalCode = input.getText().toString();
            showDialogProcessing();
        }
    });
    alert.setNegativeButton(R.string.dialog_btn_cancel, null);

    alert.show();
}