From b7b87e061508b9277e6ec3e8914b7a93e3e38797 Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Fri, 2 Mar 2018 03:56:21 +0530 Subject: [PATCH] Fixes issues #1228 added recenter button to nearby map --- .../nrw/commons/nearby/NearbyMapFragment.java | 99 +++++++---- .../drawable/ic_my_location_black_24dp.xml | 9 + .../main/res/layout-land/activity_nearby.xml | 165 ++++++++++++++++++ app/src/main/res/layout/activity_nearby.xml | 133 ++++++++------ gradle.properties | 3 + 5 files changed, 323 insertions(+), 86 deletions(-) create mode 100644 app/src/main/res/drawable/ic_my_location_black_24dp.xml create mode 100644 app/src/main/res/layout-land/activity_nearby.xml diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index bf4c181b3..7d0cda450 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -3,7 +3,6 @@ package fr.free.nrw.commons.nearby; import android.animation.ObjectAnimator; import android.animation.TypeEvaluator; import android.animation.ValueAnimator; - import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -15,8 +14,6 @@ import android.support.annotation.Nullable; import android.support.design.widget.BottomSheetBehavior; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; - -import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -82,6 +79,7 @@ public class NearbyMapFragment extends DaggerFragment { private FloatingActionButton fabPlus; private FloatingActionButton fabCamera; private FloatingActionButton fabGallery; + private FloatingActionButton fabRecenter; private View transparentView; private TextView description; private TextView title; @@ -93,7 +91,7 @@ public class NearbyMapFragment extends DaggerFragment { private TextView commonsButtonText; private TextView directionsButtonText; - private boolean isFabOpen=false; + private boolean isFabOpen = false; private Animation rotate_backward; private Animation fab_close; private Animation fab_open; @@ -109,8 +107,12 @@ public class NearbyMapFragment extends DaggerFragment { private boolean isBottomListSheetExpanded; private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06; - @Inject @Named("prefs") SharedPreferences prefs; - @Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs; + @Inject + @Named("prefs") + SharedPreferences prefs; + @Inject + @Named("direct_nearby_upload_prefs") + SharedPreferences directPrefs; public NearbyMapFragment() { } @@ -125,10 +127,12 @@ public class NearbyMapFragment extends DaggerFragment { if (bundle != null) { String gsonPlaceList = bundle.getString("PlaceList"); String gsonLatLng = bundle.getString("CurLatLng"); + Type listType = new TypeToken>() { + }.getType(); String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord"); - Type listType = new TypeToken>() {}.getType(); List placeList = gson.fromJson(gsonPlaceList, listType); - Type curLatLngType = new TypeToken() {}.getType(); + Type curLatLngType = new TypeToken() { + }.getType(); Type gsonBoundaryCoordinatesType = new TypeToken() {}.getType(); curLatLng = gson.fromJson(gsonLatLng, curLatLngType); baseMarkerOptions = NearbyController @@ -163,16 +167,15 @@ public class NearbyMapFragment extends DaggerFragment { this.getView().requestFocus(); this.getView().setOnKeyListener((v, keyCode, event) -> { if (keyCode == KeyEvent.KEYCODE_BACK) { - if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior + if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior .STATE_EXPANDED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); return true; - } - else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior + } else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior .STATE_COLLAPSED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); mapView.getMapAsync(MapboxMap::deselectMarkers); - selected=null; + selected = null; return true; } } @@ -301,11 +304,12 @@ public class NearbyMapFragment extends DaggerFragment { fabPlus = getActivity().findViewById(R.id.fab_plus); fabCamera = getActivity().findViewById(R.id.fab_camera); fabGallery = getActivity().findViewById(R.id.fab_galery); + fabRecenter = getActivity().findViewById(R.id.fab_recenter); fab_open = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_open); - fab_close = AnimationUtils.loadAnimation(getActivity(),R.anim.fab_close); - rotate_forward = AnimationUtils.loadAnimation(getActivity(),R.anim.rotate_forward); - rotate_backward = AnimationUtils.loadAnimation(getActivity(),R.anim.rotate_backward); + fab_close = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_close); + rotate_forward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_forward); + rotate_backward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_backward); transparentView = getActivity().findViewById(R.id.transparentView); @@ -330,14 +334,28 @@ public class NearbyMapFragment extends DaggerFragment { fabPlus.setOnClickListener(view -> animateFAB(isFabOpen)); bottomSheetDetails.setOnClickListener(view -> { - if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { + if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - } - else{ + } else { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } }); + fabRecenter.setOnClickListener(view -> { + if (curLatLng != null) { + mapView.getMapAsync(mapboxMap -> { + CameraPosition position = new CameraPosition.Builder() + .target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())) // Sets the new camera position + .zoom(11) // Sets the zoom + .build(); // Creates a CameraPosition from the builder + + mapboxMap.animateCamera(CameraUpdateFactory + .newCameraPosition(position), 1000); + + }); + } + }); + bottomSheetDetailsBehavior.setBottomSheetCallback(new BottomSheetBehavior .BottomSheetCallback() { @Override @@ -351,7 +369,7 @@ public class NearbyMapFragment extends DaggerFragment { transparentView.setAlpha(slideOffset); if (slideOffset == 1) { transparentView.setClickable(true); - } else if (slideOffset == 0){ + } else if (slideOffset == 0) { transparentView.setClickable(false); } } @@ -362,7 +380,7 @@ public class NearbyMapFragment extends DaggerFragment { .BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { - if (newState == BottomSheetBehavior.STATE_EXPANDED){ + if (newState == BottomSheetBehavior.STATE_EXPANDED) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); updateMapCameraAccordingToBottomSheet(true); } else { @@ -448,27 +466,35 @@ public class NearbyMapFragment extends DaggerFragment { mapboxMap.addMarkers(baseMarkerOptions); mapboxMap.setOnInfoWindowCloseListener(marker -> { - if (marker == selected){ + if (marker == selected) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); } }); + mapView.getMapAsync(mapboxMap -> { + mapboxMap.addMarkers(baseMarkerOptions); + fabRecenter.setVisibility(View.VISIBLE); + mapboxMap.setOnInfoWindowCloseListener(marker -> { + if (marker == selected) { + bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); + } + }); + + mapboxMap.setOnMarkerClickListener(marker -> { + if (marker instanceof NearbyMarker) { + this.selected = marker; + NearbyMarker nearbyMarker = (NearbyMarker) marker; + Place place = nearbyMarker.getNearbyBaseMarker().getPlace(); + passInfoToSheet(place); + bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); + bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + } + return false; + }); - mapboxMap.setOnMarkerClickListener(marker -> { - if (marker instanceof NearbyMarker) { - this.selected = marker; - NearbyMarker nearbyMarker = (NearbyMarker) marker; - Place place = nearbyMarker.getNearbyBaseMarker().getPlace(); - passInfoToSheet(place); - bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); - bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); - } - return false; }); - } - /** * Creates a series of points that create a circle on the map. * Takes the center latitude, center longitude of the circle, @@ -653,7 +679,7 @@ public class NearbyMapFragment extends DaggerFragment { } } break; - + // 3 = "Write external storage" allowed when camera selected case 3: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { @@ -684,6 +710,7 @@ public class NearbyMapFragment extends DaggerFragment { } private void animateFAB(boolean isFabOpen) { + this.isFabOpen = !isFabOpen; if (fabPlus.isShown()){ if (isFabOpen) { fabPlus.startAnimation(rotate_backward); @@ -702,14 +729,14 @@ public class NearbyMapFragment extends DaggerFragment { } } - private void closeFabs(boolean isFabOpen){ + private void closeFabs ( boolean isFabOpen){ if (isFabOpen) { fabPlus.startAnimation(rotate_backward); fabCamera.startAnimation(fab_close); fabGallery.startAnimation(fab_close); fabCamera.hide(); fabGallery.hide(); - this.isFabOpen=!isFabOpen; + this.isFabOpen = !isFabOpen; } } diff --git a/app/src/main/res/drawable/ic_my_location_black_24dp.xml b/app/src/main/res/drawable/ic_my_location_black_24dp.xml new file mode 100644 index 000000000..07d6e4694 --- /dev/null +++ b/app/src/main/res/drawable/ic_my_location_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout-land/activity_nearby.xml b/app/src/main/res/layout-land/activity_nearby.xml new file mode 100644 index 000000000..c945193ba --- /dev/null +++ b/app/src/main/res/layout-land/activity_nearby.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_nearby.xml b/app/src/main/res/layout/activity_nearby.xml index ccbd55896..31eceff07 100644 --- a/app/src/main/res/layout/activity_nearby.xml +++ b/app/src/main/res/layout/activity_nearby.xml @@ -4,12 +4,13 @@ android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> + + android:layout_height="match_parent"> + @@ -23,10 +24,10 @@ - + + + + android:elevation="6dp"> - + + + + + + + - + + + + app:pressedTranslationZ="12dp" + app:srcCompat="@drawable/ic_add_white_24dp" /> + + app:layout_anchorGravity="center_horizontal" /> + + app:layout_anchorGravity="center_horizontal" /> + + app:layout_anchorGravity="center_horizontal" /> + + app:pressedTranslationZ="12dp" + app:srcCompat="@drawable/ic_photo_camera_white_24dp" /> + + app:pressedTranslationZ="12dp" + app:srcCompat="@drawable/ic_photo_white_24dp" /> + - + app:pressedTranslationZ="12dp" + app:srcCompat="@drawable/ic_commons_icon_vector" /> - + app:menu="@menu/drawer" /> \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0f0385cbb..850003852 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,9 @@ BUTTERKNIFE_VERSION=8.6.0 org.gradle.jvmargs=-Xmx1536M buildToolsVersion=26.0.2 targetSdkVersion=25 + +#TODO: Temporary disabled. https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#aapt2 +#Refer to PR: https://github.com/commons-app/apps-android-commons/pull/932 android.enableAapt2=false SUPPORT_LIB_VERSION=26.0.2 minSdkVersion=15