android.view.MotionEvent#ACTION_OUTSIDE源码实例Demo

下面列出了android.view.MotionEvent#ACTION_OUTSIDE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: meiShi   文件: ShadowImageView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            setColorFilter(Color.parseColor("#77000000"));
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_OUTSIDE:
            setColorFilter(null);
            break;
    }


    return super.onTouchEvent(event);
}
 
源代码2 项目: Cornowser   文件: PressHoverTouchListener.java
@Override
public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction()) {
        case MotionEvent.ACTION_HOVER_ENTER:
        case MotionEvent.ACTION_DOWN:
            v.setBackgroundColor(downColor);
            break;
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_HOVER_EXIT:
        case MotionEvent.ACTION_UP:
            v.setBackgroundColor(upColor);
            break;
        default: break;
    }
    return false;
}
 
源代码3 项目: MusicBobber   文件: TouchManager.java
@Override
public boolean onTouch(@NonNull View v, @NonNull MotionEvent event) {
    boolean res = (!touchCanceled || event.getAction() == MotionEvent.ACTION_UP) && gestureDetector.onTouchEvent(event);
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        touchCanceled = false;
        gestureListener.onDown(event);
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        if (!touchCanceled) {
            gestureListener.onUpEvent(event);
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        if (!touchCanceled) {
            gestureListener.onMove(event);
        }
    } else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        gestureListener.onTouchOutsideEvent(event);
        touchCanceled = false;
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        touchCanceled = true;
    }
    return res;
}
 
源代码4 项目: Android-Music-Player   文件: libraryHome.java
public boolean dispatchTouchEvent(MotionEvent event) {

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                ONDown(event);
                break;
            case MotionEvent.ACTION_MOVE:
                 ONMove(event);
                break;
            case MotionEvent.ACTION_OUTSIDE:
                //onOut(event);
                break;
            case MotionEvent.ACTION_UP:
                ONUp(event);
                break;
            default:
                //onleave(event);
        }
        if(moved){
            return  false;
        }
        return super.dispatchTouchEvent(event);
    }
 
源代码5 项目: BannerPager   文件: BannerPager.java
private void handleEvent(MotionEvent ev) {
    //没有使能loop 或者 没有调用start
    if (!mPagerOptions.mLoopEnable || !isStartLoop) {
        return;
    }
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_OUTSIDE:
            trace("dispatchTouchEvent: " + ev.getX());
            removeHandlerMessages();
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            trace("dispatchTouchEvent: " + ev.getX());
            removeHandlerMessages();
            sendHandlerEmptyMessage();
            break;
        default:
            trace("未知事件: " + ev.getAction());
            break;
    }
}
 
源代码6 项目: Android-Music-Player   文件: abLyt.java
@Override
public boolean onTouchEvent(MotionEvent event) {
	switch (event.getAction()) {
	case MotionEvent.ACTION_DOWN:
		onDown(event);
	case MotionEvent.ACTION_MOVE:
		onMove(event);
		break;
	case MotionEvent.ACTION_OUTSIDE:
		onOut(event);
	case MotionEvent.ACTION_UP:
		onUp(event);
		break;
	default:
		onleave(event);
	}
	invalidate();
	super.onTouchEvent(event);
	return true;
}
 
源代码7 项目: Conquer   文件: CircularImageView.java
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
	// Check for clickable state and do nothing if disabled
	if (!this.isClickable()) {
		this.isSelected = false;
		return super.onTouchEvent(event);
	}

	// Set selected state based on Motion Event
	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.isSelected = true;
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_SCROLL:
		case MotionEvent.ACTION_OUTSIDE:
		case MotionEvent.ACTION_CANCEL:
			this.isSelected = false;
			break;
	}

	// Redraw image and return super type
	this.invalidate();
	return super.dispatchTouchEvent(event);
}
 
