Search in sources :

Example 76 with Point

use of android.graphics.Point in project XobotOS by xamarin.

the class View method setRight.

/**
     * Sets the right position of this view relative to its parent. This method is meant to be called
     * by the layout system and should not generally be called otherwise, because the property
     * may be changed at any time by the layout.
     *
     * @param right The bottom of this view, in pixels.
     */
public final void setRight(int right) {
    if (right != mRight) {
        updateMatrix();
        final boolean matrixIsIdentity = mTransformationInfo == null || mTransformationInfo.mMatrixIsIdentity;
        if (matrixIsIdentity) {
            if (mAttachInfo != null) {
                int maxRight;
                if (right < mRight) {
                    maxRight = mRight;
                } else {
                    maxRight = right;
                }
                invalidate(0, 0, maxRight - mLeft, mBottom - mTop);
            }
        } else {
            // Double-invalidation is necessary to capture view's old and new areas
            invalidate(true);
        }
        int oldWidth = mRight - mLeft;
        int height = mBottom - mTop;
        mRight = right;
        onSizeChanged(mRight - mLeft, height, oldWidth, height);
        if (!matrixIsIdentity) {
            if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) {
                // A change in dimension means an auto-centered pivot point changes, too
                mTransformationInfo.mMatrixDirty = true;
            }
            // force another invalidation with the new orientation
            mPrivateFlags |= DRAWN;
            invalidate(true);
        }
        mBackgroundSizeChanged = true;
        invalidateParentIfNeeded();
    }
}
Also used : Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 77 with Point

use of android.graphics.Point in project XobotOS by xamarin.

the class View method startDrag.

/**
     * Starts a drag and drop operation. When your application calls this method, it passes a
     * {@link android.view.View.DragShadowBuilder} object to the system. The
     * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)}
     * to get metrics for the drag shadow, and then calls the object's
     * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself.
     * <p>
     *  Once the system has the drag shadow, it begins the drag and drop operation by sending
     *  drag events to all the View objects in your application that are currently visible. It does
     *  this either by calling the View object's drag listener (an implementation of
     *  {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the
     *  View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method.
     *  Both are passed a {@link android.view.DragEvent} object that has a
     *  {@link android.view.DragEvent#getAction()} value of
     *  {@link android.view.DragEvent#ACTION_DRAG_STARTED}.
     * </p>
     * <p>
     * Your application can invoke startDrag() on any attached View object. The View object does not
     * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to
     * be related to the View the user selected for dragging.
     * </p>
     * @param data A {@link android.content.ClipData} object pointing to the data to be
     * transferred by the drag and drop operation.
     * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the
     * drag shadow.
     * @param myLocalState An {@link java.lang.Object} containing local data about the drag and
     * drop operation. This Object is put into every DragEvent object sent by the system during the
     * current drag.
     * <p>
     * myLocalState is a lightweight mechanism for the sending information from the dragged View
     * to the target Views. For example, it can contain flags that differentiate between a
     * a copy operation and a move operation.
     * </p>
     * @param flags Flags that control the drag and drop operation. No flags are currently defined,
     * so the parameter should be set to 0.
     * @return {@code true} if the method completes successfully, or
     * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to
     * do a drag, and so no drag operation is in progress.
     */
public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags) {
    if (ViewDebug.DEBUG_DRAG) {
        Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags);
    }
    boolean okay = false;
    Point shadowSize = new Point();
    Point shadowTouchPoint = new Point();
    shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
    if ((shadowSize.x < 0) || (shadowSize.y < 0) || (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) {
        throw new IllegalStateException("Drag shadow dimensions must not be negative");
    }
    if (ViewDebug.DEBUG_DRAG) {
        Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y);
    }
    Surface surface = new Surface();
    try {
        IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, flags, shadowSize.x, shadowSize.y, surface);
        if (ViewDebug.DEBUG_DRAG)
            Log.d(VIEW_LOG_TAG, "prepareDrag returned token=" + token + " surface=" + surface);
        if (token != null) {
            Canvas canvas = surface.lockCanvas(null);
            try {
                canvas.drawColor(0, PorterDuff.Mode.CLEAR);
                shadowBuilder.onDrawShadow(canvas);
            } finally {
                surface.unlockCanvasAndPost(canvas);
            }
            final ViewRootImpl root = getViewRootImpl();
            // Cache the local state object for delivery with DragEvents
            root.setLocalDragState(myLocalState);
            // repurpose 'shadowSize' for the last touch point
            root.getLastTouchPoint(shadowSize);
            okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, shadowSize.x, shadowSize.y, shadowTouchPoint.x, shadowTouchPoint.y, data);
            if (ViewDebug.DEBUG_DRAG)
                Log.d(VIEW_LOG_TAG, "performDrag returned " + okay);
            // Off and running!  Release our local surface instance; the drag
            // shadow surface is now managed by the system process.
            surface.release();
        }
    } catch (Exception e) {
        Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e);
        surface.destroy();
    }
    return okay;
}
Also used : IBinder(android.os.IBinder) Canvas(android.graphics.Canvas) Point(android.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(android.os.RemoteException)

Example 78 with Point

use of android.graphics.Point in project XobotOS by xamarin.

the class View method invalidate.

/**
     * Mark the area defined by the rect (l,t,r,b) as needing to be drawn.
     * The coordinates of the dirty rect are relative to the view.
     * If the view is visible, {@link #onDraw(android.graphics.Canvas)}
     * will be called at some point in the future. This must be called from
     * a UI thread. To call from a non-UI thread, call {@link #postInvalidate()}.
     * @param l the left position of the dirty region
     * @param t the top position of the dirty region
     * @param r the right position of the dirty region
     * @param b the bottom position of the dirty region
     */
public void invalidate(int l, int t, int r, int b) {
    if (ViewDebug.TRACE_HIERARCHY) {
        ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
    }
    if (skipInvalidate()) {
        return;
    }
    if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || (mPrivateFlags & INVALIDATED) != INVALIDATED) {
        mPrivateFlags &= ~DRAWING_CACHE_VALID;
        mPrivateFlags |= INVALIDATED;
        mPrivateFlags |= DIRTY;
        final ViewParent p = mParent;
        final AttachInfo ai = mAttachInfo;
        //noinspection PointlessBooleanExpression,ConstantConditions
        if (!HardwareRenderer.RENDER_DIRTY_REGIONS) {
            if (p != null && ai != null && ai.mHardwareAccelerated) {
                // fast-track for GL-enabled applications; just invalidate the whole hierarchy
                // with a null dirty rect, which tells the ViewAncestor to redraw everything
                p.invalidateChild(this, null);
                return;
            }
        }
        if (p != null && ai != null && l < r && t < b) {
            final int scrollX = mScrollX;
            final int scrollY = mScrollY;
            final Rect tmpr = ai.mTmpInvalRect;
            tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY);
            p.invalidateChild(this, tmpr);
        }
    }
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 79 with Point

use of android.graphics.Point in project XobotOS by xamarin.

the class View method gatherTransparentRegion.

/**
     * This is used by the RootView to perform an optimization when
     * the view hierarchy contains one or several SurfaceView.
     * SurfaceView is always considered transparent, but its children are not,
     * therefore all View objects remove themselves from the global transparent
     * region (passed as a parameter to this function).
     *
     * @param region The transparent region for this ViewAncestor (window).
     *
     * @return Returns true if the effective visibility of the view at this
     * point is opaque, regardless of the transparent region; returns false
     * if it is possible for underlying windows to be seen behind the view.
     *
     * {@hide}
     */
public boolean gatherTransparentRegion(Region region) {
    final AttachInfo attachInfo = mAttachInfo;
    if (region != null && attachInfo != null) {
        final int pflags = mPrivateFlags;
        if ((pflags & SKIP_DRAW) == 0) {
            // The SKIP_DRAW flag IS NOT set, so this view draws. We need to
            // remove it from the transparent region.
            final int[] location = attachInfo.mTransparentLocation;
            getLocationInWindow(location);
            region.op(location[0], location[1], location[0] + mRight - mLeft, location[1] + mBottom - mTop, Region.Op.DIFFERENCE);
        } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) {
            // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable
            // exists, so we remove the background drawable's non-transparent
            // parts from this transparent region.
            applyDrawableToTransparentRegion(mBGDrawable, region);
        }
    }
    return true;
}
Also used : Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 80 with Point

use of android.graphics.Point in project XobotOS by xamarin.

the class View method setFrame.

/**
     * Assign a size and position to this view.
     *
     * This is called from layout.
     *
     * @param left Left position, relative to parent
     * @param top Top position, relative to parent
     * @param right Right position, relative to parent
     * @param bottom Bottom position, relative to parent
     * @return true if the new size and position are different than the
     *         previous ones
     * {@hide}
     */
protected boolean setFrame(int left, int top, int right, int bottom) {
    boolean changed = false;
    if (DBG) {
        Log.d("View", this + " View.setFrame(" + left + "," + top + "," + right + "," + bottom + ")");
    }
    if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) {
        changed = true;
        // Remember our drawn bit
        int drawn = mPrivateFlags & DRAWN;
        int oldWidth = mRight - mLeft;
        int oldHeight = mBottom - mTop;
        int newWidth = right - left;
        int newHeight = bottom - top;
        boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight);
        // Invalidate our old position
        invalidate(sizeChanged);
        mLeft = left;
        mTop = top;
        mRight = right;
        mBottom = bottom;
        mPrivateFlags |= HAS_BOUNDS;
        if (sizeChanged) {
            if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) {
                // A change in dimension means an auto-centered pivot point changes, too
                if (mTransformationInfo != null) {
                    mTransformationInfo.mMatrixDirty = true;
                }
            }
            onSizeChanged(newWidth, newHeight, oldWidth, oldHeight);
        }
        if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) {
            // If we are visible, force the DRAWN bit to on so that
            // this invalidate will go through (at least to our parent).
            // This is because someone may have invalidated this view
            // before this call to setFrame came in, thereby clearing
            // the DRAWN bit.
            mPrivateFlags |= DRAWN;
            invalidate(sizeChanged);
            // parent display list may need to be recreated based on a change in the bounds
            // of any child
            invalidateParentCaches();
        }
        // Reset drawn bit to original value (invalidate turns it off)
        mPrivateFlags |= drawn;
        mBackgroundSizeChanged = true;
    }
    return changed;
}
Also used : Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)1151 Display (android.view.Display)217 Rect (android.graphics.Rect)194 Paint (android.graphics.Paint)170 WindowManager (android.view.WindowManager)138 RemoteException (android.os.RemoteException)76 RectF (android.graphics.RectF)62 Bitmap (android.graphics.Bitmap)54 Resources (android.content.res.Resources)41 View (android.view.View)41 ArrayList (java.util.ArrayList)40 ImageView (android.widget.ImageView)37 Camera (android.hardware.Camera)36 Canvas (android.graphics.Canvas)31 Matrix (android.graphics.Matrix)29 Animator (android.animation.Animator)27 SuppressLint (android.annotation.SuppressLint)27 Configuration (android.content.res.Configuration)26 IOException (java.io.IOException)24 Message (android.os.Message)22