List of usage examples for android.app AlertDialog setView
public void setView(View view)
From source file:com.tinfoil.sms.sms.KeyExchangeManager.java
/** * Set the shared secrets for the contacts. * @param context The context of the setting. * @param number The Number of the contact. * @param name The name of the contact/*w w w . ja v a2 s. c om*/ * @param entry The key exchange message. */ private static void setAndSend(final Context context, final Number number, String name, final Entry entry) { final DBAccessor dba = new DBAccessor(context); AlertDialog.Builder builder = new AlertDialog.Builder(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); final EditText sharedSecret1 = new EditText(context); sharedSecret1.setHint(context.getString(R.string.shared_secret_hint_1)); sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret1); final EditText sharedSecret2 = new EditText(context); sharedSecret2.setHint(context.getString(R.string.shared_secret_hint_2)); sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret2); builder.setMessage(context.getString(R.string.set_shared_secrets) + " " + name + ", " + number.getNumber()) .setTitle(R.string.set_shared_secrets_title).setCancelable(true) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { //Save the shared secrets String s1 = sharedSecret1.getText().toString(); String s2 = sharedSecret2.getText().toString(); if (SMSUtility.checksharedSecret(s1) && SMSUtility.checksharedSecret(s2)) { number.setSharedInfo1(s1); number.setSharedInfo2(s2); dba.updateNumberRow(number, number.getNumber(), number.getId()); respondKeyExchangeMessage(context, number, entry); } else { Toast.makeText(context, R.string.invalid_secrets, Toast.LENGTH_LONG).show(); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Cancel the key exchange Toast.makeText(context, R.string.key_exchange_cancelled, Toast.LENGTH_LONG).show(); } }); AlertDialog alert = builder.create(); alert.setView(linearLayout); alert.show(); }
From source file:com.bti360.hackathon.listview.HackathonActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case ADD_DIALOG: // We are going to create an AlertDialog with a single text input and a button // first we create the EditText final EditText edit = new EditText(this); // Next we create an AlertDialog.Builder which creates a styled AlertDialog based // on our specifications; AlertDialog.Builder builder = new AlertDialog.Builder(this); // set the title builder.setTitle("Add Person"); // set the icon to a built-in, this one is a + builder.setIcon(android.R.drawable.ic_input_add); // set the text of the only button, and add a click listener builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override/*from w w w. ja v a 2s .c om*/ public void onClick(DialogInterface dialog, int which) { // on the Ok Button we grab the text from the EditText, // clear it and then add the Name to our list String name = edit.getText().toString(); edit.setText(""); addName(name); } }); // finally let's create the dialog final AlertDialog d = builder.create(); // and set the view to our EditText d.setView(edit); // we'll set a special InputType since we are collecting a name // other's exist such as email, address, phone number, etc // this allows the IME (keyboard) to customize itself based on // expected input, e.g. show @ and .com when Email edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); // Respond to the default action on the IME (keyboard) By default it is // "Done" but it can be changed with setImeActionLabel to be something // else like a search hourglass. // In our case we want a click on "Done" to do the same thing as a click // on the Ok button in the Dialog. edit.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView tv, int actionId, KeyEvent arg2) { // same as the DialogClick Handler except we also dismiss the dialog String name = edit.getText().toString(); edit.setText(""); addName(name); d.dismiss(); return true; } }); return d; } return super.onCreateDialog(id); }
From source file:com.github.andrewlord1990.materialandroidsample.color.ColorChooserDialog.java
@NonNull @Override//w ww. j a va2s . com public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog dialog = new AlertDialog.Builder(getContext()).setTitle(title) .setPositiveButton(R.string.sample_color_chooser_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); dialog.setView(setupCustomView(dialog)); return dialog; }
From source file:com.tinfoil.sms.settings.UserKeySettings.java
public void exportKey(View view) { if (SMSUtility.isMediaWritable()) { phoneBook = new AutoCompleteTextView(this); List<String> contact = null; if (tc == null) { //Do in thread. tc = dba.getAllRows(DBAccessor.ALL); }/*from w w w .j a v a 2 s . c o m*/ if (tc != null) { if (contact == null) { contact = SMSUtility.contactDisplayMaker(tc); } } else { contact = null; } final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getBaseContext(), R.layout.auto_complete_list_item, contact); phoneBook.setAdapter(adapter); final AlertDialog.Builder popup_builder = new AlertDialog.Builder(this); popup_builder.setTitle(R.string.import_contacts_title).setCancelable(true).setView(phoneBook) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { String[] contactInfo = SMSUtility.parseAutoComplete(phoneBook.getText().toString()); //String number = null; boolean invalid = false; if (contactInfo != null) { if (contactInfo[0] == null) { contactInfo[0] = contactInfo[1]; } final Number number = dba.getNumber(contactInfo[1]); if (number != null) { AlertDialog.Builder builder = new AlertDialog.Builder(UserKeySettings.this); LinearLayout linearLayout = new LinearLayout(UserKeySettings.this); linearLayout.setOrientation(LinearLayout.VERTICAL); final EditText sharedSecret1 = new EditText(UserKeySettings.this); sharedSecret1 .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_1)); sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret1); final EditText sharedSecret2 = new EditText(UserKeySettings.this); sharedSecret2 .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_2)); sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret2); builder.setMessage(UserKeySettings.this.getString(R.string.set_shared_secrets) + " " + contactInfo[0] + ", " + number.getNumber()) .setTitle(R.string.set_shared_secrets_title).setCancelable(true) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { //Save the shared secrets String s1 = sharedSecret1.getText().toString(); String s2 = sharedSecret2.getText().toString(); if (SMSUtility.checksharedSecret(s1) && SMSUtility.checksharedSecret(s2)) { number.setSharedInfo1(s1); number.setSharedInfo2(s2); dba.updateNumberRow(number, number.getNumber(), number.getId()); number.setInitiator(true); dba.updateInitiator(number); //TODO add check for shared secrets String keyExchangeMessage = KeyExchange.sign(number, dba, SMSUtility.user); writeToFile(number.getNumber(), keyExchangeMessage); Toast.makeText(UserKeySettings.this, UserKeySettings.this .getString(R.string.written_path) + " " + path + "/" + number.getNumber() + "_" + file, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(UserKeySettings.this, R.string.invalid_secrets, Toast.LENGTH_LONG) .show(); } } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Cancel the key exchange Toast.makeText(UserKeySettings.this, R.string.key_exchange_cancelled, Toast.LENGTH_LONG).show(); } }); AlertDialog alert = builder.create(); alert.setView(linearLayout); alert.show(); } else { invalid = true; } } else { invalid = true; } if (invalid) { Toast.makeText(UserKeySettings.this, R.string.invalid_number_message, Toast.LENGTH_LONG).show(); } } }); popup_alert = popup_builder.create(); popup_alert.show(); //getExternalFilesDir(null); } }
From source file:com.todoroo.astrid.adapter.UpdateAdapter.java
public static void setupImagePopupForCommentView(View view, AsyncImageView commentPictureView, final String pictureThumb, final String pictureFull, final Bitmap updateBitmap, final String message, final Fragment fragment, ImageCache imageCache) { if ((!TextUtils.isEmpty(pictureThumb) && !"null".equals(pictureThumb)) || updateBitmap != null) { //$NON-NLS-1$ commentPictureView.setVisibility(View.VISIBLE); if (updateBitmap != null) commentPictureView.setImageBitmap(updateBitmap); else//from w w w . j av a 2 s.c o m commentPictureView.setUrl(pictureThumb); if (pictureThumb != null && imageCache.contains(pictureThumb) && updateBitmap == null) { try { commentPictureView.setDefaultImageBitmap(imageCache.get(pictureThumb)); } catch (IOException e) { e.printStackTrace(); } } else if (updateBitmap == null) { commentPictureView.setUrl(pictureThumb); } view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create(); AsyncImageView imageView = new AsyncImageView(fragment.getActivity()); imageView .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); imageView.setDefaultImageResource(android.R.drawable.ic_menu_gallery); if (updateBitmap != null) imageView.setImageBitmap(updateBitmap); else imageView.setUrl(pictureFull); image.setView(imageView); image.setMessage(message); image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); image.show(); } }); } else { commentPictureView.setVisibility(View.GONE); } }
From source file:uk.ac.ucl.excites.sapelli.collector.fragments.ProjectManagerFragment.java
private View doSetDialogView(AlertDialog dialog, Integer viewSpacingLeft, Integer viewSpacingTop, Integer viewSpacingRight, Integer viewSpacingBottom) { View rootLayout = null;//ww w . ja v a2s .co m if (dialog != null && (rootLayout = getRootLayout()) != null) { if (viewSpacingLeft == null) dialog.setView(rootLayout); else dialog.setView(rootLayout, viewSpacingLeft, viewSpacingTop, viewSpacingRight, viewSpacingBottom); } return rootLayout; }
From source file:com.guidewithme.ArticleInfoListFragment.java
private void showLicense() { final WebView wb = new WebView(getActivity()); wb.loadUrl("file:///android_asset/license.html"); final AlertDialog ad = new AlertDialog.Builder(getActivity()).setTitle(R.string.about).setCancelable(true) .create();//from w ww. j a va 2 s . co m ad.setCanceledOnTouchOutside(true); ad.setView(wb); ad.show(); }
From source file:com.jwork.dhammapada.MainActivity.java
public void displayChangeLog() { AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle("Changelog"); WebView wv = new WebView(this); wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8"); wv.setScrollContainer(true);//from www. j a v a 2 s .co m dialog.setView(wv); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName()); Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri); try { MainActivity.this.startActivity(myAppLinkToMarket); } catch (ActivityNotFoundException e) { Toast.makeText(MainActivity.this, "Failed to find Market application", Toast.LENGTH_LONG) .show(); } } }); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Donate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); openDonate(); } }); dialog.show(); }
From source file:com.garrocho.MapActivity.java
@SuppressLint("NewApi") @Override//from w w w. ja v a2 s.c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); if (savedInstanceState == null) { Bundle extras = getIntent().getExtras(); if (extras == null) { musica = null; } else { musica = extras.getString("MUSICA"); } } else { musica = (String) savedInstanceState.getSerializable("MUSICA"); } mPrefs = new SimpleGeofenceStore(this); Intent intent = new Intent(); intent.putStringArrayListExtra(String.valueOf(GeofenceUtils.LISTA_GEOFENCES_ADDED), null); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); if (mMap != null) { mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); mMap.setOnMapLongClickListener(new OnMapLongClickListener() { @Override public void onMapLongClick(final LatLng point) { CameraPosition INIT = new CameraPosition.Builder() .target(new LatLng(point.latitude, point.longitude)).zoom(17.5F).build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(INIT)); // TODO Auto-generated method stub String names[] = { "25", "50", "100", "200", "400" }; final AlertDialog alertDialog = new AlertDialog.Builder(MapActivity.this, android.R.style.Theme_Translucent).create(); LayoutInflater inflater = getLayoutInflater(); View convertView = (View) inflater.inflate(R.layout.custom, null); alertDialog.setView(convertView); alertDialog.setTitle("Selecione um Radius"); ListView lv = (ListView) convertView.findViewById(R.id.listView1); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivity.this, android.R.layout.simple_list_item_1, names); lv.setAdapter(adapter); alertDialog.show(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String item = ((TextView) arg1).getText().toString(); SimpleGeofence geofence = new SimpleGeofence(String.valueOf(mPrefs.getQtdeGeo() + 1), point.latitude, point.longitude, Float.valueOf(item), GEOFENCE_EXPIRATION_IN_MILLISECONDS, Geofence.GEOFENCE_TRANSITION_ENTER, musica); addMarkerForFence(geofence); mPrefs.setGeofence(geofence.getId(), geofence); lista.add(geofence.getId()); Intent intent = new Intent(); intent.putStringArrayListExtra(String.valueOf(GeofenceUtils.LISTA_GEOFENCES_ADDED), lista); MapActivity.this.setResult(Activity.RESULT_OK, intent); alertDialog.dismiss(); Toast.makeText(MapActivity.this, "GeoFence Adicionada!", Toast.LENGTH_LONG).show(); } }); } }); desenharMakers(); mMap.setMyLocationEnabled(true); Location location = mMap.getMyLocation(); CameraPosition INIT = null; if (location == null) { locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); location = getLastBestLocation(); } INIT = new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude())) .zoom(17.5F).build(); if (INIT != null) mMap.animateCamera(CameraUpdateFactory.newCameraPosition(INIT)); } }
From source file:com.jwork.spycamera.MainFragment.java
private void showHelp() { AlertDialog dialog = new AlertDialog.Builder(activity).create(); dialog.setTitle(this.getString(R.string.help)); WebView wv = new WebView(activity); wv.loadData(this.getString(R.string.help_html), "text/html", "utf-8"); wv.setScrollContainer(true);// www . ja v a2 s . c o m dialog.setView(wv); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, this.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Uri uri = Uri.parse("market://details?id=" + activity.getPackageName()); Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri); try { activity.startActivity(myAppLinkToMarket); } catch (ActivityNotFoundException e) { Toast.makeText(activity, "Failed to find Market application", Toast.LENGTH_LONG).show(); } } }); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Share It", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Utility.shareIt(activity); } }); dialog.show(); }