Permalink
Browse files

Remaining fling code

  • Loading branch information...
1 parent 3c7189d commit 7bb26f9c4931869138a1c626a571bfadb5cd4e7f @rscottm rscottm committed Nov 11, 2012
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/org/ruboto/irb/IRB.java
@@ -1098,4 +1098,44 @@ public void onClick(DialogInterface dialog, int id) {
}
});
}
+
+ /*********************************************************************************************
+ *
+ * Fling Listener
+ */
+
+ class FlingGestureListener extends android.view.GestureDetector.SimpleOnGestureListener {
+ private android.widget.Scroller scroller = null; //@scroller = android.widget.Scroller.new(@activity)
+ private int x = 0; //@x = 0
+
+ FlingGestureListener() {
+ super();
+ scroller = new android.widget.Scroller(IRB.this);
+ }
+
+ public boolean onDown(android.view.MotionEvent e) {
+ if (scroller.isFinished()) return false;
+ scroller.forceFinished(true);
+ return true;
+ }
+
+ public boolean onFling(android.view.MotionEvent e1, android.view.MotionEvent e2, float velocityX, float velocityY) {
+ if (Math.abs(velocityY) < android.view.ViewConfiguration.get(IRB.this).getScaledMinimumFlingVelocity()) return false;
+
+ x = IRB.this.sourceEditor.getScrollX();
+ int max = IRB.this.sourceEditor.getLayout().getHeight() - IRB.this.sourceEditor.getHeight() + IRB.this.sourceEditor.getLineHeight();
+ scroller.fling(0, IRB.this.sourceEditor.getScrollY(), 0, 0 - (int)velocityY, x, x, 0, max);
+
+ final Runnable run = new Runnable() {
+ public void run() {
+ if (scroller.isFinished() || !scroller.computeScrollOffset()) return;
+ IRB.this.sourceEditor.scrollTo(x, scroller.getCurrY());
+ IRB.this.sourceEditor.post(this);
+ }
+ };
+
+ IRB.this.sourceEditor.post(run);
+ return true;
+ }
+ }
}

0 comments on commit 7bb26f9

Please sign in to comment.