本文整理汇总了Java中android.view.View.onTouchEvent方法的典型用法代码示例。如果您正苦于以下问题:Java View.onTouchEvent方法的具体用法?Java View.onTouchEvent怎么用?Java View.onTouchEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.onTouchEvent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPopupWindowChangeColor
import android.view.View; //导入方法依赖的package包/类
@Test
public void testPopupWindowChangeColor() {
mFieldColorView.performClick();
final PopupWindow popupWindow = mFieldColorView.getColorPopupWindow();
final View popupWindowContentView = popupWindow.getContentView();
assertThat(popupWindowContentView).isNotNull();
// Reset color before test.
mFieldColor.setColor(0);
assertThat(mFieldColor.getColor()).isEqualTo(0);
// Simulate click on the color panel.
popupWindowContentView.onTouchEvent(
MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */, MotionEvent.ACTION_DOWN,
0f /* x */, 0f /* y */, 0 /* metaState */));
// Verify both field and field view background have been set to correct color.
final int expectedColour = 0xffffff;
assertThat(mFieldColor.getColor())
.isEqualTo(expectedColour); // setColour() masks out alpha.
assertThat(((ColorDrawable) mFieldColorView.getBackground()).getColor())
.isEqualTo(BasicFieldColorView.ALPHA_OPAQUE | expectedColour);
// Popup window should have disappeared.
assertThat(popupWindow.isShowing()).isFalse();
}
示例2: virtualClick
import android.view.View; //导入方法依赖的package包/类
public static void virtualClick(final View view, int pressTime){
long downTime = System.currentTimeMillis();
int width = view.getWidth();
int height = view.getHeight();
float x = view.getX() + width / 2;
float y = view.getY() + height / 2;
MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
long upTime = downTime + pressTime;
final MotionEvent upEvent = MotionEvent.obtain(upTime, upTime, MotionEvent.ACTION_UP, x, y, 0);
view.onTouchEvent(downEvent);
view.onTouchEvent(upEvent);
downEvent.recycle();
upEvent.recycle();
}
示例3: onSingleTapUp
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onSingleTapUp(MotionEvent e) {
int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY());
if (position != -1) {
View headerView = mDecor.getHeaderView(mRecyclerView, position);
long headerId = getAdapter().getHeaderId(position);
mOnHeaderClickListener.onHeaderClick(headerView, position, headerId);
mRecyclerView.playSoundEffect(SoundEffectConstants.CLICK);
headerView.onTouchEvent(e);
return true;
}
return false;
}
示例4: onSingleTapUp
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onSingleTapUp(MotionEvent e) {
int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY());
if (position != -1) {
View headerView = mDecor.getHeaderView(mRecyclerView, position);
long headerId = getAdapter().getHeaderId(position);
mOnHeaderClickListener.onHeaderClick(headerView, position, headerId);
mRecyclerView.playSoundEffect(SoundEffectConstants.CLICK);
headerView.onTouchEvent(e);
return true;
}
return false;
}
示例5: onTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mTargets == null) return true;
View selectedTarget = null;
float selectedDistance = 0;
// newX and newY are in the coordinates of the selectedTarget.
float newX = 0;
float newY = 0;
for (View target : mTargets) {
if (!target.isShown()) continue;
mCachedTargetBounds.set(0, 0, target.getWidth(), target.getHeight());
offsetDescendantRectToMyCoords(target, mCachedTargetBounds);
float x = event.getX();
float y = event.getY();
float dx = distanceToRange(
mCachedTargetBounds.left, mCachedTargetBounds.right, x);
float dy = distanceToRange(
mCachedTargetBounds.top, mCachedTargetBounds.bottom, y);
float distance = Math.abs(dx) + Math.abs(dy);
if (selectedTarget == null || distance < selectedDistance) {
selectedTarget = target;
selectedDistance = distance;
newX = x + dx;
newY = y + dy;
}
}
if (selectedTarget == null) return false;
event.setLocation(newX, newY);
return selectedTarget.onTouchEvent(event);
}
示例6: onTouch
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
boolean b = scaleGestureDetector.onTouchEvent(motionEvent);
boolean c = gestureDetector.onTouchEvent(motionEvent);
return b || c || view.onTouchEvent(motionEvent);
}
示例7: onLongPress
import android.view.View; //导入方法依赖的package包/类
private void onLongPress() {
clearCallbacks();
View src = this.mSrc;
if (src.isEnabled() && !src.isLongClickable() && onForwardingStarted()) {
src.getParent().requestDisallowInterceptTouchEvent(true);
long now = SystemClock.uptimeMillis();
MotionEvent e = MotionEvent.obtain(now, now, 3, 0.0f, 0.0f, 0);
src.onTouchEvent(e);
e.recycle();
this.mForwarding = true;
this.mWasLongPress = true;
}
}