public void addPlaceToDB() { // int duration = Toast.LENGTH_LONG; if (this.currentPlace != null) { try { placeDB.openDatabase(); boolean exists = placeDB.existsPlace(placeIdToDB); if (exists) { Dialog d2 = new Dialog(this); d2.setTitle("This Place is already in your Place List!"); d2.show(); } else { // long timeOpensInMilliseconds = Long.valueOf(eventToCalendar.getTime())* // 1000;//startDate.getTimeInMillis(); // long timeClosesInMilliseconds = Long.valueOf(eventToCalendar.getTime())* // 1000;//endDate.getTimeInMillis(); placeDB.createPlaceRecord( placeIdToDB, currentPlace.getName(), currentPlace.getLocation().getAddress(), currentPlace.getLocation().getLatitude(), currentPlace.getLocation().getLongitude(), currentPlace.getDescription(), currentPlace.getWebsite(), placeSourceToDB); // eventDB.createEventRecord(eventNameOnly, createdCalendarEventID, eLocation); Dialog d = new Dialog(this); d.setTitle("New Place Added to your Place List!"); d.show(); } placeDB.closeDatabase(); } catch (Exception e) { e.printStackTrace(); } } }
public void showPlace(Place place) { if (place != null) { this.currentPlace = place; // create place name. TextView name = (TextView) findViewById(R.id.place_name); if (name != null) { name.setText(place.getName()); } // create PLACE description. TextView description = (TextView) findViewById(R.id.place_description); if (description != null) { String descStr = place.getDescription(); if (descStr != null && !descStr.isEmpty() && !descStr.equals("null")) { description.setText(descStr); } else { description.setVisibility(View.GONE); } } if (place.getImage() != null && !place.getImage().isEmpty()) { // place image ImageView image = (ImageView) findViewById(R.id.place_image); if (image != null) { DataManager.getSingleton().downloadBitmap(place.getImage(), image); } } // place location Location location = place.getLocation(); if (location != null) { TextView placeLocation = (TextView) findViewById(R.id.place_location); if (placeLocation != null) { placeLocation.setText(location.getAddress()); } // place distance. TextView distance = (TextView) findViewById(R.id.place_distance); if (distance != null) { float[] distanceResults = new float[1]; android.location.Location currentLocation = AppLocationManager.getCurrentLocation(); DecimalFormat df = new DecimalFormat("#.#"); if (currentLocation != null) { android.location.Location.distanceBetween( currentLocation.getLatitude(), currentLocation.getLongitude(), Double.valueOf(location.getLatitude()), Double.valueOf(location.getLongitude()), distanceResults); double miles = distanceResults[0] / 1609.34; // i mile = // 1.60934km distance.setText(df.format(miles) + "mi"); } else { distance.setText("--"); } } MapView map = (MapView) findViewById(R.id.mapview); if (map != null) { MapController mc = map.getController(); if (mc != null) { List<Overlay> mapOverlaysList = map.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.red_pointer_icon); // creating an ItemizedOverlayActivity object so we can // have multiple overlays // added to a list to show them in a map ItemizedOverlayActivity itemizedoverlay = new ItemizedOverlayActivity(drawable, this); GeoPoint geoPoint = new GeoPoint( (int) (Double.valueOf(location.getLatitude()) * 1E6), (int) (Double.valueOf(location.getLongitude()) * 1E6)); // Creates an overlay item with a geopoint to show in // the map OverlayItem overlayitem = new OverlayItem(geoPoint, "Place", place.getName()); itemizedoverlay.addOverlay(overlayitem); mapOverlaysList.add(itemizedoverlay); mc.setCenter(geoPoint); mc.setZoom(17); } } showEventList(place.getEventsAtPlace()); } } } // end showPlace