List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:fi.mikuz.boarder.gui.DropboxMenu.java
@Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case R.id.menu_share: Thread thread = new Thread() { public void run() { Looper.prepare();/*from w ww. jav a 2s . c o m*/ try { final ArrayList<String> boards = mCbla.getAllSelectedTitles(); if (!(mOperation == DOWNLOAD_OPERATION)) { mToastMessage = "Select 'Download' mode"; mHandler.post(mShowToast); } else if (boards.size() < 1) { mToastMessage = "Select boards to share"; mHandler.post(mShowToast); } else { String shareString = "I want to share some cool soundboards to you!\n\n" + "To use the boards you need to have Boarder for Android:\n" + ExternalIntent.mExtLinkMarket + "\n\n" + "Here are the boards:\n"; for (String board : boards) { shareString += board + " - " + mApi.createCopyRef("/" + board).copyRef + "\n"; } shareString += "\n\n" + "Importing a board:\n" + "1. Open Boarder'\n" + "2. Open Dropbox from menu in 'Soundboard Menu'\n" + "3. Open 'Import share' from menu\n" + "4. Copy a reference from above to textfield\n"; Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sharing boards"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareString); startActivity(Intent.createChooser(sharingIntent, "Share via")); } } catch (DropboxException e) { Log.e(TAG, "Unable to share", e); } } }; thread.start(); return true; case R.id.menu_import_share: LayoutInflater removeInflater = (LayoutInflater) DropboxMenu.this .getSystemService(LAYOUT_INFLATER_SERVICE); View importLayout = removeInflater.inflate(R.layout.dropbox_menu_alert_import_share, (ViewGroup) findViewById(R.id.alert_remove_sound_root)); AlertDialog.Builder importBuilder = new AlertDialog.Builder(DropboxMenu.this); importBuilder.setView(importLayout); importBuilder.setTitle("Import share"); final EditText importCodeInput = (EditText) importLayout.findViewById(R.id.importCodeInput); final EditText importNameInput = (EditText) importLayout.findViewById(R.id.importNameInput); importBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { t = new Thread() { public void run() { Looper.prepare(); try { mApi.addFromCopyRef(importCodeInput.getText().toString(), "/" + importNameInput.getText().toString()); mToastMessage = "Download the board from 'Download'"; mHandler.post(mShowToast); } catch (DropboxException e) { Log.e(TAG, "Unable to get shared board", e); } } }; t.start(); } }); importBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); importBuilder.show(); return true; } return super.onMenuItemSelected(featureId, item); }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
private String getInputFromAlertDialog(final String title, final String message, final boolean password) { final FutureActivityTask<String> task = new FutureActivityTask<String>() { @Override/*from w ww . ja v a2 s. com*/ public void onCreate() { super.onCreate(); final EditText input = new EditText(getActivity()); if (password) { input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); input.setTransformationMethod(new PasswordTransformationMethod()); } AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(title); alert.setMessage(message); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); setResult(input.getText().toString()); finish(); } }); alert.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); setResult(null); finish(); } }); alert.show(); } }; mTaskQueue.execute(task); try { return task.getResult(); } catch (Exception e) { Log.e("Failed to display dialog.", e); throw new RuntimeException(e); } }
From source file:uk.bowdlerize.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_add: { AlertDialog.Builder builder = new AlertDialog.Builder(this); // Get the layout inflater LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_add_url, null); final EditText urlET = (EditText) dialogView.findViewById(R.id.urlET); builder.setView(dialogView) .setPositiveButton(R.string.action_add, new DialogInterface.OnClickListener() { @Override/*w w w . j ava2 s. c om*/ public void onClick(DialogInterface dialog, int id) { Bundle extras = new Bundle(); Intent receiveURLIntent = new Intent(MainActivity.this, CensorCensusService.class); extras.putString("url", urlET.getText().toString()); extras.putString("hash", MD5(urlET.getText().toString())); extras.putInt("urgency", 0); extras.putBoolean("local", true); //Add our extra info if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE) .getBoolean("sendISPMeta", true)) { WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE)); if (wifiMgr.isWifiEnabled() && null != wifiInfo.getSSID()) { LocalCache lc = null; Pair<Boolean, String> seenBefore = null; try { lc = new LocalCache(MainActivity.this); lc.open(); seenBefore = lc.findSSID(wifiInfo.getSSID().replaceAll("\"", "")); } catch (Exception e) { e.printStackTrace(); } if (null != lc) lc.close(); if (seenBefore.first) { extras.putString("isp", seenBefore.second); } else { extras.putString("isp", "unknown"); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } else { try { extras.putString("isp", telephonyManager.getNetworkOperatorName()); } catch (Exception e) { e.printStackTrace(); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } } receiveURLIntent.putExtras(extras); startService(receiveURLIntent); dialog.cancel(); } }).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditExpenseActivity.java
/** * Called when dialog appears to show current expense photo. * // w w w .j av a 2 s . c o m * Loads photo to be displayed. * ImageView is the location for the image to be displayed, height and width * are of the size the the image will be displayed in. * * @param ImageView * @param int width * @param int height */ private void loadPhoto(ImageView imageView, int width, int height) { ImageView tempImageView = imageView; AlertDialog.Builder imageDialog = new AlertDialog.Builder(this); LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.image_adapter, (ViewGroup) findViewById(R.id.layout_root)); ImageView image = (ImageView) layout.findViewById(R.id.fullimage); image.setImageDrawable(tempImageView.getDrawable()); imageDialog.setView(layout); String showDate = null; if (expense.getDate() != null) { showDate = sdf.format(expense.getDate()); } else { showDate = ""; } imageDialog.setPositiveButton( expense.getName() + " " + showDate + " " + expense.getScale() + " " + "Size: " + size + " Byte", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); imageDialog.create(); imageDialog.show(); }
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
private void displayAlertWithMessage(String errorcode) { String errorMessage = getResources().getString(R.string.alert_message_write_error) + "\n" + getResources().getString(R.string.alert_message_write_error_code) + errorcode + "\n" + getResources().getString(R.string.alert_message_try_again); AlertDialog alert;//from www . jav a 2 s . c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); TextView myMsg = new TextView(getActivity()); myMsg.setText(errorMessage); myMsg.setGravity(Gravity.CENTER_HORIZONTAL); builder.setView(myMsg); builder.setTitle(getActivity().getResources().getString(R.string.app_name)).setCancelable(false) .setPositiveButton(getActivity().getResources().getString(R.string.alert_message_exit_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert = builder.create(); alert.setCanceledOnTouchOutside(false); alert.show(); }
From source file:com.app.viaje.viaje.MapsActivity.java
/** * @description ::/*from w ww .jav a 2 s . co m*/ * Shows the AlertDialog that creates * a new post */ private void showMarkerPostDialog() { final EditText input = new EditText(MapsActivity.this); //Get the text from EditText. input.setInputType(InputType.TYPE_CLASS_TEXT); //Create AlertDialog Builder. AlertDialog.Builder builder = new AlertDialog.Builder(MapsActivity.this); builder.setTitle("Post"); builder.setMessage("What about the post?"); builder.setView(input); builder.setPositiveButton("Post", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { textContent = input.getText().toString().trim(); if (textContent.isEmpty()) { Snackbar snackbar = Snackbar.make(relativeLayout, "Post must not be empty..", Snackbar.LENGTH_LONG); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.RED); snackbar.show(); } else { sendThePostToFirebase(textContent); } } }); builder.create().show(); }
From source file:com.remobile.dialogs.Notification.java
/** * Builds and shows a native Android prompt dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The following results are returned to the JavaScript callback identified by callbackId: * buttonIndex Index number of the button selected * input1 The text entered in the prompt dialog box * * @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 callbackContext The callback context. *///from w ww .j ava2s. c o m public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { final Activity activity = this.cordova.getActivity(); Runnable runnable = new Runnable() { public void run() { final EditText promptInput = new EditText(activity); promptInput.setHint(defaultText); AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(promptInput); final JSONObject result = new JSONObject(); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 2); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); } ; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.amazonaws.youruserpools.UserActivity.java
private void showUserDetail(final String attributeType, final String attributeValue) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(attributeType);// w w w . j a v a2s. c om final EditText input = new EditText(UserActivity.this); input.setText(attributeValue); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); input.setLayoutParams(lp); input.requestFocus(); builder.setView(input); builder.setNeutralButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { String newValue = input.getText().toString(); if (!newValue.equals(attributeValue)) { showWaitDialog("Updating..."); updateAttribute(AppHelper.getSignUpFieldsC2O().get(attributeType), newValue); } userDialog.dismiss(); } catch (Exception e) { // Log failure } } }).setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { userDialog.dismiss(); deleteAttribute(AppHelper.getSignUpFieldsC2O().get(attributeType)); } catch (Exception e) { // Log failure } } }); userDialog = builder.create(); userDialog.show(); }
From source file:com.example.spencerdepas.translationapp.activities.DMVSimulationActivity.java
private void showSelectQuestionDialog() { Log.d(TAG, "showAlertDialog"); // Prepare grid view GridView gridView = new GridView(this); List<Integer> mList = new ArrayList<Integer>(); for (int i = 1; i < 21; i++) { mList.add(i);/* w w w . j a va 2 s . c o m*/ } // gridView.setAdapter(new ArrayAdapter<>(this, R.layout.custom_list_item, mList)); gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); boolean hasBeenAnswered = hasBeenAnswered(position); int color = 0x00FFFFFF; // Transparent if (hasBeenAnswered) { view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid)); } else { view.setBackgroundColor(color); } return view; } }); gridView.setNumColumns(4); // Set grid view to alertDialog final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(gridView); builder.setTitle(getResources().getString(R.string.select_question)); builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d(TAG, "DISMISS"); dialog.dismiss(); } }); final AlertDialog ad = builder.show(); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // do something here Log.d(TAG, "onclick"); saveAnswer(); unSelectRadioButtons(); loadRadioButtonSelection(); if (position == 0) { makePrevousButtonUnclickable(); } else { makePrevousButtonClickable(); } mNextButton.setText(getResources().getString(R.string.next_button)); Log.d(TAG, "int pos : " + position); goToSelectedQuestion(position); ad.dismiss(); } }); }
From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java
public void openDialog() { // get prompts.xml view LayoutInflater li = LayoutInflater.from(GetAllVehicalSellerDetails.this); View promptsView = li.inflate(R.layout.prompt, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GetAllVehicalSellerDetails.this); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); alertDialogBuilder.setTitle("Why you want to stop this"); final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text //result.setText(userInput.getText()); if (!userInput.getText().toString().trim().isEmpty()) { reason = userInput.getText().toString().trim(); getUserData(reason);// ww w . j av a2 s . c o m } else { Toast.makeText(GetAllVehicalSellerDetails.this, "Please fill your reason", Toast.LENGTH_LONG) .show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }