List of usage examples for android.view ViewParent requestDisallowInterceptTouchEvent
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);
From source file:com.sflib.CustomView.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/* ww w . j a va 2 s. c om*/ public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { L.info(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:xue.myapp.common.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w w w . ja va 2s. c o m*/ public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { LogUtil.i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.kf5.sdk.system.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w .j a va 2 s . c om public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w . j a va 2 s .c o m public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { // LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w. j av a 2 s .c o m public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { L.w("onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java
/** * Starts dragging or swiping the given View. Call with null if you want to clear it. * * @param selected The ViewHolder to swipe. Can be null if you want to cancel the * current action//from www . j a va 2 s . c o m * @param actionState The type of action */ private void select(SwipeOpenViewHolder selected, int actionState) { if (selected == this.selected && actionState == this.actionState) { return; } final int prevActionState = this.actionState; // prevent duplicate animations endRecoverAnimation(selected, true); this.actionState = actionState; int actionStateMask = (1 << (DIRECTION_FLAG_COUNT + DIRECTION_FLAG_COUNT * actionState)) - 1; boolean preventLayout = false; // close the previously selected view holder if we're swiping a new one and the flag is true if (closeOnAction && selected != null && prevSelected != null && selected != prevSelected) { closeOpenHolder(prevSelected); prevSelected = null; preventLayout = true; } // if we've got any opened positions, and closeOnAction is true, close them // NOTE: only real way for this to happen is to have a view opened during configuration change // that then has its' state saved if (closeOnAction && openedPositions.size() > 0) { for (int i = 0; i < openedPositions.size(); i++) { View child = recyclerView.getChildAt(openedPositions.keyAt(0)); if (child.getParent() != null) { RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(child); // if our selected isn't the opened position, close it if (holder instanceof SwipeOpenViewHolder && (selected == null || holder.getAdapterPosition() != selected.getViewHolder().getAdapterPosition())) { closeOpenHolder((SwipeOpenViewHolder) holder); } } openedPositions.removeAt(i); } } if (this.selected != null) { prevSelected = this.selected; // we've changed selection, we need to animate it back if (prevSelected.getViewHolder().itemView.getParent() != null) { final int swipeDir = checkPreviousSwipeDirection(prevSelected.getViewHolder()); releaseVelocityTracker(); // find where we should animate to final float targetTranslateX, targetTranslateY; getSelectedDxDy(tmpPosition); final float currentTranslateX = tmpPosition[0]; final float currentTranslateY = tmpPosition[1]; final float absTranslateX = Math.abs(currentTranslateX); final float absTranslateY = Math.abs(currentTranslateY); final SavedOpenState state; switch (swipeDir) { case LEFT: case START: targetTranslateY = 0; // check if we need to close or go to the open position if (absTranslateX > prevSelected.getEndHiddenViewSize() / 2) { targetTranslateX = prevSelected.getEndHiddenViewSize() * Math.signum(dX); state = SavedOpenState.END_OPEN; } else { targetTranslateX = 0; state = null; } break; case RIGHT: case END: targetTranslateY = 0; if (absTranslateX > prevSelected.getStartHiddenViewSize() / 2) { targetTranslateX = prevSelected.getStartHiddenViewSize() * Math.signum(dX); state = SavedOpenState.START_OPEN; } else { targetTranslateX = 0; state = null; } break; case UP: targetTranslateX = 0; if (absTranslateY > prevSelected.getEndHiddenViewSize() / 2) { targetTranslateY = prevSelected.getEndHiddenViewSize() * Math.signum(dY); state = SavedOpenState.END_OPEN; } else { targetTranslateY = 0; state = null; } break; case DOWN: targetTranslateX = 0; if (absTranslateY > prevSelected.getStartHiddenViewSize() / 2) { targetTranslateY = prevSelected.getStartHiddenViewSize() * Math.signum(dY); state = SavedOpenState.START_OPEN; } else { targetTranslateY = 0; state = null; } break; default: state = null; targetTranslateX = 0; targetTranslateY = 0; } // if state == null, we're closing it if (state == null) { openedPositions.remove(prevSelected.getViewHolder().getAdapterPosition()); } else { openedPositions.put(prevSelected.getViewHolder().getAdapterPosition(), state); } final RecoverAnimation rv = new RecoverAnimation(prevSelected, prevActionState, currentTranslateX, currentTranslateY, targetTranslateX, targetTranslateY); final long duration = callback.getAnimationDuration(recyclerView, ANIMATION_TYPE_SWIPE, targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY); rv.setDuration(duration); recoverAnimations.add(rv); rv.start(); preventLayout = true; } else { callback.clearView(recyclerView, prevSelected); } this.selected = null; } if (selected != null) { selectedFlags = (callback.getAbsoluteMovementFlags(recyclerView, selected.getViewHolder()) & actionStateMask) >> (this.actionState * DIRECTION_FLAG_COUNT); selectedStartX = selected.getViewHolder().itemView.getLeft() + ViewCompat.getTranslationX(selected.getSwipeView()); selectedStartY = selected.getViewHolder().itemView.getTop() + ViewCompat.getTranslationY(selected.getSwipeView()); this.selected = selected; } final ViewParent rvParent = recyclerView.getParent(); if (rvParent != null) { rvParent.requestDisallowInterceptTouchEvent(this.selected != null); } if (!preventLayout) { recyclerView.getLayoutManager().requestSimpleAnimationsInNextLayout(); } callback.onSelectedChanged(this.selected, this.actionState); recyclerView.invalidate(); }
From source file:com.org.lengend.photoview.library.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from w ww. ja v a 2 s. c o m public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { Logger.i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.homechart.app.commont.imagedetail.PhotoViewAttacher.java
@Override public void onDrag(float dx, float dy) { if (mScaleDragDetector.isScaling()) { return; // Do not drag if we are already scaling }//from w ww.j av a2 s. c o m ImageView imageView = getImageView(); mSuppMatrix.postTranslate(dx, dy); checkAndDisplayMatrix(); /** * Here we decide whether to let the ImageView's parent to start taking * over the touch event. * * First we check whether this function is enabled. We never want the * parent to take over if we're scaling. We then check the edge we're * on, and the direction of the scroll (i.e. if we're pulling against * the edge, aka 'overscrolling', let the parent take over). */ ViewParent parent = imageView.getParent(); if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) { if (mScrollEdge == EDGE_BOTH || (mScrollEdge == EDGE_LEFT && dx >= 1f) || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) { if (null != parent) { parent.requestDisallowInterceptTouchEvent(false); } } } else { if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } } }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override// w ww .j a v a 2s . c o m public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.example.imagegallerydemo.photoview.PhotoViewAttacher.java
@Override public void onDrag(float dx, float dy) { if (mScaleDragDetector.isScaling()) { return; // Do not drag if we are already scaling }//from w w w .ja v a 2s. c om if (DEBUG) { Log.d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy)); } ImageView imageView = getImageView(); mSuppMatrix.postTranslate(dx, dy); checkAndDisplayMatrix(); /** * Here we decide whether to let the ImageView's parent to start taking * over the touch event. * * First we check whether this function is enabled. We never want the * parent to take over if we're scaling. We then check the edge we're * on, and the direction of the scroll (i.e. if we're pulling against * the edge, aka 'overscrolling', let the parent take over). */ ViewParent parent = imageView.getParent(); if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) { if (mScrollEdge == EDGE_BOTH || (mScrollEdge == EDGE_LEFT && dx >= 1f) || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) { if (null != parent) { parent.requestDisallowInterceptTouchEvent(false); } } } else { if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } } }