List of usage examples for android.graphics LinearGradient LinearGradient
public LinearGradient(float x0, float y0, float x1, float y1, @ColorInt int color0, @ColorInt int color1, @NonNull TileMode tile)
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
public static Bitmap createAlphaGradientBitmap(Bitmap orig) { final int width = orig.getWidth(), height = orig.getHeight(); final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); final Paint paint = new Paint(); final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP);//from w w w .java 2 s . c o m paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(orig, 0, 0, null); canvas.drawRect(0, 0, width, height, paint); return bitmap; }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawSatValPanel(final Canvas canvas) { final RectF rect = mSatValRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(mDrawingRect.left, mDrawingRect.top, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); }// www . j a v a2 s .c om if (mValShader == null) { mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, 0xffffffff, 0xff000000, TileMode.CLAMP); } final int rgb = Color.HSVToColor(new float[] { mHue, 1f, 1f }); mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, 0xffffffff, rgb, TileMode.CLAMP); final ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY); mSatValPaint.setShader(mShader); canvas.drawRect(rect, mSatValPaint); final Point p = satValToPoint(mSat, mVal); mSatValTrackerPaint.setColor(0xff000000); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity, mSatValTrackerPaint); mSatValTrackerPaint.setColor(0xffdddddd); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint); }
From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java
/** * {@inheritDoc}/*from w w w .j a v a 2s. c om*/ */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; maxValue = mMaxValue; } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }
From source file:com.viewpagerindicator.RichTitlePageIndicator.java
private void drawLeftItem(Canvas canvas, int pos, Rect bound, Paint paint, boolean drawIcon) { int c1 = paint.getColor(); int c2 = 0;// w ww . ja va2 s . c o m Paint blur = new Paint(paint); Shader shader = new LinearGradient(bound.left, 0, bound.right, 0, new int[] { c2, c1 }, new float[] { 0, 1 }, TileMode.CLAMP); blur.setShader(shader); drawItem(canvas, pos, bound, blur, drawIcon); //paint.setShader(null); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}/*from w w w . j av a 2s.c om*/ */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; if (mIsShowTargetDashedLine && mTargetValue > mMaxValue) { maxValue = mTargetValue; } else { maxValue = mMaxValue; } } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawTargetLine(c); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }
From source file:com.viewpagerindicator.RichTitlePageIndicator.java
private void drawRightItem(Canvas canvas, int pos, Rect bound, Paint paint, boolean drawIcon) { int c1 = paint.getColor(); int c2 = 0;//from www.ja v a 2 s. co m Paint blur = new Paint(paint); Shader shader = new LinearGradient(bound.left, 0, bound.right, 0, new int[] { c1, c2 }, new float[] { 0, 1 }, TileMode.CLAMP); blur.setShader(shader); drawItem(canvas, pos, bound, blur, drawIcon); //paint.setShader(null); }
From source file:org.mariotaku.twidere.util.Utils.java
public static Bitmap createAlphaGradientBanner(final Bitmap orig) { if (orig == null) return null; final int width = orig.getWidth(), height = orig.getHeight(); final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); final Paint paint = new Paint(); final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP);// w w w .j a v a2 s .c om paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(orig, 0, 0, null); canvas.drawRect(0, 0, width, height, paint); return bitmap; }
From source file:info.tellmetime.TellmetimeActivity.java
/** * Generates rainbow gradient and sets it as #mSeekBarHighlight progress drawable. *///www . j a va2 s . co m private void drawRainbow() { float gradientWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 256, getResources().getDisplayMetrics()); int[] colors = { 0xFFFFFFFF, 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFF888888, 0xFF000000 }; LinearGradient rainbowGradient = new LinearGradient(0f, 0f, gradientWidth, 0f, colors, null, Shader.TileMode.CLAMP); float r = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); ShapeDrawable shape = new ShapeDrawable( new RoundRectShape(new float[] { r, r, r, r, r, r, r, r }, null, null)); shape.getPaint().setShader(rainbowGradient); mSeekBarHighlight.setProgressDrawable(shape); // Generate bitmap with the same rainbow gradient and cache it for later use to retrieve color at given position. Bitmap bitmap = Bitmap.createBitmap((int) gradientWidth, 1, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.FILL); paint.setShader(rainbowGradient); canvas.drawRect(0, 0, gradientWidth, 1, paint); mRainbow = bitmap; // Set max value to gradient's width and restore relative position. mSeekBarHighlight.setMax((int) (gradientWidth - 1)); mSeekBarHighlight.setProgress((int) ((gradientWidth - 1) * mHighlightPosition)); }
From source file:com.FluksoViz.FluksoVizActivity.java
private void make_graph_pretty(XYPlot p) { p.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 56); // Reduce the number // of range labels // Plot1.setTicksPerDomainLabel(1); p.setDomainValueFormat(new DateFormat_p1()); p.setRangeStep(XYStepMode.SUBDIVIDE, 5);// Skala Y pionowa // Plot1.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 1); // Plot1.setTicksPerRangeLabel(1); p.getTitleWidget().setClippingEnabled(false); p.getTitleWidget().pack();/*from ww w . j a v a2 s . c o m*/ int axis_font_size = 15; int title_font_size = 15; int domain_font_size = 12; if (screen_width == 320) { axis_font_size = 12; title_font_size = 9; domain_font_size = 10; } p.getTitleWidget().getLabelPaint().setTextSize(title_font_size); p.getGraphWidget().getDomainLabelPaint().setTextSize(domain_font_size); p.getGraphWidget().getDomainLabelPaint().setColor(Color.WHITE); p.getGraphWidget().getRangeLabelPaint().setColor(Color.WHITE); p.getGraphWidget().getRangeLabelPaint().setTextSize(axis_font_size); p.getGraphWidget().getDomainOriginLabelPaint().setTextSize(domain_font_size); p.getGraphWidget().getRangeOriginLabelPaint().setTextSize(axis_font_size); p.getGraphWidget().setClippingEnabled(false); p.setDomainValueFormat(new DecimalFormat("#")); p.getLegendWidget().setVisible(false); p.getDomainLabelWidget().setVisible(false); p.getRangeLabelWidget().setVisible(false); p.getGraphWidget().getGridLinePaint().setPathEffect(new DashPathEffect(new float[] { 1, 2, 1, 2 }, 0)); p.getBackgroundPaint().setColor(Color.TRANSPARENT); p.getGraphWidget().getBackgroundPaint().setColor(Color.TRANSPARENT); p.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT); p.setGridPadding(0, 10, 0, 0); // left top right bottom p.getGraphWidget().getGridLinePaint().setColor(Color.TRANSPARENT); if (sensor_number != 4) { p.setRangeLowerBoundary(0, BoundaryMode.GROW);// to ustawia } if (sensor_number == 4) { p.addMarker(new YValueMarker(0, "0", new XPositionMetric(-11, XLayoutStyle.ABSOLUTE_FROM_LEFT), Color.WHITE, Color.WHITE)); p.setRangeStep(XYStepMode.SUBDIVIDE, 2); p.getGraphWidget().getRangeOriginLinePaint().setAlpha(0); series1mFormat = new LineAndPointFormatter( // FAZA Color.rgb(0, 220, 0), // line color Color.rgb(0, 150, 0), // point color null); line1mFill.setShader( new LinearGradient(0, 0, 0, 200, Color.rgb(0, 200, 0), Color.BLACK, Shader.TileMode.MIRROR)); series1mFormat.getLinePaint().setStrokeWidth(4); series1mFormat.setFillPaint(line1mFill); series2mFormat = new LineAndPointFormatter( // faza 2 solar Color.rgb(200, 200, 0), // line Color.rgb(100, 100, 0), // point color null); line2mFill.setShader( new LinearGradient(0, 150, 0, 120, Color.rgb(250, 250, 0), Color.BLACK, Shader.TileMode.CLAMP)); series2mFormat.setFillDirection(FillDirection.TOP); series2mFormat.setFillPaint(line2mFill); series2mFormat.getLinePaint().setStrokeWidth(5); series3mFormat = new LineAndPointFormatter( // FAZA 3 formater Color.rgb(0, 220, 0), // line color Color.rgb(0, 150, 0), // point color null); line3mFill.setAlpha(255); line3mFill.setShader(new LinearGradient(0, 0, 0, 50, Color.BLACK, Color.BLACK, Shader.TileMode.MIRROR)); series3mFormat.getLinePaint().setStrokeWidth(7); series3mFormat.setFillPaint(line3mFill); series4mFormat = new LineAndPointFormatter(Color.rgb(0, 140, 220), // line Color.rgb(0, 120, 190), // point color null); line4mFill = new Paint(); line4mFill.setAlpha(190); line4mFill.setShader(new LinearGradient(0, 0, 0, 50, Color.BLACK, Color.BLACK, Shader.TileMode.MIRROR)); series4mFormat.getLinePaint().setStrokeWidth(5); series4mFormat.setFillPaint(line4mFill); series4mFormat.setFillDirection(FillDirection.TOP); // XYRegionFormatter region4Formatter = new // XYRegionFormatter(Color.BLUE); // series4mFormat.addRegion(new RectRegion(Double.NEGATIVE_INFINITY, // Double.POSITIVE_INFINITY, 0, -1000, "R1"), region4Formatter); } // p.setRangeLowerBoundary(0, BoundaryMode.GROW);// to ustawia // min i max // Plot1.setRangeUpperBoundary(11, BoundaryMode.FIXED); p.setRangeValueFormat(new DecimalFormat("#")); p.setBorderStyle(Plot.BorderStyle.SQUARE, null, null); p.setBorderPaint(null); p.disableAllMarkup(); // To get rid of them call disableAllMarkup(): }
From source file:t3.giftbook.util.FlipViewPager.java
/** * ??//from w ww . ja va2 s .c om */ private void drawFlippingPage(Canvas canvas) { if (mOffset == 0) { //?????????????Flip?????(draw??) return; } int scrollX = this.getScrollX(); if (currentPageBmp == null || currentPageBmp.isRecycled() || nextPageBmp.isRecycled()) { currentPageBmp = prepareBmp(canvas); currentPageCnv = new Canvas(currentPageBmp); nextPageBmp = prepareBmp(canvas); nextPageCnv = new Canvas(nextPageBmp); } if (currentPageBmp != null) { final int currentPage = mPosition; final int nextPage = currentPage + 1; if (currentPageCnv != null) { if (lastDrawedPage != currentPage) { try { //mPosition????????bounds???? //1???mOffset??????return. //???????????mPosition??????? final long time = System.currentTimeMillis(); drawChildTo(currentPageCnv, currentPage, time); drawChildTo(nextPageCnv, nextPage, time); //??currentPageBmp, nextPageBmp???????????? lastDrawedPage = currentPage; } catch (IllegalArgumentException e) { Log.w(TAG, e); } } } /* * canvas????????????? * ??????????? * ????????????? */ //? final Rect screenLeftSide = new Rect(scrollX, 0, scrollX + this.getWidth() / 2, this.getHeight()); //?? final Rect screenRightSide = new Rect(scrollX + this.getWidth() / 2, 0, scrollX + this.getWidth() / 1, this.getHeight()); //bmp? final Rect pageLeftSide = new Rect((int) (this.getWidth() * 0.0f), 0, (int) (this.getWidth() * 0.5f), this.getHeight()); //bmp?? final Rect pageRightSide = new Rect((int) (this.getWidth() * 0.5f), 0, (int) (this.getWidth() * 1.0f), this.getHeight()); /* * ???Flip?? */ //? Paint white = new Paint() { { this.setColor(Color.WHITE); } }; canvas.drawRect(screenLeftSide, white); canvas.drawRect(screenRightSide, white); //??????? canvas.drawBitmap(currentPageBmp, pageLeftSide, screenLeftSide, new Paint()); //???????? canvas.drawBitmap(nextPageBmp, pageRightSide, screenRightSide, new Paint()); // Paint shadow = new Paint() { { this.setColor(Color.BLACK); } }; final int meshCols = 30; final float meshColsf = (float) meshCols; final int meshRows = 30; final float meshRowsf = (float) meshRows; //?????????? if (mOffset <= 0.5) { final float offsetRate = (0.5f - mOffset) * 2; final float invOffsetRate = 1f - offsetRate; //??? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenRightSide, shadow); //??????????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX <= meshCols / 2) { rVerts[xPosition] = screenRightSide.left; //?????????? rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenRightSide.left + offsetRate * screenRightSide.width() / meshColsf * (meshXf - meshColsf / 2f) * 2f; rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / 2f - screenRightSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshXf - meshColsf / 2f)); } } } canvas.drawBitmapMesh(currentPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //???? final Paint pageRootPaint = new Paint() { { int shadow1 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow2 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient((float) screenRightSide.left, (float) screenRightSide.top + screenRightSide.height() / 2, (float) screenRightSide.left + screenRightSide.width() * offsetRate, (float) screenRightSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenRightSide.left, screenRightSide.top, screenRightSide.right, screenRightSide.bottom, pageRootPaint); } else { final float offsetRate = (mOffset - 0.5f) * 2; final float invOffsetRate = 1f - offsetRate; //?? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenLeftSide, shadow); //???????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final float meshXfInv = meshColsf / 2f - meshXf; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX >= meshCols / 2) { rVerts[xPosition] = screenLeftSide.right; //??????????? rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenLeftSide.right - offsetRate * screenLeftSide.width() + offsetRate * screenLeftSide.width() / meshColsf * (meshXf) * 2f; rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / 2f - screenLeftSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshColsf / 2f - meshXf)); } } } canvas.drawBitmapMesh(nextPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //??? final Paint pageRootPaint = new Paint() { { int shadow2 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow1 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient( (float) screenLeftSide.right - screenRightSide.width() * offsetRate, (float) screenLeftSide.top + screenRightSide.height() / 2, (float) screenLeftSide.right, (float) screenLeftSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenLeftSide.left, screenLeftSide.top, screenLeftSide.right, screenLeftSide.bottom, pageRootPaint); } // int y = 0; // canvas.drawRect(0,0,canvas.getWidth(), 300, new Paint() {{this.setColor(Color.WHITE); this.setAlpha(100);}}); // Paint debugPrint = new Paint() {{this.setColor(Color.RED); this.setTextSize(30);}}; // canvas.drawText("b.width = " + bkbmp.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("b.height = " + bkbmp.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.width = " + canvas.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.height = " + canvas.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("scrollX = " + getScrollX() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mPosition = " + mPosition , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("lastPosition = " + lastDrawedPage , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffset = " + mOffset , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("offsetRate = " + offsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("invOffsetRate = " + invOffsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffsetPixels = " + mOffsetPixels , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("index = " + getCurrentItem() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); } }