summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2015-10-27 16:11:48 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2015-10-28 07:28:19 +0100
commita67645cb390e95cf602635a8ee02e25dfa9a5fb7 (patch)
tree313b7ec6484173dc8033dd692b9646b38d5bf277 /android
parent3e999eeda01987168e73be2bcf2ff30831241101 (diff)
downloadqtlocation-mapboxgl-a67645cb390e95cf602635a8ee02e25dfa9a5fb7.tar.gz
[android] #2224 inflate children map view through xml
[android] - #2224 make UserLocationView inflatable through xml. using setter to attach MapView [android] #2224 - renamed fragment layout file, reordered views in layout file map view
Diffstat (limited to 'android')
-rw-r--r--android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java2
-rw-r--r--android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java67
-rw-r--r--android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java24
-rw-r--r--android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml (renamed from android/MapboxGLAndroidSDK/src/main/res/layout/mapview.xml)0
-rw-r--r--android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml36
5 files changed, 72 insertions, 57 deletions
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java
index 92405dc5cc..9a1861ec19 100644
--- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java
+++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java
@@ -37,7 +37,7 @@ public class MapFragment extends Fragment {
Log.v(TAG, "onCreateView");
// Create the map
- mMap = (MapView) inflater.inflate(R.layout.mapview, container, false);
+ mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
// Set accessToken
mMap.setAccessToken(ApiAccess.getToken(container.getContext()));
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
index 983f30b949..3f865bea45 100644
--- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
+++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
@@ -29,7 +29,6 @@ import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
-import android.support.v4.content.ContextCompat;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
import android.support.v7.app.AlertDialog;
@@ -41,13 +40,13 @@ import android.view.GestureDetector;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewConfiguration;
-import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -188,9 +187,6 @@ public final class MapView extends FrameLayout {
// Receives changes to network connectivity
private ConnectivityReceiver mConnectivityReceiver;
- // Holds the context
- private Context mContext;
-
// Used for user location
private UserLocationView mUserLocationView;
@@ -502,7 +498,7 @@ public final class MapView extends FrameLayout {
*
* @param location The current location of the My Location dot The type of map change event.
*/
- void onMyLocationChange(@Nullable Location location);
+ void onMyLocationChange(@Nullable Location location);
}
//
@@ -586,16 +582,15 @@ public final class MapView extends FrameLayout {
return;
}
- // Save the context
- mContext = context;
+ // Inflate content
+ View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this);
if (!isInEditMode()) {
setWillNotDraw(false);
}
- // Create the TextureView
- mTextureView = new TextureView(mContext);
- addView(mTextureView);
+ // Reference the TextureView
+ mTextureView = (TextureView) view.findViewById(R.id.textureView);
mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
// Check if we are in Android Studio UI editor to avoid error in layout preview
@@ -657,36 +652,18 @@ public final class MapView extends FrameLayout {
}
// Setup user location UI
- mUserLocationView = new UserLocationView(this, getContext());
- addView(mUserLocationView);
+ mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView);
+ mUserLocationView.setMapView(this);
// Setup compass
- mCompassView = new CompassView(mContext);
+ mCompassView = (CompassView) view.findViewById(R.id.compassView);
mCompassView.setOnClickListener(new CompassView.CompassClickListener(this));
- addView(mCompassView);
// Setup Mapbox logo
- mLogoView = new ImageView(mContext);
- mLogoView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.attribution_logo));
- mLogoView.setContentDescription(getResources().getString(R.string.mapboxIconContentDescription));
- ViewGroup.LayoutParams logoParams = new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- mLogoView.setLayoutParams(logoParams);
- addView(mLogoView);
+ mLogoView = (ImageView) view.findViewById(R.id.logoView);
// Setup Attributions control
- mAttributionsView = new ImageView(mContext);
- mAttributionsView.setClickable(true);
- mAttributionsView.setImageResource(R.drawable.ic_info_selector);
- int attrPadding = (int) (DIMENSION_SEVEN_DP * mScreenDensity);
- mAttributionsView.setPadding(attrPadding, attrPadding, attrPadding, attrPadding);
- mAttributionsView.setAdjustViewBounds(true);
- mAttributionsView.setContentDescription(getResources()
- .getString(R.string.attributionsIconContentDescription));
- LayoutParams attrParams = new FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- mAttributionsView.setLayoutParams(attrParams);
- addView(mAttributionsView);
+ mAttributionsView = (ImageView) view.findViewById(R.id.attributionView);
mAttributionsView.setOnClickListener(new AttributionOnClickListener(this));
// Load the attributes
@@ -942,7 +919,7 @@ public final class MapView extends FrameLayout {
public void onResume() {
// Register for connectivity changes
mConnectivityReceiver = new ConnectivityReceiver();
- mContext.registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
+ getContext().registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
mUserLocationView.resume();
mNativeMapView.resume();
@@ -2041,7 +2018,7 @@ public final class MapView extends FrameLayout {
/**
* Changes the map's viewing area to fit the given coordinate bounds, optionally animating the change.
*
- * @param bounds The bounds that the viewport will show in its entirety.
+ * @param bounds The bounds that the viewport will show in its entirety.
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
@@ -2053,8 +2030,8 @@ public final class MapView extends FrameLayout {
* Changes the map’s viewport to fit the given coordinate bounds with additional padding at the
* edge of the map, optionally animating the change.
*
- * @param bounds The bounds that the viewport will show in its entirety.
- * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
+ * @param bounds The bounds that the viewport will show in its entirety.
+ * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
@@ -2074,8 +2051,8 @@ public final class MapView extends FrameLayout {
* and animating the change.
*
* @param coordinates The coordinates that the viewport will show.
- * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
- * @param animated If true, animates the change. If false, immediately changes the map.
+ * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
+ * @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
public void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, boolean animated) {
@@ -2088,12 +2065,13 @@ public final class MapView extends FrameLayout {
private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
mNativeMapView.setVisibleCoordinateBounds(coordinates, new RectF(padding.left / mScreenDensity,
- padding.top / mScreenDensity, padding.right / mScreenDensity, padding.bottom / mScreenDensity),
+ padding.top / mScreenDensity, padding.right / mScreenDensity, padding.bottom / mScreenDensity),
direction, duration);
}
/**
* Gets the currently selected marker.
+ *
* @return The currently selected marker.
*/
@UiThread
@@ -3017,7 +2995,6 @@ public final class MapView extends FrameLayout {
}
-
/**
* Sets a callback that's invoked on every frame rendered to the map view.
*
@@ -3175,7 +3152,7 @@ public final class MapView extends FrameLayout {
/**
* Sets the current my location tracking mode.
- * <p>
+ * <p/>
* My location racking disables gestures, automatically moves the viewport to the users
* location and shows the direction the user is heading.
*
@@ -3248,8 +3225,8 @@ public final class MapView extends FrameLayout {
* @param gravity One of the values from {@link Gravity}.
* @see Gravity
*/
- @UiThread
- public void setCompassGravity(int gravity) {
+ @UiThread
+ public void setCompassGravity(int gravity) {
setWidgetGravity(mCompassView, gravity);
}
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java
index 06ef550a7d..121b25e835 100644
--- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java
+++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java
@@ -80,24 +80,22 @@ final class UserLocationView extends View {
@MyLocationTracking.Mode
private int mMyLocationTrackingMode;
- public UserLocationView(MapView mapView, Context context) {
+ public UserLocationView(Context context) {
super(context);
- initialize(mapView, context);
+ initialize(context);
}
- public UserLocationView(MapView mapView, Context context, AttributeSet attrs) {
+ public UserLocationView(Context context, AttributeSet attrs) {
super(context, attrs);
- initialize(mapView, context);
+ initialize(context);
}
- public UserLocationView(MapView mapView, Context context, AttributeSet attrs, int defStyleAttr) {
+ public UserLocationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- initialize(mapView, context);
+ initialize(context);
}
- private void initialize(MapView mapView, Context context) {
- mMapView = mapView;
-
+ private void initialize(Context context) {
// View configuration
setEnabled(false);
setWillNotDraw(false);
@@ -178,6 +176,10 @@ final class UserLocationView extends View {
mUserLocationStaleDrawable.setBounds(mUserLocationStaleDrawableBounds);
}
+ public void setMapView(MapView mapView) {
+ mMapView = mapView;
+ }
+
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
@@ -359,7 +361,7 @@ final class UserLocationView extends View {
previousCoordinate = new LatLng(mUserLocation);
}
- if(mMyLocationTrackingMode== MyLocationTracking.TRACKING_NONE) {
+ if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
// moving marker above map
mMarkerCoordinateAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
mMarkerCoordinateAnimator.setDuration(1000);
@@ -367,7 +369,7 @@ final class UserLocationView extends View {
previousCoordinate, new LatLng(location)
));
mMarkerCoordinateAnimator.start();
- }else{
+ } else {
// moving map under the tracker
mMarkerCoordinate = new LatLng(location);
mMapView.setCenterCoordinate(mMarkerCoordinate, true);
diff --git a/android/MapboxGLAndroidSDK/src/main/res/layout/mapview.xml b/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml
index 22afd6e513..22afd6e513 100644
--- a/android/MapboxGLAndroidSDK/src/main/res/layout/mapview.xml
+++ b/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml
diff --git a/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml b/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml
new file mode 100644
index 0000000000..c4eaecc079
--- /dev/null
+++ b/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <TextureView
+ android:id="@+id/textureView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <com.mapbox.mapboxsdk.views.CompassView
+ android:id="@+id/compassView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <ImageView
+ android:id="@+id/logoView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@string/mapboxIconContentDescription"
+ android:src="@drawable/attribution_logo" />
+
+ <ImageView
+ android:id="@+id/attributionView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:adjustViewBounds="true"
+ android:clickable="true"
+ android:contentDescription="@string/attributionsIconContentDescription"
+ android:padding="7dp"
+ android:src="@drawable/ic_info_selector" />
+
+ <com.mapbox.mapboxsdk.views.UserLocationView
+ android:id="@+id/userLocationView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+</merge> \ No newline at end of file