diff options
author | tobrunvannuland <tobrun.van.nuland@gmail.com> | 2015-09-01 08:36:53 +0200 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-09-11 15:11:44 -0700 |
commit | 7341ada02ea42b2d916792fd3cb07bb3742476eb (patch) | |
tree | 85d7458c7c019605dbec1a2925abb3a9f0324334 /android/java/MapboxGLAndroidSDK/src | |
parent | d57b47b1ebdffa7a1f33519d618ac590b607761e (diff) | |
download | qtlocation-mapboxgl-7341ada02ea42b2d916792fd3cb07bb3742476eb.tar.gz |
Added info icon and map box logo
Diffstat (limited to 'android/java/MapboxGLAndroidSDK/src')
11 files changed, 215 insertions, 4 deletions
diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index e96cf3ed0b..c8cbcc5545 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -1,17 +1,23 @@ package com.mapbox.mapboxgl.views; import android.app.ActivityManager; +import android.app.AlertDialog; +import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.content.res.TypedArray; +import android.content.res.XmlResourceParser; import android.graphics.Bitmap; import android.graphics.Matrix; import android.graphics.PointF; import android.graphics.RectF; import android.graphics.SurfaceTexture; +import android.graphics.drawable.Drawable; import android.hardware.GeomagneticField; import android.hardware.Sensor; import android.hardware.SensorEvent; @@ -20,10 +26,12 @@ import android.hardware.SensorManager; import android.location.Location; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.ScaleGestureDetectorCompat; import android.text.TextUtils; @@ -38,6 +46,8 @@ 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; import android.widget.ZoomButtonsController; @@ -95,6 +105,10 @@ public class MapView extends FrameLayout implements LocationListener { private static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled"; private static final String STATE_USER_LOCATION_TRACKING_MODE = "userLocationTrackingMode"; + // Used for positioning views + private static final float DIMENSION_SIXTEEN_DP = 16f; + private static final float DIMENSION_TEN_DP = 10f; + /** * Every annotation that has been added to the map. */ @@ -156,6 +170,12 @@ public class MapView extends FrameLayout implements LocationListener { private float mCompassBearing; private boolean mCompassValid = false; + // Used for MapboxLogo + private ImageView mLogoView; + + // Used for attributions control + private ImageView mAttributionsView; + // Used for map toggle mode private long t0 = new Date().getTime(); @@ -306,6 +326,8 @@ public class MapView extends FrameLayout implements LocationListener { // Get the screen's density mScreenDensity = context.getResources().getDisplayMetrics().density; + int tenDp = (int)(10 * mScreenDensity); + int sixteenDp = (int)(16 * mScreenDensity); // Get the cache path String cachePath = context.getCacheDir().getAbsolutePath(); @@ -373,13 +395,30 @@ public class MapView extends FrameLayout implements LocationListener { mCompassView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.compass)); mCompassView.setContentDescription(getResources().getString(R.string.compassContentDescription)); LayoutParams lp = new FrameLayout.LayoutParams((int)(48 * mScreenDensity), (int)(48 * mScreenDensity)); - lp.gravity = Gravity.TOP | Gravity.END; - int tenDp = (int)(10 * mScreenDensity); - lp.setMargins(tenDp, tenDp, tenDp, tenDp); mCompassView.setLayoutParams(lp); addView(mCompassView); mCompassView.setOnClickListener(new CompassOnClickListener()); + // Setup Mapbox logo + mLogoView = new ImageView(mContext); + mLogoView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_logo_mapbox)); + mLogoView.setContentDescription(getResources().getString(R.string.mapboxIconContentDescription)); + LayoutParams logoParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + mLogoView.setLayoutParams(logoParams); + addView(mLogoView); + + // Setup Attributions control + mAttributionsView = new ImageView(mContext); + Drawable attrDrawable = ContextCompat.getDrawable(mContext, R.drawable.ic_info_outline_black_24dp); + attrDrawable = DrawableCompat.wrap(attrDrawable); + DrawableCompat.setTintList(attrDrawable, getResources().getColorStateList(R.color.material_bg_selector, mContext.getTheme())); + mAttributionsView.setImageDrawable(attrDrawable); + 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.setOnClickListener(new AttributionOnClickListener()); + // Setup Support For Listener Tracking // MapView's internal listener is setup in onCreate() mOnMapChangedListener = new ArrayList<>(); @@ -412,7 +451,29 @@ public class MapView extends FrameLayout implements LocationListener { } setStyleClasses(styleClasses); } + + // Compass setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compassEnabled, true)); + setCompassGravity(typedArray.getInt(R.styleable.MapView_compassGravity, Gravity.TOP | Gravity.END)); + setWidgetMargins(mCompassView, typedArray.getDimension(R.styleable.MapView_compassMarginLeft, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compassMarginTop, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compassMarginRight, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compassMarginBottom, DIMENSION_TEN_DP)); + + // Logo + setLogoGravity(typedArray.getInt(R.styleable.MapView_logoGravity, Gravity.BOTTOM | Gravity.START)); + setWidgetMargins(mLogoView, typedArray.getDimension(R.styleable.MapView_logoMarginLeft, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logoMarginTop, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logoMarginRight, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logoMarginBottom, DIMENSION_SIXTEEN_DP)); + + // Attribution + setAttributionGravity(typedArray.getInt(R.styleable.MapView_attributionGravity, Gravity.BOTTOM | Gravity.END)); + setWidgetMargins(mAttributionsView, typedArray.getDimension(R.styleable.MapView_attributionMarginLeft, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_attributionMarginTop, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_attributionMarginRight, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_attributionMarginBottom, DIMENSION_SIXTEEN_DP)); + setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_myLocationEnabled, false)); } finally { typedArray.recycle(); @@ -1835,6 +1896,48 @@ public class MapView extends FrameLayout implements LocationListener { updateMap(MapChange.MapChangeNullChange); } + public void setCompassGravity(int gravity){ + setWidgetGravity(mCompassView, gravity); + } + + public void setCompassMargins(int left, int top, int right, int bottom){ + setWidgetMargins(mCompassView, left, top, right, bottom); + } + + public void setLogoGravity(int gravity){ + setWidgetGravity(mLogoView, gravity); + } + + public void setLogoMargins(int left, int top, int right, int bottom){ + setWidgetMargins(mLogoView, left, top, right, bottom); + } + + public void setAttributionGravity(int gravity){ + setWidgetGravity(mAttributionsView, gravity); + } + + public void setAttributionMargins(int left, int top, int right, int bottom) { + setWidgetMargins(mAttributionsView, left, top, right, bottom); + } + + private void setWidgetGravity(@NonNull final View view, int gravity){ + LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); + layoutParams.gravity = gravity; + view.setLayoutParams(layoutParams); + } + + private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom){ + LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); + layoutParams.setMargins(left,top,right,bottom); + view.setLayoutParams(layoutParams); + } + + private void setWidgetMargins(@NonNull final View view, float leftDp, float topDp, float rightDp, float bottomDp){ + LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); + layoutParams.setMargins((int)(leftDp*mScreenDensity),(int)(topDp*mScreenDensity),(int)(rightDp*mScreenDensity),(int)(bottomDp*mScreenDensity)); + view.setLayoutParams(layoutParams); + } + // This class handles sensor updates to calculate compass bearing private class CompassListener implements SensorEventListener { @@ -1889,6 +1992,30 @@ public class MapView extends FrameLayout implements LocationListener { } + private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { + + // Called when someone presses the attribution icon + @Override + public void onClick(View v) { + Context context = v.getContext(); + String[] items = context.getResources().getStringArray(R.array.attribution_names); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.attributionsDialogTitle); + builder.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, items), this); + builder.show(); + } + + // Called when someone selects an attribution + @Override + public void onClick(DialogInterface dialog, int which) { + Context context = ((Dialog)dialog).getContext(); + String[]links = context.getResources().getStringArray(R.array.attribution_links); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(links[which])); + context.startActivity(intent); + } + } + /** * LOST's LocationListener Callback * @param location New Location diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/color/material_bg_selector.xml b/android/java/MapboxGLAndroidSDK/src/main/res/color/material_bg_selector.xml new file mode 100644 index 0000000000..0da674ac74 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/color/material_bg_selector.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android" > + <item + android:color="?attr/colorPrimaryDark" + android:state_pressed="true"/> + <item + android:color="?attr/colorPrimary" /> +</selector>
\ No newline at end of file diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_info_outline_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_info_outline_black_24dp.png Binary files differnew file mode 100644 index 0000000000..4b5ab06e19 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_info_outline_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_info_outline_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_info_outline_black_24dp.png Binary files differnew file mode 100644 index 0000000000..e0c9fe0eb8 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_info_outline_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_info_outline_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_info_outline_black_24dp.png Binary files differnew file mode 100644 index 0000000000..b706f0d06a --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_info_outline_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_info_outline_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_info_outline_black_24dp.png Binary files differnew file mode 100644 index 0000000000..3847a9fe74 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_info_outline_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_logo_mapbox.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_logo_mapbox.png Binary files differnew file mode 100644 index 0000000000..d1260a16f3 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_logo_mapbox.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_info_outline_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_info_outline_black_24dp.png Binary files differnew file mode 100644 index 0000000000..c1e2a03a4b --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_info_outline_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml new file mode 100644 index 0000000000..3e937722c0 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/arrays.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <array name="attribution_names"> + <item>© Mapbox</item> + <item>© OpenStreetMap</item> + <item>Improve this map</item> + </array> + <array name="attribution_links" formatted="false" translatable="false"> + <item>https://www.mapbox.com/about/maps/</item> + <item>http://www.openstreetmap.org/about/</item> + <item>https://www.mapbox.com/map-feedback</item> + </array> +</resources>
\ No newline at end of file diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 7148429dbd..901044375f 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -11,7 +11,67 @@ <attr name="styleUrl" format="string" /> <attr name="accessToken" format="string"/> <attr name="styleClasses" format="string"/> - <attr name="compassEnabled" format="boolean" /> <attr name="myLocationEnabled" format="boolean" /> + <attr name="compassEnabled" format="boolean" /> + <attr name="compassGravity"> + <flag name="top" value="0x30" /> + <flag name="bottom" value="0x50" /> + <flag name="left" value="0x03" /> + <flag name="right" value="0x05" /> + <flag name="center_vertical" value="0x10" /> + <flag name="fill_vertical" value="0x70" /> + <flag name="center_horizontal" value="0x01" /> + <flag name="fill_horizontal" value="0x07" /> + <flag name="center" value="0x11" /> + <flag name="fill" value="0x77" /> + <flag name="clip_vertical" value="0x80" /> + <flag name="clip_horizontal" value="0x08" /> + <flag name="start" value="0x00800003" /> + <flag name="end" value="0x00800005" /> + </attr> + <attr name="compassMarginLeft" format="dimension"/> + <attr name="compassMarginTop" format="dimension"/> + <attr name="compassMarginRight" format="dimension"/> + <attr name="compassMarginBottom" format="dimension"/> + <attr name="logoGravity"> + <flag name="top" value="0x30" /> + <flag name="bottom" value="0x50" /> + <flag name="left" value="0x03" /> + <flag name="right" value="0x05" /> + <flag name="center_vertical" value="0x10" /> + <flag name="fill_vertical" value="0x70" /> + <flag name="center_horizontal" value="0x01" /> + <flag name="fill_horizontal" value="0x07" /> + <flag name="center" value="0x11" /> + <flag name="fill" value="0x77" /> + <flag name="clip_vertical" value="0x80" /> + <flag name="clip_horizontal" value="0x08" /> + <flag name="start" value="0x00800003" /> + <flag name="end" value="0x00800005" /> + </attr> + <attr name="logoMarginLeft" format="dimension"/> + <attr name="logoMarginTop" format="dimension"/> + <attr name="logoMarginRight" format="dimension"/> + <attr name="logoMarginBottom" format="dimension"/> + <attr name="attributionGravity"> + <flag name="top" value="0x30" /> + <flag name="bottom" value="0x50" /> + <flag name="left" value="0x03" /> + <flag name="right" value="0x05" /> + <flag name="center_vertical" value="0x10" /> + <flag name="fill_vertical" value="0x70" /> + <flag name="center_horizontal" value="0x01" /> + <flag name="fill_horizontal" value="0x07" /> + <flag name="center" value="0x11" /> + <flag name="fill" value="0x77" /> + <flag name="clip_vertical" value="0x80" /> + <flag name="clip_horizontal" value="0x08" /> + <flag name="start" value="0x00800003" /> + <flag name="end" value="0x00800005" /> + </attr> + <attr name="attributionMarginLeft" format="dimension"/> + <attr name="attributionMarginTop" format="dimension"/> + <attr name="attributionMarginRight" format="dimension"/> + <attr name="attributionMarginBottom" format="dimension"/> </declare-styleable> </resources> diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml index ff91a160de..455fdb0269 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -4,4 +4,7 @@ <string name="infoWindowTitle">Title</string> <string name="infoWindowDescription">Description</string> <string name="infoWindowAddress">Address</string> + <string name="attributionsIconContentDescription">Attribution icon. Click to show attribution dialog.</string> + <string name="attributionsDialogTitle">Mapbox for Android</string> + <string name="mapboxIconContentDescription">Mapbox logo.</string> </resources> |