List of usage examples for android.graphics Paint setStyle
public void setStyle(Style style)
From source file:com.frapim.windwatch.Notifier.java
public Bitmap createIcon(Context context, Wind wind) { Paint paint = new Paint(); int color = wind.scale.getColor(context); paint.setColor(color);//from w w w. j a v a 2s .co m paint.setStyle(Style.FILL_AND_STROKE); Bitmap bitmap = Bitmap.createBitmap(mBigIconSize, mBigIconSize, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Bitmap backgroundBmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.turbine); Bitmap backgroundScaled = Bitmap.createScaledBitmap(backgroundBmp, mBigIconSize, mBigIconSize, false); canvas.drawBitmap(backgroundScaled, new Matrix(), new Paint()); canvas.drawPath(getArrowPath(wind.degrees), paint); return bitmap; }
From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java
@Override void doDraw(Canvas canvas, Paint paint) { if (!mPath.isEmpty()) { paint.setStyle(Paint.Style.FILL); int color = blendColors(mStartColor, mEndColor, mCurrentScale); paint.setColor(color);//from w w w .j a v a 2 s . c o m canvas.drawPath(mPath, paint); } }
From source file:nu.yona.app.customview.graph.SpreadGraph.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); this.mCanvas = canvas; float fullWidth = canvas.getWidth(); float heightOfbar = GraphUtils.convertSizeToDeviceDependent(mContext, graphHeight); //first bar//from ww w . j a va2 s . c om float mXStart = 0, mYStart = heightOfbar; // basically (X1, Y1) float bottom = heightOfbar; // height (distance from Y1 to Y2) mStartPoint = 0; mMiddlePoint = (fullWidth / 2); float spreadtime = fullWidth; float mPartSize = spreadtime / mNoParts; //todraw text from height float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor); //draw graphics of sun and moon Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)); float bitmapWidth = moonBitmap.getWidth() / 2; mCanvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)), mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null); float textPoint = (mMiddlePoint / 2) / 2; mCanvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw + scaleFactor, getFontStyle()); float textPoint2 = textPoint * 2 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw + scaleFactor, getFontStyle()); float textPoint3 = textPoint * 5; mCanvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint4 = textPoint * 6 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint5 = textPoint * 7 + ((textPoint / 2)); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5, bottom + (5 * scaleFactor), null); if (mListZoneSpread != null && mListZoneSpread.size() > 0) { float currentStartPos; float currentEndPos; Paint barGraphPaint = new Paint(); barGraphPaint.setStyle(Paint.Style.STROKE); barGraphPaint.setStrokeWidth(5); boolean skipThis; for (TimeZoneSpread timeZoneSpread : mListZoneSpread) { skipThis = false; currentStartPos = (float) timeZoneSpread.getIndex() * mPartSize; Path barPath = new Path(); if (timeZoneSpread.getColor() == GraphUtils.COLOR_PINK || timeZoneSpread.getColor() == GraphUtils.COLOR_BLUE) { currentEndPos = timeZoneSpread.getUsedValue(); barGraphPaint.setColor(timeZoneSpread.getColor()); } else if (timeZoneSpread.getColor() == GraphUtils.COLOR_GREEN) { if (timeZoneSpread.getUsedValue() == 15) { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BULLET_DOT); } else { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BLUE); } } else if (timeZoneSpread.getUsedValue() != 15 && timeZoneSpread.getColor() == GraphUtils.COLOR_BULLET_LIGHT_DOT) { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); skipThis = true; } else { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); } if (!skipThis) { float newXPos = mXStart + currentStartPos; barPath.moveTo(newXPos + 2, mYStart); float noPartsHeight = heightOfbar / 15; barPath.lineTo(currentStartPos + 2, mYStart - (currentEndPos * noPartsHeight) - 1); canvas.drawPath(barPath, barGraphPaint); } } } }
From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java
/** * Creates a bus stop icon with the given direction arrow, or without a direction arrow if * the direction is NO_DIRECTION//from ww w .j a v a 2 s. c o m * * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in * constants in this class, or NO_DIRECTION if the stop icon shouldn't have a * direction arrow * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow * if direction is NO_DIRECTION */ private static Bitmap createBusStopIcon(String direction) throws NullPointerException { if (direction == null) { throw new IllegalArgumentException(direction); } Resources r = Application.get().getResources(); Context context = Application.get(); Float directionAngle = null; // 0-360 degrees Bitmap bm; Canvas c; Drawable shape; Float rotationX = null, rotationY = null; // Point around which to rotate the arrow Paint arrowPaintFill = new Paint(); arrowPaintFill.setStyle(Paint.Style.FILL); arrowPaintFill.setAntiAlias(true); if (direction.equals(NO_DIRECTION)) { // Don't draw the arrow bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, bm.getWidth(), bm.getHeight()); } else if (direction.equals(NORTH)) { directionAngle = 0f; bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // For NORTH, no rotation occurs - use center of image anyway so we have some value rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(NORTH_WEST)) { directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = mPx / 2f + mBuffer / 2f; rotationY = bm.getHeight() / 2f - mBuffer / 2f; } else if (direction.equals(WEST)) { directionAngle = 0f; // Arrow is drawn pointing West, so no rotation bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight()); arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // For WEST rotationX = bm.getHeight() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(SOUTH_WEST)) { directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx); arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = bm.getWidth() / 2f - mBuffer / 4f; rotationY = mPx / 2f + mBuffer / 4f; } else if (direction.equals(SOUTH)) { directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer)); arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2, bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(SOUTH_EAST)) { directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, mPx, mPx); arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer, bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = (mPx + mBuffer / 2) / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(EAST)) { directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180 bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, mPx, bm.getHeight()); arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2, bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(NORTH_EAST)) { directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around middle of circle rotationX = (float) mPx / 2; rotationY = bm.getHeight() - (float) mPx / 2; } else { throw new IllegalArgumentException(direction); } shape.draw(c); if (direction.equals(NO_DIRECTION)) { // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow return bm; } /** * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same * size for all orientations */ // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle) final float CUTOUT_HEIGHT = mPx / 12; Path path = new Path(); float x1 = 0, y1 = 0; // Tip of arrow float x2 = 0, y2 = 0; // lower left float x3 = 0, y3 = 0; // cutout in arrow bottom float x4 = 0, y4 = 0; // lower right if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST) || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) { // Arrow is drawn pointing NORTH // Tip of arrow x1 = mPx / 2; y1 = 0; // lower left x2 = (mPx / 2) - (mArrowWidthPx / 2); y2 = mArrowHeightPx; // cutout in arrow bottom x3 = mPx / 2; y3 = mArrowHeightPx - CUTOUT_HEIGHT; // lower right x4 = (mPx / 2) + (mArrowWidthPx / 2); y4 = mArrowHeightPx; } else if (direction.equals(EAST) || direction.equals(WEST)) { // Arrow is drawn pointing WEST // Tip of arrow x1 = 0; y1 = mPx / 2; // lower left x2 = mArrowHeightPx; y2 = (mPx / 2) - (mArrowWidthPx / 2); // cutout in arrow bottom x3 = mArrowHeightPx - CUTOUT_HEIGHT; y3 = mPx / 2; // lower right x4 = mArrowHeightPx; y4 = (mPx / 2) + (mArrowWidthPx / 2); } path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x4, y4); path.lineTo(x1, y1); path.close(); // Rotate arrow around (rotationX, rotationY) point Matrix matrix = new Matrix(); matrix.postRotate(directionAngle, rotationX, rotationY); path.transform(matrix); c.drawPath(path, arrowPaintFill); c.drawPath(path, mArrowPaintStroke); return bm; }
From source file:com.jaspersoft.android.jaspermobile.widget.AnnotationView.java
private void addPath() { Paint annotationPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); annotationPaint.setColor(mColor);//from w w w . j a v a 2 s. com annotationPaint.setStyle(Paint.Style.STROKE); annotationPaint.setStrokeJoin(Paint.Join.ROUND); annotationPaint.setStrokeCap(Paint.Cap.ROUND); DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); int strokeSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mSize, metrics); annotationPaint.setStrokeWidth(strokeSize); Path annotationPath = new Path(); annotationPath.moveTo(mStartX, mStartY); mDrawingCache.add(new Pair<>(annotationPaint, annotationPath)); }
From source file:com.madgag.android.lazydrawables.samples.DemoListActivity.java
private ImageResourceDownloader<String, Bitmap> slowImageMaker() { return new ImageResourceDownloader<String, Bitmap>() { public Bitmap get(String key) { Log.d(TAG, "Asked to download " + key); try { Thread.sleep(4000L); } catch (InterruptedException e) { }/* w w w .ja v a 2 s . c om*/ Bitmap bitmap = Bitmap.createBitmap(80, 80, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(0xff0000ff); c.drawCircle(0, 0, 50, paint); paint.setColor(0xffff007f); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); paint.setTextSize(30); c.drawText(key, 0, 3, 0, 60, paint); Log.d(TAG, "Done drawing... " + key); return bitmap; } }; }
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 ww w.ja v a 2s . com // 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.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 w ww .j av a2s.com // 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:com.raspi.chatapp.util.Notification.java
private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) { Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); RectF mInnerRectF = new RectF(); mInnerRectF.set(0, 0, width, width); mInnerRectF.offset(0, 0);//from www . j ava 2s .c o m Paint mBgPaint = new Paint(); mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mBgPaint.setStyle(Paint.Style.FILL); mBgPaint.setColor(bgColor); TextPaint mTitleTextPaint = new TextPaint(); mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); mTitleTextPaint.setTextAlign(Paint.Align.CENTER); mTitleTextPaint.setLinearText(true); mTitleTextPaint.setColor(Color.WHITE); mTitleTextPaint.setTextSize(width * 0.8f); float centerX = mInnerRectF.centerX(); float centerY = mInnerRectF.centerY(); int xPos = (int) centerX; int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2); if (round) c.drawOval(mInnerRectF, mBgPaint); else c.drawRect(mInnerRectF, mBgPaint); c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint); return b; }
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; }/*w w w . j a v a2 s. com*/ // 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; }