use of android.view.MotionEvent in project robolectric by robolectric.
the class VelocityTrackerTest method doMotion.
/**
* Construct a new MotionEvent involving two pointers at {@code time}. Pointer 2 will be
* considered active.
*/
private static MotionEvent doMotion(long time, float pointer1X, float pointer1Y, float pointer2X, float pointer2Y) {
MotionEvent event = MotionEvent.obtain(0, time, MotionEvent.ACTION_MOVE, pointer2X, pointer2Y, 0);
ShadowMotionEvent shadowEvent = Shadows.shadowOf(event);
shadowEvent.setPointer2(pointer1X, pointer1Y);
shadowEvent.setPointerIndex(0);
// we put our active pointer (the second one down) first, so flip the IDs so that they match up
// properly
shadowEvent.setPointerIds(1, 0);
return event;
}
use of android.view.MotionEvent in project robolectric by robolectric.
the class ShadowViewGroupTest method shouldKnowWhenOnInterceptTouchEventWasCalled.
@Test
public void shouldKnowWhenOnInterceptTouchEventWasCalled() throws Exception {
ViewGroup viewGroup = new FrameLayout(context);
MotionEvent touchEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);
viewGroup.onInterceptTouchEvent(touchEvent);
assertThat(shadowOf(viewGroup).getInterceptedTouchEvent()).isEqualTo(touchEvent);
}
use of android.view.MotionEvent in project xabber-android by redsolution.
the class ContactListFragment method stopMovement.
/**
* Stop fling scrolling.
*/
private void stopMovement() {
MotionEvent event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0);
listView.onTouchEvent(event);
event.recycle();
}
use of android.view.MotionEvent in project FileDownloader by lingochamp.
the class HybridTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hybrid_test);
uiHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == WHAT_NEED_AUTO_2_BOTTOM) {
needAuto2Bottom = true;
}
return false;
}
});
assignViews();
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
uiHandler.removeMessages(WHAT_NEED_AUTO_2_BOTTOM);
needAuto2Bottom = false;
}
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
uiHandler.removeMessages(WHAT_NEED_AUTO_2_BOTTOM);
uiHandler.sendEmptyMessageDelayed(WHAT_NEED_AUTO_2_BOTTOM, 1000);
}
return false;
}
});
}
use of android.view.MotionEvent in project cardslib by gabrielemariotti.
the class BaseDismissAnimation method invokeCallbak.
protected void invokeCallbak(final View dismissView) {
// Animate the dismissed list item to zero-height and fire the dismiss callback when
// all dismissed list item animations have completed. This triggers layout on each animation
// frame; in the future we may want to do something smarter and more performant.
final int dismissPosition = mBaseAdapter.getPosition(((CardViewWrapper) dismissView).getCard());
final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
final int originalHeight = dismissView.getHeight();
ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
--mDismissAnimationRefCount;
if (mDismissAnimationRefCount == 0) {
// No active animations, process all pending dismisses.
// Sort by descending position
Collections.sort(mPendingDismisses);
int[] dismissPositions = new int[mPendingDismisses.size()];
for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
dismissPositions[i] = mPendingDismisses.get(i).position;
}
mCallbacks.onDismiss(mCardListView, dismissPositions);
// Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
// animation with a stale position
mDownPosition = ListView.INVALID_POSITION;
ViewGroup.LayoutParams lp;
for (PendingDismissData pendingDismiss : mPendingDismisses) {
// Reset view presentation
pendingDismiss.view.setAlpha(1f);
pendingDismiss.view.setTranslationX(0);
lp = pendingDismiss.view.getLayoutParams();
lp.height = 0;
pendingDismiss.view.setLayoutParams(lp);
}
// Send a cancel event
long time = SystemClock.uptimeMillis();
MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
mCardListView.dispatchTouchEvent(cancelEvent);
mPendingDismisses.clear();
}
}
});
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
lp.height = (Integer) valueAnimator.getAnimatedValue();
dismissView.setLayoutParams(lp);
}
});
mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
animator.start();
}
Aggregations