List of usage examples for android.graphics Canvas drawRect
public void drawRect(@NonNull Rect r, @NonNull Paint paint)
From source file:com.justwayward.reader.view.RVPIndicator.java
/** * (?view)/* w w w .j a v a2s . c o m*/ */ @Override protected void dispatchDraw(Canvas canvas) { // ? canvas.save(); switch (mIndicatorStyle) { case STYLE_BITMAP: canvas.translate(mTranslationX, 0); canvas.drawBitmap(mBitmap, null, mRectF, mPaint); break; case STYLE_LINE: canvas.translate(mTranslationX, getHeight() - mIndicatorHeight); canvas.drawRect(mRectF, mPaint); break; case STYLE_SQUARE: canvas.translate(mTranslationX, 0); canvas.drawRect(mRectF, mPaint); break; case STYLE_TRIANGLE: canvas.translate(mTranslationX, 0); // // mPaint.setPathEffect(new CornerPathEffect(10)); mPath = new Path(); int midOfTab = getWidth() / mTabVisibleCount / 2; mPath.moveTo(midOfTab, getHeight() - mIndicatorHeight); mPath.lineTo(midOfTab - mIndicatorWidth / 2, getHeight()); mPath.lineTo(midOfTab + mIndicatorWidth / 2, getHeight()); mPath.close(); canvas.drawPath(mPath, mPaint); break; } // ?? canvas.restore(); super.dispatchDraw(canvas); }
From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java
/** * Draws a black border over the screenshot of the view passed in. *//*from w w w .j ava2 s . com*/ protected Bitmap getBitmapWithBorder(View v) { Bitmap bitmap = getBitmapFromView(v); Canvas canvas = new Canvas(bitmap); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, 0, 0, null); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(LINE_THICKNESS); int accentColor = ControlHelper.getColor(getContext(), R.attr.colorAccent); paint.setColor(accentColor); canvas.drawRect(rect, paint); return bitmap; }
From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java
/** Draws a black border over the screenshot of the view passed in. */ private Bitmap getBitmapWithBorder(View v) { Bitmap bitmap = getBitmapFromView(v); Canvas can = new Canvas(bitmap); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(LINE_THICKNESS); paint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent)); can.drawBitmap(bitmap, 0, 0, null);/*from w w w . j a va 2 s . c om*/ can.drawRect(rect, paint); return bitmap; }
From source file:com.valtech.androidtoolkit.view.indicator.RectPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;//from w w w . j ava2s . co m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } float dX; float dY; for (int iLoop = 0; iLoop < count; iLoop++) { dX = iLoop * rectSize; dY = 0; canvas.drawRect(new RectF(dX, dY, dX + rectSize, dY + 10), mPaintPageFill); canvas.drawRect(new RectF(dX, dY, dX + rectSize, dY + 10), mPaintStroke); } float cx = (mSnap ? mSnapPage : mCurrentPage); if (!mSnap && (mPageSize != 0)) { cx += (mCurrentOffset * 1.0f / mPageSize); } cx = ((mCurrentOffset * 1.0f) / width) * rectSize; dX = (mCurrentPage * rectSize) + cx; dY = 0; canvas.drawRect(new RectF(dX, dY, dX + rectSize, dY + 10), mPaintFill); }
From source file:app.axe.imooc.zxing.app.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode./*from www . ja va2s. c o m*/ * * @param barcode A bitmap of the captured image. * @param rawResult The decoded results which contains the points to draw. */ private void drawResultPoints(Bitmap barcode, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.result_image_border)); paint.setStrokeWidth(3.0f); paint.setStyle(Paint.Style.STROKE); Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2); canvas.drawRect(border, paint); paint.setColor(getResources().getColor(R.color.result_points)); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1]); } else if (points.length == 4 && (rawResult.getBarcodeFormat().equals(BarcodeFormat.UPC_A)) || (rawResult.getBarcodeFormat().equals(BarcodeFormat.EAN_13))) { // Hacky special case -- draw two lines, for the barcode and // metadata drawLine(canvas, paint, points[0], points[1]); drawLine(canvas, paint, points[2], points[3]); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { canvas.drawPoint(point.getX(), point.getY(), paint); } } } }
From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java
private static void drawStrings(String[] strings, Canvas c, Paint textPaint, Paint backgroundPaint) { // FIXME: The math here is ugly and blunt and probably not too // efficient or flexible. It might even fail. This needs to be // fixed and made less-ugly later. // We need SOME strings. If we've got nothing, bail out. if (strings.length < 1) return;/* w ww.jav a 2 s . co m*/ // First, init our variables. This is as good a place as any to do so. Rect textBounds = new Rect(); int[] heights = new int[strings.length]; int totalHeight = INFOBOX_MARGIN * 2; int longestWidth = 0; // Now, loop through the strings, adding to the height and keeping track // of the longest width. int i = 0; for (String s : strings) { textPaint.getTextBounds(s, 0, s.length(), textBounds); if (textBounds.width() > longestWidth) longestWidth = textBounds.width(); totalHeight += textBounds.height(); heights[i] = textBounds.height(); i++; } // Now, we have us a rectangle. Draw that. Rect drawBounds = new Rect(c.getWidth() - longestWidth - (INFOBOX_MARGIN * 2), 0, c.getWidth(), totalHeight); c.drawRect(drawBounds, backgroundPaint); // Now, place each of the strings. We'll assume the topmost one is in // index 0. They should all be left-justified, too. i = 0; int curHeight = 0; for (String s : strings) { Log.d(DEBUG_TAG, "Drawing " + s + " at " + (drawBounds.left + INFOBOX_MARGIN) + "," + (INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight)); c.drawText(s, drawBounds.left + INFOBOX_MARGIN, INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight, textPaint); curHeight += heights[i]; i++; } }
From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) return;/* w w w . ja v a 2 s . co m*/ final int count = getCount(); if (count == 0) return; Rect areaRect = new Rect(); areaRect.left = getPaddingLeft(); areaRect.right = getWidth() - getPaddingRight(); areaRect.top = getPaddingTop(); areaRect.bottom = getHeight() - getPaddingBottom(); int btnWidth = areaRect.width() / count; Rect tabRect = new Rect(areaRect); tabRect.top = tabRect.height() - mUnderlineHeight; tabRect.left += (mScrollingToPage + mPageOffset) * btnWidth; tabRect.right = tabRect.left + btnWidth; mPaint.setColor(mUnderlineColor); canvas.drawRect(tabRect, mPaint); mPaint.setColor(mTextColor); mPaint.setTextSize(mTextSize); for (int pos = 0; pos < count; pos++) { tabRect.set(areaRect); tabRect.left += pos * btnWidth; tabRect.right = tabRect.left + btnWidth; String pageTitle = getPageTitle(pos); RectF bounds = new RectF(tabRect); bounds.right = mPaint.measureText(pageTitle, 0, pageTitle.length()); bounds.bottom = mPaint.descent() - mPaint.ascent(); bounds.left += (tabRect.width() - bounds.right) / 2.0f; bounds.top += (tabRect.height() - bounds.bottom) / 2.0f; canvas.drawText(pageTitle, bounds.left, bounds.top - mPaint.ascent(), mPaint); } }
From source file:com.spatialnetworks.fulcrum.widget.DynamicListView.java
/** * Draws a black border over the screenshot of the view passed in. */// www . j ava 2 s.com private Bitmap getBitmapWithBorder(View v) { Bitmap bitmap = getBitmapFromView(v); Canvas can = new Canvas(bitmap); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(LINE_THICKNESS); paint.setColor(ContextCompat.getColor(getContext(), R.color.gray_230)); can.drawBitmap(bitmap, 0, 0, null); can.drawRect(rect, paint); return bitmap; }
From source file:com.example.sergey.currentweather.ui.fragment.MainFragment.java
private void initSwipe() { ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {/*from ww w. j a v a 2 s . c om*/ @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { int position = viewHolder.getAdapterPosition(); if (direction == ItemTouchHelper.LEFT) { deleteData(mCityListAdapter.removeItem(position)); } } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { Bitmap icon; if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; float height = (float) itemView.getBottom() - (float) itemView.getTop(); float width = height / 3; if (dX < 0) { mPoint.setColor(Color.parseColor("#D32F2F")); RectF background = new RectF((float) itemView.getRight() + dX, (float) itemView.getTop(), (float) itemView.getRight(), (float) itemView.getBottom()); c.drawRect(background, mPoint); icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_delete_white); RectF icon_dest = new RectF((float) itemView.getRight() - 2 * width, (float) itemView.getTop() + width, (float) itemView.getRight() - width, (float) itemView.getBottom() - width); c.drawBitmap(icon, null, icon_dest, mPoint); } } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); itemTouchHelper.attachToRecyclerView(mRecyclerView); }
From source file:com.home.library.vpi.TitlePageIndicator.java
public void setBackGroundColor(Canvas canvas) { if (mScrollState != ViewPager.SCROLL_STATE_IDLE) { mBackGroundPaint.setColor(mBackGroundColor); }/* ww w .j av a2s .c o m*/ Rect bgRect = new Rect(getLeft(), getTop(), getRight(), getBottom()); canvas.drawRect(bgRect, mBackGroundPaint); }