List of usage examples for android.graphics Canvas getWidth
public int getWidth()
From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; final float ascent = mTextPaint.ascent() * mScale; final float descent = mTextPaint.descent() * mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT); }/*from w w w. jav a 2 s . c om*/ if (mUseTexture) { y = y - h + descent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:piuk.blockchain.android.ui.zxing.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring }//w w w .j a va 2s . c om cameraManager.setFramingViewSize(new Point(this.getWidth(), this.getHeight())); Rect frame = cameraManager.getFramingRect(); if (frame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // Draw a red "laser scanner" line through the middle to show decoding is active paint.setColor(laserColor); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; int middle = frame.height() / 2 + frame.top; canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); Rect previewFrame = cameraManager.getFramingRectInPreview(); assert previewFrame != null; float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:com.justwayward.reader.view.RVPIndicator.java
public RVPIndicator(Context context, AttributeSet attrs) { super(context, attrs); // //from w ww . j a v a2 s . c om TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RVPIndicator); mTabVisibleCount = a.getInt(R.styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a.getColor(R.styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.getColor(R.styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.getDimensionPixelSize(R.styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.getColor(R.styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.getInt(R.styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a.getDrawable(R.styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable instanceof BitmapDrawable) { mBitmap = ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9? Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heart_love); } a.recycle(); /** * */ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(mIndicatorColor); mPaint.setStyle(Style.FILL); }
From source file:com.mwm.loyal.libs.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override/* ww w .j ava2 s.c om*/ public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // Draw a red "laser scanner" line through the middle to permissionDialog decoding is active paint.setColor(laserColor); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; int middle = frame.height() / 2 + frame.top; canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java
@Override public void draw(@NonNull Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = this.mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, this.mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (this.mTitleToDraw != null) { float x = this.mTextLeft; float y = this.mTextTop; final float ascent = this.mTextPaint.ascent() * this.mScale; final float descent = this.mTextPaint.descent() * this.mScale; final float h = descent - ascent; if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(this.mTextLeft, y - h + descent, this.mTextRight, y + descent, DEBUG_DRAW_PAINT); }//from ww w . j av a2 s.c om if (this.mUseTexture) { y = y - h + descent; } if (this.mScale != 1f) { canvas.scale(this.mScale, this.mScale, x, y); } if (this.mUseTexture && this.mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint); } else { canvas.drawText(this.mTitleToDraw, x, y, this.mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:me.test.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override/*from ww w . ja v a 2s. c om*/ public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); if (!isFirst) { isFirst = true; slideTop = frame.top; } // // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // paint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_dark)); // canvas.drawRect(frame.left, frame.top, frame.left + 50, frame.top + 10, paint); canvas.drawRect(frame.left, frame.top, frame.left + 10, frame.top + 50, paint); //? canvas.drawRect(frame.right - 50, frame.top, frame.right, frame.top + 10, paint); canvas.drawRect(frame.right - 10, frame.top, frame.right, frame.top + 50, paint); // canvas.drawRect(frame.left, frame.bottom - 10, frame.left + 50, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - 50, frame.left + 10, frame.bottom, paint); //? canvas.drawRect(frame.right - 50, frame.bottom - 10, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - 10, frame.bottom - 50, frame.right, frame.bottom, paint); //,??SPEEN_DISTANCE slideTop += 5; if (slideTop >= frame.bottom) { slideTop = frame.top; } canvas.drawRect(frame.left + 5, slideTop - 6 / 2, frame.right - 5, slideTop + 6 / 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:foam.starwisp.DrawableMap.java
public Marker AddText(final LatLng location, final String text, final int padding, final int fontSize, int colour) { Marker marker = null;/*from w w w . j a v a2 s . c o m*/ final TextView textView = new TextView(m_Context); textView.setText(text); textView.setTextSize(fontSize); textView.setTypeface(m_Context.m_Typeface); final Paint paintText = textView.getPaint(); final Rect boundsText = new Rect(); paintText.getTextBounds(text, 0, textView.length(), boundsText); paintText.setTextAlign(Paint.Align.CENTER); final Bitmap.Config conf = Bitmap.Config.ARGB_8888; final Bitmap bmpText = Bitmap.createBitmap(boundsText.width() + 2 * padding, boundsText.height() + 2 * padding, conf); final Canvas canvasText = new Canvas(bmpText); paintText.setColor(Color.BLACK); canvasText.drawText(text, (canvasText.getWidth() / 2) + 3, (canvasText.getHeight() - padding - boundsText.bottom) + 3, paintText); paintText.setColor(colour); canvasText.drawText(text, canvasText.getWidth() / 2, canvasText.getHeight() - padding - boundsText.bottom, paintText); final MarkerOptions markerOptions = new MarkerOptions().position(location) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1); marker = map.addMarker(markerOptions); return marker; }
From source file:github.madmarty.madsonic.util.Util.java
public static Bitmap createBitmapFromDrawable(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); }/*from ww w .j a v a 2 s. com*/ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:org.cicadasong.samples.tubestatus.TubeStatus.java
protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setTextAlign(Paint.Align.CENTER); paint.setTypeface(Typeface.DEFAULT_BOLD); // We've centered the output vertically, so it works with the reduced canvas height in // widget mode. int y = canvas.getHeight() / 2; int x = canvas.getWidth() / 2; paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(11);/* w w w . j ava2s . c om*/ canvas.drawText(TubeLine.allLines.get(selectionIndex).name, x, y - paint.descent() - 1, paint); paint.setTextSize(11); // TODO dynamically adjust font size depending on length of status string? canvas.drawText(status, x, y + (int) -paint.ascent() + 1, paint); }