Skip to content

Commit dc9c882

Browse files
committed
fling in mouse tracking mode
1 parent 2e8a672 commit dc9c882

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ public void run() {
204204
if (mScroller.isFinished()) {
205205
return;
206206
}
207+
// Check whether mouse tracking was turned on during fling.
208+
if (mouseTrackingActive()) {
209+
return;
210+
}
207211

208212
boolean more = mScroller.computeScrollOffset();
209213
int newTopRow = mScroller.getCurrY();
@@ -218,6 +222,47 @@ public void run() {
218222

219223
}
220224
};
225+
226+
private class MouseTrackerFlingRunner implements Runnable {
227+
private Scroller mScroller;
228+
private int mLastY;
229+
private MotionEvent mMotionEvent;
230+
231+
public void fling(MotionEvent e, float velocityX, float velocityY) {
232+
float SCALE = 0.15f;
233+
mScroller.fling(0, 0,
234+
-(int) (velocityX * SCALE), -(int) (velocityY * SCALE),
235+
0, 0, -100, 100);
236+
mLastY = 0;
237+
mMotionEvent = e;
238+
post(this);
239+
}
240+
241+
public void run() {
242+
if (mScroller.isFinished()) {
243+
return;
244+
}
245+
// Check whether mouse tracking was turned off during fling.
246+
if (!mouseTrackingActive()) {
247+
return;
248+
}
249+
250+
boolean more = mScroller.computeScrollOffset();
251+
int newY = mScroller.getCurrY();
252+
for(; mLastY < newY; mLastY++) {
253+
sendMouseEventCode(mMotionEvent, 65);
254+
}
255+
for(; mLastY > newY; mLastY--) {
256+
sendMouseEventCode(mMotionEvent, 64);
257+
}
258+
259+
if (more) {
260+
post(this);
261+
}
262+
}
263+
};
264+
private MouseTrackerFlingRunner mMouseTrackerFlingRunner = new MouseTrackerFlingRunner();
265+
221266
private float mScrollRemainder;
222267
private TermKeyListener mKeyListener;
223268

@@ -288,6 +333,7 @@ public EmulatorView(Context context, AttributeSet attrs, int defStyle) {
288333
private void commonConstructor(Context context) {
289334
// TODO: See if we want to use the API level 11 constructor to get new flywheel feature.
290335
mScroller = new Scroller(context);
336+
mMouseTrackerFlingRunner.mScroller = new Scroller(context);
291337
}
292338

293339
/**
@@ -917,16 +963,18 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
917963
return true;
918964
}
919965

920-
// XXX - handle mouse tracking
921-
922-
float SCALE = 0.25f;
923-
mScroller.fling(0, mTopRow,
924-
-(int) (velocityX * SCALE), -(int) (velocityY * SCALE),
925-
0, 0,
926-
-mTranscriptScreen.getActiveTranscriptRows(), 0);
927966
mScrollRemainder = 0.0f;
928-
// onScroll(e1, e2, 0.1f * velocityX, -0.1f * velocityY);
929-
post(mFlingRunner);
967+
if (mouseTrackingActive()) {
968+
mMouseTrackerFlingRunner.fling(e1, velocityX, velocityY);
969+
} else {
970+
float SCALE = 0.25f;
971+
mScroller.fling(0, mTopRow,
972+
-(int) (velocityX * SCALE), -(int) (velocityY * SCALE),
973+
0, 0,
974+
-mTranscriptScreen.getActiveTranscriptRows(), 0);
975+
// onScroll(e1, e2, 0.1f * velocityX, -0.1f * velocityY);
976+
post(mFlingRunner);
977+
}
930978
return true;
931979
}
932980

0 commit comments

Comments
 (0)