Search in sources :

Example 51 with PointF

use of android.graphics.PointF in project MagicIndicator by hackware1993.

the class CircleNavigator method onPageScrolled.

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mFollowTouch) {
        if (mCirclePoints.isEmpty()) {
            return;
        }
        int currentPosition = Math.min(mCirclePoints.size() - 1, position);
        int nextPosition = Math.min(mCirclePoints.size() - 1, position + 1);
        PointF current = mCirclePoints.get(currentPosition);
        PointF next = mCirclePoints.get(nextPosition);
        mIndicatorX = current.x + (next.x - current.x) * mStartInterpolator.getInterpolation(positionOffset);
        invalidate();
    }
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 52 with PointF

use of android.graphics.PointF in project MagicIndicator by hackware1993.

the class ScaleCircleNavigator method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (mTouchable) {
                mDownX = x;
                mDownY = y;
                return true;
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mCircleClickListener != null) {
                if (Math.abs(x - mDownX) <= mTouchSlop && Math.abs(y - mDownY) <= mTouchSlop) {
                    float max = Float.MAX_VALUE;
                    int index = 0;
                    for (int i = 0; i < mCirclePoints.size(); i++) {
                        PointF pointF = mCirclePoints.get(i);
                        float offset = Math.abs(pointF.x - x);
                        if (offset < max) {
                            max = offset;
                            index = i;
                        }
                    }
                    mCircleClickListener.onClick(index);
                }
            }
            break;
        default:
            break;
    }
    return super.onTouchEvent(event);
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 53 with PointF

use of android.graphics.PointF in project platform_frameworks_base by android.

the class ViewRootImpl method dispatchMoved.

public void dispatchMoved(int newX, int newY) {
    if (DEBUG_LAYOUT)
        Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY);
    if (mTranslator != null) {
        PointF point = new PointF(newX, newY);
        mTranslator.translatePointInScreenToAppWindow(point);
        newX = (int) (point.x + 0.5);
        newY = (int) (point.y + 0.5);
    }
    Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY);
    mHandler.sendMessage(msg);
}
Also used : Message(android.os.Message) PointF(android.graphics.PointF)

Example 54 with PointF

use of android.graphics.PointF in project platform_frameworks_base by android.

the class ViewGroup method dispatchDragEvent.

// TODO: Write real docs
@Override
public boolean dispatchDragEvent(DragEvent event) {
    boolean retval = false;
    final float tx = event.mX;
    final float ty = event.mY;
    // Dispatch down the view hierarchy
    final PointF localPoint = getLocalPoint();
    switch(event.mAction) {
        case DragEvent.ACTION_DRAG_STARTED:
            {
                // Clear the state to recalculate which views we drag over.
                mCurrentDragChild = null;
                // Set up our tracking of drag-started notifications
                mCurrentDragStartEvent = DragEvent.obtain(event);
                if (mChildrenInterestedInDrag == null) {
                    mChildrenInterestedInDrag = new HashSet<View>();
                } else {
                    mChildrenInterestedInDrag.clear();
                }
                // Now dispatch down to our children, caching the responses
                final int count = mChildrenCount;
                final View[] children = mChildren;
                for (int i = 0; i < count; i++) {
                    final View child = children[i];
                    child.mPrivateFlags2 &= ~View.DRAG_MASK;
                    if (child.getVisibility() == VISIBLE) {
                        if (notifyChildOfDragStart(children[i])) {
                            retval = true;
                        }
                    }
                }
                // Notify itself of the drag start.
                mIsInterestedInDrag = super.dispatchDragEvent(event);
                if (mIsInterestedInDrag) {
                    retval = true;
                }
                if (!retval) {
                    // Neither us nor any of our children are interested in this drag, so stop tracking
                    // the current drag event.
                    mCurrentDragStartEvent.recycle();
                    mCurrentDragStartEvent = null;
                }
            }
            break;
        case DragEvent.ACTION_DRAG_ENDED:
            {
                // Release the bookkeeping now that the drag lifecycle has ended
                final HashSet<View> childrenInterestedInDrag = mChildrenInterestedInDrag;
                if (childrenInterestedInDrag != null) {
                    for (View child : childrenInterestedInDrag) {
                        // If a child was interested in the ongoing drag, it's told that it's over
                        if (child.dispatchDragEvent(event)) {
                            retval = true;
                        }
                    }
                    childrenInterestedInDrag.clear();
                }
                if (mCurrentDragStartEvent != null) {
                    mCurrentDragStartEvent.recycle();
                    mCurrentDragStartEvent = null;
                }
                if (mIsInterestedInDrag) {
                    if (super.dispatchDragEvent(event)) {
                        retval = true;
                    }
                    mIsInterestedInDrag = false;
                }
            }
            break;
        case DragEvent.ACTION_DRAG_LOCATION:
        case DragEvent.ACTION_DROP:
            {
                // Find the [possibly new] drag target
                View target = findFrontmostDroppableChildAt(event.mX, event.mY, localPoint);
                if (target != mCurrentDragChild) {
                    if (sCascadedDragDrop) {
                        // For pre-Nougat apps, make sure that the whole hierarchy of views that contain
                        // the drag location is kept in the state between ENTERED and EXITED events.
                        // (Starting with N, only the innermost view will be in that state).
                        final int action = event.mAction;
                        // Position should not be available for ACTION_DRAG_ENTERED and
                        // ACTION_DRAG_EXITED.
                        event.mX = 0;
                        event.mY = 0;
                        if (mCurrentDragChild != null) {
                            event.mAction = DragEvent.ACTION_DRAG_EXITED;
                            mCurrentDragChild.dispatchDragEnterExitInPreN(event);
                        }
                        if (target != null) {
                            event.mAction = DragEvent.ACTION_DRAG_ENTERED;
                            target.dispatchDragEnterExitInPreN(event);
                        }
                        event.mAction = action;
                        event.mX = tx;
                        event.mY = ty;
                    }
                    mCurrentDragChild = target;
                }
                if (target == null && mIsInterestedInDrag) {
                    target = this;
                }
                // Dispatch the actual drag notice, localized into the target coordinates.
                if (target != null) {
                    if (target != this) {
                        event.mX = localPoint.x;
                        event.mY = localPoint.y;
                        retval = target.dispatchDragEvent(event);
                        event.mX = tx;
                        event.mY = ty;
                        if (mIsInterestedInDrag) {
                            final boolean eventWasConsumed;
                            if (sCascadedDragDrop) {
                                eventWasConsumed = retval;
                            } else {
                                eventWasConsumed = event.mEventHandlerWasCalled;
                            }
                            if (!eventWasConsumed) {
                                retval = super.dispatchDragEvent(event);
                            }
                        }
                    } else {
                        retval = super.dispatchDragEvent(event);
                    }
                }
            }
            break;
    }
    return retval;
}
Also used : PointF(android.graphics.PointF) HashSet(java.util.HashSet)

Example 55 with PointF

use of android.graphics.PointF in project platform_frameworks_base by android.

the class ViewGroup method onResolvePointerIcon.

@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    final float x = event.getX(pointerIndex);
    final float y = event.getY(pointerIndex);
    if (isOnScrollbarThumb(x, y) || isDraggingScrollBar()) {
        return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_ARROW);
    }
    // Check what the child under the pointer says about the pointer.
    final int childrenCount = mChildrenCount;
    if (childrenCount != 0) {
        final ArrayList<View> preorderedList = buildOrderedChildList();
        final boolean customOrder = preorderedList == null && isChildrenDrawingOrderEnabled();
        final View[] children = mChildren;
        for (int i = childrenCount - 1; i >= 0; i--) {
            final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
            final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
            final PointF point = getLocalPoint();
            if (isTransformedTouchPointInView(x, y, child, point)) {
                final PointerIcon pointerIcon = dispatchResolvePointerIcon(event, pointerIndex, child);
                if (pointerIcon != null) {
                    if (preorderedList != null)
                        preorderedList.clear();
                    return pointerIcon;
                }
                break;
            }
        }
        if (preorderedList != null)
            preorderedList.clear();
    }
    // implementation.
    return super.onResolvePointerIcon(event, pointerIndex);
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Aggregations

PointF (android.graphics.PointF)686 Paint (android.graphics.Paint)132 Point (android.graphics.Point)53 RectF (android.graphics.RectF)53 Matrix (android.graphics.Matrix)43 Test (org.junit.Test)40 Path (android.graphics.Path)29 View (android.view.View)28 Drawable (android.graphics.drawable.Drawable)23 ArrayList (java.util.ArrayList)23 MotionEvent (android.view.MotionEvent)22 NonNull (android.support.annotation.NonNull)21 Rect (android.graphics.Rect)18 ValueAnimator (android.animation.ValueAnimator)14 ViewGroup (android.view.ViewGroup)11 List (java.util.List)11 Animator (android.animation.Animator)10 Bitmap (android.graphics.Bitmap)10 GestureDetector (android.view.GestureDetector)10 LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)9