Skip to content

Commit 0aaaeb5

Browse files
authored
Merge pull request #417 from peterLaurence/fix#415
Fix#415
2 parents 2cbf51b + 5348072 commit 0aaaeb5

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Javadocs are [here](http://moagrius.github.io/TileView/index.html?com/qozix/tile
4444
### Installation
4545
Gradle:
4646
```
47-
compile 'com.qozix:tileview:'2.2.6'
47+
compile 'com.qozix:tileview:'2.2.7'
4848
```
4949

5050
The library is hosted on jcenter, and is not currently available from maven.
@@ -64,7 +64,7 @@ A demo application, built in Android Studio, is available in the `demo` folder o
6464
at the 2nd column from left and 3rd row from top.
6565
1. Create a new application with a single activity ('Main').
6666
1. Save the image tiles to your `assets` directory.
67-
1. Add `compile 'com.qozix:tileview:2.2.6'` to your gradle dependencies.
67+
1. Add `compile 'com.qozix:tileview:2.2.7'` to your gradle dependencies.
6868
1. In the Main Activity, use this for `onCreate`:
6969
```
7070
@Override

tileview/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
defaultConfig {
77
minSdkVersion 11
88
targetSdkVersion 23
9-
versionCode 37
10-
versionName "2.2.6"
9+
versionCode 38
10+
versionName "2.2.7"
1111
}
1212
buildTypes {
1313
release {

tileview/src/main/java/com/qozix/tileview/widgets/ZoomPanLayout.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class ZoomPanLayout extends ViewGroup implements
4949
private int mOffsetY;
5050

5151
private float mEffectiveMinScale = 0;
52+
private float mMinimumScaleX;
53+
private float mMinimumScaleY;
5254
private boolean mShouldLoopScale = true;
5355

5456
private boolean mIsFlinging;
@@ -538,9 +540,9 @@ public void scrollTo( int x, int y ) {
538540
}
539541

540542
private void calculateMinimumScaleToFit() {
541-
float minimumScaleX = getWidth() / (float) mBaseWidth;
542-
float minimumScaleY = getHeight() / (float) mBaseHeight;
543-
float recalculatedMinScale = calculatedMinScale(minimumScaleX, minimumScaleY);
543+
mMinimumScaleX = getWidth() / (float) mBaseWidth;
544+
mMinimumScaleY = getHeight() / (float) mBaseHeight;
545+
float recalculatedMinScale = calculatedMinScale(mMinimumScaleX, mMinimumScaleY);
544546
if( recalculatedMinScale != mEffectiveMinScale ) {
545547
mEffectiveMinScale = recalculatedMinScale;
546548
if( mScale < mEffectiveMinScale ){
@@ -566,11 +568,32 @@ protected int getHalfHeight() {
566568
return FloatMathHelper.scale( getHeight(), 0.5f );
567569
}
568570

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

588+
/**
589+
* See {@link #getConstrainedScrollX(int)}
590+
*/
573591
protected int getConstrainedScrollY( int y ) {
592+
if ( mScale < mMinimumScaleY && mEffectiveMinScale != mMinimumScaleY ) {
593+
float scaleFactor = mScale / ( mMinimumScaleY - mEffectiveMinScale ) +
594+
mEffectiveMinScale / ( mEffectiveMinScale - mMinimumScaleY );
595+
return (int) ( scaleFactor * getScrollY() );
596+
}
574597
return Math.max( getScrollMinY(), Math.min( y, getScrollLimitY() ) );
575598
}
576599

0 commit comments

Comments
 (0)