From 7420b53a6fa4bf3f170d22832038fe8ce9dc2c3a Mon Sep 17 00:00:00 2001 From: Vincent Karuri Date: Thu, 31 Jan 2019 14:26:21 +0300 Subject: [PATCH 01/35] Make my location circle radius configurable --- .../io/ona/kujaku/activities/MapActivity.java | 2 +- .../ona/kujaku/interfaces/IKujakuMapView.java | 5 +++-- .../io/ona/kujaku/views/KujakuMapView.java | 22 +++++++++---------- .../ona/kujaku/views/KujakuMapViewTest.java | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/library/src/main/java/io/ona/kujaku/activities/MapActivity.java b/library/src/main/java/io/ona/kujaku/activities/MapActivity.java index aa217c124..e8b94e3f0 100644 --- a/library/src/main/java/io/ona/kujaku/activities/MapActivity.java +++ b/library/src/main/java/io/ona/kujaku/activities/MapActivity.java @@ -231,7 +231,7 @@ public void onMapReady(MapboxMap mapboxMap) { } if (!mapboxStyleJSON.has(MapBoxStyleHelper.KEY_MAP_CENTER)) { - kujakuMapView.focusOnUserLocation(true); + kujakuMapView.focusOnUserLocation(true, null); } } }); diff --git a/library/src/main/java/io/ona/kujaku/interfaces/IKujakuMapView.java b/library/src/main/java/io/ona/kujaku/interfaces/IKujakuMapView.java index 938d6b3c5..fd4bf810c 100644 --- a/library/src/main/java/io/ona/kujaku/interfaces/IKujakuMapView.java +++ b/library/src/main/java/io/ona/kujaku/interfaces/IKujakuMapView.java @@ -70,9 +70,10 @@ public interface IKujakuMapView extends IKujakuMapViewLowLevel { * intervention. If the MY LOCATION BUTTON is visible, it will turn blue as long as this mode is on. * This can be turned off by the user if s/he touches the map to scroll it to a specific location. * - * @param focusOnMyLocation + * @param focusOnMyLocation Whether to focus on the current user location or not + * @param radius Radius of the outer circle of the current user location symbol */ - void focusOnUserLocation(boolean focusOnMyLocation); + void focusOnUserLocation(boolean focusOnMyLocation, @Nullable Integer radius); /** diff --git a/library/src/main/java/io/ona/kujaku/views/KujakuMapView.java b/library/src/main/java/io/ona/kujaku/views/KujakuMapView.java index c344f94f1..7a761f461 100644 --- a/library/src/main/java/io/ona/kujaku/views/KujakuMapView.java +++ b/library/src/main/java/io/ona/kujaku/views/KujakuMapView.java @@ -205,7 +205,7 @@ private void init(@Nullable AttributeSet attributeSet) { currentLocationBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - focusOnUserLocation(true); + focusOnUserLocation(true, null); // Enable asking for enabling the location by resetting this flag in case it was true hasAlreadyRequestedEnableLocation = false; @@ -238,8 +238,8 @@ public void onGlobalLayout() { featureMap = new HashMap<>(); } - private void showUpdatedUserLocation() { - updateUserLocationLayer(latestLocation); + private void showUpdatedUserLocation(Integer radius) { + updateUserLocationLayer(latestLocation, radius); if (updateUserLocationOnMap || !isMapScrolled) { // Focus on the new location @@ -279,7 +279,7 @@ public void onLocationChanged(Location location) { } if (updateUserLocationOnMap) { - showUpdatedUserLocation(); + showUpdatedUserLocation(null); } } }); @@ -415,7 +415,7 @@ public void enableAddPoint(boolean canAddPoint, @Nullable final OnLocationChange // 3. Show the circle icon on the currrent position -> This will happen whenever there are location updates updateUserLocationOnMap = true; if (latestLocation != null) { - showUpdatedUserLocation(); + showUpdatedUserLocation(null); } } else { // This should just disable the layout and any ongoing operations for focus @@ -423,7 +423,7 @@ public void enableAddPoint(boolean canAddPoint, @Nullable final OnLocationChange } } - private void updateUserLocationLayer(@NonNull LatLng latLng) { + private void updateUserLocationLayer(@NonNull LatLng latLng, Integer radius) { com.mapbox.geojson.Feature feature = com.mapbox.geojson.Feature.fromGeometry( com.mapbox.geojson.Point.fromLngLat( @@ -449,7 +449,7 @@ private void updateUserLocationLayer(@NonNull LatLng latLng) { userLocationOuterCircle = new CircleLayer(pointsOuterLayerId, pointsSourceId); userLocationOuterCircle.setProperties( circleColor("#81c2ee"), - circleRadius(25f), + circleRadius(radius == null ? 25f : radius), circleStrokeWidth(1f), circleStrokeColor("#74b7f6"), circleOpacity(0.3f), @@ -778,7 +778,7 @@ public void onMoveBegin(@NonNull MoveGestureDetector detector) { isMapScrolled = true; // We should assume the user no longer wants us to focus on their location - focusOnUserLocation(false); + focusOnUserLocation(false, null); } @Override @@ -922,7 +922,7 @@ public void setOnFeatureClickListener(@NonNull OnFeatureClickListener onFeatureC } @Override - public void focusOnUserLocation(boolean focusOnMyLocation) { + public void focusOnUserLocation(boolean focusOnMyLocation, Integer radius) { if (focusOnMyLocation) { isMapScrolled = false; changeImageButtonResource(currentLocationBtn, R.drawable.ic_cross_hair_blue); @@ -930,7 +930,7 @@ public void focusOnUserLocation(boolean focusOnMyLocation) { // Enable the listener & show the current user location updateUserLocationOnMap = true; if (latestLocation != null) { - showUpdatedUserLocation(); + showUpdatedUserLocation(radius); } } else { @@ -1123,7 +1123,7 @@ public void onResult(LocationSettingsResult result) { // The user had already requested for permissions, so we should not request again // We should disable these two modes since they cannot be achieved in the current stage setWarmGps(false); - focusOnUserLocation(false); + focusOnUserLocation(false, null); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: diff --git a/library/src/test/java/io/ona/kujaku/views/KujakuMapViewTest.java b/library/src/test/java/io/ona/kujaku/views/KujakuMapViewTest.java index 702f115d7..9ebb79f8e 100644 --- a/library/src/test/java/io/ona/kujaku/views/KujakuMapViewTest.java +++ b/library/src/test/java/io/ona/kujaku/views/KujakuMapViewTest.java @@ -216,7 +216,7 @@ public void showCurrentLocationBtnShouldChangeVisibleWhenCalled() { public void focusOnUserLocationShouldChangeTargetIconWhenCalled() throws NoSuchFieldException, IllegalAccessException { String updateUserLocationOnMap = "updateUserLocationOnMap"; - kujakuMapView.focusOnUserLocation(true); + kujakuMapView.focusOnUserLocation(true, null); assertTrue((boolean) getValueInPrivateField(KujakuMapView.class, kujakuMapView, updateUserLocationOnMap)); ImageButton imageButton = kujakuMapView.findViewById(R.id.ib_mapview_focusOnMyLocationIcon); @@ -224,7 +224,7 @@ public void focusOnUserLocationShouldChangeTargetIconWhenCalled() throws NoSuchF assertEquals(R.drawable.ic_cross_hair_blue, drawableResId); - kujakuMapView.focusOnUserLocation(false); + kujakuMapView.focusOnUserLocation(false, null); assertFalse((boolean) getValueInPrivateField(KujakuMapView.class, kujakuMapView, updateUserLocationOnMap)); drawableResId = Shadows.shadowOf(imageButton.getDrawable()).getCreatedFromResId(); From ba752a55e182057cb8f5ef9b3f922e4af220418f Mon Sep 17 00:00:00 2001 From: Vincent Karuri Date: Thu, 31 Jan 2019 16:33:10 +0300 Subject: [PATCH 02/35] Add layout for ConfigurableLocationCircleActivity --- sample/src/main/AndroidManifest.xml | 12 ++- .../BaseNavigationDrawerActivity.java | 4 + .../ConfigurableLocationCircleActivity.java | 75 ++++++++++++++++++ .../activity_configurable_location_circle.xml | 10 +++ .../content_configurable_location_circle.xml | 76 +++++++++++++++++++ .../activity_navigation_drawer_drawer.xml | 3 + sample/src/main/res/values-sw600dp/dimens.xml | 1 + sample/src/main/res/values/dimens.xml | 1 + sample/src/main/res/values/strings.xml | 3 + 9 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 sample/src/main/java/io/ona/kujaku/sample/activities/ConfigurableLocationCircleActivity.java create mode 100644 sample/src/main/res/layout/activity_configurable_location_circle.xml create mode 100644 sample/src/main/res/layout/content_configurable_location_circle.xml diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index a6a26cea8..212a7e062 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -46,7 +46,7 @@ android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + \ No newline at end of file diff --git a/sample/src/main/java/io/ona/kujaku/sample/activities/BaseNavigationDrawerActivity.java b/sample/src/main/java/io/ona/kujaku/sample/activities/BaseNavigationDrawerActivity.java index 876444f66..2ccda73bf 100644 --- a/sample/src/main/java/io/ona/kujaku/sample/activities/BaseNavigationDrawerActivity.java +++ b/sample/src/main/java/io/ona/kujaku/sample/activities/BaseNavigationDrawerActivity.java @@ -172,6 +172,10 @@ public boolean onNavigationItemSelected(MenuItem item) { finish(); return true; + case R.id.nav_configurable_circle: + startActivity(new Intent(this, ConfigurableLocationCircleActivity.class)); + finish(); + return true; default: break; } diff --git a/sample/src/main/java/io/ona/kujaku/sample/activities/ConfigurableLocationCircleActivity.java b/sample/src/main/java/io/ona/kujaku/sample/activities/ConfigurableLocationCircleActivity.java new file mode 100644 index 000000000..024f45325 --- /dev/null +++ b/sample/src/main/java/io/ona/kujaku/sample/activities/ConfigurableLocationCircleActivity.java @@ -0,0 +1,75 @@ +package io.ona.kujaku.sample.activities; + +import android.os.Bundle; + +import com.mapbox.mapboxsdk.Mapbox; + +import io.ona.kujaku.sample.BuildConfig; +import io.ona.kujaku.sample.R; +import io.ona.kujaku.views.KujakuMapView; + +public class ConfigurableLocationCircleActivity extends BaseNavigationDrawerActivity { + + private KujakuMapView kujakuMapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Mapbox.getInstance(this, BuildConfig.MAPBOX_SDK_ACCESS_TOKEN); + + kujakuMapView = findViewById(R.id.configurable_circle_activity_map_view); + } + + + @Override + protected int getContentView() { + return R.layout.activity_configurable_location_circle; + } + + @Override + protected void onResume() { + super.onResume(); + if (kujakuMapView != null) kujakuMapView.onResume(); + } + + @Override + protected void onStart() { + super.onStart(); + if (kujakuMapView != null) kujakuMapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + if (kujakuMapView != null) kujakuMapView.onStop(); + } + + @Override + protected void onPause() { + super.onPause(); + if (kujakuMapView != null) kujakuMapView.onPause(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (kujakuMapView != null) kujakuMapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if (kujakuMapView != null) kujakuMapView.onSaveInstanceState(outState); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + if (kujakuMapView != null) kujakuMapView.onLowMemory(); + } + + @Override + protected int getSelectedNavigationItem() { + return R.id.nav_configurable_circle; + } +} diff --git a/sample/src/main/res/layout/activity_configurable_location_circle.xml b/sample/src/main/res/layout/activity_configurable_location_circle.xml new file mode 100644 index 000000000..ad91eb098 --- /dev/null +++ b/sample/src/main/res/layout/activity_configurable_location_circle.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/content_configurable_location_circle.xml b/sample/src/main/res/layout/content_configurable_location_circle.xml new file mode 100644 index 000000000..b792add0e --- /dev/null +++ b/sample/src/main/res/layout/content_configurable_location_circle.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + +