List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:com.andryr.musicplayer.fragments.dialog.ListDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(mTitle);//from ww w.j a v a 2s .c om View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_list_dialog, null); RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); recyclerView.setAdapter(mAdapter); builder.setView(rootView); return builder.create(); }
From source file:cochrane343.journal.MainActivity.java
@Override public void onAddExpense(final String description, final long costInCents, final long category) { final int selectedMonth = viewPager.getCurrentItem(); final boolean selectedMonthIsCurrentMonth = selectedMonth == DateTimeHelper.getMonthsSinceEpoch(); if (selectedMonthIsCurrentMonth) { addExpenseToCurrentMonth(description, costInCents, category); } else {/* ww w .j a va 2 s. co m*/ if (shouldShowPastExpenseWarning()) { // TODO Consider refactoring into separate method final LayoutInflater inflater = LayoutInflater.from(this); final View warningLayout = inflater.inflate(R.layout.past_expense_warning, null); final CheckBox doNotAskAgainCheckbox = (CheckBox) warningLayout .findViewById(R.id.do_not_show_again); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(warningLayout).setTitle(R.string.label_past_expense) .setMessage(R.string.label_past_expense_message) .setPositiveButton(R.string.label_yes_add_to_past, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { if (doNotAskAgainCheckbox.isChecked()) { setShowPastExpenseWarning(false); } addExpenseToEndOfSelectedMonth(description, costInCents, category); } }) .setNegativeButton(R.string.label_no_add_to_current, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (doNotAskAgainCheckbox.isChecked()) { setShowPastExpenseWarning(false); } addExpenseToCurrentMonth(description, costInCents, category); } }).show(); } else { addExpenseToEndOfSelectedMonth(description, costInCents, category); } } }
From source file:com.example.amapapplicationtest.MainActivity.java
/** Called when the activity is first created. */ @Override//from ww w . ja v a 2 s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initMap(); LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); String provider = lm.getBestProvider(new Criteria(), true); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { googlemap.animateCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder googlemap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } if (provider == null) { onProviderDisabled(provider); } data = new MarkerDataSource(context); try { data.open(); } catch (Exception e) { Log.i("hello", "hello"); } List<MyMarkerObj> m = data.getMyMarkers(); for (int i = 0; i < m.size(); i++) { String[] slatlng = m.get(i).getPosition().split(" "); LatLng lat = new LatLng(Double.valueOf(slatlng[0]), Double.valueOf(slatlng[1])); googlemap.addMarker( new MarkerOptions().title(m.get(i).getTitle()).snippet(m.get(i).getSnippet()).position(lat)); googlemap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { public void onInfoWindowClick(Marker marker) { Toast.makeText(getBaseContext(), "Info Window clicked@" + marker.getId(), Toast.LENGTH_SHORT) .show(); } }); // marker.view(); // data.getMarker(new MyMarkerObj(marker.getTitle(), marker.getSnippet(), marker.getPosition().latitude + " " + marker.getPosition().longitude)); } googlemap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { public void onMapLongClick(final LatLng latlng) { LayoutInflater li = LayoutInflater.from(context); final View v = li.inflate(R.layout.alertlayout, null); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setView(v); builder.setCancelable(false); builder.setPositiveButton("Create", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EditText title = (EditText) v.findViewById(R.id.ettitle); EditText snippet = (EditText) v.findViewById(R.id.etsnippet); googlemap.addMarker(new MarkerOptions().title(title.getText().toString()) .snippet(snippet.getText().toString()) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)) .position(latlng)); String sll = latlng.latitude + " " + latlng.longitude; data.addMarker( new MyMarkerObj(title.getText().toString(), snippet.getText().toString(), sll)); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } }); }
From source file:com.googlecode.android_scripting.facade.ui.SeekBarDialogTask.java
@Override public void onCreate() { super.onCreate(); mSeekBar = new SeekBar(getActivity()); mSeekBar.setMax(mMax);//from w w w . ja va 2 s. c o m mSeekBar.setProgress(mProgress); mSeekBar.setPadding(10, 0, 10, 3); mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar arg0) { } public void onStartTrackingTouch(SeekBar arg0) { } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { EventFacade eventFacade = getEventFacade(); if (eventFacade != null) { JSONObject result = new JSONObject(); try { result.put("which", "seekbar"); result.put("progress", mSeekBar.getProgress()); result.put("fromuser", fromUser); eventFacade.postEvent("dialog", result); } catch (JSONException e) { Log.e(e); } } } }); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (mTitle != null) { builder.setTitle(mTitle); } if (mMessage != null) { builder.setMessage(mMessage); } builder.setView(mSeekBar); configureButtons(builder, getActivity()); addOnCancelListener(builder, getActivity()); mDialog = builder.show(); mShowLatch.countDown(); }
From source file:ca.rmen.android.scrumchatter.dialog.InputDialogFragment.java
@Override @NonNull/*from ww w. j a v a 2 s .c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState); if (savedInstanceState != null) mEnteredText = savedInstanceState.getString(DialogFragmentFactory.EXTRA_ENTERED_TEXT); Bundle arguments = getArguments(); final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID); final InputDialogEditTextBinding binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.input_dialog_edit_text, null, false); final Bundle extras = arguments.getBundle(DialogFragmentFactory.EXTRA_EXTRAS); final Class<?> inputValidatorClass = (Class<?>) arguments .getSerializable(DialogFragmentFactory.EXTRA_INPUT_VALIDATOR_CLASS); final String prefilledText = arguments.getString(DialogFragmentFactory.EXTRA_ENTERED_TEXT); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE)); builder.setView(binding.getRoot()); binding.edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); binding.edit.setHint(arguments.getString(DialogFragmentFactory.EXTRA_INPUT_HINT)); binding.edit.setText(prefilledText); if (!TextUtils.isEmpty(mEnteredText)) binding.edit.setText(mEnteredText); // Notify the activity of the click on the OK button. OnClickListener listener = null; if ((getActivity() instanceof DialogInputListener)) { listener = (dialog, which) -> { FragmentActivity activity = getActivity(); if (activity == null) Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?"); else ((DialogInputListener) activity).onInputEntered(actionId, binding.edit.getText().toString(), extras); }; } builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, listener); final AlertDialog dialog = builder.create(); // Show the keyboard when the EditText gains focus. binding.edit.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { Window window = dialog.getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); final Context context = getActivity(); try { final InputValidator validator = inputValidatorClass == null ? null : (InputValidator) inputValidatorClass.newInstance(); Log.v(TAG, "input validator = " + validator); // Validate the text as the user types. binding.edit.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mEnteredText = binding.edit.getText().toString(); if (validator != null) validateText(context, dialog, binding.edit, validator, actionId, extras); } }); dialog.setOnShowListener(dialogInterface -> { Log.v(TAG, "onShow"); validateText(context, dialog, binding.edit, validator, actionId, extras); }); } catch (Exception e) { Log.e(TAG, "Could not instantiate validator " + inputValidatorClass + ": " + e.getMessage(), e); } return dialog; }
From source file:com.docd.purefm.ui.dialogs.PartitionInfoDialog.java
public Dialog onCreateDialog(final Bundle savedInstanceState) { final Activity activity = this.getActivity(); if (activity == null || activity.isFinishing()) { return null; }/* ww w . j a va 2s. c o m*/ //noinspection InflateParams mView = activity.getLayoutInflater().inflate(R.layout.dialog_partition_info, null); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_info)); builder.setTitle(R.string.menu_partition); builder.setView(mView); builder.setNeutralButton(R.string.close, null); return builder.create(); }
From source file:company.test.Test.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. int id = item.getItemId(); switch (id) { case R.id.add_item: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Add a task"); builder.setMessage("What do you want to do?"); final EditText inputField = new EditText(this); builder.setView(inputField); builder.setPositiveButton("Add", new DialogInterface.OnClickListener() { @Override/*from w ww .j ava2 s.com*/ public void onClick(DialogInterface dialogInterface, int i) { String task = inputField.getText().toString(); Log.d("MainActivity", task); SQLiteDatabase db = helper.getWritableDatabase(); ContentValues values = new ContentValues(); values.clear(); values.put(ItemContract.Columns.ITEM, task); db.insertWithOnConflict(ItemContract.TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE); activity.updateUI(); } }); builder.setNegativeButton("Cancel", null); builder.create().show(); return true; case R.id.action_settings: Log.d("MainActivity", "Settings"); return true; default: return false; } }
From source file:com.andryr.musicplayer.fragments.dialog.AlbumEditorDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.edit_tags); View dialogView = getActivity().getLayoutInflater().inflate(R.layout.fragment_album_editor_dialog, null); builder.setView(dialogView); mTitleEditText = (EditText) dialogView.findViewById(R.id.title); mArtistEditText = (EditText) dialogView.findViewById(R.id.artist); mYearEditText = (EditText) dialogView.findViewById(R.id.year); mTitleEditText.setText(mAlbum.getAlbumName()); mArtistEditText.setText(mAlbum.getArtistName()); mYearEditText.setText(String.valueOf(mAlbum.getYear())); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override/*from w ww . j a va 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { final Activity activity = getActivity(); dismiss(); new AsyncTask<Object, Object, Boolean>() { @Override protected Boolean doInBackground(Object... params) { return saveTags(activity); } @Override protected void onPostExecute(Boolean b) { super.onPostExecute(b); if (b) { if (mListener != null) { mListener.onEditionSuccess(); } } else { Toast.makeText(getActivity(), R.string.tags_edition_failed, Toast.LENGTH_SHORT).show(); } } }.execute(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }); return builder.create(); }
From source file:com.drisoftie.frags.comp.BaseDiagResult.java
@Override public Dialog onCreateDialog(@NonNull Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(getArguments().getInt(getString(R.string.bundl_diag_layout)), null); createDialogComponents(v);//w w w . j a v a2s .c o m builder.setView(v); if (getArguments().containsKey(getString(R.string.bundl_diag_title))) { Object arg = getArguments().get(getString(R.string.bundl_diag_title)); if (arg instanceof String) { builder.setTitle(getArguments().getString(getString(R.string.bundl_diag_title))); } else if (arg instanceof Integer) { builder.setTitle(getArguments().getInt(getString(R.string.bundl_diag_title))); } } if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) { builder.setPositiveButton(getArguments().getInt(getString(R.string.bundl_diag_btn_positive)), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); } if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) { builder.setNegativeButton(getArguments().getInt(getString(R.string.bundl_diag_btn_negative)), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); } AlertDialog diag = builder.create(); diag.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); return diag; }
From source file:pl.bcichecki.rms.client.android.dialogs.DeviceDetailsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (device == null) { throw new IllegalStateException("Device has not been set!"); }/*from ww w . j a v a 2 s . co m*/ context = getActivity(); eventsRestClient = new EventsRestClient(getActivity(), UserProfileHolder.getUsername(), UserProfileHolder.getPassword(), SharedPreferencesWrapper.getServerRealm(), SharedPreferencesWrapper.getServerAddress(), SharedPreferencesWrapper.getServerPort(), SharedPreferencesWrapper.getWebserviceContextPath()); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); dialogBuilder.setTitle(getString(R.string.dialog_device_details_title, device.getName())); dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_device_details, null)); dialogBuilder.setNeutralButton(R.string.dialog_device_details_btn_show_reservations, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Date now = new Date(); final Date from = DateUtils.round(DateUtils.addDays(now, DAYS_BACK - 1), Calendar.DAY_OF_MONTH); final Date till = DateUtils.round(DateUtils.addDays(now, DAYS_AHEAD + 1), Calendar.DAY_OF_MONTH); final FragmentManager fragmentManager = getFragmentManager(); Log.d(getTag(), "Retrieving device's events for " + device); eventsRestClient.getDevicesEvents(device, from, till, new GsonHttpResponseHandler<List<Event>>(new TypeToken<List<Event>>() { }.getType(), true) { @Override public void onFailure(Throwable error, String content) { Log.d(getTag(), "Retrieving device's events from " + from.toString() + " till " + till.toString() + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error) .getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(context, R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(context, R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(context, R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(getTag(), "Retrieving device's events finished."); } @Override public void onStart() { Log.d(getTag(), "Retrieving device's events from " + from.toString() + " till " + till.toString() + " started."); } @Override public void onSuccess(int statusCode, List<Event> events) { Log.d(getTag(), "Retrieving device's events from " + from.toString() + " till " + till.toString() + " successful. Retrieved " + events.size() + " objects."); DeviceReservationsDialog deviceReservationsDialog = new DeviceReservationsDialog(); deviceReservationsDialog.setDevice(device); deviceReservationsDialog.setEvents(events); deviceReservationsDialog.show(fragmentManager, getTag()); } }); } }); dialogBuilder.setPositiveButton(R.string.general_close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Nothing to do... } }); AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { TextView nameTextView = (TextView) ((AlertDialog) dialog) .findViewById(R.id.dialog_device_details_name_text); nameTextView.setText(device.getName()); TextView descriptionTextView = (TextView) ((AlertDialog) dialog) .findViewById(R.id.dialog_device_details_description_text); descriptionTextView.setText(device.getName()); } }); return dialog; }