源代码8 项目: android-flat-button   文件: FButton.java
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            updateBackground(pressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
            break;
        case MotionEvent.ACTION_MOVE:
            Rect r = new Rect();
            view.getLocalVisibleRect(r);
            if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() + 3 * mShadowHeight) &&
                    !r.contains((int) motionEvent.getX(), (int) motionEvent.getY() - 3 * mShadowHeight)) {
                updateBackground(unpressedDrawable);
                this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            }
            break;
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            updateBackground(unpressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            break;
    }
    return false;
}
 
源代码9 项目: NavigationTabStrip   文件: NavigationTabStrip.java
@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning()) return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true;

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            // Action down touch
            mIsActionDown = true;
            if (!mIsViewPagerMode) break;
            // Detect if we touch down on tab, later to move
            mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex;
            break;
        case MotionEvent.ACTION_MOVE:
            // If tab touched, so move
            if (mIsTabActionDown) {
                mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true);
                break;
            }
            if (mIsActionDown) break;
        case MotionEvent.ACTION_UP:
            // Press up and set tab index relative to current coordinate
            if (mIsActionDown) setTabIndex((int) (event.getX() / mTabSize));
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_OUTSIDE:
        default:
            // Reset action touch variables
            mIsTabActionDown = false;
            mIsActionDown = false;
            break;
    }

    return true;
}
 
源代码10 项目: Banner   文件: Banner.java
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_OUTSIDE:
            startAutoPlay();
            break;
        case MotionEvent.ACTION_DOWN:
            stopAutoPlay();
            break;
    }
    return super.dispatchTouchEvent(ev);
}
 
源代码11 项目: Noyze   文件: PopupWindow.java
/** @hide */
public boolean shouldCloseOnTouch(MotionEvent event) {
    if (mCloseOnTouchOutside && (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE || isOutOfBounds(event)) && mDecor != null) {
        return true;
    }
    
    return false;
}
 
源代码12 项目: Netease   文件: MyRecyclerView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.d("HorizontalImage", "parent onTouchEvent" + event.getAction());
    switch (event.getAction()) {
       /* 这段代码理论是不要的,因为onInterceptTouchEvent已经处理了所有情况,这里有少数情况会触发。
        case MotionEvent.ACTION_DOWN:
            getParent().requestDisallowInterceptTouchEvent(true);
            firstTime = true;
            x = event.getX();
            y = event.getY();
            break;*/
        case MotionEvent.ACTION_MOVE:
            if (firstTime) {
                float deltaX = Math.abs(x - event.getX());
                float deltaY = Math.abs(y - event.getY());

                if (deltaX > 1 || deltaY > 1) {
                    // 水平滑动距离大于两倍的垂直距离才判断为水平
                    if (deltaX > deltaY * 2) {
                        getParent().requestDisallowInterceptTouchEvent(true);
                    } else {
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }
                    firstTime = false;
                }
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_OUTSIDE:
            getParent().requestDisallowInterceptTouchEvent(false);
            ((HorizontalImageRecyclerViewAdapter)getAdapter()).isIntercept = false;
            break;
    }
    return super.onTouchEvent(event);

}
 
源代码13 项目: NewFastFrame   文件: BannerViewPager.java
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        startAutoPlay();
    } else if (action == MotionEvent.ACTION_DOWN) {
        stopAutoPlay();
    }
    return super.dispatchTouchEvent(ev);
}
 
源代码14 项目: PowerMenu   文件: AbstractPowerMenu.java
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_OUTSIDE && !showBackground) {
    dismiss();
    return true;
  }
  return false;
}
 
源代码15 项目: FireFiles   文件: LineColorPicker.java
@Override
public boolean onTouchEvent(MotionEvent event) {

	int actionId = event.getAction();

	int newColor;

	switch (actionId) {
	case MotionEvent.ACTION_DOWN:
		isClick = true;
		break;
	case MotionEvent.ACTION_UP:
		newColor = getColorAtXY(event.getX(), event.getY());

		setSelectedColor(newColor);

		if (isClick) {
			performClick();
		}

		break;

	case MotionEvent.ACTION_MOVE:
		newColor = getColorAtXY(event.getX(), event.getY());

		setSelectedColor(newColor);

		break;
	case MotionEvent.ACTION_CANCEL:
		isClick = false;
		break;

	case MotionEvent.ACTION_OUTSIDE:
		isClick = false;
		break;

	default:
		break;
	}

	return true;
}
 
