Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
- private static final String TAG = "CustomInfoWindow";
- private View window;
- private Context context;
- private POI place;
- private ImageView img;
- private Marker lastMarker = null;
- public CustomInfoWindow(Context context,POI place) {
- this.context = context;
- this.place = place;
- Log.d(TAG, "CustomInfoWindow: PHOTO by POI "+place.getID()+" "+ place.getPhotos());
- }
- @Override
- public View getInfoWindow(Marker marker) {
- return null;
- }
- @Override
- public View getInfoContents(Marker marker) {
- if (window == null){
- window = LayoutInflater.from(context).inflate(R.layout.custom_marker_info,null);
- }
- TextView tv_Title = (TextView)window.findViewById(R.id.marker_title);
- tv_Title.setText(marker.getTitle());
- TextView tv_Snippet = (TextView)window.findViewById(R.id.marker_snippet);
- tv_Snippet.setText( marker.getSnippet());
- img = (ImageView)window.findViewById(R.id.marker_image);
- new DownloadMarkerPhoto(img).execute(place.getPhotos());
- return window;
- }
- }
- public class DownloadMarkerPhoto extends AsyncTask<String, Void, Bitmap> {
- private static String TAG = "DownloadMarkerPhoto";
- private ImageView image;
- public DownloadMarkerPhoto(ImageView image){
- this.image = image;
- }
- @Override
- protected Bitmap doInBackground(String... urls) {
- String url = urls[0];
- Bitmap bmpImg = null;
- try {
- Log.d(TAG, "doInBackground: PHOTOO " + url);
- InputStream in = new java.net.URL(url).openStream();
- bmpImg = BitmapFactory.decodeStream(in);
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- }
- return bmpImg;
- }
- protected void onPostExecute(Bitmap bmpImage){
- try {
- image.setImageBitmap(bmpImage);
- } catch(Exception e) {
- Log.e(TAG, "onPostExecute: ", e );
- }
- }
- }
- private void addNewMarker(final POI placeInfo){
- mMap.setInfoWindowAdapter(new CustomInfoWindow(MapsActivity.this,placeInfo));
- try {
- String snippet = "ID: " + placeInfo.getID() + "nCategory: "+ placeInfo.getCategory();
- mMarker = mMap.addMarker(new MarkerOptions()
- .title(placeInfo.getPOI_name())
- .position(new LatLng(placeInfo.getLatitude(),placeInfo.getLongitude()))
- .snippet(snippet));
- }catch (NullPointerException e){
- Log.e(TAG, "moveCamera: NullPointerException thrown: " + e.getMessage() );
- }
- }
Add Comment
Please, Sign In to add comment