From 1c4369fd52fce418796d2af4b54d380053b520da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 24 Feb 2015 16:12:49 -0800 Subject: [PATCH 1/7] Removed special cased zoom level for HiDPI No need to load higher-resolution vector tiles for HiDPI displays. Fixes #907. --- src/mbgl/map/source.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 13f3f30c9..508bbe413 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -206,7 +206,6 @@ TileData::State Source::addTile(Map& map, uv::worker& worker, double Source::getZoom(const TransformState& state) const { double offset = std::log(util::tileSize / info.tile_size) / std::log(2); - offset += (state.getPixelRatio() > 1.0 ? 1 :0); return state.getZoom() + offset; } From 77cf66d91f9cefabb9f598c463def5ab35fb68cc Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 13:21:23 -0600 Subject: [PATCH 2/7] #895 - Fixing missing JavaDoc warnings. --- .../multitouch/BaseGestureDetector.java | 62 ++++++++--------- .../multitouch/TwoFingerGestureDetector.java | 68 +++++++++---------- .../gesturedetectors/BaseGestureDetector.java | 32 ++++----- .../TwoFingerGestureDetector.java | 38 +++++------ 4 files changed, 100 insertions(+), 100 deletions(-) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/BaseGestureDetector.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/BaseGestureDetector.java index dafac2a1a..8c0c54498 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/BaseGestureDetector.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/BaseGestureDetector.java @@ -12,15 +12,15 @@ import android.view.MotionEvent; * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ public abstract class BaseGestureDetector { @@ -29,12 +29,12 @@ public abstract class BaseGestureDetector { protected MotionEvent mPrevEvent; protected MotionEvent mCurrEvent; - + protected float mCurrPressure; protected float mPrevPressure; protected long mTimeDelta; - - + + /** * This value is the threshold ratio between the previous combined pressure * and the current combined pressure. When pressure decreases rapidly @@ -44,19 +44,19 @@ public abstract class BaseGestureDetector { */ protected static final float PRESSURE_THRESHOLD = 0.67f; - + public BaseGestureDetector(Context context) { - mContext = context; + mContext = context; } - + /** * All gesture detectors need to be called through this method to be able to * detect gestures. This method delegates work to handler methods * (handleStartProgressEvent, handleInProgressEvent) implemented in * extending classes. - * - * @param event - * @return + * + * @param event MotionEvent + * @return true */ public boolean onTouchEvent(MotionEvent event){ final int actionCode = event.getAction() & MotionEvent.ACTION_MASK; @@ -67,37 +67,37 @@ public abstract class BaseGestureDetector { } return true; } - + /** * Called when the current event occurred when NO gesture is in progress * yet. The handling in this implementation may set the gesture in progress * (via mGestureInProgress) or out of progress - * @param actionCode - * @param event + * @param actionCode Action Code from MotionEvent + * @param event MotionEvent */ protected abstract void handleStartProgressEvent(int actionCode, MotionEvent event); - + /** * Called when the current event occurred when a gesture IS in progress. The * handling in this implementation may set the gesture out of progress (via * mGestureInProgress). - * @param actionCode - * @param event + * @param actionCode Action Code from MotionEvent + * @param event MotionEvent */ protected abstract void handleInProgressEvent(int actionCode, MotionEvent event); - - + + protected void updateStateByEvent(MotionEvent curr){ final MotionEvent prev = mPrevEvent; - + // Reset mCurrEvent if (mCurrEvent != null) { mCurrEvent.recycle(); mCurrEvent = null; } mCurrEvent = MotionEvent.obtain(curr); - - + + // Delta time mTimeDelta = curr.getEventTime() - prev.getEventTime(); @@ -105,7 +105,7 @@ public abstract class BaseGestureDetector { mCurrPressure = curr.getPressure(curr.getActionIndex()); mPrevPressure = prev.getPressure(prev.getActionIndex()); } - + protected void resetState() { if (mPrevEvent != null) { mPrevEvent.recycle(); @@ -130,7 +130,7 @@ public abstract class BaseGestureDetector { /** * Return the time difference in milliseconds between the previous accepted * GestureDetector event and the current GestureDetector event. - * + * * @return Time difference since the last move event in milliseconds. */ public long getTimeDelta() { @@ -140,11 +140,11 @@ public abstract class BaseGestureDetector { /** * Return the event time of the current GestureDetector event being * processed. - * + * * @return Current GestureDetector event time in milliseconds. */ public long getEventTime() { return mCurrEvent.getEventTime(); } - + } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java index 57e4e21d2..6c6a0e4bf 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/TwoFingerGestureDetector.java @@ -14,15 +14,15 @@ import android.view.ViewConfiguration; * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { @@ -30,33 +30,33 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { private final float mEdgeSlop; private float mRightSlopEdge; private float mBottomSlopEdge; - + protected float mPrevFingerDiffX; protected float mPrevFingerDiffY; protected float mCurrFingerDiffX; protected float mCurrFingerDiffY; - + private float mCurrLen; private float mPrevLen; - + public TwoFingerGestureDetector(Context context) { super(context); - + ViewConfiguration config = ViewConfiguration.get(context); - mEdgeSlop = config.getScaledEdgeSlop(); + mEdgeSlop = config.getScaledEdgeSlop(); } - + @Override protected abstract void handleStartProgressEvent(int actionCode, MotionEvent event); @Override protected abstract void handleInProgressEvent(int actionCode, MotionEvent event); - + protected void updateStateByEvent(MotionEvent curr){ super.updateStateByEvent(curr); - + final MotionEvent prev = mPrevEvent; - + mCurrLen = -1; mPrevLen = -1; @@ -69,7 +69,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { final float pvy = py1 - py0; mPrevFingerDiffX = pvx; mPrevFingerDiffY = pvy; - + // Current final float cx0 = curr.getX(0); final float cy0 = curr.getY(0); @@ -80,11 +80,11 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { mCurrFingerDiffX = cvx; mCurrFingerDiffY = cvy; } - + /** * Return the current distance between the two pointers forming the * gesture in progress. - * + * * @return Distance between pointers in pixels. */ public float getCurrentSpan() { @@ -99,7 +99,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * Return the previous distance between the two pointers forming the * gesture in progress. - * + * * @return Previous distance between pointers in pixels. */ public float getPreviousSpan() { @@ -110,52 +110,52 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { } return mPrevLen; } - + /** - * MotionEvent has no getRawX(int) method; simulate it pending future API approval. + * MotionEvent has no getRawX(int) method; simulate it pending future API approval. * @param event * @param pointerIndex - * @return + * @return Raw X value or 0 */ protected static float getRawX(MotionEvent event, int pointerIndex) { float offset = event.getX() - event.getRawX(); if(pointerIndex < event.getPointerCount()){ return event.getX(pointerIndex) + offset; - } + } return 0f; } /** - * MotionEvent has no getRawY(int) method; simulate it pending future API approval. + * MotionEvent has no getRawY(int) method; simulate it pending future API approval. * @param event * @param pointerIndex - * @return + * @return Raw Y value or 0 */ protected static float getRawY(MotionEvent event, int pointerIndex) { float offset = event.getY() - event.getRawY(); if(pointerIndex < event.getPointerCount()){ return event.getY(pointerIndex) + offset; - } + } return 0f; } /** * Check if we have a sloppy gesture. Sloppy gestures can happen if the edge * of the user's hand is touching the screen, for example. - * - * @param event - * @return + * + * @param event MotionEvent + * @return {@code true} if is a sloppy gesture, {@code false} if not */ protected boolean isSloppyGesture(MotionEvent event){ // As orientation can change, query the metrics in touch down DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); mRightSlopEdge = metrics.widthPixels - mEdgeSlop; mBottomSlopEdge = metrics.heightPixels - mEdgeSlop; - + final float edgeSlop = mEdgeSlop; final float rightSlop = mRightSlopEdge; final float bottomSlop = mBottomSlopEdge; - + final float x0 = event.getRawX(); final float y0 = event.getRawY(); final float x1 = getRawX(event, 1); @@ -172,8 +172,8 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { return true; } else if (p1sloppy) { return true; - } + } return false; - } + } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java index 720a1f541..622e8f759 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java @@ -6,19 +6,19 @@ import android.view.MotionEvent; /** * @author Almer Thie (code.almeros.com) Copyright (c) 2013, Almer Thie * (code.almeros.com) - * + * * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -61,9 +61,9 @@ public abstract class BaseGestureDetector { * detect gestures. This method delegates work to handler methods * (handleStartProgressEvent, handleInProgressEvent) implemented in * extending classes. - * - * @param event - * @return + * + * @param event MotionEvent + * @return {@code true} as handled */ public boolean onTouchEvent(MotionEvent event) { final int actionCode = event.getAction() & MotionEvent.ACTION_MASK; @@ -79,9 +79,9 @@ public abstract class BaseGestureDetector { * Called when the current event occurred when NO gesture is in progress * yet. The handling in this implementation may set the gesture in progress * (via mGestureInProgress) or out of progress - * - * @param actionCode - * @param event + * + * @param actionCode Action Code from MotionEvent + * @param event MotionEvent */ protected abstract void handleStartProgressEvent(int actionCode, MotionEvent event); @@ -90,10 +90,10 @@ public abstract class BaseGestureDetector { * Called when the current event occurred when a gesture IS in progress. The * handling in this implementation may set the gesture out of progress (via * mGestureInProgress). - * * - * @param actionCode - * @param event + * + * @param actionCode Action Code from MotionEvent + * @param event MotionEvent */ protected abstract void handleInProgressEvent(int actionCode, MotionEvent event); @@ -130,7 +130,7 @@ public abstract class BaseGestureDetector { /** * Returns {@code true} if a gesture is currently in progress. - * + * * @return {@code true} if a gesture is currently in progress, {@code false} * otherwise. */ @@ -141,7 +141,7 @@ public abstract class BaseGestureDetector { /** * Return the time difference in milliseconds between the previous accepted * GestureDetector event and the current GestureDetector event. - * + * * @return Time difference since the last move event in milliseconds. */ public long getTimeDelta() { @@ -151,7 +151,7 @@ public abstract class BaseGestureDetector { /** * Return the event time of the current GestureDetector event being * processed. - * + * * @return Current GestureDetector event time in milliseconds. */ public long getEventTime() { diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java index e26d6b5ae..91e5ef13c 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java @@ -9,19 +9,19 @@ import android.view.ViewConfiguration; /** * @author Almer Thie (code.almeros.com) Copyright (c) 2013, Almer Thie * (code.almeros.com) - * + * * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -97,7 +97,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * Return the current distance between the two pointers forming the gesture * in progress. - * + * * @return Distance between pointers in pixels. */ public float getCurrentSpan() { @@ -112,7 +112,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * Return the previous distance between the two pointers forming the gesture * in progress. - * + * * @return Previous distance between pointers in pixels. */ public float getPreviousSpan() { @@ -127,10 +127,10 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * MotionEvent has no getRawX(int) method; simulate it pending future API * approval. - * - * @param event - * @param pointerIndex - * @return + * + * @param event Motion Event + * @param pointerIndex Pointer Index + * @return Raw x value or 0 */ protected static float getRawX(MotionEvent event, int pointerIndex) { float offset = event.getX() - event.getRawX(); @@ -143,10 +143,10 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * MotionEvent has no getRawY(int) method; simulate it pending future API * approval. - * - * @param event - * @param pointerIndex - * @return + * + * @param event Motion Event + * @param pointerIndex Pointer Index + * @return Raw y value or 0 */ protected static float getRawY(MotionEvent event, int pointerIndex) { float offset = event.getY() - event.getRawY(); @@ -159,9 +159,9 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * Check if we have a sloppy gesture. Sloppy gestures can happen if the edge * of the user's hand is touching the screen, for example. - * - * @param event - * @return + * + * @param event Motion Event + * @return {@code true} if is sloppy gesture, {@code false} if not */ protected boolean isSloppyGesture(MotionEvent event) { // As orientation can change, query the metrics in touch down @@ -194,8 +194,8 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { /** * Determine (multi)finger focal point (a.k.a. center point between all * fingers) - * - * @param e + * + * @param e Motion Event * @return PointF focal point */ public static PointF determineFocalPoint(MotionEvent e) { From 78f37879a3e83a16d95f1c0d3e50e15841987079 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 16:08:32 -0600 Subject: [PATCH 3/7] Use Build constants instead of integers --- .../src/main/java/com/mapbox/mapboxgl/lib/MapView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index d157cc07f..4eeda79e8 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -10,6 +10,7 @@ import android.content.res.TypedArray; import android.graphics.PointF; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.view.GestureDetectorCompat; @@ -178,7 +179,7 @@ public class MapView extends SurfaceView { requestFocus(); // Register the SurfaceHolder callbacks - if (android.os.Build.VERSION.SDK_INT >= 9) { + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { getHolder().addCallback(new Callbacks2()); } else { getHolder().addCallback(new Callbacks()); From 885185b35215b61fc771a04c28cddec711509815 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 16:25:03 -0600 Subject: [PATCH 4/7] #823 - Adding OkHttp dependency. Initial setup of JavaFileSource as a singleton class. --- android/java/MapboxGLAndroidSDK/build.gradle | 1 + .../mapboxgl/lib/util/JavaFileSource.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java diff --git a/android/java/MapboxGLAndroidSDK/build.gradle b/android/java/MapboxGLAndroidSDK/build.gradle index 806134394..ebfe98cd8 100644 --- a/android/java/MapboxGLAndroidSDK/build.gradle +++ b/android/java/MapboxGLAndroidSDK/build.gradle @@ -31,6 +31,7 @@ dependencies { compile 'commons-validator:commons-validator:1.4.1' compile 'com.android.support:support-annotations:21.0.3' compile 'com.android.support:support-v4:21.0.3' + compile 'com.squareup.okhttp:okhttp:2.2.0' } android { diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java new file mode 100644 index 000000000..91863accf --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java @@ -0,0 +1,24 @@ +package com.mapbox.mapboxgl.lib.util; + +public class JavaFileSource { + + private static JavaFileSource instance = null; + + /** + * Private Constructor to support Singleton pattern + */ + private JavaFileSource() { + super(); + } + + /** + * Get the singleton instance of JavaFileSource + * @return Reference to the Singleton Instance of JavaFileSource + */ + public static JavaFileSource getInstance() { + if (instance == null) { + instance = new JavaFileSource(); + } + return instance; + } +} From 2bfafaddb1a824cbc7ec4315aac40995328cbd7c Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 16:48:54 -0600 Subject: [PATCH 5/7] #823 - Building request method --- .../mapboxgl/lib/util/JavaFileSource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java index 91863accf..f9b141797 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java @@ -1,14 +1,22 @@ package com.mapbox.mapboxgl.lib.util; +import com.squareup.okhttp.Callback; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; + public class JavaFileSource { private static JavaFileSource instance = null; + // Single reference to OkHttp for performance gains + private OkHttpClient client; + /** * Private Constructor to support Singleton pattern */ private JavaFileSource() { super(); + client = new OkHttpClient(); } /** @@ -21,4 +29,18 @@ public class JavaFileSource { } return instance; } + + /** + * Make an HTTP Request + * @param resourceUrl URL to resource + * @param callback Callback class + * @return Request created + */ + public Request request(final String resourceUrl, final Callback callback) { + Request request = new Request.Builder().url(resourceUrl).build(); + + client.newCall(request).enqueue(callback); + + return request; + } } From a4b6067d4f680c42e7ec033b41bc02c63d111e18 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 17:01:13 -0600 Subject: [PATCH 6/7] #823 - Building cancel method. Refactoring request to not return OkHttp Request object to help keep FileSource self contained. --- .../mapboxgl/lib/constants/MapboxConstants.java | 10 ++++++++++ .../com/mapbox/mapboxgl/lib/util/JavaFileSource.java | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/constants/MapboxConstants.java diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/constants/MapboxConstants.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/constants/MapboxConstants.java new file mode 100644 index 000000000..4816dbf4d --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/constants/MapboxConstants.java @@ -0,0 +1,10 @@ +package com.mapbox.mapboxgl.lib.constants; + +import java.util.Locale; + +public class MapboxConstants { + + // Default Locale for data processing (ex: String.toLowerCase(MAPBOX_LOCALE, "foo")) + public static final Locale MAPBOX_LOCALE = Locale.US; + +} diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java index f9b141797..1081657b0 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxgl.lib.util; +import com.mapbox.mapboxgl.lib.constants.MapboxConstants; import com.squareup.okhttp.Callback; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; @@ -34,13 +35,13 @@ public class JavaFileSource { * Make an HTTP Request * @param resourceUrl URL to resource * @param callback Callback class - * @return Request created */ - public Request request(final String resourceUrl, final Callback callback) { - Request request = new Request.Builder().url(resourceUrl).build(); - + public void request(final String resourceUrl, final Callback callback) { + Request request = new Request.Builder().url(resourceUrl).tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)).build(); client.newCall(request).enqueue(callback); + } - return request; + public void cancel(final String resourceUrl) { + client.cancel(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)); } } From 380fd1fbf4c8d148bb231a99007498713a07829f Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 25 Feb 2015 17:17:56 -0600 Subject: [PATCH 7/7] #823 - Adding JavaDoc for cancel() --- .../java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java index 1081657b0..40e7964eb 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/lib/util/JavaFileSource.java @@ -41,6 +41,10 @@ public class JavaFileSource { client.newCall(request).enqueue(callback); } + /** + * Attempt to cancel HTTP Request made + * @param resourceUrl URL of request to cancel + */ public void cancel(final String resourceUrl) { client.cancel(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)); }