3
3
import android .animation .ObjectAnimator ;
4
4
import android .animation .TypeEvaluator ;
5
5
import android .animation .ValueAnimator ;
6
-
7
6
import android .content .Intent ;
8
7
import android .content .SharedPreferences ;
9
8
import android .content .pm .PackageManager ;
15
14
import android .support .design .widget .BottomSheetBehavior ;
16
15
import android .support .design .widget .CoordinatorLayout ;
17
16
import android .support .design .widget .FloatingActionButton ;
18
-
19
- import android .util .Log ;
20
17
import android .view .Gravity ;
21
18
import android .view .KeyEvent ;
22
19
import android .view .LayoutInflater ;
@@ -82,6 +79,7 @@ public class NearbyMapFragment extends DaggerFragment {
82
79
private FloatingActionButton fabPlus ;
83
80
private FloatingActionButton fabCamera ;
84
81
private FloatingActionButton fabGallery ;
82
+ private FloatingActionButton fabRecenter ;
85
83
private View transparentView ;
86
84
private TextView description ;
87
85
private TextView title ;
@@ -93,7 +91,7 @@ public class NearbyMapFragment extends DaggerFragment {
93
91
private TextView commonsButtonText ;
94
92
private TextView directionsButtonText ;
95
93
96
- private boolean isFabOpen = false ;
94
+ private boolean isFabOpen = false ;
97
95
private Animation rotate_backward ;
98
96
private Animation fab_close ;
99
97
private Animation fab_open ;
@@ -109,8 +107,12 @@ public class NearbyMapFragment extends DaggerFragment {
109
107
private boolean isBottomListSheetExpanded ;
110
108
private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06 ;
111
109
112
- @ Inject @ Named ("prefs" ) SharedPreferences prefs ;
113
- @ Inject @ Named ("direct_nearby_upload_prefs" ) SharedPreferences directPrefs ;
110
+ @ Inject
111
+ @ Named ("prefs" )
112
+ SharedPreferences prefs ;
113
+ @ Inject
114
+ @ Named ("direct_nearby_upload_prefs" )
115
+ SharedPreferences directPrefs ;
114
116
115
117
public NearbyMapFragment () {
116
118
}
@@ -125,10 +127,12 @@ public void onCreate(Bundle savedInstanceState) {
125
127
if (bundle != null ) {
126
128
String gsonPlaceList = bundle .getString ("PlaceList" );
127
129
String gsonLatLng = bundle .getString ("CurLatLng" );
130
+ Type listType = new TypeToken <List <Place >>() {
131
+ }.getType ();
128
132
String gsonBoundaryCoordinates = bundle .getString ("BoundaryCoord" );
129
- Type listType = new TypeToken <List <Place >>() {}.getType ();
130
133
List <Place > placeList = gson .fromJson (gsonPlaceList , listType );
131
- Type curLatLngType = new TypeToken <fr .free .nrw .commons .location .LatLng >() {}.getType ();
134
+ Type curLatLngType = new TypeToken <fr .free .nrw .commons .location .LatLng >() {
135
+ }.getType ();
132
136
Type gsonBoundaryCoordinatesType = new TypeToken <fr .free .nrw .commons .location .LatLng []>() {}.getType ();
133
137
curLatLng = gson .fromJson (gsonLatLng , curLatLngType );
134
138
baseMarkerOptions = NearbyController
@@ -163,16 +167,15 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
163
167
this .getView ().requestFocus ();
164
168
this .getView ().setOnKeyListener ((v , keyCode , event ) -> {
165
169
if (keyCode == KeyEvent .KEYCODE_BACK ) {
166
- if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior
170
+ if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior
167
171
.STATE_EXPANDED ) {
168
172
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
169
173
return true ;
170
- }
171
- else if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior
174
+ } else if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior
172
175
.STATE_COLLAPSED ) {
173
176
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
174
177
mapView .getMapAsync (MapboxMap ::deselectMarkers );
175
- selected = null ;
178
+ selected = null ;
176
179
return true ;
177
180
}
178
181
}
@@ -301,11 +304,12 @@ private void initViews() {
301
304
fabPlus = getActivity ().findViewById (R .id .fab_plus );
302
305
fabCamera = getActivity ().findViewById (R .id .fab_camera );
303
306
fabGallery = getActivity ().findViewById (R .id .fab_galery );
307
+ fabRecenter = getActivity ().findViewById (R .id .fab_recenter );
304
308
305
309
fab_open = AnimationUtils .loadAnimation (getActivity (), R .anim .fab_open );
306
- fab_close = AnimationUtils .loadAnimation (getActivity (),R .anim .fab_close );
307
- rotate_forward = AnimationUtils .loadAnimation (getActivity (),R .anim .rotate_forward );
308
- rotate_backward = AnimationUtils .loadAnimation (getActivity (),R .anim .rotate_backward );
310
+ fab_close = AnimationUtils .loadAnimation (getActivity (), R .anim .fab_close );
311
+ rotate_forward = AnimationUtils .loadAnimation (getActivity (), R .anim .rotate_forward );
312
+ rotate_backward = AnimationUtils .loadAnimation (getActivity (), R .anim .rotate_backward );
309
313
310
314
transparentView = getActivity ().findViewById (R .id .transparentView );
311
315
@@ -330,14 +334,28 @@ private void setListeners() {
330
334
fabPlus .setOnClickListener (view -> animateFAB (isFabOpen ));
331
335
332
336
bottomSheetDetails .setOnClickListener (view -> {
333
- if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior .STATE_COLLAPSED ) {
337
+ if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior .STATE_COLLAPSED ) {
334
338
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
335
- }
336
- else {
339
+ } else {
337
340
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
338
341
}
339
342
});
340
343
344
+ fabRecenter .setOnClickListener (view -> {
345
+ if (curLatLng != null ) {
346
+ mapView .getMapAsync (mapboxMap -> {
347
+ CameraPosition position = new CameraPosition .Builder ()
348
+ .target (new LatLng (curLatLng .getLatitude (), curLatLng .getLongitude ())) // Sets the new camera position
349
+ .zoom (11 ) // Sets the zoom
350
+ .build (); // Creates a CameraPosition from the builder
351
+
352
+ mapboxMap .animateCamera (CameraUpdateFactory
353
+ .newCameraPosition (position ), 1000 );
354
+
355
+ });
356
+ }
357
+ });
358
+
341
359
bottomSheetDetailsBehavior .setBottomSheetCallback (new BottomSheetBehavior
342
360
.BottomSheetCallback () {
343
361
@ Override
@@ -351,7 +369,7 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
351
369
transparentView .setAlpha (slideOffset );
352
370
if (slideOffset == 1 ) {
353
371
transparentView .setClickable (true );
354
- } else if (slideOffset == 0 ){
372
+ } else if (slideOffset == 0 ) {
355
373
transparentView .setClickable (false );
356
374
}
357
375
}
@@ -362,7 +380,7 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
362
380
.BottomSheetCallback () {
363
381
@ Override
364
382
public void onStateChanged (@ NonNull View bottomSheet , int newState ) {
365
- if (newState == BottomSheetBehavior .STATE_EXPANDED ){
383
+ if (newState == BottomSheetBehavior .STATE_EXPANDED ) {
366
384
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
367
385
updateMapCameraAccordingToBottomSheet (true );
368
386
} else {
@@ -448,27 +466,35 @@ private void addNearbyMarkerstoMapBoxMap() {
448
466
449
467
mapboxMap .addMarkers (baseMarkerOptions );
450
468
mapboxMap .setOnInfoWindowCloseListener (marker -> {
451
- if (marker == selected ){
469
+ if (marker == selected ) {
452
470
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
453
471
}
454
472
});
473
+ mapView .getMapAsync (mapboxMap -> {
474
+ mapboxMap .addMarkers (baseMarkerOptions );
475
+ fabRecenter .setVisibility (View .VISIBLE );
476
+ mapboxMap .setOnInfoWindowCloseListener (marker -> {
477
+ if (marker == selected ) {
478
+ bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
479
+ }
480
+ });
481
+
482
+ mapboxMap .setOnMarkerClickListener (marker -> {
483
+ if (marker instanceof NearbyMarker ) {
484
+ this .selected = marker ;
485
+ NearbyMarker nearbyMarker = (NearbyMarker ) marker ;
486
+ Place place = nearbyMarker .getNearbyBaseMarker ().getPlace ();
487
+ passInfoToSheet (place );
488
+ bottomSheetListBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
489
+ bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
490
+ }
491
+ return false ;
492
+ });
455
493
456
- mapboxMap .setOnMarkerClickListener (marker -> {
457
- if (marker instanceof NearbyMarker ) {
458
- this .selected = marker ;
459
- NearbyMarker nearbyMarker = (NearbyMarker ) marker ;
460
- Place place = nearbyMarker .getNearbyBaseMarker ().getPlace ();
461
- passInfoToSheet (place );
462
- bottomSheetListBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
463
- bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
464
- }
465
- return false ;
466
494
});
467
-
468
495
}
469
496
470
497
471
-
472
498
/**
473
499
* Creates a series of points that create a circle on the map.
474
500
* Takes the center latitude, center longitude of the circle,
@@ -653,7 +679,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
653
679
}
654
680
}
655
681
break ;
656
-
682
+
657
683
// 3 = "Write external storage" allowed when camera selected
658
684
case 3 : {
659
685
if (grantResults .length > 0 && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
@@ -684,6 +710,7 @@ private void openWebView(Uri link) {
684
710
}
685
711
686
712
private void animateFAB (boolean isFabOpen ) {
713
+ this .isFabOpen = !isFabOpen ;
687
714
if (fabPlus .isShown ()){
688
715
if (isFabOpen ) {
689
716
fabPlus .startAnimation (rotate_backward );
@@ -702,14 +729,14 @@ private void animateFAB(boolean isFabOpen) {
702
729
}
703
730
}
704
731
705
- private void closeFabs ( boolean isFabOpen ){
732
+ private void closeFabs ( boolean isFabOpen ){
706
733
if (isFabOpen ) {
707
734
fabPlus .startAnimation (rotate_backward );
708
735
fabCamera .startAnimation (fab_close );
709
736
fabGallery .startAnimation (fab_close );
710
737
fabCamera .hide ();
711
738
fabGallery .hide ();
712
- this .isFabOpen = !isFabOpen ;
739
+ this .isFabOpen = !isFabOpen ;
713
740
}
714
741
}
715
742
0 commit comments