List of usage examples for android.app AlertDialog.Builder create
public void create()
From source file:li.barter.fragments.ChatsFragment.java
@Override public void onDialogClick(final DialogInterface dialog, final int which) { if ((mChatDialogFragment != null) && mChatDialogFragment.getDialog().equals(dialog)) { if (which == 0) { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Confirm"); // set dialog message alertDialogBuilder.setMessage(getResources().getString(R.string.delete_chat_alert_message)) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { deleteChat(mDeleteChatId); dialog.dismiss(); }//from ww w . j a va2 s .c o m }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog final AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else if (which == 1) { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Confirm"); // set dialog message alertDialogBuilder.setMessage(getResources().getString(R.string.block_user_alert_message)) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { blockUser(mBlockUserId); dialog.dismiss(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog final AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } else { super.onDialogClick(dialog, which); } }
From source file:RhodesService.java
private File downloadPackage(String url) throws IOException { final Context ctx = RhodesActivity.getContext(); final Thread thisThread = Thread.currentThread(); final Runnable cancelAction = new Runnable() { public void run() { thisThread.interrupt();/*from w w w. ja v a 2 s . c om*/ } }; BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage("Cancel download?"); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { cancelAction.run(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Nothing } }); dialog.show(); } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) { cancelAction.run(); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD); filter.addAction(ACTION_CANCEL_DOWNLOAD); ctx.registerReceiver(downloadReceiver, filter); File tmpFile = null; InputStream is = null; OutputStream os = null; try { updateDownloadNotification(url, -1, 0); /* List<File> folders = new ArrayList<File>(); folders.add(Environment.getDownloadCacheDirectory()); folders.add(Environment.getDataDirectory()); folders.add(ctx.getCacheDir()); folders.add(ctx.getFilesDir()); try { folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir)); } catch (NameNotFoundException e1) { // Ignore } folders.add(Environment.getExternalStorageDirectory()); for (File folder : folders) { File tmpRootFolder = new File(folder, "rhodownload"); File tmpFolder = new File(tmpRootFolder, ctx.getPackageName()); if (tmpFolder.exists()) deleteFilesInFolder(tmpFolder.getAbsolutePath()); else tmpFolder.mkdirs(); File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk"); Logger.D(TAG, "Check path " + of.getAbsolutePath() + "..."); try { os = new FileOutputStream(of); } catch (FileNotFoundException e) { Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path"); continue; } Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app"); tmpFile = of; break; } */ tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk"); os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE); Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "..."); URL u = new URL(url); URLConnection conn = u.openConnection(); int totalBytes = -1; if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; totalBytes = httpConn.getContentLength(); } is = conn.getInputStream(); int downloaded = 0; updateDownloadNotification(url, totalBytes, downloaded); long prevProgress = 0; byte[] buf = new byte[65536]; for (;;) { if (thisThread.isInterrupted()) { tmpFile.delete(); Logger.D(TAG, "Download of " + url + " was canceled"); return null; } int nread = is.read(buf); if (nread == -1) break; //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes..."); os.write(buf, 0, nread); downloaded += nread; if (totalBytes > 0) { // Update progress view only if current progress is greater than // previous by more than 10%. Otherwise, if update it very frequently, // user will no have chance to click on notification view and cancel if need long progress = downloaded * 10 / totalBytes; if (progress > prevProgress) { updateDownloadNotification(url, totalBytes, downloaded); prevProgress = progress; } } } Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath()); return tmpFile; } catch (IOException e) { if (tmpFile != null) tmpFile.delete(); throw e; } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (os != null) os.close(); } catch (IOException e) { } mNM.cancel(DOWNLOAD_PACKAGE_ID); ctx.unregisterReceiver(downloadReceiver); } }
From source file:de.j4velin.mapsmeasure.Map.java
@SuppressLint("NewApi") @Override/*from w w w. j a va 2s . co m*/ public void onCreate(final Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); } catch (final BadParcelableException bpe) { bpe.printStackTrace(); } setContentView(R.layout.activity_map); formatter_no_dec.setMaximumFractionDigits(0); formatter_two_dec.setMaximumFractionDigits(2); final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE); // use metric a the default everywhere, except in the US metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US)); final View topCenterOverlay = findViewById(R.id.topCenterOverlay); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final View menuButton = findViewById(R.id.menu); if (menuButton != null) { menuButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { mDrawerLayout.openDrawer(GravityCompat.START); } }); } if (mDrawerLayout != null) { mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { private boolean menuButtonVisible = true; @Override public void onDrawerStateChanged(int newState) { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onDrawerSlide(final View drawerView, final float slideOffset) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setAlpha(1 - slideOffset); if (menuButtonVisible && menuButton != null && slideOffset > 0) { menuButton.setVisibility(View.INVISIBLE); menuButtonVisible = false; } } @Override public void onDrawerOpened(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.INVISIBLE); } @Override public void onDrawerClosed(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.VISIBLE); if (menuButton != null) { menuButton.setVisibility(View.VISIBLE); menuButtonVisible = true; } } }); } mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mMap == null) { Dialog d = GooglePlayServicesUtil .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0); d.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); d.show(); return; } marker = BitmapDescriptorFactory.fromResource(R.drawable.marker); mMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker click) { addPoint(click.getPosition()); return true; } }); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { if (mMap.getMyLocation() != null) { LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude()); double distance = SphericalUtil.computeDistanceBetween(myLocation, mMap.getCameraPosition().target); // Only if the distance is less than 50cm we are on our location, add the marker if (distance < 0.5) { Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show(); addPoint(myLocation); } } return false; } }); // check if open with csv file if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { try { Util.loadFromFile(getIntent().getData(), this); if (!trace.isEmpty()) mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16)); } catch (IOException e) { Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(final Bundle bundle) { Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (l != null && mMap.getCameraPosition().zoom <= 2) { mMap.moveCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16)); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int cause) { } }).build(); mGoogleApiClient.connect(); valueTv = (TextView) findViewById(R.id.distance); updateValueText(); valueTv.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (type == MeasureType.DISTANCE) changeType(MeasureType.AREA); // only switch to elevation mode is an internet connection is // available and user has access to this feature else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION) changeType(MeasureType.ELEVATION); else changeType(MeasureType.DISTANCE); } }); View delete = findViewById(R.id.delete); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { removeLast(); } }); delete.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(final View v) { AlertDialog.Builder builder = new AlertDialog.Builder(Map.this); builder.setMessage(getString(R.string.delete_all, trace.size())); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clear(); dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } }); mMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(final LatLng center) { addPoint(center); } }); // Drawer stuff ListView drawerList = (ListView) findViewById(R.id.left_drawer); drawerListAdapert = new DrawerListAdapter(this); drawerList.setAdapter(drawerListAdapert); drawerList.setDivider(null); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) { switch (position) { case 0: // Search before Android 5.0 Dialogs.getSearchDialog(Map.this).show(); closeDrawer(); break; case 2: // Units Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show(); closeDrawer(); break; case 3: // distance changeType(MeasureType.DISTANCE); break; case 4: // area changeType(MeasureType.AREA); break; case 5: // elevation if (PRO_VERSION) { changeType(MeasureType.ELEVATION); } else { Dialogs.getElevationAccessDialog(Map.this, mService).show(); } break; case 7: // map changeView(GoogleMap.MAP_TYPE_NORMAL); break; case 8: // satellite changeView(GoogleMap.MAP_TYPE_HYBRID); break; case 9: // terrain changeView(GoogleMap.MAP_TYPE_TERRAIN); break; case 11: // save Dialogs.getSaveNShare(Map.this, trace).show(); closeDrawer(); break; case 12: // more apps try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (ActivityNotFoundException anf) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 13: // about Dialogs.getAbout(Map.this).show(); closeDrawer(); break; default: break; } } }); changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL)); changeType(MeasureType.DISTANCE); // KitKat translucent decor enabled? -> Add some margin/padding to the // drawer and the map if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { int statusbar = Util.getStatusBarHeight(this); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams(); lp.setMargins(0, statusbar + 10, 0, 0); topCenterOverlay.setLayoutParams(lp); // on most devices and in most orientations, the navigation bar // should be at the bottom and therefore reduces the available // display height int navBarHeight = Util.getNavigationBarHeight(this); DisplayMetrics total, available; total = new DisplayMetrics(); available = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(available); API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total); boolean navBarOnRight = getResources() .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE && (total.widthPixels - available.widthPixels > 0); if (navBarOnRight) { // in landscape on phones, the navigation bar might be at the // right side, reducing the available display width mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0); drawerList.setPadding(0, statusbar + 10, 0, 0); if (menuButton != null) menuButton.setPadding(0, 0, 0, 0); } else { mMap.setPadding(0, statusbar, 0, navBarHeight); drawerList.setPadding(0, statusbar + 10, 0, 0); drawerListAdapert.setMarginBottom(navBarHeight); if (menuButton != null) menuButton.setPadding(0, 0, 0, navBarHeight); } } mMap.setMyLocationEnabled(true); PRO_VERSION |= prefs.getBoolean("pro", false); if (!PRO_VERSION) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND") .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE); } }
From source file:org.thomasamsler.android.flashcards.fragment.CardSetsFragment.java
private void deleteCardSet(final int listItemPosition) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setMessage(R.string.delete_card_set_dialog_message); builder.setCancelable(false);//from w w w .java2 s.c o m builder.setPositiveButton(R.string.delete_card_set_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { CardSet cardSet = mCardSets.get(listItemPosition); List<CardSet> cardSets = mDataSource.getCardSets(); if (cardSets.contains(cardSet)) { mDataSource.deleteCardSet(cardSet); } mCardSets.remove(listItemPosition); Collections.sort(mCardSets); mArrayAdapter.notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.delete_card_set_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java
@SuppressWarnings("nls") private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.tr_alert_gps_title)).setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_CODE_ENABLE_GPS); showingNoGPSAlertMessage = false; }//from w w w .jav a 2 s. c o m }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); showingNoGPSAlertMessage = false; showIntroDialog(); } }); final AlertDialog alert = builder.create(); alert.show(); }
From source file:de.fhg.fokus.famium.presentation.CDVPresentationPlugin.java
private void showDisplaySelectionDialog(final PresentationSession session) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); Collection<SecondScreenPresentation> collection = getPresentations().values(); int size = collection.size(); int counter = 0; final SecondScreenPresentation presentations[] = new SecondScreenPresentation[size]; String items[] = new String[size]; for (SecondScreenPresentation presentation : collection) { presentations[counter] = presentation; items[counter++] = presentation.getDisplay().getName(); }// ww w.jav a 2 s .c o m builder.setTitle("Select Presentation Display").setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SecondScreenPresentation presentation = presentations[which]; session.setPresentation(presentation); getSessions().put(session.getId(), session); } }).setCancelable(false).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { session.setState(PresentationSession.DISCONNECTED); } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.raceyourself.android.samsung.ProviderService.java
private void popupNetworkDialog() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(//ww w . j a v a 2 s . co m "RaceYourself needs to connect to the internet to register your device. Please check your connection and press retry.") .setCancelable(false).setPositiveButton("Retry", new DialogInterface.OnClickListener() { public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { runUserInit(); } }).setNegativeButton("Quit", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) { ProviderService.this.stopSelf(); } }).setTitle("RaceYourself Gear Edition"); alert = builder.create(); alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); alert.show(); }
From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java
private void createDevicesListDialog() { deviceNames = new String[devices.size()]; chosenDevices = new boolean[devices.size()]; for (int i = 0; i < devices.size(); i++) { deviceNames[i] = devices.get(i).getName(); }//from w ww . j a v a2s . c om AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); dialogBuilder.setTitle(R.string.activity_edit_event_pick_devices); dialogBuilder.setMultiChoiceItems(deviceNames, chosenDevices, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { pickedDevices.add(devices.get(which)); devicesText.setError(null); } else { pickedDevices.remove(devices.get(which)); } updateDevicesText(); } }); dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Nothing to do... } }); devicesListDialog = dialogBuilder.create(); }
From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java
@Override public void onRequestcompleted(int requestCode, Object result) { timeoutHandler.removeCallbacks(timeout); if (mPd != null && mPd.isShowing()) { // clear pd from memory to avoid progress bar freeze when showed again removeDialog(DIALOG_PROGRESS);// w w w .j a v a2s .c om } // //Log.d(Constants.PROJECT_TAG, "Request result " + (String) result); if (requestCode == AVService.REQUEST_IMAGE) { new AlertDialog.Builder(this).setMessage(R.string.news_photo_added) .setPositiveButton(android.R.string.ok, null).show(); requestAdditionalPhotos(); return; } if (requestCode == AVService.REQUEST_JSON && result != null) { try { JSONObject answer = new JSONArray((String) result).getJSONObject(0); boolean isIncident = JsonData.VALUE_REQUEST_NEW_INCIDENT .equals(answer.getString(JsonData.PARAM_REQUEST)); boolean isOk = (JsonData.VALUE_INCIDENT_SAVED == (answer.getJSONObject(JsonData.PARAM_ANSWER) .getInt(JsonData.PARAM_STATUS))); if (isIncident && isOk) { /* * FileInputStream fis_close = openFileInput(CAPTURE_CLOSE); * FileInputStream fis_far = openFileInput(CAPTURE_FAR); */ File img_close = new File(getFilesDir() + "/" + CAPTURE_CLOSE); if (!img_close.exists() || ((ImageView) findViewById(R.id.ImageView_close)).getDrawable() == null) { img_close = null; } File img_far = new File(getFilesDir() + "/" + CAPTURE_ARROW); if (!img_far.exists() || ((ImageView) findViewById(R.id.ImageView_far)).getDrawable() == null) { img_far = null; } // if (!img_far.exists()) { // img_far = new File(getFilesDir() + "/" + CAPTURE_FAR); // } // TODO add a listener which handles commands properly AVService.getInstance(this).postImage(null, Utils.getUdid(this), img_comment, answer.getJSONObject(JsonData.PARAM_ANSWER).getString(JsonData.ANSWER_INCIDENT_ID), img_far, img_close, true); AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alert; builder.setMessage(R.string.report_detail_new_report_ok).setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); alert = builder.create(); alert.show(); } else { // hotfix nico : here we can have valid answer for incident updates !!! // handle answer and display popup here instead of when we click on buttons int statuscode = answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS); if (statuscode == 0) { // FIXME end activity when resolve incident ?? switch (mCurrentAction) { case ACTION_GET_IMAGES: //Log.d("AlerteVoirie_PM", "images : " + result); JSONArray imgList = answer.getJSONObject(JsonData.PARAM_ANSWER) .getJSONArray(JsonData.PARAM_PHOTOS); ViewGroup photocontainer = (ViewGroup) findViewById(R.id.extra_images_container); photocontainer.removeAllViews(); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); for (int i = 0; i < imgList.length() - 2; i++) { JSONObject imgObj = imgList.getJSONObject(i); //Log.d("AlerteVoirie_PM", "received image obj : " + imgObj); View v = getLayoutInflater().inflate(R.layout.extra_photo, null); v.setLayoutParams(params); TextView date = (TextView) v.findViewById(R.id.textView_date); TextView comment = (TextView) v.findViewById(R.id.textView_comment); ImageView icon = (ImageView) v.findViewById(R.id.imageView_icon); // format date String dateString = imgObj.getString(JsonData.PARAM_IMAGES_DATE); date.setText(getFormatedDate(dateString)); comment.setText(imgObj.getString(JsonData.PARAM_IMAGES_COMMENT)); imgd.download(imgObj.getString(JsonData.PARAM_IMAGES_URL), icon); photocontainer.addView(v); } if (imgList.length() > 2) { findViewById(R.id.TextView_additional_photos_header).setVisibility(View.VISIBLE); } else { findViewById(R.id.TextView_additional_photos_header).setVisibility(View.GONE); } break; case ACTION_CONFIRM_INCIDENT: findViewById(R.id.existing_incidents_confirmed).setEnabled(false); new AlertDialog.Builder(this).setMessage(R.string.news_incidents_confirmed) .setPositiveButton(android.R.string.ok, null).show(); break; case ACTION_INVALID_INCIDENT: { AlertDialog dialog = new AlertDialog.Builder(this) .setMessage(R.string.news_incidents_invalidated) .setPositiveButton(android.R.string.ok, null).create(); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); dialog.show(); break; } case ACTION_SOLVE_INCIDENT: { AlertDialog dialog = new AlertDialog.Builder(this) .setMessage(R.string.news_incidents_resolved) .setPositiveButton(android.R.string.ok, null).create(); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); dialog.show(); break; } default: // assume it's a generic update request in other cases ... new AlertDialog.Builder(this).setMessage(R.string.report_detail_update_ok) .setPositiveButton(android.R.string.ok, null).show(); break; } } else { // other things // FIXME show popups instead of toasts ! if ((answer.getJSONObject(JsonData.PARAM_ANSWER).getInt(JsonData.PARAM_STATUS)) == 18) { findViewById(R.id.existing_incidents_confirmed).setEnabled(false); Toast.makeText(this, getString(R.string.incident_already_confirmed), Toast.LENGTH_LONG) .show(); } else { //Log.d("AlerteVoirie_PM", "erreur ?"); Toast.makeText(this, getString(R.string.server_error), Toast.LENGTH_LONG).show(); } } } } catch (JSONException e) { Log.e(Constants.PROJECT_TAG, "Erreur d'envoi d'image", e); } /* * catch (FileNotFoundException e) { * // TODO Auto-generated catch block * Log.e(Constants.PROJECT_TAG,"File not found",e); * } */ } else if (requestCode == AVService.REQUEST_ERROR) { AVServiceErrorException error = (AVServiceErrorException) result; String errorString = null; switch (error.errorCode) { case 19: // already invalidated errorString = getString(R.string.error_already_invalidated); break; default: errorString = getString(R.string.server_error); break; } new AlertDialog.Builder(this).setTitle(R.string.error_popup_title).setMessage(errorString) .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).show(); } }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
public boolean onItemLongClick(final AdapterView<?> parent, final View v, final int position, final long id) { final CharSequence[] items = getResources().getTextArray(R.array.menu_contextual); AlertDialog.Builder b = new AlertDialog.Builder(this); final ResultadoBusqueda rb = (ResultadoBusqueda) parent.getAdapter().getItem(position); b.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss();/*from w ww . j av a 2s . c o m*/ switch (item) { case 0: onItemClick(parent, v, position, id); break; case 1: //TODO: Pasar a GMaps la versin localizada de "Current location" para que haga l la bsqueda de origen String latlongactual = lBest.getLatitude() + "," + lBest.getLongitude(); String latlongdestino = rb.getEstacion().getLoc().getLatitude() + "," + rb.getEstacion().getLoc().getLongitude(); Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse( "http://maps.google.com/maps?saddr=" + latlongactual + "&daddr=" + latlongdestino)); startActivity(intent); break; } } }); AlertDialog alert = b.create(); alert.show(); return true; }