Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
  2. private static final String TAG = "CustomInfoWindow";
  3. private View window;
  4. private Context context;
  5. private POI place;
  6. private ImageView img;
  7. private Marker lastMarker = null;
  8. public CustomInfoWindow(Context context,POI place) {
  9. this.context = context;
  10. this.place = place;
  11. Log.d(TAG, "CustomInfoWindow: PHOTO by POI "+place.getID()+" "+ place.getPhotos());
  12. }
  13.  
  14. @Override
  15. public View getInfoWindow(Marker marker) {
  16. return null;
  17. }
  18.  
  19. @Override
  20. public View getInfoContents(Marker marker) {
  21. if (window == null){
  22. window = LayoutInflater.from(context).inflate(R.layout.custom_marker_info,null);
  23. }
  24.  
  25. TextView tv_Title = (TextView)window.findViewById(R.id.marker_title);
  26.  
  27. tv_Title.setText(marker.getTitle());
  28.  
  29.  
  30. TextView tv_Snippet = (TextView)window.findViewById(R.id.marker_snippet);
  31. tv_Snippet.setText( marker.getSnippet());
  32.  
  33. img = (ImageView)window.findViewById(R.id.marker_image);
  34.  
  35. new DownloadMarkerPhoto(img).execute(place.getPhotos());
  36.  
  37.  
  38. return window;
  39. }
  40.  
  41. }
  42.  
  43. public class DownloadMarkerPhoto extends AsyncTask<String, Void, Bitmap> {
  44.  
  45.  
  46. private static String TAG = "DownloadMarkerPhoto";
  47. private ImageView image;
  48.  
  49. public DownloadMarkerPhoto(ImageView image){
  50. this.image = image;
  51. }
  52. @Override
  53. protected Bitmap doInBackground(String... urls) {
  54. String url = urls[0];
  55. Bitmap bmpImg = null;
  56.  
  57. try {
  58. Log.d(TAG, "doInBackground: PHOTOO " + url);
  59. InputStream in = new java.net.URL(url).openStream();
  60. bmpImg = BitmapFactory.decodeStream(in);
  61.  
  62. } catch (Exception e) {
  63.  
  64. Log.e(TAG, e.toString());
  65. }
  66.  
  67. return bmpImg;
  68. }
  69.  
  70. protected void onPostExecute(Bitmap bmpImage){
  71. try {
  72. image.setImageBitmap(bmpImage);
  73.  
  74. } catch(Exception e) {
  75.  
  76. Log.e(TAG, "onPostExecute: ", e );
  77. }
  78. }
  79. }
  80.  
  81. private void addNewMarker(final POI placeInfo){
  82. mMap.setInfoWindowAdapter(new CustomInfoWindow(MapsActivity.this,placeInfo));
  83. try {
  84. String snippet = "ID: " + placeInfo.getID() + "nCategory: "+ placeInfo.getCategory();
  85. mMarker = mMap.addMarker(new MarkerOptions()
  86. .title(placeInfo.getPOI_name())
  87. .position(new LatLng(placeInfo.getLatitude(),placeInfo.getLongitude()))
  88. .snippet(snippet));
  89. }catch (NullPointerException e){
  90. Log.e(TAG, "moveCamera: NullPointerException thrown: " + e.getMessage() );
  91. }
  92.  
  93. }
Add Comment
Please, Sign In to add comment