Search in sources :

Example 46 with ViewParent

use of android.view.ViewParent in project weiciyuan by qii.

the class PhotoViewAttacher method onTouch.

@Override
public final boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;
    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch(ev.getAction()) {
            case ACTION_DOWN:
                // event
                if (null != parent) {
                    parent.requestDisallowInterceptTouchEvent(true);
                } else {
                    Log.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:
                // 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 && mScaleDragDetector.onTouchEvent(ev)) {
            handled = true;
        }
        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }
    }
    return handled;
}
Also used : RectF(android.graphics.RectF) ViewParent(android.view.ViewParent) ImageView(android.widget.ImageView)

Example 47 with ViewParent

use of android.view.ViewParent in project weiciyuan by qii.

the class PhotoViewAttacher method onDrag.

@Override
public final void onDrag(float dx, float dy) {
    if (mScaleDragDetector.isScaling()) {
        // Do not drag if we are already scaling
        return;
    }
    if (DEBUG) {
        LogManager.getLogger().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) {
        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);
        }
    }
}
Also used : ViewParent(android.view.ViewParent) ImageView(android.widget.ImageView)

Example 48 with ViewParent

use of android.view.ViewParent in project FlyRefresh by race604.

the class PullHeaderLayout method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    MotionEvent vtev = MotionEvent.obtain(ev);
    final int actionMasked = MotionEventCompat.getActionMasked(ev);
    if (actionMasked == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;
    }
    vtev.offsetLocation(0, mNestedYOffset);
    switch(actionMasked) {
        case MotionEvent.ACTION_DOWN:
            {
                if ((mIsBeingDragged = !mScroller.isFinished())) {
                    final ViewParent parent = getParent();
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
                /*
                 * If being flinged and user touches, stop the fling. isFinished
                 * will be false if being flinged.
                 */
                if (!mScroller.isFinished()) {
                    mScroller.abortAnimation();
                }
                // Remember where the motion event started
                mLastMotionY = (int) ev.getY();
                mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
                startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
                break;
            }
        case MotionEvent.ACTION_MOVE:
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                break;
            }
            final int y = (int) MotionEventCompat.getY(ev, activePointerIndex);
            int deltaY = mLastMotionY - y;
            if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
                deltaY -= mScrollConsumed[1];
                vtev.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
            if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {
                final ViewParent parent = getParent();
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
                mIsBeingDragged = true;
                if (deltaY > 0) {
                    deltaY -= mTouchSlop;
                } else {
                    deltaY += mTouchSlop;
                }
            }
            if (mIsBeingDragged) {
                // Scroll to follow the motion event
                mLastMotionY = y - mScrollOffset[1];
                final int scrolledDeltaY = moveBy(deltaY);
                final int unconsumedY = deltaY - scrolledDeltaY;
                if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) {
                    mLastMotionY -= mScrollOffset[1];
                    vtev.offsetLocation(0, mScrollOffset[1]);
                    mNestedYOffset += mScrollOffset[1];
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mIsBeingDragged) {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
                if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
                    flingWithNestedDispatch(-initialVelocity);
                }
                mActivePointerId = INVALID_POINTER;
                endDrag();
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            if (mIsBeingDragged && getChildCount() > 0) {
                mActivePointerId = INVALID_POINTER;
                endDrag();
            }
            break;
        case MotionEventCompat.ACTION_POINTER_DOWN:
            {
                final int index = MotionEventCompat.getActionIndex(ev);
                mLastMotionY = (int) MotionEventCompat.getY(ev, index);
                mActivePointerId = MotionEventCompat.getPointerId(ev, index);
                break;
            }
        case MotionEventCompat.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            mLastMotionY = (int) MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
            break;
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(vtev);
    }
    vtev.recycle();
    return true;
}
Also used : VelocityTracker(android.view.VelocityTracker) ViewParent(android.view.ViewParent) MotionEvent(android.view.MotionEvent)

Example 49 with ViewParent

use of android.view.ViewParent in project mobile-android by photo.

the class Workspace method getScreenForView.

/**
	 * Gets the screen for view.
	 * 
	 * @param v
	 *           the v
	 * @return the screen for view
	 */
public int getScreenForView(View v) {
    int result = -1;
    if (v != null) {
        ViewParent vp = v.getParent();
        int count = mItemCount;
        for (int i = 0; i < count; i++) {
            if (vp == getChildAt(i)) {
                return i;
            }
        }
    }
    return result;
}
Also used : ViewParent(android.view.ViewParent)

Example 50 with ViewParent

use of android.view.ViewParent in project Libraries-for-Android-Developers by eoecn.

the class ActionBarView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    addView(mHomeLayout);
    if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
        final ViewParent parent = mCustomNavView.getParent();
        if (parent != this) {
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(mCustomNavView);
            }
            addView(mCustomNavView);
        }
    }
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

Aggregations

ViewParent (android.view.ViewParent)409 ViewGroup (android.view.ViewGroup)185 View (android.view.View)156 ImageView (android.widget.ImageView)36 Rect (android.graphics.Rect)32 VelocityTracker (android.view.VelocityTracker)32 TextView (android.widget.TextView)24 FrameLayout (android.widget.FrameLayout)17 SuppressLint (android.annotation.SuppressLint)16 Paint (android.graphics.Paint)15 AdapterView (android.widget.AdapterView)14 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)13 ViewTreeObserver (android.view.ViewTreeObserver)12 LayoutParams (android.view.WindowManager.LayoutParams)11 Description (org.hamcrest.Description)11 ExpandableNotificationRow (com.android.systemui.statusbar.ExpandableNotificationRow)10 SignalClusterView (com.android.systemui.statusbar.SignalClusterView)10 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)10 MotionEvent (android.view.MotionEvent)9 EditText (android.widget.EditText)9