public FaceRectView(Context context, AttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { mPaint = new Paint(); mPaint.Style = Paint.Style.STROKE; mMatrix = new Matrix(); mAspectRatio = new Matrix(); mRevisionZoomRect = new RectF(); mActualRect = new RectF(); mBoundRect = new RectF(); }
/// <summary>RoundRectShape constructor.</summary> /// <remarks> /// RoundRectShape constructor. /// Specifies an outer (round)rect and an optional inner (round)rect. /// </remarks> /// <param name="outerRadii"> /// An array of 8 radius values, for the outer roundrect. /// The first two floats are for the /// top-left corner (remaining pairs correspond clockwise). /// For no rounded corners on the outer rectangle, /// pass null. /// </param> /// <param name="inset"> /// A RectF that specifies the distance from the inner /// rect to each side of the outer rect. /// For no inner, pass null. /// </param> /// <param name="innerRadii"> /// An array of 8 radius values, for the inner roundrect. /// The first two floats are for the /// top-left corner (remaining pairs correspond clockwise). /// For no rounded corners on the inner rectangle, /// pass null. /// If inset parameter is null, this parameter is ignored. /// </param> public RoundRectShape(float[] outerRadii, android.graphics.RectF inset, float[] innerRadii ) { // this is what we actually draw if (outerRadii != null && outerRadii.Length < 8) { throw new System.IndexOutOfRangeException("outer radii must have >= 8 values"); } if (innerRadii != null && innerRadii.Length < 8) { throw new System.IndexOutOfRangeException("inner radii must have >= 8 values"); } mOuterRadii = outerRadii; mInset = inset; mInnerRadii = innerRadii; if (inset != null) { mInnerRect = new android.graphics.RectF(); } mPath = new android.graphics.Path(); }
/// <summary> /// Returns an immutable bitmap from subset of the source bitmap, /// transformed by the optional matrix. /// </summary> /// <remarks> /// Returns an immutable bitmap from subset of the source bitmap, /// transformed by the optional matrix. It is /// initialized with the same density as the original bitmap. /// </remarks> /// <param name="source">The bitmap we are subsetting</param> /// <param name="x">The x coordinate of the first pixel in source</param> /// <param name="y">The y coordinate of the first pixel in source</param> /// <param name="width">The number of pixels in each row</param> /// <param name="height">The number of rows</param> /// <param name="m">Optional matrix to be applied to the pixels</param> /// <param name="filter"> /// true if the source should be filtered. /// Only applies if the matrix contains more than just /// translation. /// </param> /// <returns>A bitmap that represents the specified subset of source</returns> /// <exception cref="System.ArgumentException"> /// if the x, y, width, height values are /// outside of the dimensions of the source bitmap. /// </exception> public static android.graphics.Bitmap createBitmap(android.graphics.Bitmap source , int x, int y, int width, int height, android.graphics.Matrix m, bool filter) { checkXYSign(x, y); checkWidthHeight(width, height); if (x + width > source.getWidth()) { throw new System.ArgumentException("x + width must be <= bitmap.width()"); } if (y + height > source.getHeight()) { throw new System.ArgumentException("y + height must be <= bitmap.height()"); } // check if we can just return our argument unchanged if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() && height == source.getHeight() && (m == null || m.isIdentity())) { return source; } int neww = width; int newh = height; android.graphics.Canvas canvas = new android.graphics.Canvas(); android.graphics.Bitmap bitmap; android.graphics.Paint paint; android.graphics.Rect srcR = new android.graphics.Rect(x, y, x + width, y + height ); android.graphics.RectF dstR = new android.graphics.RectF(0, 0, width, height); android.graphics.Bitmap.Config newConfig = android.graphics.Bitmap.Config.ARGB_8888; android.graphics.Bitmap.Config config = source.getConfig(); // GIF files generate null configs, assume ARGB_8888 if (config != null) { switch (config) { case android.graphics.Bitmap.Config.RGB_565: { newConfig = android.graphics.Bitmap.Config.RGB_565; break; } case android.graphics.Bitmap.Config.ALPHA_8: { newConfig = android.graphics.Bitmap.Config.ALPHA_8; break; } case android.graphics.Bitmap.Config.ARGB_4444: case android.graphics.Bitmap.Config.ARGB_8888: default: { //noinspection deprecation newConfig = android.graphics.Bitmap.Config.ARGB_8888; break; } } } if (m == null || m.isIdentity()) { bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha()); paint = null; } else { // not needed bool transformed = !m.rectStaysRect(); android.graphics.RectF deviceR = new android.graphics.RectF(); m.mapRect(deviceR, dstR); neww = Sharpen.Util.Round(deviceR.width()); newh = Sharpen.Util.Round(deviceR.height()); bitmap = createBitmap(neww, newh, transformed ? android.graphics.Bitmap.Config.ARGB_8888 : newConfig, transformed || source.hasAlpha()); canvas.translate(-deviceR.left, -deviceR.top); canvas.concat(m); paint = new android.graphics.Paint(); paint.setFilterBitmap(filter); if (transformed) { paint.setAntiAlias(true); } } // The new bitmap was created from a known bitmap source so assume that // they use the same density bitmap.mDensity = source.mDensity; canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); canvas.setBitmap(null); return bitmap; }
/// <summary>Draw one child of this View Group.</summary> /// <remarks> /// Draw one child of this View Group. This method is responsible for getting /// the canvas in the right state. This includes clipping, translating so /// that the child's scrolled origin is at 0, 0, and applying any animation /// transformations. /// </remarks> /// <param name="canvas">The canvas on which to draw the child</param> /// <param name="child">Who to draw</param> /// <param name="drawingTime">The time at which draw is occuring</param> /// <returns>True if an invalidate() was issued</returns> protected internal virtual bool drawChild(android.graphics.Canvas canvas, android.view.View child, long drawingTime) { bool more = false; int cl = child.mLeft; int ct = child.mTop; int cr = child.mRight; int cb = child.mBottom; bool childHasIdentityMatrix = child.hasIdentityMatrix(); int flags = mGroupFlags; if ((flags & FLAG_CLEAR_TRANSFORMATION) == FLAG_CLEAR_TRANSFORMATION) { mChildTransformation.clear(); mGroupFlags &= ~FLAG_CLEAR_TRANSFORMATION; } android.view.animation.Transformation transformToApply = null; android.view.animation.Transformation invalidationTransform; android.view.animation.Animation a = child.getAnimation(); bool concatMatrix = false; bool scalingRequired = false; bool caching; int layerType = mDrawLayers ? child.getLayerType() : LAYER_TYPE_NONE; bool hardwareAccelerated = canvas.isHardwareAccelerated(); if ((flags & FLAG_CHILDREN_DRAWN_WITH_CACHE) == FLAG_CHILDREN_DRAWN_WITH_CACHE || (flags & FLAG_ALWAYS_DRAWN_WITH_CACHE) == FLAG_ALWAYS_DRAWN_WITH_CACHE) { caching = true; if (mAttachInfo != null) { scalingRequired = mAttachInfo.mScalingRequired; } } else { caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; } if (a != null) { bool initialized = a.isInitialized(); if (!initialized) { a.initialize(cr - cl, cb - ct, getWidth(), getHeight()); a.initializeInvalidateRegion(0, 0, cr - cl, cb - ct); child.onAnimationStart(); } more = a.getTransformation(drawingTime, mChildTransformation, scalingRequired ? mAttachInfo .mApplicationScale : 1f); if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { if (mInvalidationTransformation == null) { mInvalidationTransformation = new android.view.animation.Transformation(); } invalidationTransform = mInvalidationTransformation; a.getTransformation(drawingTime, invalidationTransform, 1f); } else { invalidationTransform = mChildTransformation; } transformToApply = mChildTransformation; concatMatrix = a.willChangeTransformationMatrix(); if (more) { if (!a.willChangeBounds()) { if ((flags & (FLAG_OPTIMIZE_INVALIDATE | FLAG_ANIMATION_DONE)) == FLAG_OPTIMIZE_INVALIDATE) { mGroupFlags |= FLAG_INVALIDATE_REQUIRED; } else { if ((flags & FLAG_INVALIDATE_REQUIRED) == 0) { // The child need to draw an animation, potentially offscreen, so // make sure we do not cancel invalidate requests mPrivateFlags |= DRAW_ANIMATION; invalidate(cl, ct, cr, cb); } } } else { if (mInvalidateRegion == null) { mInvalidateRegion = new android.graphics.RectF(); } android.graphics.RectF region = mInvalidateRegion; a.getInvalidateRegion(0, 0, cr - cl, cb - ct, region, invalidationTransform); // The child need to draw an animation, potentially offscreen, so // make sure we do not cancel invalidate requests mPrivateFlags |= DRAW_ANIMATION; int left = cl + (int)region.left; int top = ct + (int)region.top; invalidate(left, top, left + (int)(region.width() + .5f), top + (int)(region.height () + .5f)); } } } else { if ((flags & FLAG_SUPPORT_STATIC_TRANSFORMATIONS) == FLAG_SUPPORT_STATIC_TRANSFORMATIONS) { bool hasTransform = getChildStaticTransformation(child, mChildTransformation); if (hasTransform) { int transformType = mChildTransformation.getTransformationType(); transformToApply = transformType != android.view.animation.Transformation.TYPE_IDENTITY ? mChildTransformation : null; concatMatrix = (transformType & android.view.animation.Transformation.TYPE_MATRIX ) != 0; } } } concatMatrix |= !childHasIdentityMatrix; // Sets the flag as early as possible to allow draw() implementations // to call invalidate() successfully when doing animations child.mPrivateFlags |= DRAWN; if (!concatMatrix && canvas.quickReject(cl, ct, cr, cb, android.graphics.Canvas.EdgeType .BW) && (child.mPrivateFlags & DRAW_ANIMATION) == 0) { return more; } float alpha = child.getAlpha(); // Bail out early if the view does not need to be drawn if (alpha <= android.view.ViewConfiguration.ALPHA_THRESHOLD && (child.mPrivateFlags & ALPHA_SET) == 0 && !(child is android.view.SurfaceView)) { return more; } if (hardwareAccelerated) { // Clear INVALIDATED flag to allow invalidation to occur during rendering, but // retain the flag's value temporarily in the mRecreateDisplayList flag child.mRecreateDisplayList = (child.mPrivateFlags & INVALIDATED) == INVALIDATED; child.mPrivateFlags &= ~INVALIDATED; } child.computeScroll(); int sx = child.mScrollX; int sy = child.mScrollY; android.view.DisplayList displayList = null; android.graphics.Bitmap cache = null; bool hasDisplayList = false; if (caching) { if (!hardwareAccelerated) { if (layerType != LAYER_TYPE_NONE) { layerType = LAYER_TYPE_SOFTWARE; child.buildDrawingCache(true); } cache = child.getDrawingCache(true); } else { switch (layerType) { case LAYER_TYPE_SOFTWARE: { child.buildDrawingCache(true); cache = child.getDrawingCache(true); break; } case LAYER_TYPE_NONE: { // Delay getting the display list until animation-driven alpha values are // set up and possibly passed on to the view hasDisplayList = child.canHaveDisplayList(); break; } } } } bool hasNoCache = cache == null || hasDisplayList; bool offsetForScroll = cache == null && !hasDisplayList && layerType != LAYER_TYPE_HARDWARE; int restoreTo = canvas.save(); if (offsetForScroll) { canvas.translate(cl - sx, ct - sy); } else { canvas.translate(cl, ct); if (scalingRequired) { // mAttachInfo cannot be null, otherwise scalingRequired == false float scale = 1.0f / mAttachInfo.mApplicationScale; canvas.scale(scale, scale); } } if (transformToApply != null || alpha < 1.0f || !child.hasIdentityMatrix()) { if (transformToApply != null || !childHasIdentityMatrix) { int transX = 0; int transY = 0; if (offsetForScroll) { transX = -sx; transY = -sy; } if (transformToApply != null) { if (concatMatrix) { // Undo the scroll translation, apply the transformation matrix, // then redo the scroll translate to get the correct result. canvas.translate(-transX, -transY); canvas.concat(transformToApply.getMatrix()); canvas.translate(transX, transY); mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; } float transformAlpha = transformToApply.getAlpha(); if (transformAlpha < 1.0f) { alpha *= transformToApply.getAlpha(); mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; } } if (!childHasIdentityMatrix) { canvas.translate(-transX, -transY); canvas.concat(child.getMatrix()); canvas.translate(transX, transY); } } if (alpha < 1.0f) { mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; if (hasNoCache) { int multipliedAlpha = (int)(255 * alpha); if (!child.onSetAlpha(multipliedAlpha)) { int layerFlags = android.graphics.Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; if ((flags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN || layerType != LAYER_TYPE_NONE) { layerFlags |= android.graphics.Canvas.CLIP_TO_LAYER_SAVE_FLAG; } if (layerType == LAYER_TYPE_NONE) { int scrollX = hasDisplayList ? 0 : sx; int scrollY = hasDisplayList ? 0 : sy; canvas.saveLayerAlpha(scrollX, scrollY, scrollX + cr - cl, scrollY + cb - ct, multipliedAlpha , layerFlags); } } else { // Alpha is handled by the child directly, clobber the layer's alpha child.mPrivateFlags |= ALPHA_SET; } } } } else { if ((child.mPrivateFlags & ALPHA_SET) == ALPHA_SET) { child.onSetAlpha(255); child.mPrivateFlags &= ~ALPHA_SET; } } if ((flags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN) { if (offsetForScroll) { canvas.clipRect(sx, sy, sx + (cr - cl), sy + (cb - ct)); } else { if (!scalingRequired || cache == null) { canvas.clipRect(0, 0, cr - cl, cb - ct); } else { canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); } } } if (hasDisplayList) { displayList = child.getDisplayList(); if (!displayList.isValid()) { // Uncommon, but possible. If a view is removed from the hierarchy during the call // to getDisplayList(), the display list will be marked invalid and we should not // try to use it again. displayList = null; hasDisplayList = false; } } if (hasNoCache) { bool layerRendered = false; if (layerType == LAYER_TYPE_HARDWARE) { android.view.HardwareLayer layer = child.getHardwareLayer(); if (layer != null && layer.isValid()) { child.mLayerPaint.setAlpha((int)(alpha * 255)); ((android.view.HardwareCanvas)canvas).drawHardwareLayer(layer, 0, 0, child.mLayerPaint ); layerRendered = true; } else { int scrollX = hasDisplayList ? 0 : sx; int scrollY = hasDisplayList ? 0 : sy; canvas.saveLayer(scrollX, scrollY, scrollX + cr - cl, scrollY + cb - ct, child.mLayerPaint , android.graphics.Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | android.graphics.Canvas.CLIP_TO_LAYER_SAVE_FLAG ); } } if (!layerRendered) { if (!hasDisplayList) { // Fast path for layouts with no backgrounds if ((child.mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { child.mPrivateFlags &= ~DIRTY_MASK; child.dispatchDraw(canvas); } else { child.draw(canvas); } } else { child.mPrivateFlags &= ~DIRTY_MASK; ((android.view.HardwareCanvas)canvas).drawDisplayList(displayList, cr - cl, cb - ct, null); } } } else { if (cache != null) { child.mPrivateFlags &= ~DIRTY_MASK; android.graphics.Paint cachePaint; if (layerType == LAYER_TYPE_NONE) { cachePaint = mCachePaint; if (alpha < 1.0f) { cachePaint.setAlpha((int)(alpha * 255)); mGroupFlags |= FLAG_ALPHA_LOWER_THAN_ONE; } else { if ((flags & FLAG_ALPHA_LOWER_THAN_ONE) == FLAG_ALPHA_LOWER_THAN_ONE) { cachePaint.setAlpha(255); mGroupFlags &= ~FLAG_ALPHA_LOWER_THAN_ONE; } } } else { cachePaint = child.mLayerPaint; cachePaint.setAlpha((int)(alpha * 255)); } canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); } } canvas.restoreToCount(restoreTo); if (a != null && !more) { if (!hardwareAccelerated && !a.getFillAfter()) { child.onSetAlpha(255); } finishAnimatingView(child, a); } if (more && hardwareAccelerated) { // invalidation is the trigger to recreate display lists, so if we're using // display lists to render, force an invalidate to allow the animation to // continue drawing another frame invalidate(true); if (a.hasAlpha() && (child.mPrivateFlags & ALPHA_SET) == ALPHA_SET) { // alpha animations should cause the child to recreate its display list child.invalidate(true); } } child.mRecreateDisplayList = false; return more; }
public RoundRectShape(float[] arg0, android.graphics.RectF arg1, float[] arg2) : base(global::MonoJavaBridge.JNIEnv.ThreadEnv) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject(android.graphics.drawable.shapes.RoundRectShape.staticClass, global::android.graphics.drawable.shapes.RoundRectShape._RoundRectShape4243, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2)); Init(@__env, handle); }
public override void drawPatch(android.graphics.Bitmap bitmap, byte[] chunks, android.graphics.RectF dst, android.graphics.Paint paint) { throw new System.NotImplementedException(); }
public override void drawRoundRect(android.graphics.RectF rect, float rx, float ry , android.graphics.Paint paint) { throw new System.NotImplementedException(); }
public override void drawOval(android.graphics.RectF oval, android.graphics.Paint paint) { throw new System.NotImplementedException(); }
public override void drawBitmap(android.graphics.Bitmap bitmap, android.graphics.Rect src, android.graphics.RectF dst, android.graphics.Paint paint) { throw new System.NotImplementedException(); }
public RectF(android.graphics.RectF arg0) : base(global::MonoJavaBridge.JNIEnv.ThreadEnv) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject(android.graphics.RectF.staticClass, global::android.graphics.RectF._RectF3741, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)); Init(@__env, handle); }
public static bool intersects(android.graphics.RectF arg0, android.graphics.RectF arg1) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; return(@__env.CallStaticBooleanMethod(android.graphics.RectF.staticClass, global::android.graphics.RectF._intersects3720, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1))); }
public LayoutParams(StackView _enclosing, android.content.Context c, android.util.AttributeSet attrs) : base(c, attrs) { this._enclosing = _enclosing; parentRect = new android.graphics.Rect(); invalidateRect = new android.graphics.Rect(); invalidateRectf = new android.graphics.RectF(); globalInvalidateRect = new android.graphics.Rect(); this.horizontalOffset = 0; this.verticalOffset = 0; this.width = 0; this.height = 0; }
internal LayoutParams(StackView _enclosing, android.view.View view) : base(0, 0) { this._enclosing = _enclosing; parentRect = new android.graphics.Rect(); invalidateRect = new android.graphics.Rect(); invalidateRectf = new android.graphics.RectF(); globalInvalidateRect = new android.graphics.Rect(); this.width = 0; this.height = 0; this.horizontalOffset = 0; this.verticalOffset = 0; this.mView = view; }
private void init(android.content.Context context) { // Get both the scrollbar states drawables android.content.res.TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS ); useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE)); mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE); mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT); mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT); mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING); mScrollCompleted = true; getSectionsFromIndexer(); mOverlaySize = context.getResources().getDimensionPixelSize([email protected] .fastscroll_overlay_size); mOverlayPos = new android.graphics.RectF(); mScrollFade = new android.widget.FastScroller.ScrollFade(this); mPaint = new android.graphics.Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(android.graphics.Paint.Align.CENTER); mPaint.setTextSize(mOverlaySize / 2); android.content.res.ColorStateList textColor = ta.getColorStateList(TEXT_COLOR); int textColorNormal = textColor.getDefaultColor(); mPaint.setColor(textColorNormal); mPaint.setStyle(android.graphics.Paint.Style.FILL_AND_STROKE); // to show mOverlayDrawable properly if (mList.getWidth() > 0 && mList.getHeight() > 0) { onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0); } mState = STATE_NONE; refreshDrawableState(); ta.recycle(); mScaledTouchSlop = android.view.ViewConfiguration.get(context).getScaledTouchSlop (); mMatchDragPosition = context.getApplicationInfo().targetSdkVersion >= android.os.Build .VERSION_CODES.HONEYCOMB; setScrollbarPosition(mList.getVerticalScrollbarPosition()); }
internal android.graphics.Path buildRing(android.graphics.drawable.GradientDrawable .GradientState st) { if (mRingPath != null && (!st.mUseLevelForShape || !mPathIsDirty)) { return mRingPath; } mPathIsDirty = false; float sweep = st.mUseLevelForShape ? (360.0f * getLevel() / 10000.0f) : 360f; android.graphics.RectF bounds = new android.graphics.RectF(mRect); float x = bounds.width() / 2.0f; float y = bounds.height() / 2.0f; float thickness = st.mThickness != -1 ? st.mThickness : bounds.width() / st.mThicknessRatio; // inner radius float radius = st.mInnerRadius != -1 ? st.mInnerRadius : bounds.width() / st.mInnerRadiusRatio; android.graphics.RectF innerBounds = new android.graphics.RectF(bounds); innerBounds.inset(x - radius, y - radius); bounds = new android.graphics.RectF(innerBounds); bounds.inset(-thickness, -thickness); if (mRingPath == null) { mRingPath = new android.graphics.Path(); } else { mRingPath.reset(); } android.graphics.Path ringPath = mRingPath; // arcTo treats the sweep angle mod 360, so check for that, since we // think 360 means draw the entire oval if (sweep < 360 && sweep > -360) { ringPath.setFillType(android.graphics.Path.FillType.EVEN_ODD); // inner top ringPath.moveTo(x + radius, y); // outer top ringPath.lineTo(x + radius + thickness, y); // outer arc ringPath.arcTo(bounds, 0.0f, sweep, false); // inner arc ringPath.arcTo(innerBounds, sweep, -sweep, false); ringPath.close(); } else { // add the entire ovals ringPath.addOval(bounds, android.graphics.Path.Direction.CW); ringPath.addOval(innerBounds, android.graphics.Path.Direction.CCW); } return ringPath; }