Advertisement
Guest User

Untitled

a guest
Feb 20th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Android.App;
  6. using Android.Content;
  7. using Android.OS;
  8. using Android.Runtime;
  9. using Android.Util;
  10. using Android.Views;
  11. using Android.Widget;
  12. using Java.Lang;
  13. using Android.Graphics;
  14. using Android.Text;
  15. using Android.Gms.Maps;
  16. using Android.Gms.Maps.Model;
  17.  
  18. namespace WurthReservationAndroid
  19. {
  20.     public class MapWrapper : RelativeLayout
  21.     {
  22.         private GoogleMap map;
  23.         private int bottomOffsetPixels;
  24.         public Marker marker;
  25.         private View infoWindow;
  26.  
  27.         public MapWrapper(Context context) : base(context)
  28.         {
  29.         }
  30.  
  31.         public MapWrapper(Context context, IAttributeSet attrs) : base(context, attrs)
  32.         {
  33.         }
  34.  
  35.         public MapWrapper(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
  36.         {
  37.         }
  38.  
  39.         public MapWrapper(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
  40.         {
  41.         }
  42.  
  43.         public void init(GoogleMap map, int bottomOffsetPixels) {
  44.             this.map = map;
  45.             this.bottomOffsetPixels = bottomOffsetPixels;
  46.         }
  47.  
  48.         public void setMarkerWithInfoWindow(Marker marker, View infoWindow) {
  49.             this.marker = marker;
  50.             this.infoWindow = infoWindow;
  51.         }
  52.  
  53.         public override bool DispatchTouchEvent (MotionEvent ev)
  54.         {
  55.             bool ret = false;
  56.             // Make sure that the infoWindow is shown and we have all the needed references
  57.             if (marker != null && marker.IsInfoWindowShown && map != null && infoWindow != null) {
  58.                 // Get a marker position on the screen
  59.                 Point point = map.Projection.ToScreenLocation(marker.Position);
  60.                 // Make a copy of the MotionEvent and adjust it's location
  61.                 // so it is relative to the infoWindow left top corner
  62.                 MotionEvent copyEv = MotionEvent.Obtain(ev);
  63.                 copyEv.OffsetLocation(
  64.                     -point.X + (infoWindow.Width / 2),
  65.                     -point.Y + infoWindow.Height + bottomOffsetPixels);
  66.  
  67.                 // Dispatch the adjusted MotionEvent to the infoWindow
  68.                 ret = infoWindow.DispatchTouchEvent(copyEv);
  69.                 //detect click en voyant la différence, si c'est entre -18dp et -60dp et -125 et +125, infowindo custom où on appel showInfoWindow
  70.             }
  71.             // If the infoWindow consumed the touch event, then just return true.
  72.             // Otherwise pass this event to the super class and return it's result
  73.             return ret || base.DispatchTouchEvent(ev);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement