Search in sources :

Example 1 with RegionIterator

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

the class WebView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    // initialized. In either case, just draw the background color and return
    if (mNativeClass == 0) {
        canvas.drawColor(mBackgroundColor);
        return;
    }
    // just starts. Draw the background and return.
    if ((mContentWidth | mContentHeight) == 0 && mHistoryPicture == null) {
        canvas.drawColor(mBackgroundColor);
        return;
    }
    if (canvas.isHardwareAccelerated()) {
        mZoomManager.setHardwareAccelerated();
    }
    int saveCount = canvas.save();
    if (mInOverScrollMode && !getSettings().getUseWebViewBackgroundForOverscrollBackground()) {
        drawOverScrollBackground(canvas);
    }
    if (mTitleBar != null) {
        canvas.translate(0, getTitleHeight());
    }
    boolean drawJavaRings = !mTouchHighlightRegion.isEmpty() && (mTouchMode == TOUCH_INIT_MODE || mTouchMode == TOUCH_SHORTPRESS_START_MODE || mTouchMode == TOUCH_SHORTPRESS_MODE || mTouchMode == TOUCH_DONE_MODE);
    boolean drawNativeRings = !drawJavaRings;
    if (USE_WEBKIT_RINGS) {
        drawNativeRings = !drawJavaRings && !isInTouchMode();
    }
    drawContent(canvas, drawNativeRings);
    canvas.restoreToCount(saveCount);
    if (AUTO_REDRAW_HACK && mAutoRedraw) {
        invalidate();
    }
    mWebViewCore.signalRepaintDone();
    if (mOverScrollGlow != null && mOverScrollGlow.drawEdgeGlows(canvas)) {
        invalidate();
    }
    // paint the highlight in the end
    if (drawJavaRings) {
        long delay = System.currentTimeMillis() - mTouchHighlightRequested;
        if (delay < ViewConfiguration.getTapTimeout()) {
            Rect r = mTouchHighlightRegion.getBounds();
            postInvalidateDelayed(delay, r.left, r.top, r.right, r.bottom);
        } else {
            if (mTouchHightlightPaint == null) {
                mTouchHightlightPaint = new Paint();
                mTouchHightlightPaint.setColor(HIGHLIGHT_COLOR);
            }
            RegionIterator iter = new RegionIterator(mTouchHighlightRegion);
            Rect r = new Rect();
            while (iter.next(r)) {
                canvas.drawRect(r, mTouchHightlightPaint);
            }
        }
    }
    if (DEBUG_TOUCH_HIGHLIGHT) {
        if (getSettings().getNavDump()) {
            if ((mTouchHighlightX | mTouchHighlightY) != 0) {
                if (mTouchCrossHairColor == null) {
                    mTouchCrossHairColor = new Paint();
                    mTouchCrossHairColor.setColor(Color.RED);
                }
                canvas.drawLine(mTouchHighlightX - mNavSlop, mTouchHighlightY - mNavSlop, mTouchHighlightX + mNavSlop + 1, mTouchHighlightY + mNavSlop + 1, mTouchCrossHairColor);
                canvas.drawLine(mTouchHighlightX + mNavSlop + 1, mTouchHighlightY - mNavSlop, mTouchHighlightX - mNavSlop, mTouchHighlightY + mNavSlop + 1, mTouchCrossHairColor);
            }
        }
    }
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint) RegionIterator(android.graphics.RegionIterator) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 2 with RegionIterator

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

the class WebView method drawTextSelectionHandles.

