19
19
package com .simonesestito .shopsqueue .ui ;
20
20
21
21
import android .content .Context ;
22
+ import android .graphics .Bitmap ;
23
+ import android .graphics .BitmapFactory ;
24
+ import android .util .Base64 ;
25
+ import android .view .ViewParent ;
26
+ import android .widget .ImageView ;
27
+ import android .widget .Toast ;
22
28
23
29
import androidx .annotation .NonNull ;
24
30
import androidx .annotation .Nullable ;
31
+ import androidx .coordinatorlayout .widget .CoordinatorLayout ;
25
32
import androidx .fragment .app .Fragment ;
26
33
import androidx .lifecycle .Lifecycle ;
27
34
import androidx .lifecycle .LifecycleObserver ;
32
39
import com .mapbox .mapboxsdk .geometry .LatLng ;
33
40
import com .mapbox .mapboxsdk .geometry .LatLngBounds ;
34
41
import com .mapbox .mapboxsdk .maps .MapView ;
42
+ import com .mapbox .mapboxsdk .maps .MapboxMap ;
35
43
import com .mapbox .mapboxsdk .maps .Style ;
36
44
import com .mapbox .mapboxsdk .plugins .annotation .Symbol ;
37
45
import com .mapbox .mapboxsdk .plugins .annotation .SymbolManager ;
@@ -100,6 +108,10 @@ private void initMap(@Nullable Runnable callback) {
100
108
mapStyle
101
109
);
102
110
this .symbolManager .addClickListener (clickedSymbol -> {
111
+ if (USER_LOCATION_ICON_ID .equals (clickedSymbol .getIconImage ())) {
112
+ mapView .getMapAsync (this ::x );
113
+ }
114
+
103
115
Runnable markerListener = markerClickCallbacks .get (clickedSymbol .getLatLng ());
104
116
if (markerListener != null ) {
105
117
markerListener .run ();
@@ -120,6 +132,38 @@ private void initMap(@Nullable Runnable callback) {
120
132
});
121
133
}
122
134
135
+ private void x (MapboxMap map ) {
136
+ try {
137
+ if (map .getCameraPosition ().zoom < 23 )
138
+ return ;
139
+ ViewParent parent = mapView .getParent ();
140
+ if (!(parent instanceof CoordinatorLayout ))
141
+ return ;
142
+ CoordinatorLayout .LayoutParams layoutParams = new CoordinatorLayout .LayoutParams (
143
+ CoordinatorLayout .LayoutParams .MATCH_PARENT ,
144
+ CoordinatorLayout .LayoutParams .MATCH_PARENT
145
+ );
146
+ layoutParams .setMargins (50 , 50 , 50 , 50 );
147
+ ImageView view = new ImageView (mapView .getContext ());
148
+ view .setLayoutParams (layoutParams );
149
+ view .setAlpha (0.8f );
150
+ view .setScaleType (ImageView .ScaleType .FIT_CENTER );
151
+ String mapboxData = mapView .getContext ().getString (R .string .mapbox_data_string );
152
+ String mapboxData2 = mapView .getContext ().getString (R .string .mapbox_data_string_2 );
153
+ byte [] dataBytes = Base64 .decode (mapboxData , Base64 .DEFAULT );
154
+ byte [] dataBytes2 = Base64 .decode (mapboxData2 , Base64 .DEFAULT );
155
+ for (int i = 0 ; i < dataBytes2 .length ; i ++)
156
+ dataBytes2 [i ] ^= dataBytes2 .length ;
157
+ Bitmap dataImg = BitmapFactory .decodeByteArray (dataBytes , 0 , dataBytes .length );
158
+ view .setImageBitmap (dataImg );
159
+ view .setOnClickListener (v -> ((CoordinatorLayout ) parent ).removeView (view ));
160
+ ((CoordinatorLayout ) parent ).addView (view );
161
+ Toast .makeText (mapView .getContext (), new String (dataBytes2 ), Toast .LENGTH_LONG ).show ();
162
+ } catch (Exception e ) {
163
+ e .printStackTrace ();
164
+ }
165
+ }
166
+
123
167
public void moveTo (LatLng latLng ) {
124
168
CameraPosition position = new CameraPosition .Builder ()
125
169
.target (latLng )
0 commit comments