/** * Draw underline * * @param canvas The canvas */ private void drawUnderline(Canvas canvas) { if (mShowUnderline) { View parent = (View) getParent(); if (parent != null && (parent.getPaddingLeft() != 0 || parent.getPaddingRight() != 0)) { final int pPaddingLeft = parent.getPaddingLeft(); final int pPaddingRight = parent.getPaddingRight(); canvas.save(); // allow drawing out of bounds Rect clipBounds = canvas.getClipBounds(); clipBounds.inset(-(pPaddingLeft + pPaddingRight), 0); canvas.clipRect(clipBounds, Region.Op.REPLACE); if (mUnderlineGravity == UnderlineGravity.TOP) { // If on top ignore bottom padding canvas.drawRect( -pPaddingLeft, mUnderlinePaddingTop, getWidth() + pPaddingLeft + pPaddingRight, mUnderlineHeight + mUnderlinePaddingTop, mUnderlinePaint); } else { // If on bottom ignore top padding canvas.drawRect( -pPaddingLeft, getHeight() - mUnderlineHeight - mUnderlinePaddingBottom, getWidth() + pPaddingLeft + pPaddingRight, getHeight() - mUnderlinePaddingBottom, mUnderlinePaint); } canvas.restore(); } else { if (mUnderlineGravity == UnderlineGravity.TOP) { // If on top ignore bottom padding canvas.drawRect( 0, mUnderlinePaddingTop, getWidth(), mUnderlineHeight + mUnderlinePaddingTop, mUnderlinePaint); } else { // If on bottom ignore top padding canvas.drawRect( 0, getHeight() - mUnderlineHeight - mUnderlinePaddingBottom, getWidth(), getHeight() - mUnderlinePaddingBottom, mUnderlinePaint); } } } }
private void onDraw0(Canvas canvas) { if (Constants.LOG_V) Log.v(TAG, "onDraw(" + canvas.getClipBounds() + ")"); canvas.save(); canvas.translate(offsetX, offsetY); canvas.clipRect(0, 0, size * cellWidth, size * cellHeight); Rect clipBounds = canvas.getClipBounds(); if (theme.isDrawAreaColors(puzzle.getPuzzleType())) drawAreaColors(canvas, clipBounds); else drawBackground(canvas); drawExtraRegions(canvas, clipBounds); if (puzzle.isSolved()) drawCongrats(canvas); else if (paused) drawPaused(canvas); else { drawHighlightedCells(canvas, clipBounds); drawMarkedPosition(canvas); } if (!preview && puzzle.hasErrors()) drawErrors(canvas, clipBounds); drawValues(canvas, clipBounds); drawGrid(canvas); drawRegionBorders(canvas, clipBounds); canvas.restore(); drawOuterBorder(canvas); }
protected void onDraw(Canvas paramCanvas) { // today round if (mIsToday) { Paint painta = new Paint(); painta.setStyle(Paint.Style.STROKE); painta.setColor(Color.BLACK); painta.setAntiAlias(true); Rect rect = paramCanvas.getClipBounds(); RectF rt = new RectF(rect); rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12); paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 5, getMeasuredHeight() / 5, painta); Paint paintb = new Paint(); paintb.setColor(Color.GRAY); paintb.setAntiAlias(true); paintb.setAlpha(50); paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 6, getMeasuredWidth() / 6, paintb); } // solar text Paint paint1 = new Paint(); paint1.setAntiAlias(true); paint1.setFakeBoldText(true); paint1.setTextSize(getMeasuredWidth() / 2); if (mDay.mIsWeekEnd) { paint1.setColor(ECalendarActivity.mHolidayColor); } else { paint1.setColor(Color.BLACK); } Rect text = new Rect(); paint1.getTextBounds(mDay.mSolarDay, 0, mDay.mSolarDay.length(), text); int w = getMeasuredWidth(); int w1 = text.width(); float fw = (w - w1) / 2; float fh = getMeasuredHeight() / 2 + 1; paramCanvas.drawText(mDay.mSolarDay, fw, fh, paint1); // lunar text Paint paint2 = new Paint(); paint2.setAntiAlias(true); paint2.setTextSize(getMeasuredWidth() / 4); if (mDay.mIsFestival) { paint2.setColor(ECalendarActivity.mHolidayColor); } else { paint2.setColor(Color.BLACK); } paint2.getTextBounds(mDay.mLunarDay, 0, mDay.mLunarDay.length(), text); w1 = text.width(); fw = (w - w1) / 2; fh = getMeasuredHeight() / 2 + 2 + text.height(); paramCanvas.drawText(mDay.mLunarDay, fw, fh, paint2); if (mDay.mHasDiary) { Paint pd = new Paint(); pd.setStyle(Paint.Style.STROKE); pd.setColor(ECalendarActivity.mHolidayColor); pd.setStrokeWidth(2); Rect rect = paramCanvas.getClipBounds(); RectF rt = new RectF(rect); rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12); paramCanvas.drawLine(rt.left + rt.width() / 4, rt.top, rt.right - rt.width() / 4, rt.top, pd); } }
// Member Functions public void onDraw(Canvas canvas) { // May add more creeps if (m_random.nextInt() % 10 == 0) { int tmpRand = m_random.nextInt(3); Creep tmp = new Creep(tmpRand); tmp.setOnPath(m_paths.get(m_random.nextInt(10))); m_creeps.add(tmp); } if (canvas != null) { canvas.drawColor(Color.BLACK); if (m_background != null && m_background.bitmap != null) canvas.drawBitmap(m_background.bitmap, null, canvas.getClipBounds(), null); } for (int i = 0; i < m_towers.size(); i++) { m_towers.get(i).draw(canvas); } for (int i = 0; i < m_creeps.size(); i++) { if (m_creeps.get(i).advanceAlongPath()) { m_creeps.get(i).onDeath(); m_creeps.remove(i); if (i > 0) i--; } else { m_creeps.get(i).draw(canvas); } } CoreActivity.m_inputTower.draw(canvas); }
@Override protected void onTileReadyToDraw( final Canvas c, final Drawable currentMapTile, final Rect tileRect) { // Get the offsets for where to draw the tiles relative to where the minimap is located final int xOffset = (tileRect.left - mTileArea.left) + (mMiniMapCanvasRect.left); final int yOffset = (tileRect.top - mTileArea.top) + (mMiniMapCanvasRect.top); // Set the drawable's location currentMapTile.setBounds( xOffset, yOffset, xOffset + tileRect.width(), yOffset + tileRect.height()); // Save the current clipping bounds final Rect oldClip = c.getClipBounds(); // Check to see if the drawing area intersects with the minimap area if (mIntersectionRect.setIntersect(oldClip, mMiniMapCanvasRect)) { // If so, then clip that area c.clipRect(mIntersectionRect); // Draw the tile, which will be appropriately clipped currentMapTile.draw(c); // Restore the original clipping bounds c.clipRect(oldClip); } }
/** * update the canvas with latest changes to model drawing. Zoom is managed. Changes performed by * tool are managed. */ @Override protected void onDraw(Canvas canvas) { dLogger.start(); Rect bounds = mModel.getBounds(); Rect dummyBounds = new Rect(); if (bounds != null && canvas.getClipBounds(dummyBounds)) { // Draw current path in a scratch buffer Rect tmp = (Rect) new Rect(mWindowRect); // TODO restore code to manage part of change only. // mCoordinateMapper.fromReference(bounds); // find out what part of the canvas is impacted. tmp.intersect(mWindowRect); // We don't update outside of the screen Rect srcRect = mCoordinateMapper.toReference(tmp); Log.i( "onDraw", "refreshing partial area " + tmp + " from " + srcRect + " clip bounds were " + dummyBounds); mModel.renderTentativeUpdates(mTool, srcRect); // update the impacted part from the corresponding input part. mModel.copyRendered(canvas, srcRect, tmp); } else { Rect srcRect = mCoordinateMapper.toReference(mWindowRect); Log.i("onDraw", "refreshing whole area" + mWindowRect + " from " + srcRect); mModel.copyReference(canvas, srcRect, mWindowRect); } // canvas.drawPath(mPath, mPaint); //TODO all drawing should be performed in reference bitmap dLogger.end(); }
/** * Doing effects, etc, that we don't need to do every draw() * * @param bitmap */ private void setAndPreprocessBitmap(Bitmap bitmap) { if (bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) return; // if (waveform != null && waveform != bitmap) waveform.recycle(); waveform = bitmap; int scaledWidth = width * 2; int scaledHeight = height; // no change here. int clippedWidth = getScaledWidth(scaledWidth, bitmap); Bitmap clipped = clipBitmap(bitmap, clippedWidth); Bitmap canvasbmp = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(canvasbmp); Rect canvasrect = canvas.getClipBounds(); Rect clippedrect = new Rect(0, 0, clipped.getWidth(), clipped.getHeight()); paint.setFilterBitmap(true); paint.setAlpha(120); canvas.drawBitmap(makeBlurry(bitmap, 3), clippedrect, canvasrect, paint); paint.setFilterBitmap(false); paint.setAlpha(180); canvas.drawBitmap(bitmap, clippedrect, canvasrect, paint); oldProcessedWaveform = processedWaveform; processedWaveform = canvasbmp; timeSinceTransition = System.currentTimeMillis(); // if (oldwaveform != null) oldwaveform.recycle(); clipped.recycle(); }
public void draw(Canvas c, float mOffset) { c.save(); c.drawColor(map.getColor()); if (processedWaveform != null) { float offset = mOffset * -(processedWaveform.getWidth() - c.getClipBounds().width()); long time = System.currentTimeMillis(); if (time - timeSinceTransition < transitionTime) { // transition mode. float progress = (float) (time - timeSinceTransition) / (float) transitionTime; displaypaint.setAlpha((int) ((1 - progress) * 255)); long before = System.currentTimeMillis(); if (oldProcessedWaveform != null) c.drawBitmap(oldProcessedWaveform, offset, 0, displaypaint); displaypaint.setAlpha((int) (progress * 255)); c.drawBitmap(processedWaveform, offset, 0, displaypaint); long after = System.currentTimeMillis(); Log.d("WaveformDrawer", "Time to draw transition: " + (after - before)); } else { // int ms = Math.abs((int)(time % 5000) - 2500); // displaypaint.setAlpha(200+ms/50); displaypaint.setAlpha(255); long before = System.currentTimeMillis(); c.drawBitmap(processedWaveform, offset, 0, null); long after = System.currentTimeMillis(); Log.d("WaveformDrawer", "Time to draw bitmap: " + (after - before)); } } c.restore(); }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (canvas == null) { return; } canvas.getClipBounds(clipBounds); int normalizedOffset = offset; int layerWidth = bitmap.getWidth(); if (offset < -layerWidth) { offset += (int) (Math.floor(Math.abs(normalizedOffset) / (float) layerWidth) * layerWidth); } int left = offset; while (left < clipBounds.width()) { canvas.drawBitmap(bitmap, getBitmapLeft(layerWidth, left), 0, null); left += layerWidth; } if (isStarted) { offset -= speed; postInvalidateOnAnimation(); } }
private void switchAnimation(Canvas canvas) { // Determine the animation parameters. Rect rect = new Rect(); canvas.getClipBounds(rect); float ARview = (float) rect.width() / rect.height(); float ARimage = (float) mImage.getWidth() / mImage.getHeight(); if (ARimage > ARview) { mScaledImageWidth = (int) ((float) mImage.getWidth() * rect.bottom / mImage.getHeight()); mScaledImageHeight = rect.bottom; } else { mScaledImageWidth = rect.right; mScaledImageHeight = (int) ((float) mImage.getHeight() * rect.right / mImage.getWidth()); } mCurrentMove = mCurrentMove == ANIMATION_MOVE_1 ? ANIMATION_MOVE_2 : ANIMATION_MOVE_1; mCurrentAnim = new TranslateAnimation( mCurrentMove == ANIMATION_MOVE_1 ? 0 : rect.right - mScaledImageWidth, mCurrentMove == ANIMATION_MOVE_1 ? rect.right - mScaledImageWidth : 0, mCurrentMove == ANIMATION_MOVE_1 ? 0 : rect.bottom - mScaledImageHeight, mCurrentMove == ANIMATION_MOVE_1 ? rect.bottom - mScaledImageHeight : 0); int animationDuration = mScaledImageHeight == rect.bottom ? (mScaledImageWidth - rect.right) * 60 : (mScaledImageHeight - rect.bottom) * 60; if (animationDuration <= 10) animationDuration = 10; mCurrentAnim.setDuration(animationDuration); mCurrentAnim.setInterpolator(new LinearInterpolator()); mCurrentAnim.initialize(mImage.getWidth(), mImage.getHeight(), rect.right, rect.bottom); }
private void drawBlurBackground(Canvas canvas) { if (mBlurredView != null) { if (prepare()) { if (mBlurredBackgroundColor != 0) { mBitmapToBlur.eraseColor(mBlurredBackgroundColor); } mBlurredView.draw(mBlurringCanvas); blur(); NiceTabLayout tabLayout = (NiceTabLayout) getParent(); if (tabLayout != null) { final int pPaddingLeft = tabLayout.getPaddingLeft(); final int pPaddingRight = tabLayout.getPaddingRight(); canvas.save(); if (tabLayout.getPaddingLeft() != 0 || tabLayout.getPaddingRight() != 0) { // allow drawing out of bounds Rect clipBounds = canvas.getClipBounds(); clipBounds.inset(-(pPaddingLeft + pPaddingRight), 0); canvas.clipRect(clipBounds, Region.Op.REPLACE); } canvas.translate( mBlurredView.getLeft() - getLeft() + tabLayout.getScrollX(), mBlurredView.getTop() - getTop()); canvas.scale(mDownSampleFactor, mDownSampleFactor); canvas.drawBitmap(mBlurredBitmap, 0, 0, null); canvas.drawColor(mOverlayColor); canvas.restore(); } } } }
public void run() { Rect dstRect = new Rect(); long startTime = System.nanoTime(); while (running) { if (!holder.getSurface().isValid()) { continue; } float deltaTime = (System.nanoTime() - startTime) / 10000000.000f; startTime = System.nanoTime(); if (deltaTime > 3.15) { deltaTime = (float) 3.15; } game.getCurrentScreen().update(deltaTime); game.getCurrentScreen().paint(deltaTime); Canvas canvas = holder.lockCanvas(); canvas.getClipBounds(dstRect); canvas.drawBitmap(frameBuffer, null, dstRect, null); holder.unlockCanvasAndPost(canvas); } }
private void renderGameImage() { Canvas screen = getHolder().lockCanvas(); if (screen != null) { screen.getClipBounds(gameImageDst); screen.drawBitmap(gameImage, gameImageSrc, gameImageDst, null); getHolder().unlockCanvasAndPost(screen); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (bmp != null) { // paint.setColor(Color.BLUE); clip = canvas.getClipBounds(); float w = clip.width(), w2 = w / 2.0f, h = clip.height(), h2 = h / 2.0f; // canvas.drawRect(0,0,w-1,h-1, paint); // canvas.drawCircle(w2, h2, 10, paint); matrixLock.lock(); Matrix m = new Matrix(); m.reset(); m.postTranslate(0, 80); m.postConcat(matrix); canvas.setMatrix(m); matrixLock.unlock(); clip = canvas.getClipBounds(); w = clip.width(); w2 = w / 2.0f; h = clip.height(); h2 = h / 2.0f; // paint.setColor(Color.GREEN); // canvas.drawRect(0,0,w-1,h-1, paint); bmpLock.lock(); float left = scale * (w2 - (float) bmp.getWidth() / 2.0f); float top = scale * (h2 - (float) bmp.getHeight() / 2.0f); Bitmap _bmp = bmp; // check if rotated, and set the matrix accordingly if (!mLookingRight) { Matrix _m = new Matrix(); _m.preScale(-1.0f, 1.0f); _bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), _m, false); } canvas.drawBitmap(_bmp, left, top, paint); // paint.setColor(Color.RED); // canvas.drawRect(left, top, left + bmp.getWidth(), top + bmp.getHeight(), paint); bmpLock.unlock(); } }
public boolean play(Canvas out, Context context) { float aspect = out.getHeight() * 1.0f / out.getWidth(); int width = 1000; Bitmap bitmap = Bitmap.createBitmap(width, Math.round(width * aspect), Bitmap.Config.RGB_565); Canvas c = new Canvas(bitmap); bounds = c.getClipBounds(); windowBounds = out.getClipBounds(); if (paint == null) { String currentSize = Shared.getOptionAtribute( context.getString(R.string.FontSize), getString(R.string.current), context); String textColour = Shared.getOptionAtribute( context.getString(R.string.Colours), getString(R.string.text), context); paint = new Paint(); paint.setColor( Color.parseColor( Shared.getOption(context.getString(R.string.Colours) + "/" + textColour, context) .getTextContent())); paint.setTextSize( new Integer( Shared.getOption(context.getString(R.string.FontSize) + "/" + currentSize, context) .getTextContent())); String font = Shared.getOptionAtribute( getString(R.string.Font), getString(R.string.current), getApplicationContext()); Typeface face = Typeface.createFromAsset( getAssets(), Shared.getOption(getString(R.string.Font) + "/" + font, getApplicationContext()) .getTextContent()); paint.setTypeface(face); } c.drawText("tap the screen", 50, 50, paint); c.drawText("to start", 50, 100, paint); c.drawText("the test.", 50, 150, paint); c.drawText("Pick the Months", 50, 200, paint); c.drawText("in reverse order", 50, 250, paint); // c.drawText("",50,300,paint); out.drawBitmap(bitmap, c.getClipBounds(), out.getClipBounds(), paint); return finished; }
@Override protected void onDraw(@NonNull Canvas canvas) { if (customBackground != null) { canvas.getClipBounds(tempRect); customBackground.setBounds(tempRect); customBackground.setState(getDrawableState()); customBackground.draw(canvas); } super.onDraw(canvas); }
protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.getClipBounds(mRect); final CategoryDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); chart.draw(canvas, new Rectangle2D.Double(0, 0, mRect.width(), mRect.height())); Paint p = new Paint(); p.setColor(Color.RED); }
protected void dispatchDraw(Canvas paramCanvas) { if ((!this.hasAlpha) && (this.alpha != 255)) paramCanvas.saveLayerAlpha(new RectF(paramCanvas.getClipBounds()), this.alpha, 31); while (true) { if ((!this.hasScaled) && (this.scale != 1.0F)) paramCanvas.scale(this.scale, this.scale, this.centerPoint.x, this.centerPoint.y); super.dispatchDraw(paramCanvas); paramCanvas.restore(); return; paramCanvas.save(); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Rect rec = canvas.getClipBounds(); RectF rectF = new RectF(rec); Paint paint = new Paint(); paint.setColor(Color.parseColor("#C7D0D2")); paint.setAntiAlias(true); paint.setStrokeWidth(2); paint.setStyle(Paint.Style.STROKE); canvas.drawRoundRect(rectF, 2, 2, paint); }
@Override protected void onDraw(Canvas canvas) { long t = System.currentTimeMillis(); super.onDraw(canvas); canvas.getClipBounds(mRect); int top = mRect.top; int left = mRect.left; int width = mRect.width(); int height = mRect.height(); mChart.draw(canvas, left, top, width, height); System.out.println("t=" + (System.currentTimeMillis() - t)); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw border Rect rec = canvas.getClipBounds(); rec.bottom--; rec.right--; Paint paint = new Paint(); paint.setColor(LED_COLORS[colorIndex]); paint.setStyle(Paint.Style.FILL); canvas.drawRect(rec, paint); }
public static Bitmap addFrame(Bitmap bitmap, int width, int color) { Bitmap bitmap2 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap2); Rect rect = canvas.getClipBounds(); rect.bottom -= width; rect.right -= width; Paint recPaint = new Paint(); recPaint.setColor(color); recPaint.setStrokeWidth(width); recPaint.setStyle(Paint.Style.STROKE); canvas.drawRect(rect, recPaint); canvas.drawBitmap(bitmap, 0, 0, null); return bitmap2; }
public void draw(Canvas paramCanvas) { this.hasScaled = false; this.hasAlpha = false; if (this.alpha != 255) { this.hasAlpha = true; paramCanvas.saveLayerAlpha(new RectF(paramCanvas.getClipBounds()), this.alpha, 31); } while (true) { if (this.scale != 1.0F) { this.hasScaled = true; paramCanvas.scale(this.scale, this.scale, this.centerPoint.x, this.centerPoint.y); } super.draw(paramCanvas); paramCanvas.restore(); this.hasScaled = false; return; paramCanvas.save(); } }
public void run() { Rect dstRect = new Rect(); // create a new rectangle long startTime = System.nanoTime(); // gets the initial start time while (running) { if (!holder.getSurface().isValid()) continue; float deltaTime = (System.nanoTime() - startTime) / 1000000000.0f; // gets the nanotime of the next frame, divide to get it in seconds startTime = System.nanoTime(); // gets the time for the next frame game.getCurrentScreen().update(deltaTime); game.getCurrentScreen().present(deltaTime); // call the update and present methods each frame Canvas canvas = holder.lockCanvas(); // lock the canvas canvas.getClipBounds(dstRect); // get the clip bounds canvas.drawBitmap(framebuffer, null, dstRect, null); // draw the framebuffer to the canvas holder.unlockCanvasAndPost(canvas); // unlock and update the surfaceholder } }
@Override public void draw(Canvas canvas) { final Rect r = new Rect(getBounds()); if (canvas.getClipBounds(sTempRect) && !Rect.intersects(sTempRect, r)) { // The draw region has been clipped. return; } if (mIndicatorRectDirty) { initIndicatorRect(); } final float iconScale; if ((mAnimationProgress >= ANIMATION_PROGRESS_STARTED) && (mAnimationProgress < ANIMATION_PROGRESS_COMPLETED)) { mPaint.setAlpha((int) ((1 - mAnimationProgress) * 255)); mBgDrawable.setAlpha(mPaint.getAlpha()); mBgDrawable.draw(canvas); canvas.drawOval(mIndicatorRect, mPaint); iconScale = ICON_SCALE_FACTOR + (1 - ICON_SCALE_FACTOR) * mAnimationProgress; } else if (mAnimationProgress == ANIMATION_PROGRESS_STOPPED) { mPaint.setAlpha(255); iconScale = ICON_SCALE_FACTOR; mBgDrawable.setAlpha(255); mBgDrawable.draw(canvas); if (mProgress >= 100) { canvas.drawOval(mIndicatorRect, mPaint); } else if (mProgress > 0) { canvas.drawArc(mIndicatorRect, -90, mProgress * 3.6f, false, mPaint); } } else { iconScale = 1; } canvas.save(); canvas.scale(iconScale, iconScale, r.exactCenterX(), r.exactCenterY()); mIcon.draw(canvas); canvas.restore(); }
/** @see android.view.View#onDraw(android.graphics.Canvas) */ @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setAntiAlias(true); effect.setEffect(paint); paint.setColor(Color.DKGRAY); paint.setStrokeWidth(5); canvas.drawLine(20, 10, 140, 20, paint); paint.setTextSize(26); canvas.drawText("Android", 40, 50, paint); // create a new Paint to draw the widget structure paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawText(String.valueOf(id), 2.0F, 12.0F, paint); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(2); canvas.drawRect(canvas.getClipBounds(), paint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Skip rows that are not in the canvas clipping bounds. Rect bounds = canvas.getClipBounds(); for (int i = 0; i < mLayoutRows.size(); i++) { Row row = mLayoutRows.get(i); if (row.getLayoutTop() + row.getMeasuredHeight() <= bounds.top) { // Before the canvas bounds, so skip to next row. continue; } if (row.getLayoutTop() >= bounds.bottom) { // After the canvas bounds, so no more to do. break; } row.draw(canvas); } }
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mSlideableView != child) { // if main view // Clip against the slider; no sense drawing what will immediately // be covered, // Unless the panel is set to overlay content canvas.getClipBounds(mTmpRect); if (!mOverlayContent) { if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } } if (mClipPanel) { canvas.clipRect(mTmpRect); } result = super.drawChild(canvas, child, drawingTime); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } } else { result = super.drawChild(canvas, child, drawingTime); } canvas.restoreToCount(save); return result; }
/* * Enabled aggressive block sorting */ @Override protected boolean drawChild(Canvas canvas, View view, long l) { boolean bl; LayoutParams layoutParams = (LayoutParams)view.getLayoutParams(); int n = canvas.save(2); if (this.mCanSlide && !layoutParams.slideable && this.mSlideableView != null) { canvas.getClipBounds(this.mTmpRect); if (this.isLayoutRtlSupport()) { this.mTmpRect.left = Math.max(this.mTmpRect.left, this.mSlideableView.getRight()); } else { this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft()); } canvas.clipRect(this.mTmpRect); } if (Build.VERSION.SDK_INT >= 11) { bl = super.drawChild(canvas, view, l); } else if (layoutParams.dimWhenOffset && this.mSlideOffset > 0.0f) { Bitmap bitmap; if (!view.isDrawingCacheEnabled()) { view.setDrawingCacheEnabled(true); } if ((bitmap = view.getDrawingCache()) != null) { canvas.drawBitmap(bitmap, view.getLeft(), view.getTop(), layoutParams.dimPaint); bl = false; } else { Log.e("SlidingPaneLayout", "drawChild: child view " + view + " returned null drawing cache"); bl = super.drawChild(canvas, view, l); } } else { if (view.isDrawingCacheEnabled()) { view.setDrawingCacheEnabled(false); } bl = super.drawChild(canvas, view, l); } canvas.restoreToCount(n); return bl; }
@Override public void onDraw(Canvas canvas) { int w = canvas.getWidth(); int h = canvas.getHeight(); Rect clip = canvas.getClipBounds(); int cw = clip.width(); int ch = clip.height(); if (cw > 0 && ch > 0) { w = cw; h = ch; } int inset = 20; float startX = 0 + inset; float startY = 0 + inset; float stopX = w - inset; float stopY = h - inset; float origoX = startX + MARGIN_X_AXIS; float origoY = stopY - MARGIN_Y_AXIS; float xmaxX = stopX - origoX - X_LINE_MARGIN; float maxProb = -origoY - Y_LINE_MARGIN + startY; // X and Y axisbug canvas.drawLine(origoX, origoY, origoX, startY, axisPaint); canvas.drawLine(origoX, origoY, stopX, origoY, axisPaint); // canvas.drawLine(startX, startY, stopX, stopY, axisPaint); canvas.drawText("Battery drain %/s", origoX, stopY - 20, textPaint); Path path = new Path(); path.addRect(new RectF(clip), Path.Direction.CW); canvas.drawTextOnPath("Probability", path, w * 2 + h + h / 2, +40, textPaint); if (xVals == null || yVals == null) { canvas.drawText("With", stopX, startY + 30, withTextPaint); canvas.drawText("Without", stopX, startY + 60, withoutTextPaint); } else { String anShort = appName; if (anShort == null) anShort = "Unknown"; int dot = anShort.lastIndexOf('.'); if (dot > 0) { int lastPart = anShort.length() - dot; if (lastPart > 7) anShort = anShort.substring(dot + 1); else { if (anShort.length() > 15 + 3) { anShort = "..." + anShort.substring(anShort.length() - 15); } } } String withString = anShort; String withoutString = anShort; switch (type) { case BUG: withString = anShort + " " + getContext().getString(R.string.runninghere); withoutString = anShort + " " + getContext().getString(R.string.runningelsewhere); break; case HOG: withString = anShort + " " + getContext().getString(R.string.running); withoutString = anShort + " " + getContext().getString(R.string.notrunning); break; case MODEL: withString = getContext().getString(R.string.onmodel) + " " + anShort; withoutString = getContext().getString(R.string.onothermodels); break; case OS: withString = getContext().getString(R.string.withos) + " " + anShort; withoutString = getContext().getString(R.string.withotheroses); break; case SIMILAR: withString = getContext().getString(R.string.withsimilarapps); withoutString = getContext().getString(R.string.withdifferentapps); break; default: } canvas.drawText(withString, stopX, startY + 30, withTextPaint); canvas.drawText(withoutString, stopX, startY + 60, withoutTextPaint); float xmax = 0.0f; float ymax = 0.0f; for (int i = 0; i < xVals.length && i < yVals.length; ++i) { float next = (float) xVals[i]; float nexty = (float) yVals[i]; if (next > xmax) xmax = next; if (nexty > ymax) ymax = nexty; } for (int i = 0; i < xValsWithout.length && i < yValsWithout.length; ++i) { float next = (float) xValsWithout[i]; float nexty = (float) yValsWithout[i]; if (next > xmax) xmax = next; if (nexty > ymax) ymax = nexty; } String xmaxS = xmax + ""; if (xmaxS.length() > 6) xmaxS = xmaxS.substring(0, 6); String ymaxS = ymax + ""; if (ymaxS.length() > 4) ymaxS = ymaxS.substring(0, 4); canvas.drawText(xmaxS + "", xmaxX, stopY - 20, textPaint); canvas.drawText(ymaxS + "", startX, startY + 30, textPaint); float lastX = 0.0f, lastY = 0.0f; for (int i = 0; i < xVals.length && i < yVals.length; ++i) { float x = (float) xVals[i]; float y = (float) yVals[i]; if (y == 0.0) continue; x /= xmax; // Now x is a fraction of max. All x values are from origoX to w // - origoX - offset: x = origoX + X_LINE_MARGIN + x * xmaxX; y /= ymax; y = origoY + Y_LINE_MARGIN + y * maxProb; if (lastX != 0 || lastY != 0) { canvas.drawLine(lastX, lastY, x, y, withPaint); } lastX = x; lastY = y; } lastX = 0.0f; lastY = 0.0f; for (int i = 0; i < xValsWithout.length && i < yValsWithout.length; ++i) { float x = (float) xValsWithout[i]; float y = (float) yValsWithout[i]; if (y == 0.0) continue; x /= xmax; x = origoX + X_LINE_MARGIN + x * xmaxX; y /= ymax; y = origoY + Y_LINE_MARGIN + y * maxProb; if (lastX != 0 || lastY != 0) { canvas.drawLine(lastX, lastY, x, y, withoutPaint); } lastX = x; lastY = y; } } }