From 3d1d519d090b13e0eef700372544c3242ddf2f58 Mon Sep 17 00:00:00 2001 From: peterLaurence Date: Wed, 11 May 2016 13:30:38 +0200 Subject: [PATCH 1/3] Fix #304 : Real to relative coordinates. --- .../tileview/geom/CoordinateTranslater.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tileview/src/main/java/com/qozix/tileview/geom/CoordinateTranslater.java b/tileview/src/main/java/com/qozix/tileview/geom/CoordinateTranslater.java index 9f64633f..c8563b6f 100644 --- a/tileview/src/main/java/com/qozix/tileview/geom/CoordinateTranslater.java +++ b/tileview/src/main/java/com/qozix/tileview/geom/CoordinateTranslater.java @@ -119,9 +119,15 @@ public int translateAndScaleY( double y, float scale ) { * @param x The x value to be translated. * @return The relative value of the x coordinate supplied. */ + public double translateAbsoluteToRelativeX( float x ) { + return mLeft + ( x * mDiffX / mWidth ); + } + + /** + * Pipes to {@link #translateAbsoluteToRelativeX( float )} + */ public double translateAbsoluteToRelativeX( int x ) { - double factor = x / mWidth; - return mLeft + (factor * mDiffX); + return translateAbsoluteToRelativeX( (float) x ); } /** @@ -131,8 +137,15 @@ public double translateAbsoluteToRelativeX( int x ) { * @param scale The scale to apply. * @return The relative value of the x coordinate supplied. */ + public double translateAndScaleAbsoluteToRelativeX( float x, float scale ) { + return translateAbsoluteToRelativeX( x / scale ); + } + + /** + * @see #translateAndScaleAbsoluteToRelativeX(float, float) + */ public double translateAndScaleAbsoluteToRelativeX( int x, float scale ) { - return translateAbsoluteToRelativeX( FloatMathHelper.unscale( x, scale ) ); + return translateAbsoluteToRelativeX( x / scale ); } /** @@ -141,9 +154,15 @@ public double translateAndScaleAbsoluteToRelativeX( int x, float scale ) { * @param y The y value to be translated. * @return The relative value of the y coordinate supplied. */ + public double translateAbsoluteToRelativeY( float y ) { + return mTop + ( y * mDiffY / mHeight ); + } + + /** + * Pipes to {@link #translateAbsoluteToRelativeY( float )} + */ public double translateAbsoluteToRelativeY( int y ) { - double factor = y / mHeight; - return mTop + (factor * mDiffY); + return translateAbsoluteToRelativeY( (float) y ); } /** @@ -153,8 +172,15 @@ public double translateAbsoluteToRelativeY( int y ) { * @param scale The scale to apply. * @return The relative value of the y coordinate supplied. */ + public double translateAndScaleAbsoluteToRelativeY( float y, float scale ) { + return translateAbsoluteToRelativeY( y / scale ); + } + + /** + * @see #translateAndScaleAbsoluteToRelativeY(float, float) + */ public double translateAndScaleAbsoluteToRelativeY( int y, float scale ) { - return translateAbsoluteToRelativeY( FloatMathHelper.unscale( y, scale ) ); + return translateAbsoluteToRelativeY( y / scale ); } /** From f4ceb4b73c7cdd913e3bfb85d7009e409740035d Mon Sep 17 00:00:00 2001 From: peterLaurence Date: Thu, 12 May 2016 21:06:57 +0200 Subject: [PATCH 2/3] Fix OOM on zoom-out. --- .../java/com/qozix/tileview/TileView.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tileview/src/main/java/com/qozix/tileview/TileView.java b/tileview/src/main/java/com/qozix/tileview/TileView.java index 95431931..71142586 100644 --- a/tileview/src/main/java/com/qozix/tileview/TileView.java +++ b/tileview/src/main/java/com/qozix/tileview/TileView.java @@ -85,6 +85,7 @@ public class TileView extends ZoomPanLayout implements private RenderThrottleHandler mRenderThrottleHandler; private boolean mShouldRenderWhilePanning = false; + private boolean mShouldUpdateDetailLevelWhileZooming = false; /** * Constructor to use when creating a TileView from code. @@ -716,6 +717,23 @@ public void setShouldRenderWhilePanning( boolean shouldRender ) { mTileCanvasViewGroup.setRenderBuffer( buffer ); } + /** + * By default, when a zoom begins, the current {@link DetailLevel} is locked so it is used to + * provide tiles until the zoom ends. This ensures that the {@link TileView} is updated + * consistently. + *

+ * However, a zoom out may require a lot of tiles of the locked {@code DetailLevel} to be rendered. + * In worst case, it can cause {@link OutOfMemoryError}. + * Then, disabling the {@code DetailLevel} lock is a bandage to that issue. Using + * {@code setShouldUpdateDetailLevelWhileZooming( true )} is not advised unless you have that issue. + *

+ * + * @param shouldUpdate True if it should lock {@link DetailLevel} when a zoom begins. + */ + public void setShouldUpdateDetailLevelWhileZooming( boolean shouldUpdate ) { + mShouldUpdateDetailLevelWhileZooming = shouldUpdate; + } + /** * Allows the use of a custom {@link DetailLevelManager}. *

@@ -795,7 +813,9 @@ public void onPanEnd( int x, int y, Origination origin ) { @Override public void onZoomBegin( float scale, Origination origin ) { - mDetailLevelManager.lockDetailLevel(); + if( !mShouldUpdateDetailLevelWhileZooming ) { + mDetailLevelManager.lockDetailLevel(); + } mDetailLevelManager.setScale( scale ); } From bc977270c3995f3b7822e4cf9c2bc321ac94978f Mon Sep 17 00:00:00 2001 From: peterLaurence Date: Thu, 12 May 2016 21:10:42 +0200 Subject: [PATCH 3/3] Bump version 2.1.6 --- README.md | 4 ++-- tileview/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2cf211aa..33b0d289 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Javadocs are [here](http://moagrius.github.io/TileView/index.html?com/qozix/tile ###Installation Gradle: ``` -compile 'com.qozix:tileview:2.1.5' +compile 'com.qozix:tileview:2.1.6' ``` The library is hosted on jcenter, and is not currently available from maven. @@ -56,7 +56,7 @@ A demo application, built in Android Studio, is available in the `demo` folder o at the 2nd column from left and 3rd row from top. 1. Create a new application with a single activity ('Main'). 1. Save the image tiles to your `assets` directory. -1. Add `compile 'com.qozix:tileview:2.1.5'` to your gradle dependencies. +1. Add `compile 'com.qozix:tileview:2.1.6'` to your gradle dependencies. 1. In the Main Activity, use this for `onCreate`: ``` @Override diff --git a/tileview/build.gradle b/tileview/build.gradle index 63ffdb3e..abce339d 100644 --- a/tileview/build.gradle +++ b/tileview/build.gradle @@ -6,8 +6,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 22 - versionCode 30 - versionName "2.1.5" + versionCode 31 + versionName "2.1.6" } buildTypes { release {