From 729a793b0eb55f3016bff54cf7fe22039b10b76e Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Thu, 22 Oct 2015 11:16:39 +1100 Subject: [PATCH] Add style string resources Use _ in public resources ids Make visibility attributes enums Make attrs public Remove info window margin public value Reformat XML code Test app uses XML map properties for InfoWindow activities Fixes #2703 --- .../com/mapbox/mapboxsdk/constants/Style.java | 2 + .../com/mapbox/mapboxsdk/views/MapView.java | 66 +++++++++--------- .../src/main/res-public/values/public.xml | 38 ++++++++++- .../main/res/color/material_bg_selector.xml | 9 +-- .../main/res/drawable/ic_info_selector.xml | 4 +- .../main/res/layout/attribution_list_item.xml | 6 +- .../main/res/layout/infowindow_content.xml | 33 +++++---- .../src/main/res/layout/infowindow_view.xml | 2 +- .../src/main/res/values/attrs.xml | 67 +++++++++++-------- .../src/main/res/values/strings.xml | 7 ++ .../src/main/res/values/styles.xml | 1 + .../mapboxsdk/testapp/InfoWindowActivity.java | 3 - .../testapp/InfoWindowAdapterActivity.java | 4 -- .../main/res/layout/activity_infowindow.xml | 13 ++-- .../layout/activity_infowindow_adapter.xml | 15 +++-- 15 files changed, 161 insertions(+), 109 deletions(-) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java index f13fad335..1b0b16bb7 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java @@ -23,6 +23,8 @@ public class Style { public @interface StyleUrl { } + // IMPORTANT: If you change any of these you also need to edit them in strings.xml + /** * Mapbox Streets: Our signature style. */ diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 515f1a74d..dd757082c 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -17,7 +17,6 @@ import android.graphics.Matrix; import android.graphics.PointF; import android.graphics.RectF; import android.graphics.SurfaceTexture; -import android.graphics.drawable.BitmapDrawable; import android.location.Location; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -38,7 +37,6 @@ import android.support.v7.app.AlertDialog; import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; -import android.util.Log; import android.view.GestureDetector; import android.view.Gravity; import android.view.InputDevice; @@ -684,26 +682,26 @@ public final class MapView extends FrameLayout { // Load the attributes TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0); try { - double centerLatitude = typedArray.getFloat(R.styleable.MapView_centerLatitude, 0.0f); - double centerLongitude = typedArray.getFloat(R.styleable.MapView_centerLongitude, 0.0f); + double centerLatitude = typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f); + double centerLongitude = typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f); LatLng centerCoordinate = new LatLng(centerLatitude, centerLongitude); setCenterCoordinate(centerCoordinate); // need to set zoom level first because of limitation on rotating when zoomed out - setZoomLevel(typedArray.getFloat(R.styleable.MapView_zoomLevel, 0.0f)); + setZoomLevel(typedArray.getFloat(R.styleable.MapView_zoom_level, 0.0f)); setDirection(typedArray.getFloat(R.styleable.MapView_direction, 0.0f)); - setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoomEnabled, true)); - setScrollEnabled(typedArray.getBoolean(R.styleable.MapView_scrollEnabled, true)); - setRotateEnabled(typedArray.getBoolean(R.styleable.MapView_rotateEnabled, true)); - setDebugActive(typedArray.getBoolean(R.styleable.MapView_debugActive, false)); - if (typedArray.getString(R.styleable.MapView_styleUrl) != null) { - setStyleUrl(typedArray.getString(R.styleable.MapView_styleUrl)); + setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true)); + setScrollEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true)); + setRotateEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true)); + setDebugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false)); + if (typedArray.getString(R.styleable.MapView_style_url) != null) { + setStyleUrl(typedArray.getString(R.styleable.MapView_style_url)); } - if (typedArray.getString(R.styleable.MapView_accessToken) != null) { - setAccessToken(typedArray.getString(R.styleable.MapView_accessToken)); + if (typedArray.getString(R.styleable.MapView_access_token) != null) { + setAccessToken(typedArray.getString(R.styleable.MapView_access_token)); } - if (typedArray.getString(R.styleable.MapView_styleClasses) != null) { + if (typedArray.getString(R.styleable.MapView_style_classes) != null) { List styleClasses = Arrays.asList(typedArray - .getString(R.styleable.MapView_styleClasses).split("\\s*,\\s*")); + .getString(R.styleable.MapView_style_classes).split("\\s*,\\s*")); for (String styleClass : styleClasses) { if (styleClass.length() == 0) { styleClasses.remove(styleClass); @@ -713,31 +711,31 @@ public final class MapView extends FrameLayout { } // 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)); + setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true)); + setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END)); + setWidgetMargins(mCompassView, typedArray.getDimension(R.styleable.MapView_compass_margin_left, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compass_margin_top, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP) + , typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP)); // Logo - setLogoVisibility(typedArray.getInt(R.styleable.MapView_logoVisibility, VISIBLE)); - 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)); + setLogoVisibility(typedArray.getInt(R.styleable.MapView_logo_visibility, View.VISIBLE)); + setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START)); + setWidgetMargins(mLogoView, typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) + , typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP)); // Attribution - setAttributionVisibility(typedArray.getInt(R.styleable.MapView_attributionVisibility, VISIBLE)); - setAttributionGravity(typedArray.getInt(R.styleable.MapView_attributionGravity, Gravity.BOTTOM)); - setWidgetMargins(mAttributionsView, typedArray.getDimension(R.styleable.MapView_attributionMarginLeft, DIMENSION_SEVENTYSIX_DP) - , typedArray.getDimension(R.styleable.MapView_attributionMarginTop, DIMENSION_SEVEN_DP) - , typedArray.getDimension(R.styleable.MapView_attributionMarginRight, DIMENSION_SEVEN_DP) - , typedArray.getDimension(R.styleable.MapView_attributionMarginBottom, DIMENSION_SEVEN_DP)); + setAttributionVisibility(typedArray.getInt(R.styleable.MapView_attribution_visibility, View.VISIBLE)); + setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM)); + setWidgetMargins(mAttributionsView, typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTYSIX_DP) + , typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP) + , typedArray.getDimension(R.styleable.MapView_attribution_margin_right, DIMENSION_SEVEN_DP) + , typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP)); // User location - setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_myLocationEnabled, false)); + setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false)); } finally { typedArray.recycle(); } diff --git a/android/java/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/android/java/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 64412f3b0..f6cb05662 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -2,5 +2,41 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0da674ac7..64d7f46c2 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/color/material_bg_selector.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/color/material_bg_selector.xml @@ -1,8 +1,5 @@ - - - + + + \ No newline at end of file diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable/ic_info_selector.xml b/android/java/MapboxGLAndroidSDK/src/main/res/drawable/ic_info_selector.xml index fdbabbae1..9f550f66d 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/drawable/ic_info_selector.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable/ic_info_selector.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/layout/attribution_list_item.xml b/android/java/MapboxGLAndroidSDK/src/main/res/layout/attribution_list_item.xml index f0a912158..1252fb194 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/layout/attribution_list_item.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/layout/attribution_list_item.xml @@ -3,9 +3,9 @@ android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceListItemSmall" - android:textColor="@android:color/white" android:gravity="center_vertical" + android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingLeft="16dp" android:paddingRight="16dp" - android:minHeight="?android:attr/listPreferredItemHeightSmall" /> + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:textColor="@android:color/white" /> diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_content.xml b/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_content.xml index eed2f0c2c..47c5d90d7 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_content.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_content.xml @@ -1,54 +1,53 @@ - + android:background="@color/white" + android:orientation="vertical" + android:padding="5dp"> + android:maxEms="17" + android:text="@string/infoWindowTitle" + android:textColor="@color/black" + android:textSize="18sp" /> + android:text="@string/infoWindowDescription" + android:textColor="@color/black" + android:textSize="14sp" /> + android:textColor="@color/black" + android:textSize="12sp" + android:visibility="gone" /> + android:layout_height="8dp" + android:layout_below="@+id/infowindow_content" /> diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_view.xml b/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_view.xml index 731abefd4..ff4764242 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_view.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/layout/infowindow_view.xml @@ -1,4 +1,4 @@ + android:layout_height="wrap_content" /> diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 2eae497b7..be946714d 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -1,19 +1,20 @@ + - - - + + + - - - - - - - - - - + + + + + + + + + + @@ -29,11 +30,11 @@ - - - - - + + + + + @@ -49,12 +50,16 @@ - - - - - - + + + + + + + + + + @@ -70,10 +75,14 @@ - - - - - + + + + + + + + + diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml index be9a1d38c..a29d7de7c 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -7,4 +7,11 @@ Title Description Address + + + asset://styles/streets-v8.json + asset://styles/emerald-v8.json + asset://styles/light-v8.json + asset://styles/dark-v8.json + asset://styles/satellite-v8.json diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/styles.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/styles.xml index a0859a998..9ad12f76a 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/styles.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/styles.xml @@ -1,6 +1,7 @@ +