private void drawTextSelectionHandles(Canvas canvas) {
    if (mTextSelectionPaint == null) {
        mTextSelectionPaint = new Paint();
        mTextSelectionPaint.setColor(HIGHLIGHT_COLOR);
    }
    mTextSelectionRegion.setEmpty();
    nativeGetTextSelectionRegion(mTextSelectionRegion);
    Rect r = new Rect();
    RegionIterator iter = new RegionIterator(mTextSelectionRegion);
    int start_x = -1;
    int start_y = -1;
    int end_x = -1;
    int end_y = -1;
    while (iter.next(r)) {
        r = new Rect(contentToViewDimension(r.left), contentToViewDimension(r.top), contentToViewDimension(r.right), contentToViewDimension(r.bottom));
        // last one is where it ends
        if (start_x < 0 || start_y < 0) {
            start_x = r.left;
            start_y = r.bottom;
        }
        end_x = r.right;
        end_y = r.bottom;
        canvas.drawRect(r, mTextSelectionPaint);
    }
    if (mSelectHandleLeft == null) {
        mSelectHandleLeft = mContext.getResources().getDrawable(com.android.internal.R.drawable.text_select_handle_left);
    }
    // Magic formula copied from TextView
    start_x -= (mSelectHandleLeft.getIntrinsicWidth() * 3) / 4;
    mSelectHandleLeft.setBounds(start_x, start_y, start_x + mSelectHandleLeft.getIntrinsicWidth(), start_y + mSelectHandleLeft.getIntrinsicHeight());
    if (mSelectHandleRight == null) {
        mSelectHandleRight = mContext.getResources().getDrawable(com.android.internal.R.drawable.text_select_handle_right);
    }
    end_x -= mSelectHandleRight.getIntrinsicWidth() / 4;
    mSelectHandleRight.setBounds(end_x, end_y, end_x + mSelectHandleRight.getIntrinsicWidth(), end_y + mSelectHandleRight.getIntrinsicHeight());
    mSelectHandleLeft.draw(canvas);
    mSelectHandleRight.draw(canvas);
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint) RegionIterator(android.graphics.RegionIterator) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 3 with RegionIterator

use of android.graphics.RegionIterator in project JustAndroid by chinaltz.

the class AbHighlightView method draw.

/**
     * Draw.
     *
     * @param canvas the canvas
     */
public void draw(Canvas canvas) {
    if (mHidden) {
        return;
    }
    canvas.save();
    Path path = new Path();
    if (!hasFocus()) {
        mOutlinePaint.setColor(0xFF000000);
        canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        contextView.getDrawingRect(viewDrawingRect);
        if (mCircle) {
            float width = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);
        } else {
            path.addRect(new RectF(mDrawRect), Path.Direction.CW);
            mOutlinePaint.setColor(0xFFFF8A00);
        }
        Region region = new Region();
        region.set(viewDrawingRect);
        region.op(mDrawRect, Region.Op.DIFFERENCE);
        RegionIterator iter = new RegionIterator(region);
        Rect r = new Rect();
        while (iter.next(r)) {
            canvas.drawRect(r, hasFocus() ? mFocusPaint : mNoFocusPaint);
        }
        canvas.restore();
        canvas.drawPath(path, mOutlinePaint);
        if (mMode == ModifyMode.Grow) {
            if (mCircle) {
                int width = mResizeDrawableDiagonal.getIntrinsicWidth();
                int height = mResizeDrawableDiagonal.getIntrinsicHeight();
                int d = (int) Math.round(Math.cos(/* 45deg */
                Math.PI / 4D) * (mDrawRect.width() / 2D));
                int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
                int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
                mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight());
                mResizeDrawableDiagonal.draw(canvas);
            } else {
            //
            }
        }
        if (mCircle) {
        } else {
            int left = mDrawRect.left + 1;
            int right = mDrawRect.right + 1;
            int top = mDrawRect.top + 4;
            int bottom = mDrawRect.bottom + 3;
            int widthWidth = mResizeDrawableDiagonal.getIntrinsicWidth() / 2;
            int widthHeight = mResizeDrawableDiagonal.getIntrinsicHeight() / 2;
            mResizeDrawableDiagonal2.setBounds(left - widthWidth, top - widthHeight, left + widthWidth, top + widthHeight);
            mResizeDrawableDiagonal2.draw(canvas);
            mResizeDrawableDiagonal.setBounds(right - widthWidth, top - widthHeight, right + widthWidth, top + widthHeight);
            mResizeDrawableDiagonal.draw(canvas);
            mResizeDrawableDiagonal.setBounds(left - widthWidth, bottom - widthHeight, left + widthWidth, bottom + widthHeight);
            mResizeDrawableDiagonal.draw(canvas);
            mResizeDrawableDiagonal2.setBounds(right - widthWidth, bottom - widthHeight, right + widthWidth, bottom + widthHeight);
            mResizeDrawableDiagonal2.draw(canvas);
        }
    }
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) Rect(android.graphics.Rect) Region(android.graphics.Region) RegionIterator(android.graphics.RegionIterator) Paint(android.graphics.Paint)

