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:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.CircularBorderDrawable.java
/** * Creates a vertical {@link LinearGradient} * @return/*from w w w . j av a 2s. c o m*/ */ private Shader createGradientShader() { final Rect rect = mRect; copyBounds(rect); final float borderRatio = mBorderWidth / rect.height(); final int[] colors = new int[6]; colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mTintColor); colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mTintColor); colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mTintColor); colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mTintColor); colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mTintColor); colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mTintColor); final float[] positions = new float[6]; positions[0] = 0f; positions[1] = borderRatio; positions[2] = 0.5f; positions[3] = 0.5f; positions[4] = 1f - borderRatio; positions[5] = 1f; return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP); }
From source file:project.pamela.slambench.fragments.AccuracyPlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false); // Retrieve bench number Intent mIntent = super.getActivity().getIntent(); final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0); SLAMResult value = SLAMBenchApplication.getResults().get(intValue); if (!value.isFinished()) { Log.e(SLAMBenchApplication.LOG_TAG, this.getResources().getString(R.string.debug_proposed_value_not_valid)); return llLayout; }//from w w w . j av a 2 s . c o m // initialize our XYPlot reference: XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); plot.setTitle(value.test.name); plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number)); plot.setRangeLabel(this.getResources().getString(R.string.legend_ate)); plot.setBackgroundColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##")); int border = 60; int legendsize = 110; plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget() .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL)); // reduce the number of range labels plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10); plot.setDomainValueFormat(new DecimalFormat("#")); plot.setRangeStep(XYStepMode.SUBDIVIDE, 10); plot.getLayoutManager().remove(plot.getTitleWidget()); // Set legend plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2)); Paint bgPaint = new Paint(); bgPaint.setColor(Color.BLACK); bgPaint.setStyle(Paint.Style.FILL); bgPaint.setAlpha(140); plot.getLegendWidget().setBackgroundPaint(bgPaint); plot.getLegendWidget() .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL)); plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP); plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE); int fillcolor = Color.rgb(255, 213, 226); int strokecolor = Color.rgb(225, 99, 70); Double accuracyNumbers[] = value.getATEList(); XYSeries series = new SimpleXYSeries(Arrays.asList(accuracyNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, this.getResources().getString(R.string.legend_ate)); LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null); Paint lineFill = new Paint(); lineFill.setAlpha(200); DisplayMetrics metrics = new DisplayMetrics(); super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); lineFill.setShader( new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR)); seriesFormat.setPointLabeler(new PointLabeler() { @Override public String getLabel(XYSeries series, int index) { return "o"; } }); seriesFormat.setFillPaint(lineFill); plot.addSeries(series, seriesFormat); // same as above LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null); //change the line width Paint paint = lineFormat.getLinePaint(); paint.setStrokeWidth(5); lineFormat.setLinePaint(paint); if (SLAMBenchApplication.getBenchmark() != null) { Number[] line = { 0, SLAMBenchApplication.getBenchmark().getMaxAccuracyError(), value.test.dataset.getFrameCount() - 1, SLAMBenchApplication.getBenchmark().getMaxAccuracyError() }; XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, getResources().getString(R.string.legend_error_limit)); plot.addSeries(expected, lineFormat); } plot.redraw(); plot.calculateMinMaxVals(); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED); plot.setRangeBoundaries(0, maxXY.y * 1.2f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:com.wareninja.opensource.gravatar4android.common.Utils.java
public static Bitmap getBitmapWithReflection(Bitmap originalImage) { //The gap we want between the reflection and the original image final int reflectionGap = 4; int width = originalImage.getWidth(); int height = originalImage.getHeight(); //This will not scale but will flip on the Y axis Matrix matrix = new Matrix(); matrix.preScale(1, -1);// w w w . j av a 2 s . c o m //Create a Bitmap with the flip matrix applied to it. //We only want the bottom half of the image Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false); //Create a new bitmap with same width but taller to fit reflection Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); //Create a new Canvas with the bitmap that's big enough for //the image plus gap plus reflection Canvas canvas = new Canvas(bitmapWithReflection); //Draw in the original image canvas.drawBitmap(originalImage, 0, 0, null); //Draw in the gap Paint deafaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); //Draw in the reflection canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); //Create a shader that is a linear gradient that covers the reflection Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); //Set the paint to use this shader (linear gradient) paint.setShader(shader); //Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); //Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:com.cooltechworks.views.ScratchImageView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mScratchBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mScratchBitmap); Rect rect = new Rect(0, 0, mScratchBitmap.getWidth(), mScratchBitmap.getHeight()); mDrawable.setBounds(rect);// w ww . ja v a 2 s . c om int startGradientColor = ContextCompat.getColor(getContext(), R.color.scratch_start_gradient); int endGradientColor = ContextCompat.getColor(getContext(), R.color.scratch_end_gradient); mGradientBgPaint.setShader(new LinearGradient(0, 0, 0, getHeight(), startGradientColor, endGradientColor, Shader.TileMode.MIRROR)); mCanvas.drawRect(rect, mGradientBgPaint); mDrawable.draw(mCanvas); }
From source file:project.pamela.slambench.fragments.TemperaturePlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false); // Retrieve bench number Intent mIntent = super.getActivity().getIntent(); final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0); SLAMResult value = SLAMBenchApplication.getResults().get(intValue); if (!value.isFinished()) { Log.e(SLAMBenchApplication.LOG_TAG, this.getResources().getString(R.string.debug_proposed_value_not_valid)); return llLayout; }//from w ww . j av a 2s. co m // initialize our XYPlot reference: XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); plot.setBackgroundColor(Color.WHITE); plot.setTitle(value.test.name); plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number)); plot.setRangeLabel(this.getResources().getString(R.string.legend_degrees)); plot.setBackgroundColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##")); int border = 60; int legendsize = 110; plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget() .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL)); // reduce the number of range labels plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10); plot.setDomainValueFormat(new DecimalFormat("#")); plot.setRangeStep(XYStepMode.SUBDIVIDE, 10); //Remove legend //plot.getLayoutManager().remove(plot.getLegendWidget()); //plot.getLayoutManager().remove(plot.getDomainLabelWidget()); //plot.getLayoutManager().remove(plot.getRangeLabelWidget()); plot.getLayoutManager().remove(plot.getTitleWidget()); // Set legend plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2)); Paint bgPaint = new Paint(); bgPaint.setColor(Color.BLACK); bgPaint.setStyle(Paint.Style.FILL); bgPaint.setAlpha(140); plot.getLegendWidget().setBackgroundPaint(bgPaint); plot.getLegendWidget() .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL)); plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP); plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE); int strokecolor = Color.rgb(67, 137, 192); int fillcolor = Color.rgb(213, 229, 255); Double temperatureNumbers[] = value.gettemperatureList(); XYSeries series = new SimpleXYSeries(Arrays.asList(temperatureNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, this.getResources().getString(R.string.legend_degrees)); LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null); Paint lineFill = new Paint(); lineFill.setAlpha(200); DisplayMetrics metrics = new DisplayMetrics(); super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); lineFill.setShader( new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR)); seriesFormat.setPointLabeler(new PointLabeler() { @Override public String getLabel(XYSeries series, int index) { return "o"; } }); seriesFormat.setFillPaint(lineFill); plot.addSeries(series, seriesFormat); plot.redraw(); plot.calculateMinMaxVals(); PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue()); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED); plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:project.pamela.slambench.fragments.PowerPlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false); // Retrieve bench number Intent mIntent = super.getActivity().getIntent(); final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0); SLAMResult value = SLAMBenchApplication.getResults().get(intValue); if (!value.isFinished()) { Log.e(SLAMBenchApplication.LOG_TAG, this.getResources().getString(R.string.debug_proposed_value_not_valid)); return llLayout; }/*from w ww .j av a 2s . c o m*/ // initialize our XYPlot reference: XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); plot.setTitle(value.test.name); plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number)); plot.setRangeLabel(this.getResources().getString(R.string.legend_power)); plot.setBackgroundColor(Color.WHITE); plot.getBorderPaint().setColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##")); int border = 60; int legendsize = 110; plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget() .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL)); // reduce the number of range labels plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10); plot.setDomainValueFormat(new DecimalFormat("#")); plot.setRangeStep(XYStepMode.SUBDIVIDE, 10); //Remove legend //plot.getLayoutManager().remove(plot.getLegendWidget()); //plot.getLayoutManager().remove(plot.getDomainLabelWidget()); //plot.getLayoutManager().remove(plot.getRangeLabelWidget()); plot.getLayoutManager().remove(plot.getTitleWidget()); // Set legend plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2)); Paint bgPaint = new Paint(); bgPaint.setColor(Color.BLACK); bgPaint.setStyle(Paint.Style.FILL); bgPaint.setAlpha(140); plot.getLegendWidget().setBackgroundPaint(bgPaint); plot.getLegendWidget() .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL)); plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP); plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE); int strokecolor = Color.rgb(91, 255, 159); int fillcolor = Color.rgb(91, 255, 184); Double powerNumbers[] = value.getPowerList(); for (int i = 0; i < value.test.dataset.getFrameCount(); i++) { powerNumbers[i] = powerNumbers[i] / -1000; } XYSeries series = new SimpleXYSeries(Arrays.asList(powerNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, this.getResources().getString(R.string.legend_power)); LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null); Paint lineFill = new Paint(); lineFill.setAlpha(200); DisplayMetrics metrics = new DisplayMetrics(); super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); lineFill.setShader( new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR)); seriesFormat.setPointLabeler(new PointLabeler() { @Override public String getLabel(XYSeries series, int index) { return "o"; } }); seriesFormat.setFillPaint(lineFill); plot.addSeries(series, seriesFormat); // same as above LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null); //change the line width Paint paint = lineFormat.getLinePaint(); paint.setStrokeWidth(5); lineFormat.setLinePaint(paint); Number[] line = { 0, 3, value.test.dataset.getFrameCount() - 1, 3 }; XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, getResources().getString(R.string.legend_power_limit)); plot.addSeries(expected, lineFormat); plot.redraw(); plot.calculateMinMaxVals(); PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue()); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED); plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:com.shollmann.igcparser.ui.activity.FlightPreviewActivity.java
public PaintDrawable getColorScala() { ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override//from ww w . j a va 2s. c o m public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width, height, 0, 0, new int[] { getResources().getColor(R.color.altitude_0_100), getResources().getColor(R.color.altitude_100_300), getResources().getColor(R.color.altitude_300_500), getResources().getColor(R.color.altitude_500_1000), getResources().getColor(R.color.altitude_1000_1500), getResources().getColor(R.color.altitude_1500_2000), getResources().getColor(R.color.altitude_2000_2500), getResources().getColor(R.color.altitude_more_than_2500) }, new float[] { 0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f }, Shader.TileMode.REPEAT); return linearGradient; } }; PaintDrawable paint = new PaintDrawable(); paint.setShape(new RectShape()); paint.setShaderFactory(shaderFactory); return paint; }
From source file:github.daneren2005.dsub.util.ImageLoader.java
private Bitmap createUnknownImage(int size, int primaryColor, String topText, String bottomText) { Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint color = new Paint(); color.setColor(primaryColor);//from www . j av a2 s .c o m canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color); color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR)); canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color); if (topText != null || bottomText != null) { Paint font = new Paint(); font.setFlags(Paint.ANTI_ALIAS_FLAG); font.setColor(Color.WHITE); font.setTextSize(3.0f + size * 0.07f); if (topText != null) { canvas.drawText(topText, size * 0.05f, size * 0.6f, font); } if (bottomText != null) { canvas.drawText(bottomText, size * 0.05f, size * 0.8f, font); } } return bitmap; }
From source file:project.pamela.slambench.fragments.FrequencyPlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false); // Retrieve bench number Intent mIntent = super.getActivity().getIntent(); final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0); SLAMResult value = SLAMBenchApplication.getResults().get(intValue); if (!value.isFinished()) { Log.e(SLAMBenchApplication.LOG_TAG, this.getResources().getString(R.string.debug_proposed_value_not_valid)); return llLayout; }/*from ww w.j a va2s. c o m*/ // initialize our XYPlot reference: XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); plot.setBackgroundColor(Color.WHITE); plot.setTitle(value.test.name); plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number)); plot.setRangeLabel(this.getResources().getString(R.string.frequency_domain)); plot.setBackgroundColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##")); int border = 60; int legendsize = 110; plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget() .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL)); // reduce the number of range labels plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10); plot.setDomainValueFormat(new DecimalFormat("#")); plot.setRangeStep(XYStepMode.SUBDIVIDE, 10); //Remove legend //plot.getLayoutManager().remove(plot.getLegendWidget()); //plot.getLayoutManager().remove(plot.getDomainLabelWidget()); //plot.getLayoutManager().remove(plot.getRangeLabelWidget()); plot.getLayoutManager().remove(plot.getTitleWidget()); // Set legend plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2)); Paint bgPaint = new Paint(); bgPaint.setColor(Color.BLACK); bgPaint.setStyle(Paint.Style.FILL); bgPaint.setAlpha(140); plot.getLegendWidget().setBackgroundPaint(bgPaint); plot.getLegendWidget() .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL)); plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP); plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE); for (int i = 0; i < value.getCPUCount(); i++) { int strokecolor = Color.rgb(i * (255 / value.getCPUCount()), 137, 192); int fillcolor = Color.rgb(i * (255 / value.getCPUCount()), 229, 255); Double frequencyNumbers[] = value.getfrequencyList(i); XYSeries series = new SimpleXYSeries(Arrays.asList(frequencyNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, this.getResources().getString(R.string.frequency_legend, i)); LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null); seriesFormat.setPointLabeler(new PointLabeler() { @Override public String getLabel(XYSeries series, int index) { return "o"; } }); Paint lineFill = new Paint(); lineFill.setAlpha(150); DisplayMetrics metrics = new DisplayMetrics(); super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); lineFill.setShader(new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR)); seriesFormat.setFillPaint(lineFill); plot.addSeries(series, seriesFormat); } plot.redraw(); plot.calculateMinMaxVals(); PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue()); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED); plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:android.support.design.widget.CircularBorderDrawable.java
/** * Creates a vertical {@link LinearGradient} * @return// w w w .j ava 2 s . c o m */ private Shader createGradientShader() { final Rect rect = mRect; copyBounds(rect); final float borderRatio = mBorderWidth / rect.height(); final int[] colors = new int[6]; colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor); colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor); colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mCurrentBorderTintColor); colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mCurrentBorderTintColor); colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor); colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor); final float[] positions = new float[6]; positions[0] = 0f; positions[1] = borderRatio; positions[2] = 0.5f; positions[3] = 0.5f; positions[4] = 1f - borderRatio; positions[5] = 1f; return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP); }