Skip to content

Commit

Permalink
Fix OOM on zoom-out.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-lr committed May 12, 2016
1 parent 3d1d519 commit f4ceb4b
Showing 1 changed file with 21 additions and 1 deletion.
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

0 comments on commit f4ceb4b

Please sign in to comment.