/** * Drawing src bitmap to dest bitmap with rounded corners * * @param src source bitmap * @param dest destination bitmap * @param radius radius in destination bitmap scale * @param clearColor clear color */ public static void drawRoundedCorners(Bitmap src, Bitmap dest, int radius, int clearColor) { clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); Rect sourceRect = WorkCache.RECT1.get(); Rect destRect = WorkCache.RECT2.get(); sourceRect.set(0, 0, src.getWidth(), src.getHeight()); destRect.set(0, 0, dest.getWidth(), dest.getHeight()); RectF roundRect = WorkCache.RECTF1.get(); roundRect.set(0, 0, dest.getWidth(), dest.getHeight()); Paint paint = WorkCache.PAINT.get(); paint.reset(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setAntiAlias(true); canvas.drawRoundRect(roundRect, radius, radius, paint); paint.reset(); paint.setFilterBitmap(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, sourceRect, destRect, paint); canvas.setBitmap(null); }
private void drawPlaceHolder(Canvas canvas) { placeholderPaint.setColor(layout.placeHolderColor); placeholderTextPaint.setAlpha(255); placeholderPaint.setAlpha(255); avatarPaint.setAlpha(255); rect.set( layout.layoutAvatarLeft, layout.layoutAvatarTop, layout.layoutAvatarLeft + layout.layoutAvatarWidth, layout.layoutAvatarTop + layout.layoutAvatarWidth); canvas.drawRect(rect, placeholderPaint); if (layout.usePlaceholder) { canvas.drawText( layout.placeHolderName, layout.placeholderLeft, layout.placeholderTop, placeholderTextPaint); } else { rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight()); canvas.drawBitmap(placeholder, rect2, rect, avatarPaint); } }
/** * Drawing src bitmap to dest bitmap with round mask. Dest might be squared, src is recommended to * be square * * @param src source bitmap * @param dest destination bitmap * @param clearColor clear color */ public static void drawInRound(Bitmap src, Bitmap dest, int clearColor) { if (dest.getWidth() != dest.getHeight()) { throw new RuntimeException("dest Bitmap must have square size"); } clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); int r = dest.getWidth() / 2; Rect sourceRect = WorkCache.RECT1.get(); Rect destRect = WorkCache.RECT2.get(); sourceRect.set(0, 0, src.getWidth(), src.getHeight()); destRect.set(0, 0, dest.getWidth(), dest.getHeight()); Paint paint = WorkCache.PAINT.get(); paint.reset(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setAntiAlias(true); canvas.drawCircle(r, r, r, paint); paint.reset(); paint.setFilterBitmap(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, sourceRect, destRect, paint); canvas.setBitmap(null); }
/** * Gets the crop window's position relative to the source Bitmap (not the image displayed in the * CropImageView) and the original rotation. * * @return a RectF instance containing cropped area boundaries of the source Bitmap */ @SuppressWarnings("SuspiciousNameCombination") public Rect getActualCropRectNoRotation() { if (mBitmap != null) { Rect rect = getActualCropRect(); int rotateSide = mDegreesRotated / 90; if (rotateSide == 1) { rect.set( rect.top, mBitmap.getWidth() - rect.right, rect.bottom, mBitmap.getWidth() - rect.left); } else if (rotateSide == 2) { rect.set( mBitmap.getWidth() - rect.right, mBitmap.getHeight() - rect.bottom, mBitmap.getWidth() - rect.left, mBitmap.getHeight() - rect.top); } else if (rotateSide == 3) { rect.set( mBitmap.getHeight() - rect.bottom, rect.left, mBitmap.getHeight() - rect.top, rect.right); } rect.set( rect.left * mLoadedSampleSize, rect.top * mLoadedSampleSize, rect.right * mLoadedSampleSize, rect.bottom * mLoadedSampleSize); return rect; } else { return null; } }
@Override protected void onDraw(Canvas canvas) { if (mImage != null) { // Switch the current animation if needed. if (mCurrentAnim == null || mCurrentAnim.hasEnded()) switchAnimation(canvas); // Animate and draw mCurrentAnim.getTransformation(AnimationUtils.currentAnimationTimeMillis(), mTrans); mStartPos[0] = 0; mStartPos[1] = 0; mTrans.getMatrix().mapPoints(mStartPos); mSrc.set(0, 0, mImage.getWidth(), mImage.getHeight()); mDst.set( (int) mStartPos[0], (int) mStartPos[1], (int) mStartPos[0] + mScaledImageWidth, (int) mStartPos[1] + mScaledImageHeight); mPaint.setFilterBitmap(true); canvas.drawBitmap(mImage, mSrc, mDst, mPaint); super.onDraw(canvas); // Request another draw operation until time is up. invalidate(); } }
@Override protected void onDraw(Canvas canvas) { int i = 1; if (percentList != null && !percentList.isEmpty()) { for (Float f : percentList) { rect.set( BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin, (BAR_SIDE_MARGIN + barWidth) * i, getHeight() - bottomTextHeight - TEXT_TOP_MARGIN); canvas.drawRect(rect, bgPaint); rect.set( BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin + (int) ((getHeight() - topMargin) * percentList.get(i - 1)), (BAR_SIDE_MARGIN + barWidth) * i, getHeight() - bottomTextHeight - TEXT_TOP_MARGIN); canvas.drawRect(rect, fgPaint); i++; } } if (bottomTextList != null && !bottomTextList.isEmpty()) { i = 1; for (String s : bottomTextList) { canvas.drawText( s, BAR_SIDE_MARGIN * i + barWidth * (i - 1) + barWidth / 2, getHeight() - bottomTextDescent, textPaint); i++; } } }
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (mInsets != null && mInsetForeground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); // Top mTempRect.set(0, 0, width, mInsets.top); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Bottom mTempRect.set(0, height - mInsets.bottom, width, height); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Left mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Right mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); canvas.restoreToCount(sc); } }
@Override public void draw(@NonNull final Canvas canvas) { super.draw(canvas); // Only recalculate the close bounds if they are dirty if (mCloseBoundChanged) { mCloseBoundChanged = false; mClosableLayoutRect.set(0, 0, getWidth(), getHeight()); // Create the bounds for our close regions. applyCloseRegionBounds(mClosePosition, mClosableLayoutRect, mCloseRegionBounds); // The inset rect applies padding around the visible closeButton. mInsetCloseRegionBounds.set(mCloseRegionBounds); mInsetCloseRegionBounds.inset(mCloseButtonPadding, mCloseButtonPadding); // The close button sits inside the close region with padding and gravity // in the same way the close region sits inside the whole ClosableLayout applyCloseButtonBounds(mClosePosition, mInsetCloseRegionBounds, mCloseButtonBounds); mCloseDrawable.setBounds(mCloseButtonBounds); } // Draw last so that this gets drawn as the top layer. This is also why we override // draw instead of onDraw. if (mCloseDrawable.isVisible()) { mCloseDrawable.draw(canvas); } }
@Override protected void onDraw(Canvas canvas) { Drawable backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (ApplicationLoader.isCustomTheme() && backgroundDrawable != null) { phoneTextView.setTextColor(0xffffffff); shadowView.setVisibility(VISIBLE); if (backgroundDrawable instanceof ColorDrawable) { backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); backgroundDrawable.draw(canvas); } else if (backgroundDrawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap(); float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth(); float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight(); float scale = scaleX < scaleY ? scaleY : scaleX; int width = (int) (getMeasuredWidth() / scale); int height = (int) (getMeasuredHeight() / scale); int x = (bitmap.getWidth() - width) / 2; int y = (bitmap.getHeight() - height) / 2; srcRect.set(x, y, x + width, y + height); destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawBitmap(bitmap, srcRect, destRect, paint); } } else { shadowView.setVisibility(INVISIBLE); phoneTextView.setTextColor(0xffc2e5ff); super.onDraw(canvas); } }
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mContent.set( getPaddingLeft(), getPaddingTop(), r - l - getPaddingRight(), b - t - getPaddingBottom()); final int width = mContent.width(); final int height = mContent.height(); // no scrolling yet, so tell dimensions to fill exactly mHoriz.setSize(width); mVert.setSize(height); final Rect parentRect = new Rect(); final Rect childRect = new Rect(); for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); final LayoutParams params = (LayoutParams) child.getLayoutParams(); parentRect.set(mContent); if (child instanceof ChartNetworkSeriesView || child instanceof ChartGridView) { // series are always laid out to fill entire graph area // TODO: handle scrolling for series larger than content area Gravity.apply(params.gravity, width, height, parentRect, childRect); child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom); } else if (child instanceof ChartSweepView) { layoutSweep((ChartSweepView) child, parentRect, childRect); child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom); } } }
protected void onDraw(Canvas canvas) { this; JVM INSTR monitorenter ; c.set(getThumbOffset(), getHeight() / 2 - f / 4, getWidth() - getThumbOffset(), getHeight() / 2 + f / 4); d.setColor(0xff888888); canvas.drawRect(c, d); int i = getWidth(); int j = getHeight(); canvas.drawBitmap(e, i / 2 - e.getWidth() / 2, j / 2 - e.getHeight() / 2, null); if (getProgress() > 500) { c.set(getWidth() / 2, getHeight() / 2 - f / 2, (getWidth() / 2 + (getWidth() * (getProgress() - 500)) / 1000) - ((getProgress() - 500) * getThumbOffset()) / 500, getHeight() / 2 + f / 2); d.setColor(g.getResources().getColor(0x7f0f0007)); canvas.drawRect(c, d); } if (getProgress() < 500) { c.set((getWidth() / 2 - (getWidth() * (500 - getProgress())) / 1000) + ((500 - getProgress()) * getThumbOffset()) / 500, getHeight() / 2 - f / 2, getWidth() / 2, getHeight() / 2 + f / 2); d.setColor(g.getResources().getColor(0x7f0f0007)); canvas.drawRect(c, d); } super.onDraw(canvas); this; JVM INSTR monitorexit ; return; canvas; throw canvas; }
@Override public void onDraw(final Canvas canvas) { final int frame = mCurrentFrame++; if (mVerticalFrames) { final int top = mFrameSize.y * frame; mSource.set(0, top, mFrameSize.x, top + mFrameSize.y); } else { final int left = mFrameSize.x * frame; mSource.set(left, 0, left + mFrameSize.x, mFrameSize.y); } final int destWidth = mTileModeX == Shader.TileMode.REPEAT ? mScaledSize.x : mDestination.width(); final int destHeight = mTileModeY == Shader.TileMode.REPEAT ? mScaledSize.y : mDestination.height(); for (int l = mDestination.left, r = mDestination.right; l < r; l += destWidth) { for (int t = mDestination.top, b = mDestination.bottom; t < b; t += destHeight) { mTempDestination.left = l; mTempDestination.right = l + destWidth; mTempDestination.top = t; mTempDestination.bottom = t + destHeight; canvas.drawBitmap(mBitmap, mSource, mTempDestination, mPaint); } } if (mCurrentFrame >= mFrames) { mCurrentFrame = 0; } }
@Override protected void onDraw(Canvas canvas) { if (processor.isLoaded()) { int offsetLeft = (getWidth() - countInRow * smileySize) / 2; for (int i = 0; i < smileyIds.length; i++) { int row = i / countInRow; int col = i % countInRow; rect.set( col * smileySize + smileyPadding + offsetLeft, row * smileySize + smileyPadding, (col + 1) * smileySize - smileyPadding + offsetLeft, (row + 1) * smileySize - smileyPadding); if (!canvas.quickReject(rect.left, rect.top, rect.right, rect.bottom, Canvas.EdgeType.AA)) { Bitmap img = processor.getSection(smileysSections[i]); if (img != null) { sectionRect.set( smileysX[i] * smileySrcSize, smileysY[i] * smileySrcSize, (smileysX[i] + 1) * smileySrcSize, (smileysY[i] + 1) * smileySrcSize); canvas.drawBitmap(img, sectionRect, rect, paint); } } } } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw the entire background battery image in gray Rect srcRect = new Rect(0, 0, silhouette.getWidth(), silhouette.getHeight()); Rect destRect = new Rect(0, 0, getWidth(), getHeight()); canvas.drawBitmap(silhouette, srcRect, destRect, gray); Paint fillPaint; if (levelPercent < 20) { fillPaint = red; } else if (levelPercent < 50) { fillPaint = yellow; } else { fillPaint = green; } // draw a portion of the foreground battery image with the width coming from levelPercent. srcRect.set(0, 0, (int) (silhouette.getWidth() * levelPercent / 100f), silhouette.getHeight()); destRect.set(0, 0, (int) (getWidth() * levelPercent / 100f), getHeight()); canvas.drawBitmap(silhouette, srcRect, destRect, fillPaint); if (pluggedIn) { srcRect.set(0, 0, plug.getWidth(), plug.getHeight()); destRect.set(getWidth() / 5, getHeight() / 5, (getWidth() * 4) / 5, (getHeight() * 4) / 5); canvas.drawBitmap(plug, srcRect, destRect, new Paint()); } }
/** {@inheritDoc} */ @Override public void draw(Canvas canvas) { super.draw(canvas); if (mForeground != null) { final Drawable foreground = mForeground; if (mForegroundBoundsChanged) { mForegroundBoundsChanged = false; final Rect selfBounds = mSelfBounds; final Rect overlayBounds = mOverlayBounds; final int w = mRight - mLeft; final int h = mBottom - mTop; if (mForegroundInPadding) { selfBounds.set(0, 0, w, h); } else { selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom); } final int layoutDirection = getLayoutDirection(); Gravity.apply( mForegroundGravity, foreground.getIntrinsicWidth(), foreground.getIntrinsicHeight(), selfBounds, overlayBounds, layoutDirection); foreground.setBounds(overlayBounds); } foreground.draw(canvas); } }
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); if (mMoveDeltX > 0 || mMoveDeltX == 0 && mSwitchOn) { if (mSrc != null) { mSrc.set( mMoveLength - mMoveDeltX, 0, mSwitchBottom.getWidth() - mMoveDeltX, mSwitchFrame.getHeight()); } } else if (mMoveDeltX < 0 || mMoveDeltX == 0 && !mSwitchOn) { if (mSrc != null) { mSrc.set(-mMoveDeltX, 0, mSwitchFrame.getWidth() - mMoveDeltX, mSwitchFrame.getHeight()); } } Log.d("mAlpha", "mAlpha:" + mAlpha); canvas.saveLayerAlpha( new RectF(mDest), mAlpha, Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); canvas.drawBitmap(mSwitchBottom, mSrc, mDest, null); canvas.drawBitmap(mSwitchThumb, mSrc, mDest, null); canvas.drawBitmap(mSwitchFrame, 0, 0, null); canvas.drawBitmap(mSwitchMask, 0, 0, mPaint); canvas.restore(); }
/** * Draw debug information on the Canvas * * @param c Canvas to draw to */ private void drawDebugInfo(Canvas c) { paint.setColor(Color.WHITE); paint.setTextSize(10); // Draw FPS c.drawText("FPS: " + dispFps, screenDims.x - 40, 10, paint); // Draw last touch c.drawText("Last touch: " + lastTouch.x + "," + lastTouch.y, screenDims.x - 95, 25, paint); // Draw worker/renderer ratio bar if (renderTime != 0) { paint.setColor(resources.getColor(android.R.color.holo_green_dark)); ratioBarOuter.set(screenDims.x - 300, 30, screenDims.x, 40); c.drawRect(ratioBarOuter, paint); float percentage = ((float) updateTime / (float) renderTime); percentage *= 100.0F; int workerBarWidth = (int) percentage; workerBarWidth *= 3; // For 100px on a 300px bar // report("drawDebugInfo()", "W/R: " + (updateTime) + "/" + (renderTime) + " = " + // percentage + " for " + workerBarWidth + " px width"); paint.setColor(resources.getColor(android.R.color.holo_green_light)); ratioBarWorker.set(screenDims.x - 300, 30, (screenDims.x - 300) + workerBarWidth, 40); c.drawRect(ratioBarWorker, paint); } // Draw log console if (console == null) console = new Console(); console.draw(c); }
@Override protected void onDraw(Canvas canvas) { final Drawable background = mBackground; final int right = getWidth(); final int bottom = getHeight(); // Draw behind recents if (mOrientation == VERTICAL) { mDrawRect.set(0, 0, right, mFavoritesStart); } else { mDrawRect.set(0, 0, mFavoritesStart, bottom); } background.setBounds(mDrawRect); background.draw(canvas); // Draw behind favorites if (mFavoritesStart > -1) { if (mOrientation == VERTICAL) { mDrawRect.set(0, mFavoritesStart, right, mFavoritesEnd); } else { mDrawRect.set(mFavoritesStart, 0, mFavoritesEnd, bottom); } background.setBounds(mDrawRect); background.draw(canvas); } super.onDraw(canvas); }
private void getScreenBitmap() { mView.getRootView().destroyDrawingCache(); mView.getGlobalVisibleRect(mRect, point); realheight = mView.getHeight(); realwidth = mView.getWidth(); dst.set(0, 0, realwidth, realheight); int w = Math.round(realwidth * BITMAP_RATIO); int h = Math.round(realheight * BITMAP_RATIO); w = w & ~0x03; h = h & ~0x03; if (w <= 0 || h <= 0) return; if (bitmap == null || bitmap.getWidth() != w || bitmap.getHeight() != h) { bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mMatrix.setScale(BITMAP_RATIO, BITMAP_RATIO); mMatrix.invert(mDrawMatrix); src.set(0, 0, w, h); } float dx = -(Math.min(0, mView.getLeft()) + mRect.left); float dy = (-point.y); mCanvas.restoreToCount(1); mCanvas.setBitmap(bitmap); mCanvas.setMatrix(mMatrix); mCanvas.translate(dx, dy); mCanvas.save(); mView.getRootView().draw(mCanvas); }
/** 画面サイズから自位置を決定します。 */ private void updateViewLayout() { cancelAnimation(); // 前の画面座標を保存 final int oldScreenHeight = mMetrics.heightPixels; final int oldScreenWidth = mMetrics.widthPixels; final int oldPositionLimitWidth = mPositionLimitRect.width(); final int oldPositionLimitHeight = mPositionLimitRect.height(); // 新しい座標情報に切替 mWindowManager.getDefaultDisplay().getMetrics(mMetrics); final int width = getMeasuredWidth(); final int height = getMeasuredHeight(); final int newScreenWidth = mMetrics.widthPixels; final int newScreenHeight = mMetrics.heightPixels; // 移動範囲の設定 mMoveLimitRect.set(-width, -height * 2, newScreenWidth + width, newScreenHeight + height); mPositionLimitRect.set( -mOverMargin, 0, newScreenWidth - width + mOverMargin, newScreenHeight - mStatusBarHeight - height); // 縦横切替の場合 if (oldScreenWidth != newScreenWidth || oldScreenHeight != newScreenHeight) { // 画面端に移動する場合は現在の位置から左右端を設定 if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_DEFAULT) { // 右半分にある場合 if (mParams.x > (newScreenWidth - width) / 2) { mParams.x = mPositionLimitRect.right; } // 左半分にある場合 else { mParams.x = mPositionLimitRect.left; } } // 左端に移動 else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_LEFT) { mParams.x = mPositionLimitRect.left; } // 右端に移動 else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_RIGHT) { mParams.x = mPositionLimitRect.right; } // 画面端に移動しない場合は画面座標の比率から計算 else { final int newX = (int) (mParams.x * mPositionLimitRect.width() / (float) oldPositionLimitWidth + 0.5f); mParams.x = Math.min(Math.max(mPositionLimitRect.left, newX), mPositionLimitRect.right); } // スクリーン位置の比率からY座標を設定(四捨五入) final int newY = (int) (mParams.y * mPositionLimitRect.height() / (float) oldPositionLimitHeight + 0.5f); mParams.y = Math.min(Math.max(mPositionLimitRect.top, newY), mPositionLimitRect.bottom); mWindowManager.updateViewLayout(this, mParams); } }
@Override public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } }
/** * 给divider预留空间 与padding或margin类似,LayoutManager在测量阶段会调用该方法,计算出每一个Item的正确尺寸并设置偏移量。 * * @param outRect * @param view * @param parent * @param state */ @Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (OrientationHelper.HORIZONTAL == orientation) { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } else { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } }
@Override public void getItemOffsets( @NonNull Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } }
/** * 设置item分割线的size * * @param outRect * @param view * @param parent * @param state */ @Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (mOrientation == LinearLayoutManager.VERTICAL) { outRect.set(0, 0, 0, mItemSize); } else { outRect.set(0, 0, mItemSize, 0); } }
public void setFrameHeight(int height) { mFrameHeight = height; mBackgroundRect.set(0, 0, getMeasuredWidth(), Math.min(mFrameHeight, getMeasuredHeight())); mForegroundRect.set( mFrameStrokeAdjustment, mFrameStrokeAdjustment, getMeasuredWidth() - mFrameStrokeAdjustment, Math.min(getMeasuredHeight(), mFrameHeight) - mFrameStrokeAdjustment); updateGradient(); invalidate(); }
/** * Returns the frame Rect for applications runs under compatibility mode. * * @param dm the display metrics used to compute the frame size. * @param orientation the orientation of the screen. * @param outRect the output parameter which will contain the result. */ public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation, Rect outRect) { int width = dm.widthPixels; int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density + 0.5f); int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density + 0.5f); if (orientation == Configuration.ORIENTATION_LANDSCAPE) { int xOffset = (width - portraitHeight) / 2; outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth); } else { int xOffset = (width - portraitWidth) / 2; outRect.set(xOffset, 0, xOffset + portraitWidth, portraitHeight); } }
/** * Returns the task stack bounds in the current orientation. These bounds do not account for the * system insets. */ public void getTaskStackBounds( int windowWidth, int windowHeight, int topInset, int rightInset, Rect taskStackBounds) { Rect searchBarBounds = new Rect(); getSearchBarBounds(windowWidth, windowHeight, topInset, searchBarBounds); if (isLandscape && hasTransposedSearchBar) { // In landscape, the search bar appears on the left, but we overlay it on top taskStackBounds.set(0, topInset, windowWidth - rightInset, windowHeight); } else { // In portrait, the search bar appears on the top (which already has the inset) taskStackBounds.set(0, searchBarBounds.bottom, windowWidth, windowHeight); } }
@Override public void handleTile( final Canvas pCanvas, final int pTileSizePx, final MapTile pTile, final int pX, final int pY) { // no overflow detected here Log.d(IMapView.LOGTAG, "handleTile " + pTile.toString() + // ","+pX + "," + pY); Drawable currentMapTile = mTileProvider.getMapTile(pTile); boolean isReusable = currentMapTile instanceof ReusableBitmapDrawable; final ReusableBitmapDrawable reusableBitmapDrawable = isReusable ? (ReusableBitmapDrawable) currentMapTile : null; if (currentMapTile == null) { currentMapTile = getLoadingTile(); } if (currentMapTile != null) { mTilePoint.set(pX * pTileSizePx, pY * pTileSizePx); mTileRect.set( mTilePoint.x, mTilePoint.y, mTilePoint.x + pTileSizePx, mTilePoint.y + pTileSizePx); if (isReusable) { reusableBitmapDrawable.beginUsingDrawable(); } try { if (isReusable && !((ReusableBitmapDrawable) currentMapTile).isBitmapValid()) { currentMapTile = getLoadingTile(); isReusable = false; } onTileReadyToDraw(pCanvas, currentMapTile, mTileRect); } finally { if (isReusable) reusableBitmapDrawable.finishUsingDrawable(); } } if (DEBUGMODE) { mTileRect.set( pX * pTileSizePx, pY * pTileSizePx, pX * pTileSizePx + pTileSizePx, pY * pTileSizePx + pTileSizePx); pCanvas.drawText( pTile.toString(), mTileRect.left + 1, mTileRect.top + mDebugPaint.getTextSize(), mDebugPaint); pCanvas.drawLine( mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mDebugPaint); pCanvas.drawLine( mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mDebugPaint); } }
private void propagateViewportToLayouts(int contentWidth, int contentHeight) { int heightMinusTopControls = contentHeight - getTopControlsHeightPixels(); mCacheViewport.set(0, (int) mLastContentOffset, contentWidth, contentHeight); mCacheVisibleViewport.set(0, (int) mLastVisibleContentOffset, contentWidth, contentHeight); // TODO(changwan): check if this can be merged with setContentMotionEventOffsets. if (mTabVisible != null && mTabVisible.getContentViewCore() != null) { mTabVisible .getContentViewCore() .setSmartClipOffsets(-mCacheViewport.left, -mCacheViewport.top); } if (mLayoutManager != null) { mLayoutManager.pushNewViewport(mCacheViewport, mCacheVisibleViewport, heightMinusTopControls); } }
@Override public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { int spanCount = getSpanCount(parent); int childCount = parent.getAdapter().getItemCount(); if (isLastRaw(parent, itemPosition, spanCount, childCount)) // 如果是最后一行,则不需要绘制底部 { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } else if (isLastColum(parent, itemPosition, spanCount, childCount)) // 如果是最后一列,则不需要绘制右边 { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } }