use of android.view.MotionEvent in project platform_frameworks_base by android.
the class TouchUtils method longClickView.
/**
* Simulate touching the center of a view, holding until it is a long press, and then releasing.
*
* @param test The test case that is being run
* @param v The view that should be clicked
*/
public static void longClickView(InstrumentationTestCase test, View v) {
int[] xy = new int[2];
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
final float x = xy[0] + (viewWidth / 2.0f);
float y = xy[1] + (viewHeight / 2.0f);
Instrumentation inst = test.getInstrumentation();
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
inst.sendPointerSync(event);
inst.waitForIdleSync();
eventTime = SystemClock.uptimeMillis();
final int touchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x + touchSlop / 2, y + touchSlop / 2, 0);
inst.sendPointerSync(event);
inst.waitForIdleSync();
try {
Thread.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f));
} catch (InterruptedException e) {
e.printStackTrace();
}
eventTime = SystemClock.uptimeMillis();
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
inst.sendPointerSync(event);
inst.waitForIdleSync();
}
use of android.view.MotionEvent in project platform_frameworks_base by android.
the class TaskTapPointerEventListener method doGestureDetection.
private void doGestureDetection(MotionEvent motionEvent) {
if (mGestureDetector == null || mNonResizeableRegion.isEmpty()) {
return;
}
final int action = motionEvent.getAction() & MotionEvent.ACTION_MASK;
final int x = (int) motionEvent.getX();
final int y = (int) motionEvent.getY();
final boolean isTouchInside = mNonResizeableRegion.contains(x, y);
if (mInGestureDetection || action == MotionEvent.ACTION_DOWN && isTouchInside) {
// If we receive the following actions, or the pointer goes out of the area
// we're interested in, stop detecting and cancel the current detection.
mInGestureDetection = isTouchInside && action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_POINTER_UP && action != MotionEvent.ACTION_CANCEL;
if (mInGestureDetection) {
mGestureDetector.onTouchEvent(motionEvent);
} else {
MotionEvent cancelEvent = motionEvent.copy();
cancelEvent.cancel();
mGestureDetector.onTouchEvent(cancelEvent);
stopTwoFingerScroll();
}
}
}
use of android.view.MotionEvent in project platform_frameworks_base by android.
the class PointerEventDispatcher method onInputEvent.
@Override
public void onInputEvent(InputEvent event) {
try {
if (event instanceof MotionEvent && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
final MotionEvent motionEvent = (MotionEvent) event;
PointerEventListener[] listeners;
synchronized (mListeners) {
if (mListenersArray == null) {
mListenersArray = new PointerEventListener[mListeners.size()];
mListeners.toArray(mListenersArray);
}
listeners = mListenersArray;
}
for (int i = 0; i < listeners.length; ++i) {
listeners[i].onPointerEvent(motionEvent);
}
}
} finally {
finishInputEvent(event, false);
}
}
use of android.view.MotionEvent in project iosched by google.
the class AppNavigationViewAsDrawerImpl method populateAccountList.
/**
* @param accounts The list of available accounts, the current one being at position 0.
*/
private void populateAccountList(final List<Account> accounts) {
mAccountSpinner = (Spinner) mActivity.findViewById(R.id.account_spinner);
mAccountSpinner.getBackground().setColorFilter(mActivity.getResources().getColor(R.color.body_text_1_inverse), PorterDuff.Mode.SRC_ATOP);
mAccountSpinnerAdapter = new AccountSpinnerAdapter(mActivity, R.id.profile_name_text, accounts.toArray(new Account[accounts.size()]), mImageLoader);
mAccountSpinner.setAdapter(mAccountSpinnerAdapter);
mAccountSpinner.setSelection(0);
mAccountSpinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Intent switchUser = new Intent(getContext(), SwitchUserActivity.class);
mActivity.startActivityForResult(switchUser, BaseActivity.SWITCH_USER_RESULT);
return true;
}
return false;
}
});
mAccountSpinner.setEnabled(true);
}
use of android.view.MotionEvent in project material-components-android by material-components.
the class BottomSheetDialog method wrapInBottomSheet.
private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) {
final CoordinatorLayout coordinator = (CoordinatorLayout) View.inflate(getContext(), R.layout.design_bottom_sheet_dialog, null);
if (layoutResId != 0 && view == null) {
view = getLayoutInflater().inflate(layoutResId, coordinator, false);
}
FrameLayout bottomSheet = (FrameLayout) coordinator.findViewById(R.id.design_bottom_sheet);
mBehavior = BottomSheetBehavior.from(bottomSheet);
mBehavior.setBottomSheetCallback(mBottomSheetCallback);
mBehavior.setHideable(mCancelable);
if (params == null) {
bottomSheet.addView(view);
} else {
bottomSheet.addView(view, params);
}
// We treat the CoordinatorLayout as outside the dialog though it is technically inside
coordinator.findViewById(R.id.touch_outside).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mCancelable && isShowing() && shouldWindowCloseOnTouchOutside()) {
cancel();
}
}
});
// Handle accessibility events
ViewCompat.setAccessibilityDelegate(bottomSheet, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
if (mCancelable) {
info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS);
info.setDismissable(true);
} else {
info.setDismissable(false);
}
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS && mCancelable) {
cancel();
return true;
}
return super.performAccessibilityAction(host, action, args);
}
});
bottomSheet.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
// Consume the event and prevent it from falling through
return true;
}
});
return coordinator;
}
Aggregations