Skip to content

Commit

Permalink
Merge pull request #417 from peterLaurence/fix#415
Browse files Browse the repository at this point in the history
Fix#415
  • Loading branch information
p-lr authored May 25, 2017
2 parents 2cbf51b + 5348072 commit 0aaaeb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Javadocs are [here](http://moagrius.github.io/TileView/index.html?com/qozix/tile
### Installation
Gradle:
```
compile 'com.qozix:tileview:'2.2.6'
compile 'com.qozix:tileview:'2.2.7'
```

The library is hosted on jcenter, and is not currently available from maven.
Expand All @@ -64,7 +64,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.2.6'` to your gradle dependencies.
1. Add `compile 'com.qozix:tileview:2.2.7'` 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 23
versionCode 37
versionName "2.2.6"
versionCode 38
versionName "2.2.7"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class ZoomPanLayout extends ViewGroup implements
private int mOffsetY;

private float mEffectiveMinScale = 0;
private float mMinimumScaleX;
private float mMinimumScaleY;
private boolean mShouldLoopScale = true;

private boolean mIsFlinging;
Expand Down Expand Up @@ -538,9 +540,9 @@ public void scrollTo( int x, int y ) {
}

private void calculateMinimumScaleToFit() {
float minimumScaleX = getWidth() / (float) mBaseWidth;
float minimumScaleY = getHeight() / (float) mBaseHeight;
float recalculatedMinScale = calculatedMinScale(minimumScaleX, minimumScaleY);
mMinimumScaleX = getWidth() / (float) mBaseWidth;
mMinimumScaleY = getHeight() / (float) mBaseHeight;
float recalculatedMinScale = calculatedMinScale(mMinimumScaleX, mMinimumScaleY);
if( recalculatedMinScale != mEffectiveMinScale ) {
mEffectiveMinScale = recalculatedMinScale;
if( mScale < mEffectiveMinScale ){
Expand All @@ -566,11 +568,32 @@ protected int getHalfHeight() {
return FloatMathHelper.scale( getHeight(), 0.5f );
}

/**
* When the scale is less than {@code mMinimumScaleX}, either because we are using
* {@link MinimumScaleMode#FIT} or {@link MinimumScaleMode#NONE}, the scroll position takes a
* value between its starting value and 0. A linear interpolation between the
* {@code mMinimumScaleX} and the {@code mEffectiveMinScale} is used. <p>
* This strategy is used to avoid that a custom return value of {@link #getScrollMinX} (which
* default to 0) become the return value of this method which shifts the whole TileView.
*/
protected int getConstrainedScrollX( int x ) {
if ( mScale < mMinimumScaleX && mEffectiveMinScale != mMinimumScaleX ) {
float scaleFactor = mScale / ( mMinimumScaleX - mEffectiveMinScale ) +
mEffectiveMinScale / ( mEffectiveMinScale - mMinimumScaleX );
return (int) ( scaleFactor * getScrollX() );
}
return Math.max( getScrollMinX(), Math.min( x, getScrollLimitX() ) );
}

/**
* See {@link #getConstrainedScrollX(int)}
*/
protected int getConstrainedScrollY( int y ) {
if ( mScale < mMinimumScaleY && mEffectiveMinScale != mMinimumScaleY ) {
float scaleFactor = mScale / ( mMinimumScaleY - mEffectiveMinScale ) +
mEffectiveMinScale / ( mEffectiveMinScale - mMinimumScaleY );
return (int) ( scaleFactor * getScrollY() );
}
return Math.max( getScrollMinY(), Math.min( y, getScrollLimitY() ) );
}

Expand Down

0 comments on commit 0aaaeb5

Please sign in to comment.