Skip to content

Commit

Permalink
fixed positioning and scaling issues
Browse files Browse the repository at this point in the history
positioning methods need explicit scaling;
runtime scaling (not due to gestures) could cause View to scroll beyond
visible limits - added constraint in layout pass to prevent this
  • Loading branch information
moagrius committed Aug 31, 2013
1 parent 3891885 commit 3c9345d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/com/qozix/layouts/ZoomPanLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.ScrollerCompat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
Expand All @@ -18,6 +17,7 @@
import com.qozix.animation.Tween;
import com.qozix.animation.TweenListener;
import com.qozix.animation.easing.Strong;
import com.qozix.widgets.Scroller;

/**
* ZoomPanLayout extends ViewGroup to provide support for scrolling and zooming. Fling, drag, pinch and
Expand Down Expand Up @@ -85,7 +85,7 @@ public class ZoomPanLayout extends ViewGroup {

private ScrollActionHandler scrollActionHandler;

private ScrollerCompat scroller;
private Scroller scroller;
private VelocityTracker velocity;

private HashSet<GestureListener> gestureListeners = new HashSet<GestureListener>();
Expand Down Expand Up @@ -138,8 +138,8 @@ public ZoomPanLayout( Context context ) {

scrollActionHandler = new ScrollActionHandler( this );

scroller = ScrollerCompat.create( context );
//scroller.setFriction( FRICTION );
scroller = new Scroller( context );
scroller.setFriction( FRICTION );

clip = new StaticLayout( context );
super.addView( clip, -1, new LayoutParams(-1, -1) );
Expand Down Expand Up @@ -447,6 +447,7 @@ protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) {
@Override
protected void onLayout( boolean changed, int l, int t, int r, int b ) {
clip.layout( 0, 0, clip.getMeasuredWidth(), clip.getMeasuredHeight() );
constrainScroll();
if ( changed ) {
calculateMinimumScaleToFit();
}
Expand Down Expand Up @@ -533,7 +534,7 @@ private void constrainScroll() { // TODO:
Point limitScroll = new Point( currentScroll );
constrainPoint( limitScroll );
if ( !currentScroll.equals( limitScroll ) ) {
scrollToPoint( currentScroll );
scrollToPoint( limitScroll );
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/com/qozix/tileview/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ public double unscale( double value ) {
*/
public void moveTo( double x, double y ) {
Point point = positionManager.translate( x, y );
point.x *= getScale();
point.y *= getScale();
scrollToPoint( point );
}

Expand All @@ -392,6 +394,8 @@ public void moveTo( double x, double y ) {
*/
public void moveToAndCenter( double x, double y ) {
Point point = positionManager.translate( x, y );
point.x *= getScale();
point.y *= getScale();
scrollToAndCenter( point );
}

Expand All @@ -402,6 +406,8 @@ public void moveToAndCenter( double x, double y ) {
*/
public void slideTo( double x, double y ) {
Point point = positionManager.translate( x, y );
point.x *= getScale();
point.y *= getScale();
slideToPoint( point );
}

Expand All @@ -412,6 +418,8 @@ public void slideTo( double x, double y ) {
*/
public void slideToAndCenter( double x, double y ) {
Point point = positionManager.translate( x, y );
point.x *= getScale();
point.y *= getScale();
slideToAndCenter( point );
}

Expand Down

0 comments on commit 3c9345d

Please sign in to comment.