源代码16 项目: FireFiles   文件: LineColorPicker.java
@Override
public boolean onTouchEvent(MotionEvent event) {

	int actionId = event.getAction();

	int newColor;

	switch (actionId) {
	case MotionEvent.ACTION_DOWN:
		isClick = true;
		break;
	case MotionEvent.ACTION_UP:
		newColor = getColorAtXY(event.getX(), event.getY());

		setSelectedColor(newColor);

		if (isClick) {
			performClick();
		}

		break;

	case MotionEvent.ACTION_MOVE:
		newColor = getColorAtXY(event.getX(), event.getY());

		setSelectedColor(newColor);

		break;
	case MotionEvent.ACTION_CANCEL:
		isClick = false;
		break;

	case MotionEvent.ACTION_OUTSIDE:
		isClick = false;
		break;

	default:
		break;
	}

	return true;
}
 
源代码17 项目: UltimateAndroid   文件: PullToZoomListView.java
public boolean onTouchEvent(MotionEvent paramMotionEvent) {
    Log.d(TAG, "action = " + (0xFF & paramMotionEvent.getAction()));
    if (mHeaderView != null && !isHideHeader && isEnableZoom) {
        switch (0xFF & paramMotionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_OUTSIDE:
                if (!mScalingRunnable.isFinished()) {
                    mScalingRunnable.abortAnimation();
                }
                mLastMotionY = paramMotionEvent.getY();
                mActivePointerId = paramMotionEvent.getPointerId(0);
                mMaxScale = (mScreenHeight / mHeaderHeight);
                mLastScale = (mHeaderContainer.getBottom() / mHeaderHeight);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "mActivePointerId" + mActivePointerId);
                int j = paramMotionEvent.findPointerIndex(mActivePointerId);
                if (j == INVALID_VALUE) {
                    Log.e("PullToZoomListView", "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                } else {
                    if (mLastMotionY == -1.0F) {
                        mLastMotionY = paramMotionEvent.getY(j);
                    }
                    if (mHeaderContainer.getBottom() >= mHeaderHeight) {
                        ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams();
                        float f = ((paramMotionEvent.getY(j) - mLastMotionY + mHeaderContainer.getBottom()) / mHeaderHeight - mLastScale) / 2.0F + mLastScale;
                        if ((mLastScale <= 1.0D) && (f < mLastScale)) {
                            localLayoutParams.height = mHeaderHeight;
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                            return super.onTouchEvent(paramMotionEvent);
                        }
                        mLastScale = Math.min(Math.max(f, 1.0F), mMaxScale);
                        localLayoutParams.height = ((int) (mHeaderHeight * mLastScale));
                        if (localLayoutParams.height < mScreenHeight) {
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                        }
                        mLastMotionY = paramMotionEvent.getY(j);
                        return true;
                    }
                    mLastMotionY = paramMotionEvent.getY(j);
                }
                break;
            case MotionEvent.ACTION_UP:
                reset();
                endScaling();
                break;
            case MotionEvent.ACTION_CANCEL:
                int i = paramMotionEvent.getActionIndex();
                mLastMotionY = paramMotionEvent.getY(i);
                mActivePointerId = paramMotionEvent.getPointerId(i);
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                onSecondaryPointerUp(paramMotionEvent);
                mLastMotionY = paramMotionEvent.getY(paramMotionEvent.findPointerIndex(mActivePointerId));
                break;
        }
    }
    return super.onTouchEvent(paramMotionEvent);
}
 
源代码18 项目: UltimateAndroid   文件: PullToZoomListView.java
public boolean onTouchEvent(MotionEvent paramMotionEvent) {
    Log.d(TAG, "action = " + (0xFF & paramMotionEvent.getAction()));
    if (mHeaderView != null && !isHideHeader && isEnableZoom) {
        switch (0xFF & paramMotionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_OUTSIDE:
                if (!mScalingRunnable.isFinished()) {
                    mScalingRunnable.abortAnimation();
                }
                mLastMotionY = paramMotionEvent.getY();
                mActivePointerId = paramMotionEvent.getPointerId(0);
                mMaxScale = (mScreenHeight / mHeaderHeight);
                mLastScale = (mHeaderContainer.getBottom() / mHeaderHeight);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "mActivePointerId" + mActivePointerId);
                int j = paramMotionEvent.findPointerIndex(mActivePointerId);
                if (j == INVALID_VALUE) {
                    Log.e("PullToZoomListView", "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                } else {
                    if (mLastMotionY == -1.0F) {
                        mLastMotionY = paramMotionEvent.getY(j);
                    }
                    if (mHeaderContainer.getBottom() >= mHeaderHeight) {
                        ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams();
                        float f = ((paramMotionEvent.getY(j) - mLastMotionY + mHeaderContainer.getBottom()) / mHeaderHeight - mLastScale) / 2.0F + mLastScale;
                        if ((mLastScale <= 1.0D) && (f < mLastScale)) {
                            localLayoutParams.height = mHeaderHeight;
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                            return super.onTouchEvent(paramMotionEvent);
                        }
                        mLastScale = Math.min(Math.max(f, 1.0F), mMaxScale);
                        localLayoutParams.height = ((int) (mHeaderHeight * mLastScale));
                        if (localLayoutParams.height < mScreenHeight) {
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                        }
                        mLastMotionY = paramMotionEvent.getY(j);
                        return true;
                    }
                    mLastMotionY = paramMotionEvent.getY(j);
                }
                break;
            case MotionEvent.ACTION_UP:
                reset();
                endScaling();
                break;
            case MotionEvent.ACTION_CANCEL:
                int i = paramMotionEvent.getActionIndex();
                mLastMotionY = paramMotionEvent.getY(i);
                mActivePointerId = paramMotionEvent.getPointerId(i);
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                onSecondaryPointerUp(paramMotionEvent);
                mLastMotionY = paramMotionEvent.getY(paramMotionEvent.findPointerIndex(mActivePointerId));
                break;
        }
    }
    return super.onTouchEvent(paramMotionEvent);
}
 
源代码19 项目: umeng_community_android   文件: SwitchButton.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN: {
            // 如果按钮当前可用并且按下位置正好在按钮之内
            if (isEnabled() && buttonRectF.contains(event.getX(), event.getY())) {
                touchMode = TOUCH_MODE_DOWN;
                tempTotalSlideDistance = 0; // 清空总滑动距离
                touchX = event.getX(); // 记录X轴坐标
                setClickable(false); // 当用户触摸在按钮位置的时候禁用点击效果,这样做的目的是为了不让背景有按下效果
            }
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            switch (touchMode) {
                case TOUCH_MODE_IDLE: {
                    break;
                }
                case TOUCH_MODE_DOWN: {
                    final float x = event.getX();
                    if (Math.abs(x - touchX) > touchSlop) {
                        touchMode = TOUCH_MODE_DRAGGING;
                        // 禁值父View拦截触摸事件
                        // 如果不加这段代码的话,当被ScrollView包括的时候,你会发现,当你在此按钮上按下,
                        // 紧接着滑动的时候ScrollView会跟着滑动,然后按钮的事件就丢失了,这会造成很难完成滑动操作
                        // 这样一来用户会抓狂的,加上这句话呢ScrollView就不会滚动了
                        if (getParent() != null) {
                            getParent().requestDisallowInterceptTouchEvent(true);
                        }
                        touchX = x;
                        return true;
                    }
                    break;
                }
                case TOUCH_MODE_DRAGGING: {
                    float newTouchX = event.getX();
                    tempTotalSlideDistance += setSlideX(tempSlideX
                            + ((int) (newTouchX - touchX))); // 更新X轴坐标并记录总滑动距离
                    touchX = newTouchX;
                    invalidate();
                    return true;
                }
            }
            break;
        }

        case MotionEvent.ACTION_UP: {
            setClickable(true);

            // 结尾滑动操作
            if (touchMode == TOUCH_MODE_DRAGGING) {// 这是滑动操作
                touchMode = TOUCH_MODE_IDLE;
                // 如果滑动距离大于等于最小切换距离就切换状态,否则回滚
                if (Math.abs(tempTotalSlideDistance) >= Math.abs(frameDrawable
                        .getIntrinsicWidth() * minChangeDistanceScale)) {
                    toggle(); // 切换状态
                } else {
                    switchScroller.startScroll(isChecked());
                }
            } else if (touchMode == TOUCH_MODE_DOWN) { // 这是按在按钮上的单击操作
                touchMode = TOUCH_MODE_IDLE;
                toggle();
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_OUTSIDE: {
            setClickable(true);
            if (touchMode == TOUCH_MODE_DRAGGING) {
                touchMode = TOUCH_MODE_IDLE;
                switchScroller.startScroll(isChecked()); // 回滚
            } else {
                touchMode = TOUCH_MODE_IDLE;
            }
            break;
        }
    }

    super.onTouchEvent(event);
    return isEnabled();
}
 
