當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.getAction方法代碼示例

本文整理匯總了Java中android.view.MotionEvent.getAction方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.getAction方法的具體用法?Java MotionEvent.getAction怎麽用?Java MotionEvent.getAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mAutoPlayAble && !mIsOneImg) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                stopAutoPlay();
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_OUTSIDE:
                startAutoPlay();
                break;
        }
    }
    return super.dispatchTouchEvent(ev);
}
 
開發者ID:Jay-Ping,項目名稱:newIPlay,代碼行數:17,代碼來源:FlyBanner1.java

示例2: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_UP && mDragging) {
        mDragging = false;
        mVelocityHelper.calculateVelocity(ev);
        getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
                .dispatchEvent(ScrollEvent.obtain(
                        getId(),
                        ScrollEventType.END_DRAG,
                        0, /* offsetX = 0, horizontal scrolling only */
                        computeVerticalScrollOffset(),
                        mVelocityHelper.getXVelocity(),
                        mVelocityHelper.getYVelocity(),
                        getWidth(),
                        computeVerticalScrollRange(),
                        getWidth(),
                        getHeight()));
    }
    return super.onTouchEvent(ev);
}
 
開發者ID:godness84,項目名稱:react-native-recyclerview-list,代碼行數:22,代碼來源:RecyclerViewBackedScrollView.java

示例3: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            xDistance = yDistance = 0f;
            xLast = ev.getX();
            yLast = ev.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            final float curX = ev.getX();
            final float curY = ev.getY();

            xDistance += Math.abs(curX - xLast);
            yDistance += Math.abs(curY - yLast);
            xLast = curX;
            yLast = curY;
            Log.e("SiberiaDante", "xDistance :" + xDistance + "---yDistance:" + yDistance);
            return !(xDistance > yDistance || yDistance < scaledTouchSlop) && isNeedScroll;

    }
    return super.onInterceptTouchEvent(ev);
}
 
開發者ID:SiberiaDante,項目名稱:MultiScrollDemo,代碼行數:23,代碼來源:JudgeNestedScrollView.java

示例4: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {

    if(event.getAction()== MotionEvent.ACTION_UP){
        //TODO 畫水波紋
        currentRadius = 0; //重置初始狀態
        centerX = event.getX();//event.getRawX代表相對於屏幕的原點X軸上的距離
        centerY = event.getY();
        invalidate();
        //TODO 縮放動畫
        startScaleAnimation();
        //TODO 上述完成後,觸發控件的點擊事件。
        postDelayed(new Runnable() {
            @Override
            public void run() {
                //因為ontouchevent返回true。所以,此控件不能觸發對應的點擊事件。 用performClick可觸發點擊事件。
                //點擊事件的底層,也是調用此方法來觸發點擊事件。l
             performClick();
            }
        },300);
    }

    return true;
}
 
開發者ID:RealMoMo,項目名稱:72GGames_Demo,代碼行數:25,代碼來源:HomeChannelView.java

示例5: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    mScaleDetector.onTouchEvent(event);

    if (!mScaleDetector.isInProgress()) {
        mGestureDetector.onTouchEvent(event);
    }

    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_UP:
            if (getScale() < getMinScale()) {
                zoomTo(getMinScale(), 500);
            }
            break;
    }
    return true;
}
 
開發者ID:viseator,項目名稱:MontageCam,代碼行數:19,代碼來源:ImageViewTouch.java

示例6: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    // Detect when the user lifts their finger off the screen after a touch
    if (event.getAction() == MotionEvent.ACTION_UP) {
        // If not flinging then we are idle now. The user just finished a finger scroll.
        if (mFlingTracker == null || mFlingTracker.isFinished()) {
            setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE);
        }

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);

        releaseEdgeGlow();
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        unpressTouchedChild();
        releaseEdgeGlow();

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);
    }

    return super.onTouchEvent(event);
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:24,代碼來源:HorizontalListView.java

示例7: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean intercepted = false;
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            intercepted = false;
            if (!mScroller.isFinished()) {
                mScroller.abortAnimation();     //優化滑動體驗
                intercepted = true;
            }
            break;
        case MotionEvent.ACTION_MOVE:
            int deltaX = x - mLastXIntercept;
            int deltaY = y - mLastYIntercept;
            if (Math.abs(deltaX) > Math.abs(deltaY)) {
                intercepted = true;
            } else {
                intercepted = false;
            }
            break;
        case MotionEvent.ACTION_UP:
            intercepted = false;
            break;
        default:
            break;
    }

    Log.d(TAG, "onInterceptTouchEvent: " + intercepted);
    mLastX = x;
    mLastY = y;
    mLastXIntercept = x;
    mLastYIntercept = y;

    return intercepted;
}
 
開發者ID:DysaniazzZ,項目名稱:ArtOfAndroid,代碼行數:39,代碼來源:HorizontalScrollViewEx1.java

示例8: onTouch

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
        public boolean onTouch(View v, MotionEvent event) {
            if(v instanceof Button ==false)
                return false;
            mRawX = event.getRawX();
            mRawY = event.getRawY()  ;
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // 以當前父視圖左上角為原點
                    Point p=new Point();
                    p.x = (int)(mRawX - map.get(v).x);
                    p.y = (int)(mRawY - map.get(v).y);
                    mapPoint.put(v,p);
                    break;
                case MotionEvent.ACTION_MOVE:
                    // 獲取相對屏幕的坐標,以屏幕左上角為原點
//                    x = event.getRawX();
//                    y = event.getRawY();
                    map.get(v).x = (int)(mRawX - mapPoint.get(v).x);
                    map.get(v).y = (int)(mRawY - mapPoint.get(v).y);

                    windowManager.updateViewLayout(v,map.get(v)  );
                    break;

                case MotionEvent.ACTION_UP:
//                    map.get(v).x = (int)(mRawX - mapPoint.get(v).x);
//                    map.get(v).y = (int)(mRawY - mapPoint.get(v).y);
//
//                    windowManager.updateViewLayout(v,map.get(v)  );
                    break;
            }
            return false;
        }
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:34,代碼來源:FloatView.java

示例9: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if (isShouldHideKeyboard(v, ev)) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    return super.dispatchTouchEvent(ev);
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:12,代碼來源:KeyboardActivity.java

示例10: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * 因為我們不能直接給EditText設置點擊事件,所以我們用記住我們按下的位置來模擬點擊事件
 * 當我們按下的位置在 EditText的寬度 - 圖標到控件右側的間距 - 圖標的寬度 和
 * EditText的寬度 - 圖標到控件右側的間距 之間我們就算點擊了圖標,豎直方向沒有考慮
 * @param event
 * @return
 */
@Override
public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_UP){
        if(getCompoundDrawables()[2] != null){
            boolean isTouched = event.getX() > (getWidth() - getTotalPaddingRight())
                    && (event.getX() < (getWidth() - getPaddingLeft()));
            if(isTouched){
                if(mRightClickListener == null){
                    if(funcType == TYPE_CAN_CLEAR){
                        this.setText("");
                    }else if(funcType == TYPE_CAN_WATCH_PWD){
                        if(eyeOpen){
                            //變為密文,TYPE_CLASS_TEXT 和 TYPE_TEXT_VARIATION_PASSWORD 必須一起使用
                            this.setTransformationMethod(PasswordTransformationMethod.getInstance());
                            eyeOpen = false;
                        }else{
                            //變為明文
                            this.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                            eyeOpen = true;
                        }
                        switchWatchPwdIcon();
                    }
                }else {
                    //如果沒有則回調
                    mRightClickListener.onClick(this);
                }
            }
        }
    }
    return super.onTouchEvent(event);
}
 
開發者ID:jianjun0425,項目名稱:MultiFuncViewLibrary,代碼行數:39,代碼來源:MultiFuncEditText.java

示例11: onTouch

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouch(View v, MotionEvent event) {
    gestureDetector.onTouchEvent(event);
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        cancelFling();
        return true;
    }
    return false;
}
 
開發者ID:Assassinss,項目名稱:Moment,代碼行數:10,代碼來源:FullImageView.java

示例12: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		int x = (int) ev.getX();
		int y = (int) ev.getY();
		if(mStatus==Status.Open && viewDragHelper.isViewUnder(mainView, x, y)){
			return true;
		}
//		Log.e(TAG, "onInterceptTouchEvent : "+);
		if(viewDragHelper.isViewUnder(mainView, x, y)){
			switch (ev.getAction()) {
			case MotionEvent.ACTION_MOVE:
				int deltaX = x - lastX;
				int deltaY = y - lastY;
				if(Math.abs(deltaX)>Math.abs(deltaY)*2) {
//					Log.e(TAG, "移動斜角太大,攔截事件");
					viewDragHelper.cancel();
					return true;
				}
				break;
			case MotionEvent.ACTION_UP:
				lastX = 0;
				lastY = 0;
				break;
			}
			lastX = x;
			lastY = y;
		}
		return viewDragHelper.shouldInterceptTouchEvent(ev);
	}
 
開發者ID:JackChan1999,項目名稱:SlidingMenu,代碼行數:30,代碼來源:SlideMenu2.java

示例13: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * This is detect when mButtonRegion is clicked. Which means
 * play/pause action happened.
 *
 * @param event
 * @return
 */
@Override
public boolean onTouchEvent(MotionEvent event) {

    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            isDragging = isInDiscArea(x, y);
            startAngle = touchAngle(x, y);
            getParent().requestDisallowInterceptTouchEvent(true);
            return true;
        case MotionEvent.ACTION_MOVE:
            if (isDragging) {
                touchAngle = touchAngle(x, y);
                return true;
            }
            break;
        case MotionEvent.ACTION_UP:
            isDragging = false;

            if (onInteractionListener != null)
                onInteractionListener.onSeek(secondsFromDegree(calculatePastProgressDegree() + touchAngle - startAngle));

            startAngle = touchAngle = -1;

            getParent().requestDisallowInterceptTouchEvent(false);

            break;
    }

    return super.onTouchEvent(event);
}
 
開發者ID:dmllr,項目名稱:IdealMedia,代碼行數:41,代碼來源:MusicPlayerView.java

示例14: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
        if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
            getBackground().setHotspot(event.getX(), event.getY());
        }
    }
    return super.onTouchEvent(event);
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:10,代碼來源:MentionCell.java

示例15: onTouch

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // Remember where the user clicked
        mTouchX = (int)event.getX();
        mTouchY = (int)event.getY();
    }
    return false;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:9,代碼來源:Browser.java


注:本文中的android.view.MotionEvent.getAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。