List of usage examples for android.graphics Canvas drawLine
public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint)
From source file:com.bob.googleplay.view.PagerSlidingTriangleStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//ww w . j ava2 s .c o m } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, // height, rectPaint); // --> float x1 = (lineRight - lineLeft) / 2 + lineLeft; float y1 = height - indicatorHeight; float x2 = x1 - triangleWidth / 2f; float y2 = height; float x3 = x1 + triangleWidth / 2f; float y3 = height; Path path = new Path(); path.moveTo(x1, y1);// path.lineTo(x2, y2);// path.lineTo(x3, y3);// path.lineTo(x1, y1);// // rectPaint.setStyle(Style.STROKE); // rectPaint.setStrokeWidth(width) canvas.drawPath(path, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.chj.indicator.lib.TriangleSlidingIndicator.java
/** * //from w w w.j a v a 2 s. c o m */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return; } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, // height, rectPaint); float left = lineLeft; float top = height - indicatorHeight; float right = lineRight; float bottom = height; // TODO: Path path = new Path(); float x1 = (right - left) / 2 + left;// :(right+left)/2 float y1 = top; float x2 = x1 - triangleWidth / 2; float y2 = bottom; float x3 = x1 + triangleWidth / 2; float y3 = bottom; path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x1, y1); path.close(); rectPaint.setColor(Color.RED);// ? canvas.drawPath(path, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (DEBUG) {//w w w. ja v a 2s. c om Paint p = new Paint(); p.setColor(Color.RED); p.setStrokeWidth(2); p.setStyle(Paint.Style.STROKE); canvas.drawLine(0, getMaxPanelHeight(), getWidth(), getMaxPanelHeight(), p); p.setColor(Color.BLUE); canvas.drawLine(0, getExpandedHeight(), getWidth(), getExpandedHeight(), p); p.setColor(Color.GREEN); canvas.drawLine(0, calculatePanelHeightQsExpanded(), getWidth(), calculatePanelHeightQsExpanded(), p); p.setColor(Color.YELLOW); canvas.drawLine(0, calculatePanelHeightShade(), getWidth(), calculatePanelHeightShade(), p); p.setColor(Color.MAGENTA); canvas.drawLine(0, calculateQsTopPadding(), getWidth(), calculateQsTopPadding(), p); p.setColor(Color.CYAN); canvas.drawLine(0, mNotificationStackScroller.getTopPadding(), getWidth(), mNotificationStackScroller.getTopPadding(), p); } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) return;/*from www. j a v a 2 s.co m*/ canvas.save(); if (image != null) { if (mShowOriginalDirection == 0) { if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { mShowOriginalDirection = UNVEIL_VERTICAL; } else { mShowOriginalDirection = UNVEIL_HORIZONTAL; } } int px = 0; int py = 0; if (mShowOriginalDirection == UNVEIL_VERTICAL) { px = mImageBounds.width(); py = mTouch.y - mImageBounds.top; } else { px = mTouch.x - mImageBounds.left; py = mImageBounds.height(); if (showsOriginal) { px = mImageBounds.width(); } } Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py); if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { if (mTouchDown.x - mTouch.x > 0) { d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py); } } else { if (mTouchDown.y - mTouch.y > 0) { d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom); } } canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); if (mShowOriginalDirection == UNVEIL_VERTICAL) { canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint); } else { canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint); } Rect bounds = new Rect(); paint.setAntiAlias(true); paint.setTextSize(mOriginalTextSize); paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); paint.setColor(Color.WHITE); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); }
From source file:net.fastvan.indicator.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;// w w w. j a va2 s .c o m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } float startX = -1, startY = -1; //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { startX = dX = drawLong; startY = dY = shortOffset; } else { startX = dX = shortOffset; startY = dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); if (iLoop != 0) canvas.drawLine(startX - mRadius, startY, startX - mRadius * 2, startY, mPaintStroke); if (mCurrentPage > iLoop) canvas.drawCircle(dX, dY, mRadius, mPaintFill); } startX = -1; startY = -1; } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:com.lizhi.library.widget.WechatTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;// ww w . ja va 2 s . co m } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // TextView tv = ((TextView) currentTab); // String s = tv.getText().toString(); // float widths[] = new float[s.length()]; // tv.getPaint().getTextWidths(s, widths); // float StringWidth = 0; // for (float item : widths) { // StringWidth += item; // } // int padding = (int) ((tv.getWidth() - StringWidth) / 2 - mMyUnderlinePadding); // if (padding < 0) { // padding = 0; // } if (!underLine) { canvas.drawRect(lineLeft, 0, lineRight, height, rectPaint); } else { canvas.drawRect(lineLeft + mMyUnderlinePadding, height - indicatorHeight, lineRight - mMyUnderlinePadding, height, rectPaint); } // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.gx.appstore.lib.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;// w w w . j av a 2 s.com } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // // /** x1 = lineLeft+(lineRight-lineLeft)/2; y1 = height - indicatorHeight; x2 = x1 + triangleWidth/2; y2 = height; x3 = x1 - triangleWidth/2; y3 = height */ Path path = new Path(); float x1 = lineLeft + (lineRight - lineLeft) / 2; float y1 = height - indicatorHeight; int triangleWidth = 30; float x2 = x1 + triangleWidth / 2; float y2 = height; float x3 = x1 - triangleWidth / 2; float y3 = height; path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x1, y1); // canvas.drawPath(path, rectPaint); canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:net.coding.program.third.MyPagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;// w w w . j a v a2s . c o m } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); if (currentPosition == 0) { lineLeft += myFirstExtraPdddingLeft; } // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); // if (currentPosition == 0) { // lineLeft -= myFirstExtraPdddingLeft; // } lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // float myLeft = lineLeft + iconPadding + myPaddingLeft; // if (currentPosition == 0) { // myLeft += myFirstExtraPdddingLeft; // } // float myRight = lineRight - iconPadding + myPaddingLeft; // if (currentPosition == 0) { // myLeft += iconPadding; // } // if (currentPosition == (tabCount - 1)) { // myRight -= iconPadding; // } canvas.drawRect(lineLeft + iconPadding, height - indicatorHeight, lineRight - iconPadding, height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makeBMP(CalculationResult res) { Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from ww w . j a v a2 s. c om p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); /* Path pth = new Path(); pth.addArc(10, 20, 390, 790, 0, 360); p.setColor(Color.argb(20, 10, 10, 10)); p.setTextSize(30); String watermark = ""; for (int i = 0; i < 15; i++) { watermark += " "; } canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/ //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.png"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); } catch (Exception ex) { Log.e("error", ex.toString()); } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
void makePDF(CalculationResult res) { PdfDocument doc = new PdfDocument(); PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create(); PdfDocument.Page page = doc.startPage(inf); Canvas canvas = page.getCanvas(); //canvas.drawARGB(155, 253, 255, 253); canvas.drawARGB(255, 255, 255, 255); Paint p = new Paint(); p.setTypeface(Utility.getNazaninFont()); p.setTextSize(25);//from w ww .j av a2 s . co m p.setAntiAlias(true); int y = 20; Drawable d = getResources().getDrawable(R.drawable.abfa); d.setBounds(100, 10, 300, 210); d.draw(canvas); p.setTextAlign(Paint.Align.CENTER); y += 210; canvas.drawText(" ? ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(" ", 200, y, p); y += 40; canvas.drawText(":" + Utility.NowDate(), 200, y, p); y += 40; canvas.drawText("___________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.CustomerNumber, 200, y, p); y += 40; canvas.drawText(" :" + res.Title, 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p); y += 40; canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p); y += 40; Paint p1 = new Paint(); p1.setTypeface(Utility.getNazaninFont()); p1.setARGB(255, 0, 0, 0); p1.setAntiAlias(true); p1.setStrokeWidth(40); p1.setStyle(Paint.Style.STROKE); canvas.drawLine(10, y, 390, y, p1); p.setARGB(255, 255, 255, 255); canvas.drawText(" :" + Seprate3(res.TotalAmount) + " ", 200, y, p); p.setARGB(255, 0, 0, 0); y += 40; canvas.drawText("__________________________", 200, y, p); y += 40; canvas.drawText(" :" + res.BillIdentifier, 200, y, p); y += 40; canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p); doc.finishPage(page); //File file = new File(getCacheDir()+ "/billing.png"); File file = new File("/sdcard/billing.pdf"); FileOutputStream outfile; try { outfile = new FileOutputStream(file); //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile); doc.writeTo(outfile); doc.close(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); //intent.setDataAndType(Uri.fromFile(file), "image/*"); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); startActivity(intent); //new RetrieveFeedTask().execute(bmp); } catch (Exception ex) { Log.e("error", ex.toString()); new AlertDialog.Builder(this).setMessage( " ? pdf ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa ") .show(); } }