public boolean onTouchEvent(MotionEvent paramMotionEvent) {
    Log.d(TAG, "action = " + (0xFF & paramMotionEvent.getAction()));
    if (mHeaderView != null && !isHideHeader && isEnableZoom) {
        switch (0xFF & paramMotionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_OUTSIDE:
                if (!mScalingRunnable.isFinished()) {
                    mScalingRunnable.abortAnimation();
                }
                mLastMotionY = paramMotionEvent.getY();
                mActivePointerId = paramMotionEvent.getPointerId(0);
                mMaxScale = (mScreenHeight / mHeaderHeight);
                mLastScale = (mHeaderContainer.getBottom() / mHeaderHeight);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "mActivePointerId" + mActivePointerId);
                int j = paramMotionEvent.findPointerIndex(mActivePointerId);
                if (j == INVALID_VALUE) {
                    Log.e("PullToZoomListView", "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                } else {
                    if (mLastMotionY == -1.0F) {
                        mLastMotionY = paramMotionEvent.getY(j);
                    }
                    if (mHeaderContainer.getBottom() >= mHeaderHeight) {
                        ViewGroup.LayoutParams localLayoutParams = mHeaderContainer.getLayoutParams();
                        float f = ((paramMotionEvent.getY(j) - mLastMotionY + mHeaderContainer.getBottom()) / mHeaderHeight - mLastScale) / 2.0F + mLastScale;
                        if ((mLastScale <= 1.0D) && (f < mLastScale)) {
                            localLayoutParams.height = mHeaderHeight;
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                            return super.onTouchEvent(paramMotionEvent);
                        }
                        mLastScale = Math.min(Math.max(f, 1.0F), mMaxScale);
                        localLayoutParams.height = ((int) (mHeaderHeight * mLastScale));
                        if (localLayoutParams.height < mScreenHeight) {
                            mHeaderContainer.setLayoutParams(localLayoutParams);
                        }
                        mLastMotionY = paramMotionEvent.getY(j);
                        return true;
                    }
                    mLastMotionY = paramMotionEvent.getY(j);
                }
                break;
            case MotionEvent.ACTION_UP:
                reset();
                endScaling();
                break;
            case MotionEvent.ACTION_CANCEL:
                int i = paramMotionEvent.getActionIndex();
                mLastMotionY = paramMotionEvent.getY(i);
                mActivePointerId = paramMotionEvent.getPointerId(i);
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                onSecondaryPointerUp(paramMotionEvent);
                mLastMotionY = paramMotionEvent.getY(paramMotionEvent.findPointerIndex(mActivePointerId));
                break;
        }
    }
    return super.onTouchEvent(paramMotionEvent);
}