68
68
* create an instance of this fragment.
69
69
*/
70
70
public class MapWrapperFragment extends Fragment implements OnMapReadyCallback ,
71
- GoogleMap .OnMapLongClickListener ,
72
- ActivityCompat .OnRequestPermissionsResultCallback {
71
+ GoogleMap .OnMapLongClickListener ,
72
+ ActivityCompat .OnRequestPermissionsResultCallback {
73
73
74
74
private static final int LOCATION_PERMISSION_REQUEST = 19 ;
75
75
@@ -85,6 +85,10 @@ public class MapWrapperFragment extends Fragment implements OnMapReadyCallback,
85
85
private HashMap <String , PokemonMarkerExtended > markerList = new HashMap <>();
86
86
private HashMap <String , PokestopMarkerExtended > pokestopsList = new HashMap <>();
87
87
88
+ public static Snackbar pokeSnackbar ;
89
+ public static int pokemonFound = 0 ;
90
+ public static int positionNum = 0 ;
91
+
88
92
public MapWrapperFragment () {
89
93
// Required empty public constructor
90
94
}
@@ -179,6 +183,7 @@ public void onClick(View view) {
179
183
}
180
184
181
185
private void initMap () {
186
+ pokeSnackbar = Snackbar .make (getView (), "" , Snackbar .LENGTH_LONG );
182
187
if (mLocation != null && mGoogleMap != null ) {
183
188
if (ContextCompat .checkSelfPermission (mView .getContext (), Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED
184
189
|| ContextCompat .checkSelfPermission (mView .getContext (), Manifest .permission .ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
@@ -276,10 +281,10 @@ private void setPokestopsMarkers(final Collection<Pokestop> pokestops){
276
281
}
277
282
278
283
private void setPokemonMarkers (final List <CatchablePokemon > pokeList ){
284
+ positionNum ++;
279
285
if (mGoogleMap != null ) {
280
286
281
287
Set <String > markerKeys = markerList .keySet ();
282
- int pokemonFound = 0 ;
283
288
for (final CatchablePokemon poke : pokeList ) {
284
289
285
290
if (!markerKeys .contains (poke .getSpawnPointId ())) {
@@ -308,8 +313,17 @@ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
308
313
}
309
314
}
310
315
if (getView () != null ) {
311
- String text = pokemonFound > 0 ? pokemonFound + " new catchable Pokemon have been found." : "No new Pokemon have been found." ;
312
- Snackbar .make (getView (), text , Snackbar .LENGTH_SHORT ).show ();
316
+ if (positionNum != LOCATION_PERMISSION_REQUEST ) {
317
+ String text = " Searching...." + pokemonFound + " Pokemon found" ;
318
+ pokeSnackbar .setText (text );
319
+ pokeSnackbar .show ();
320
+
321
+ }
322
+ else {
323
+ String text = pokemonFound > 0 ? pokemonFound + " new catchable Pokemon have been found." : "No new Pokemon have been found." ;
324
+ pokeSnackbar .setText (text );
325
+ pokeSnackbar .show ();
326
+ }
313
327
}
314
328
updateMarkers ();
315
329
} else {
@@ -392,7 +406,6 @@ public void onMapReady(GoogleMap googleMap) {
392
406
mGoogleMap .setOnMapLongClickListener (this );
393
407
//Disable for now coz is under FAB
394
408
settings .setMapToolbarEnabled (false );
395
- initMap ();
396
409
}
397
410
398
411
@ Override
@@ -407,41 +420,41 @@ public void onMapLongClick(LatLng position) {
407
420
}
408
421
409
422
private void drawMarkerWithCircle (LatLng position ){
410
- if (mGoogleMap != null ) {
423
+ if (mGoogleMap != null ) {
411
424
412
425
413
- //Check and eventually remove old marker
414
- if (userSelectedPositionMarker != null && userSelectedPositionCircles != null ) {
415
- userSelectedPositionMarker .remove ();
416
- for (Circle circle : userSelectedPositionCircles ) {
417
- circle .remove ();
418
- }
419
- userSelectedPositionCircles .clear ();
426
+ //Check and eventually remove old marker
427
+ if (userSelectedPositionMarker != null && userSelectedPositionCircles != null ) {
428
+ userSelectedPositionMarker .remove ();
429
+ for (Circle circle : userSelectedPositionCircles ) {
430
+ circle .remove ();
420
431
}
432
+ userSelectedPositionCircles .clear ();
433
+ }
421
434
422
- if (mPref .getShowScannedPlaces ()) {
423
- double radiusInMeters = 100.0 ;
424
- int strokeColor = 0x4400CCFF ; // outline
425
- int shadeColor = 0x4400CCFF ; // fill
435
+ if (mPref .getShowScannedPlaces ()) {
436
+ double radiusInMeters = 100.0 ;
437
+ int strokeColor = 0x4400CCFF ; // outline
438
+ int shadeColor = 0x4400CCFF ; // fill
426
439
427
- SearchParams params = new SearchParams (SearchParams .DEFAULT_RADIUS * 3 , new LatLng (position .latitude , position .longitude ));
428
- List <LatLng > list = params .getSearchArea ();
429
- for (LatLng p : list ) {
430
- CircleOptions circleOptions = new CircleOptions ().center (new LatLng (p .latitude , p .longitude )).radius (radiusInMeters ).fillColor (shadeColor ).strokeColor (strokeColor ).strokeWidth (8 );
431
- userSelectedPositionCircles .add (mGoogleMap .addCircle (circleOptions ));
440
+ SearchParams params = new SearchParams (SearchParams .DEFAULT_RADIUS * 3 , new LatLng (position .latitude , position .longitude ));
441
+ List <LatLng > list = params .getSearchArea ();
442
+ for (LatLng p : list ) {
443
+ CircleOptions circleOptions = new CircleOptions ().center (new LatLng (p .latitude , p .longitude )).radius (radiusInMeters ).fillColor (shadeColor ).strokeColor (strokeColor ).strokeWidth (8 );
444
+ userSelectedPositionCircles .add (mGoogleMap .addCircle (circleOptions ));
432
445
433
- }
434
446
}
435
-
436
- userSelectedPositionMarker = mGoogleMap .addMarker (new MarkerOptions ()
437
- .position (position )
438
- .title ("Position Picked" )
439
- .icon (BitmapDescriptorFactory .fromBitmap (BitmapFactory .decodeResource (getContext ().getResources (),
440
- R .drawable .ic_my_location_white_24dp )))
441
- .anchor (0.5f , 0.5f ));
442
- } else {
443
- showMapNotInitializedError ();
444
447
}
448
+
449
+ userSelectedPositionMarker = mGoogleMap .addMarker (new MarkerOptions ()
450
+ .position (position )
451
+ .title ("Position Picked" )
452
+ .icon (BitmapDescriptorFactory .fromBitmap (BitmapFactory .decodeResource (getContext ().getResources (),
453
+ R .drawable .ic_my_location_white_24dp )))
454
+ .anchor (0.5f , 0.5f ));
455
+ } else {
456
+ showMapNotInitializedError ();
457
+ }
445
458
}
446
459
447
460
}
0 commit comments