当前位置: 首页>>代码示例>>Java>>正文


Java View.onTouchEvent方法代码示例

本文整理汇总了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();
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:27,代码来源:BasicFieldColorViewTest.java

示例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();
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:18,代码来源:ViewUtils.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:StickyRecyclerHeadersTouchListener.java

示例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;
}
 
开发者ID:sswukang,项目名称:RvAdapter,代码行数:14,代码来源:StickyRecyclerHeadersTouchListener.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:35,代码来源:LocationBarTablet.java

示例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);
}
 
开发者ID:ravi8x,项目名称:Barcode-Reader,代码行数:9,代码来源:BarcodeReader.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:ListPopupWindow.java


注:本文中的android.view.View.onTouchEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。