List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:com.cloudant.todo.TodoActivity.java
public Dialog createProgressDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final View v = this.getLayoutInflater().inflate(R.layout.dialog_loading, null); DialogInterface.OnClickListener negativeClick = new DialogInterface.OnClickListener() { @Override/*w w w. j a v a 2 s . c om*/ public void onClick(DialogInterface dialog, int which) { stopReplication(); } }; DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Toast.makeText(getApplicationContext(), R.string.replication_running, Toast.LENGTH_LONG).show(); return true; } return false; } }; builder.setView(v).setNegativeButton("Stop", negativeClick).setOnKeyListener(keyListener); return builder.create(); }
From source file:com.aware.ui.Plugins_Manager.java
private AlertDialog.Builder getPluginInfoDialog(String name, String version, String description, String developer) {/*from w w w . j a v a 2 s.c om*/ AlertDialog.Builder builder = new AlertDialog.Builder(Plugins_Manager.this); View plugin_info_view = inflater.inflate(R.layout.plugins_store_pkg_detail, null); TextView plugin_name = (TextView) plugin_info_view.findViewById(R.id.plugin_name); TextView plugin_version = (TextView) plugin_info_view.findViewById(R.id.plugin_version); TextView plugin_description = (TextView) plugin_info_view.findViewById(R.id.plugin_description); TextView plugin_developer = (TextView) plugin_info_view.findViewById(R.id.plugin_developer); plugin_name.setText(name); plugin_version.setText("Version: " + version); plugin_description.setText(description); plugin_developer.setText("Developer: " + developer); builder.setView(plugin_info_view); return builder; }
From source file:ca.ualberta.cs.drivr.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); userManager.setConnectivityManager((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)); /**//from w w w .java 2 s. co m * This calls the login activity a the beginning if there is no local user stored */ if (userManager.getUser().getUsername().isEmpty()) { Intent intent = new Intent(MainActivity.this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); context = getApplicationContext(); PreferenceManager.setDefaultValues(this, R.xml.pref_driver_mode, false); setSupportActionBar(toolbar); // Create an instance of GoogleAPIClient. if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } mFragment = (SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.main_map); mFragment.getMapAsync(this); autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager() .findFragmentById(R.id.place_autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { ConcretePlace concretePlace = new ConcretePlace(place); Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create(); if (userManager.getUserMode().equals(UserMode.RIDER)) { Intent intent = new Intent(MainActivity.this, NewRequestActivity.class); String concretePlaceJson = gson.toJson(concretePlace); intent.putExtra(NewRequestActivity.EXTRA_PLACE, concretePlaceJson); Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng()); startActivity(intent); } else if (userManager.getUserMode().equals(UserMode.DRIVER)) { Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class); String concretePlaceJson = gson.toJson(concretePlace); intent.putExtra(SearchRequestActivity.EXTRA_PLACE, concretePlaceJson); intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, ""); Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng()); startActivity(intent); } } @Override public void onError(Status status) { // Do nothing } }); // Using the floating action button menu system final FloatingActionMenu fabMenu = (FloatingActionMenu) findViewById(R.id.main_fab_menu); FloatingActionButton fabSettings = (FloatingActionButton) findViewById(R.id.fabSettings); FloatingActionButton fabRequests = (FloatingActionButton) findViewById(R.id.main_fab_requests); FloatingActionButton fabProfile = (FloatingActionButton) findViewById(R.id.main_fab_profile); FloatingActionButton fabHistory = (FloatingActionButton) findViewById(R.id.main_fah_history); FloatingActionButton fabLogin = (FloatingActionButton) findViewById(R.id.main_fab_login); final FloatingActionButton fabDriver = (FloatingActionButton) findViewById(R.id.main_driver_mode); final FloatingActionButton fabRider = (FloatingActionButton) findViewById(R.id.main_rider_mode); // Hide the settings FAB fabSettings.setVisibility(View.GONE); /* Change between user and driver mode. Will probably be replaced with an option in settings. For now the visibility of this is set to gone because we should not have too many FABs. Having too many FABs may cause confusion and rendering issues on small screens. */ keywordEditText = (EditText) findViewById(R.id.main_keyword_edit_text); FloatingActionButton fabMode = (FloatingActionButton) findViewById(R.id.main_fab_mode); fabMode.setVisibility(View.GONE); if (userManager.getUserMode().equals(UserMode.RIDER)) { fabRider.setVisibility(View.GONE); keywordEditText.setVisibility(View.GONE); } else { fabDriver.setVisibility(View.GONE); keywordEditText.setVisibility(View.VISIBLE); } keywordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class); intent.putExtra(SearchRequestActivity.EXTRA_PLACE, ""); intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, keywordEditText.getText().toString()); keywordEditText.setText(""); keywordEditText.clearFocus(); startActivity(intent); } return true; } }); fabMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked mode fab"); /* Will be able to implement code below once elasticSearch is up and running UserManager userManager = null; // Once elasticSearch is working will replace with finding a User if (userManager.getUserMode() == UserMode.DRIVER) { userManager.setUserMode(UserMode.RIDER); } else if (userManager.getUserMode() == UserMode.RIDER) { userManager.setUserMode(UserMode.DRIVER); //Will have to implement a method "FindNearbyRequests" to get requests whose source // is nearby and display it on the map //Intent intent = new Intent((MainActivity.this, FindNearbyRequests.class);) //startActivity(intent); }*/ } }); fabDriver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (userManager.getUser().getVehicleDescription().isEmpty()) { /* * From: http://stackoverflow.com/a/29048271 * Author: Syeda Zunairah * Accessed: November 29, 2016 * Creates a dialog box with an edit text to get the vehicle description. */ AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext()); final EditText edittext = new EditText(v.getContext()); edittext.setText("Vechicle Make"); edittext.clearComposingText(); alert.setTitle("Become a Driver!"); alert.setMessage( "Drivers are require to enter vehicle information!\n\nPlease enter your vehicle's make"); alert.setView(edittext); alert.setPositiveButton("Save Description", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String vehicleDescription = edittext.getText().toString(); if (!vehicleDescription.isEmpty()) { userManager.getUser().setVehicleDescription(vehicleDescription); userManager.notifyObservers(); userManager.setUserMode(UserMode.DRIVER); ElasticSearch elasticSearch = new ElasticSearch( userManager.getConnectivityManager()); elasticSearch.updateUser(userManager.getUser()); keywordEditText.setVisibility(View.VISIBLE); fabDriver.setVisibility(View.GONE); fabRider.setVisibility(View.VISIBLE); fabMenu.close(true); } dialog.dismiss(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); AlertDialog newAlert = alert.create(); newAlert.show(); } if (!userManager.getUser().getVehicleDescription().isEmpty()) { userManager.setUserMode(UserMode.DRIVER); keywordEditText.setVisibility(View.VISIBLE); fabDriver.setVisibility(View.GONE); fabRider.setVisibility(View.VISIBLE); fabMenu.close(true); } } }); fabRider.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { userManager.setUserMode(UserMode.RIDER); keywordEditText.setVisibility(View.GONE); fabRider.setVisibility(View.GONE); fabDriver.setVisibility(View.VISIBLE); fabMenu.close(true); } }); fabLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, LoginActivity.class); fabMenu.close(true); startActivity(intent); } }); fabSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked settings fab"); Intent intent = new Intent(MainActivity.this, SettingsActivity.class); fabMenu.close(true); startActivity(intent); } }); fabProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked profile fab"); Intent intent = new Intent(MainActivity.this, ProfileActivity.class); fabMenu.close(true); startActivity(intent); } }); fabHistory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked history fab"); Intent intent = new Intent(MainActivity.this, RequestHistoryActivity.class); fabMenu.close(true); startActivity(intent); } }); fabRequests.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked requests fab"); Intent intent = new Intent(MainActivity.this, RequestsListActivity.class); fabMenu.close(true); startActivity(intent); } }); setNotificationAlarm(context); }
From source file:com.dnielfe.manager.dialogs.FilePropertiesDialog.java
@Override public Dialog onCreateDialog(Bundle state) { activity = getActivity();// ww w . j a v a 2s . co m final AlertDialog.Builder builder = new AlertDialog.Builder(activity); mAdapter = new PropertiesAdapter(activity, mFile); builder.setTitle(mFile.getName()); builder.setNeutralButton(R.string.cancel, null); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final FilePermissionsPagerItem fragment = (FilePermissionsPagerItem) mAdapter.getItem(1); fragment.applyPermissions(getActivity()); } }); final View content = activity.getLayoutInflater().inflate(R.layout.dialog_properties_container, null); this.initView(content); builder.setView(content); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.GONE); } }); return dialog; }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.notifications) { if (Helpers.isOnline(MainActivity.this)) { // webView.stopLoading(); ////from w w w .ja v a 2s. c o m // WebView wvNotifications = new WebView(MainActivity.this); // wvNotifications.loadUrl("https://" + podDomain + "/notifications"); // // final AlertDialog d = new AlertDialog.Builder(MainActivity.this).setView(wvNotifications) // .setPositiveButton("Close", new DialogInterface.OnClickListener() { // @TargetApi(11) // public void onClick(DialogInterface dialog, int id) { // dialog.cancel(); // } // }).show(); // //// wvNotifications.setWebChromeClient(new WebChromeClient() { //// //// public void onProgressChanged(WebView view, int progress) { //// progressBar.setProgress(progress); // //// if (progress > 0 && progress <= 60) { //// view.loadUrl("javascript: ( function() {" + //// " if (document.getElementById('notification')) {" + //// " var count = document.getElementById('notification').innerHTML;" + //// " NotificationCounter.setNotificationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" + //// " } else {" + //// " NotificationCounter.setNotificationCount('0');" + //// " }" + //// " if (document.getElementById('conversation')) {" + //// " var count = document.getElementById('conversation').innerHTML;" + //// " NotificationCounter.setConversationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" + //// " } else {" + //// " NotificationCounter.setConversationCount('0');" + //// " }" + //// "})();"); //// } // //// if (progress > 60) { //// view.loadUrl("javascript: ( function() {" + //// " if(document.getElementById('main_nav')) {" + //// " document.getElementById('main_nav').parentNode.removeChild(" + //// " document.getElementById('main_nav'));" + //// " } else if (document.getElementById('main-nav')) {" + //// " document.getElementById('main-nav').parentNode.removeChild(" + //// " document.getElementById('main-nav'));" + //// " }" + //// "})();"); ////// fab.setVisibility(View.VISIBLE); //// } // //// if (progress == 100) { //// fab.collapse(); //// progressBar.setVisibility(View.GONE); //// } else { //// progressBar.setVisibility(View.VISIBLE); //// } //// } //// }); // // wvNotifications.setWebViewClient(new WebViewClient() { // @Override // public boolean shouldOverrideUrlLoading(WebView view, String url) { // if (!url.equals("https://" + podDomain + "/notifications")) { // Intent urlIntent = new Intent(MainActivity.URL_MESSAGE); // urlIntent.putExtra("url", url); // sendBroadcast(urlIntent); // } // d.dismiss(); // return true; // } // }); webView.loadUrl("https://" + podDomain + "/notifications"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.conversations) { if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/conversations"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.search) { fab.collapse(); if (Helpers.isOnline(MainActivity.this)) { final AlertDialog.Builder alert = new AlertDialog.Builder(this); final EditText input = new EditText(this); alert.setView(input); alert.setTitle(R.string.search_alert_title); alert.setPositiveButton(R.string.search_alert_people, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = input.getText().toString().trim(); String cleanTag = inputTag.replaceAll("\\*", ""); // this validate the input data for tagfind if (cleanTag.isEmpty()) { dialog.cancel(); // if user dont have added a tag Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG) .show(); } else { // User have added a search tag txtTitle.setText(R.string.fab1_title_person); webView.loadUrl("https://" + podDomain + "/people.mobile?q=" + cleanTag); } } }).setNegativeButton(R.string.search_alert_tag, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = input.getText().toString().trim(); String cleanTag = inputTag.replaceAll("\\#", ""); // this validate the input data for tagfind if (cleanTag.isEmpty()) { dialog.cancel(); // if user hasn't added a tag Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.search_alert_bytags_validate_needsomedata, Snackbar.LENGTH_LONG) .show(); } else { // User have added a search tag txtTitle.setText(R.string.fab1_title_tag); webView.loadUrl("https://" + podDomain + "/tags/" + cleanTag); } } }).setNeutralButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // } }); alert.show(); } } if (id == R.id.reload) { if (Helpers.isOnline(MainActivity.this)) { webView.reload(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.mobile) { if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/mobile/toggle"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.loadImg) { if (Helpers.isOnline(MainActivity.this)) { wSettings.setLoadsImagesAutomatically(!pm.getLoadImages()); pm.setLoadImages(!pm.getLoadImages()); webView.loadUrl(webView.getUrl()); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.fontSize) { if (Helpers.isOnline(MainActivity.this)) { alertFormElements(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } if (id == R.id.exit) { if (Helpers.isOnline(MainActivity.this)) { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(getString(R.string.confirm_sign_out)) .setPositiveButton(getString(android.R.string.yes).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { webView.clearCache(true); Intent i = new Intent(MainActivity.this, PodsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); finish(); } }) .setNegativeButton(getString(android.R.string.no).toUpperCase(), null).show(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); return false; } } return super.onOptionsItemSelected(item); }
From source file:com.balakrish.gpstracker.WaypointsListActivity.java
/** * Update waypoint in the database/* w ww . j av a 2 s.c o m*/ * * @param waypointId * @param title * @param lat * @param lng */ protected void updateWaypoint(long waypointId) { Context context = this; // get waypoint data from db final Waypoint wp = Waypoints.get(app.getDatabase(), waypointId); LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.add_waypoint_dialog, (ViewGroup) findViewById(R.id.add_waypoint_dialog_layout_root)); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.edit); builder.setView(layout); // creating reference to input field in order to use it in onClick // handler final EditText wpTitle = (EditText) layout.findViewById(R.id.waypointTitleInputText); wpTitle.setText(wp.getTitle()); final EditText wpDescr = (EditText) layout.findViewById(R.id.waypointDescriptionInputText); wpDescr.setText(wp.getDescr()); final EditText wpLat = (EditText) layout.findViewById(R.id.waypointLatInputText); wpLat.setText(Double.toString(wp.getLat())); final EditText wpLng = (EditText) layout.findViewById(R.id.waypointLngInputText); wpLng.setText(Double.toString(wp.getLng())); // this event will be overridden in OnShowListener for validation builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); final AlertDialog dialog = builder.create(); // override setOnShowListener in order to validate dialog without closing it dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // waypoint title from input dialog if (wpTitle.getText().toString().trim().equals("")) { Toast.makeText(WaypointsListActivity.this, R.string.waypoint_title_required, Toast.LENGTH_SHORT).show(); return; } wp.setTitle(wpTitle.getText().toString().trim()); wp.setDescr(wpDescr.getText().toString().trim()); // validate coordinates try { wp.setLat(Double.parseDouble(wpLat.getText().toString())); wp.setLng(Double.parseDouble(wpLng.getText().toString())); } catch (NumberFormatException e) { Toast.makeText(WaypointsListActivity.this, R.string.incorrect_coordinates, Toast.LENGTH_SHORT).show(); return; } try { // update waypoint data in db Waypoints.update(app.getDatabase(), wp); Toast.makeText(WaypointsListActivity.this, R.string.waypoint_updated, Toast.LENGTH_SHORT).show(); // cursor.requery(); updateWaypointsArray(); waypointsArrayAdapter.setItems(waypoints); waypointsArrayAdapter.notifyDataSetChanged(); } catch (SQLiteException e) { AppLog.e(WaypointsListActivity.this, "SQLiteException: " + e.getMessage()); return; } dialog.dismiss(); } }); } }); dialog.show(); }
From source file:com.aniruddhc.acemusic.player.Dialogs.AddMusicLibraryDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { libraryLabelID = "circle_blue_dark"; View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_add_music_library, null); TextView instructions = (TextView) rootView.findViewById(R.id.add_music_library_instructions); instructions.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); instructions.setPaintFlags(instructions.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); final ImageButton labelButton = (ImageButton) rootView.findViewById(R.id.add_music_library_label_button); final EditText musicLibraryName = (EditText) rootView.findViewById(R.id.add_music_library_text_field); musicLibraryName.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); musicLibraryName/* w w w . j av a 2s .com*/ .setPaintFlags(musicLibraryName.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); labelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Create a new array with a list of all the library labels. final Drawable[] labelsArray = { getActivity().getResources().getDrawable(R.drawable.circle_blue_dark), getActivity().getResources().getDrawable(R.drawable.circle_blue_light), getActivity().getResources().getDrawable(R.drawable.circle_green_dark), getActivity().getResources().getDrawable(R.drawable.circle_green_light), getActivity().getResources().getDrawable(R.drawable.circle_purple_dark), getActivity().getResources().getDrawable(R.drawable.circle_purple_light), getActivity().getResources().getDrawable(R.drawable.circle_red_dark), getActivity().getResources().getDrawable(R.drawable.circle_red_light), getActivity().getResources().getDrawable(R.drawable.circle_yellow_dark), getActivity().getResources().getDrawable(R.drawable.circle_yellow_light) }; //Create a new array with a list of all the library labels. final String[] labelsIdsArray = { "circle_blue_dark", "circle_blue_light", "circle_green_dark", "circle_green_light", "circle_purple_dark", "circle_purple_light", "circle_red_dark", "circle_red_light", "circle_yellow_dark", "circle_yellow_light" }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.music_library_label); ArrayList<String> labelTitles = new ArrayList<String>(); labelTitles .addAll(Arrays.asList(getActivity().getResources().getStringArray(R.array.library_labels))); builder.setAdapter(new LibraryLabelsAdapter(getActivity(), labelTitles), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); libraryLabelID = labelsIdsArray[which]; labelButton.setImageDrawable(labelsArray[which]); } }); builder.create().show(); } }); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); //Set the dialog title. builder.setTitle(R.string.add_music_library); builder.setView(rootView); builder.setPositiveButton(R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { String libraryName = musicLibraryName.getText().toString(); Intent intent = new Intent(getActivity(), MusicLibraryEditorActivity.class); Bundle bundle = new Bundle(); bundle.putString("LIBRARY_NAME", libraryName); bundle.putString("LIBRARY_ICON", libraryLabelID); intent.putExtras(bundle); startActivity(intent); dialog.dismiss(); getActivity().finish(); } }); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); getActivity().finish(); } }); return builder.create(); }
From source file:com.abc.driver.TruckActivity.java
public void chooseTruckWeight(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(this); GridView gridView1 = new GridView(this); gridView1.setNumColumns(3);//from ww w. j ava 2s . c o m SimpleAdapter adapter = new SimpleAdapter(this, mTruckWeightList, R.layout.truck_weight_griditem, new String[] { "TITLE", "TWEIGHT" }, new int[] { R.id.griditem_title, R.id.griditem_weight, }); gridView1.setAdapter(adapter); builder.setTitle("Please Choose"); builder.setInverseBackgroundForced(true); builder.setView(gridView1); final Dialog dialog = builder.create(); gridView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { mTWtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText()); mTruckWeight = ((TextView) view.findViewById(R.id.griditem_weight)).getText().toString(); mUpdateTruckTask = new UpdateTruckTask(); mUpdateTruckTask.execute("" + app.getUser().getMyTruck().getTruckId(), "" + app.getUser().getMyTruck().getTypeId(), "" + app.getUser().getMyTruck().getLengthId(), mTruckWeight, "" + app.getUser().getMyTruck().getStatusId(), "" + app.getUser().getId()); dialog.dismiss(); } }); dialog.show(); }
From source file:com.citrus.sdk.CitrusActivity.java
private void showPrompt() { final AlertDialog.Builder alert = new AlertDialog.Builder(mContext); String message = null;/*from w ww .ja v a 2 s. c om*/ String title = null; if (passwordPromptShown) { message = "Incorrect Password."; title = "Please Enter Password Again."; } else { message = "Please Enter Your Password For Citrus Account."; title = "Enter Password"; } String positiveButtonText = "Pay"; alert.setTitle(title); alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(mContext); alert.setView(input); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String password = input.getText().toString(); input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); if (!TextUtils.isEmpty(password)) { mPaymentWebview .loadUrl("javascript:(function() { " + "document.getElementById('password').value='" + password + "';" + "document.getElementById(\"verify\").submit();" + "}) ()"); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); String emailId = mCitrusClient.getUserEmailId(); getCookie(emailId, password); dialog.dismiss(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { onBackPressed(); } }); input.requestFocus(); alert.show(); }