Example 4 with RegionIterator

use of android.graphics.RegionIterator in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method onDraw.

@Override
public void onDraw(Canvas canvas) {
    if (inFullScreenMode()) {
        // no need to draw anything if we aren't visible.
        return;
    }
    // initialized. In either case, just draw the background color and return
    if (mNativeClass == 0) {
        canvas.drawColor(mBackgroundColor);
        return;
    }
    // just starts. Draw the background and return.
    if ((mContentWidth | mContentHeight) == 0 && mHistoryPicture == null) {
        canvas.drawColor(mBackgroundColor);
        return;
    }
    if (canvas.isHardwareAccelerated()) {
        mZoomManager.setHardwareAccelerated();
    } else {
        mWebViewCore.resumeWebKitDraw();
    }
    int saveCount = canvas.save();
    if (mInOverScrollMode && !getSettings().getUseWebViewBackgroundForOverscrollBackground()) {
        drawOverScrollBackground(canvas);
    }
    canvas.translate(0, getTitleHeight());
    drawContent(canvas);
    canvas.restoreToCount(saveCount);
    if (AUTO_REDRAW_HACK && mAutoRedraw) {
        invalidate();
    }
    mWebViewCore.signalRepaintDone();
    if (mOverScrollGlow != null && mOverScrollGlow.drawEdgeGlows(canvas)) {
        invalidate();
    }
    if (mFocusTransition != null) {
        mFocusTransition.draw(canvas);
    } else if (shouldDrawHighlightRect()) {
        RegionIterator iter = new RegionIterator(mTouchHighlightRegion);
        Rect r = new Rect();
        while (iter.next(r)) {
            canvas.drawRect(r, mTouchHightlightPaint);
        }
    }
    if (DEBUG_TOUCH_HIGHLIGHT) {
        if (getSettings().getNavDump()) {
            if ((mTouchHighlightX | mTouchHighlightY) != 0) {
                if (mTouchCrossHairColor == null) {
                    mTouchCrossHairColor = new Paint();
                    mTouchCrossHairColor.setColor(Color.RED);
                }
                canvas.drawLine(mTouchHighlightX - mNavSlop, mTouchHighlightY - mNavSlop, mTouchHighlightX + mNavSlop + 1, mTouchHighlightY + mNavSlop + 1, mTouchCrossHairColor);
                canvas.drawLine(mTouchHighlightX + mNavSlop + 1, mTouchHighlightY - mNavSlop, mTouchHighlightX - mNavSlop, mTouchHighlightY + mNavSlop + 1, mTouchCrossHairColor);
            }
        }
    }
}
Also used : Rect(android.graphics.Rect) RegionIterator(android.graphics.RegionIterator) Paint(android.graphics.Paint) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

Paint (android.graphics.Paint)4 Rect (android.graphics.Rect)4 RegionIterator (android.graphics.RegionIterator)4 Point (android.graphics.Point)3 Path (android.graphics.Path)1 RectF (android.graphics.RectF)1 Region (android.graphics.Region)1