Skip to content

Commit

Permalink
Merge pull request #305 from peterLaurence/fix#304
Browse files Browse the repository at this point in the history
Fix #304 & OOM on zoom-out
  • Loading branch information
p-lr committed May 14, 2016
2 parents be746e3 + bc97727 commit dc5885a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tileview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
versionCode 30
versionName "2.1.5"
versionCode 31
versionName "2.1.6"
}
buildTypes {
release {
Expand Down
22 changes: 21 additions & 1 deletion tileview/src/main/java/com/qozix/tileview/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
* <p>
* 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.
* </p>
*
* @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}.
* <p>
Expand Down Expand Up @@ -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 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand Down

0 comments on commit dc5885a

Please sign in to comment.