List of usage examples for android.graphics Paint setStyle
public void setStyle(Style style)
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @param canvasContent/*from www . jav a 2 s. c o m*/ * @param paintContent */ private void paintBoxList(Canvas canvasContent, Paint paintContent) { for (Box b : boxList) { paintContent.setColor(Color.GREEN); paintContent.setStyle(Style.FILL); paintContent.setAlpha(50); for (int i = b.getNorthWest().getX(); i < b.getSouthEast().getX(); i++) { for (int j = b.getNorthWest().getY(); j < b.getSouthEast().getY(); j++) { canvasContent.drawRect(cellDimension * i, cellDimension * j, cellDimension * i + cellDimension, cellDimension * j + cellDimension, paintContent); } } } }
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 w w .ja v a 2 s . c om*/ // 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.nextgis.maplib.display.SimpleMarkerStyle.java
protected void onDraw(GeoPoint pt, GISDisplay display) { if (null == pt) return;/*from ww w . j av a 2 s . com*/ switch (mType) { case MarkerStylePoint: Paint ptPaint = new Paint(); ptPaint.setColor(mColor); ptPaint.setStrokeWidth((float) (mSize / display.getScale())); ptPaint.setStrokeCap(Paint.Cap.ROUND); ptPaint.setAntiAlias(true); display.drawPoint((float) pt.getX(), (float) pt.getY(), ptPaint); break; case MarkerStyleCircle: Paint fillCirclePaint = new Paint(); fillCirclePaint.setColor(mColor); fillCirclePaint.setStrokeCap(Paint.Cap.ROUND); display.drawCircle((float) pt.getX(), (float) pt.getY(), mSize, fillCirclePaint); Paint outCirclePaint = new Paint(); outCirclePaint.setColor(mOutColor); outCirclePaint.setStrokeWidth((float) (mWidth / display.getScale())); outCirclePaint.setStyle(Paint.Style.STROKE); outCirclePaint.setAntiAlias(true); display.drawCircle((float) pt.getX(), (float) pt.getY(), mSize, outCirclePaint); break; case MarkerStyleDiamond: break; case MarkerStyleCross: break; case MarkerStyleTriangle: break; case MarkerStyleBox: break; } }
From source file:com.liferay.mobile.screens.viewsets.defaultviews.userportrait.UserPortraitView.java
protected Paint getBorderPaint(float borderWidth, int color) { Paint borderPaint = new Paint(); borderPaint.setAntiAlias(true);//w w w .j a v a 2 s . c o m borderPaint.setColor(ContextCompat.getColor(getContext(), color)); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidth); return borderPaint; }
From source file:com.concavenp.artistrymuse.fragments.BaseFragment.java
private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) { return new BitmapImageViewTarget(imageView) { @Override/*from ww w . ja v a 2 s. co m*/ protected void setResource(Bitmap bitmap) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int borderWidthHalf = 5; int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); int newBitmapSquare = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare, Bitmap.Config.ARGB_8888); // Initialize a new Canvas to draw empty bitmap Canvas canvas = new Canvas(roundedBitmap); // Calculation to draw bitmap at the circular bitmap center position int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; canvas.drawBitmap(bitmap, x, y, null); // Initializing a new Paint instance to draw circular border Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf * 2); borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null)); canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), roundedBitmap); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }; }
From source file:project.pamela.slambench.fragments.DurationPlot.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 ww .j a v a 2 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_duration)); 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); // Prepare Data (fill stack and add lines) KFusion.FieldIndex[] stackIndex = new KFusion.FieldIndex[] { (KFusion.FieldIndex.AQUISITION_DURATION), (KFusion.FieldIndex.PREPROCESSING_DURATION), (KFusion.FieldIndex.TRACKING_DURATION), (KFusion.FieldIndex.INTEGRATION_DURATION), (KFusion.FieldIndex.RAYCASTING_DURATION), (KFusion.FieldIndex.RENDERING_DURATION), (KFusion.FieldIndex.TOTAL_DURATION) }; Double[][] stackNumbers = new Double[][] { value.getField(stackIndex[0]), value.getField(stackIndex[1]), value.getField(stackIndex[2]), value.getField(stackIndex[3]), value.getField(stackIndex[4]), value.getField(stackIndex[5]) }; Double[][] stack = new Double[stackNumbers.length + 1][stackNumbers[0].length]; int[] stackColor = new int[] { Color.rgb(240, 0, 0), Color.rgb(255, 155, 0), Color.rgb(255, 255, 0), Color.rgb(155, 255, 98), Color.rgb(0, 212, 255), Color.rgb(0, 155, 255), Color.rgb(0, 0, 127) }; stack[0] = stackNumbers[0]; for (int i = 0; i < stackNumbers[0].length; ++i) { for (int j = 1; j < stackNumbers.length; ++j) { stack[j][i] = stack[j - 1][i] + stackNumbers[j][i]; } } stack[stackNumbers.length] = value.getField(KFusion.FieldIndex.TOTAL_DURATION); for (int i = stack.length - 1; i >= 0; --i) { // Turn the above arrays into XYSeries': XYSeries series = new SimpleXYSeries(Arrays.asList(stack[i]), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, stackIndex[i].getName()); LineAndPointFormatter seriesFormat = new LineAndPointFormatter(Color.rgb(73, 73, 73), null, stackColor[i], null); Paint paint = seriesFormat.getLinePaint(); paint.setStrokeWidth(1.0f); seriesFormat.setLinePaint(paint); // setup our line fill paint to be a slightly transparent gradient: //Paint lineFill = new Paint(); // lineFill.setAlpha(200); //lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, stackColor[i], Shader.TileMode.MIRROR)); //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, 0.033, stack[0].length - 1, 0.033 }; XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, getResources().getString(R.string.legend_realtime_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.bamobile.fdtks.util.Tools.java
public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, int borderWidth) { if (bitmap == null || bitmap.isRecycled()) { return null; }//from www .java 2 s.c om final int width = bitmap.getWidth() + borderWidth; final int height = bitmap.getHeight() + borderWidth; Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); Canvas canvas = new Canvas(canvasBitmap); float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setShader(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLUE); paint.setStrokeWidth(borderWidth); canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint); return canvasBitmap; }
From source file:org.stockchart.core.Appearance.java
public void applyFill(Paint p, RectF rect) { p.reset();//www . j a v a 2 s . c o m p.setStyle(Style.FILL); p.setColor(fPrimaryFillColor); switch (fGradient) { case LINEAR_HORIZONTAL: { p.setShader(new LinearGradient(rect.left, rect.top, rect.right, rect.top, fPrimaryFillColor, fSecondaryFillColor, TileMode.MIRROR)); } break; case LINEAR_VERTICAL: { p.setShader(new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, fPrimaryFillColor, fSecondaryFillColor, TileMode.MIRROR)); } break; default: p.setShader(null); } }
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @return/*from www. j a v a2s .c om*/ */ private Picture drawBarreds() { Picture pictureContent = new Picture(); Canvas canvasContent = pictureContent.beginRecording(getWidth(), getHeight()); Paint paintContent = new Paint(Paint.ANTI_ALIAS_FLAG); canvasContent.save(); paintContent.setColor(Color.BLUE); paintContent.setStyle(Style.STROKE); paintContent.setStrokeWidth(2); paintContent.setAlpha(50); try { cellDimension = block.getCellDimension(); JSONArray barred = block.getBarred(); int rows = block.getShape().getInt(0); int cols = block.getShape().getInt(1); // this code draws all the shape: for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { canvasContent.drawRect(cellDimension * j, cellDimension * i, cellDimension * j + cellDimension, cellDimension * i + cellDimension, paintContent); } } paintContent.setColor(Color.RED); paintContent.setStyle(Style.FILL); paintContent.setAlpha(50); for (int i = 0; i < barred.length(); i++) { JSONArray pos = barred.getJSONArray(i); canvasContent.drawRect(cellDimension * pos.getInt(1), cellDimension * pos.getInt(0), cellDimension * pos.getInt(1) + cellDimension, cellDimension * pos.getInt(0) + cellDimension, paintContent); } this.paintBoxList(canvasContent, paintContent); } catch (JSONException e) { e.printStackTrace(); Log.e("Exception in DrawComponents.drawBarreds", "" + e.getMessage()); } canvasContent.restore(); pictureContent.endRecording(); return pictureContent; }
From source file:com.silentcircle.contacts.ContactPhotoManager.java
/** * If necessary, decodes bytes stored in the holder to Bitmap. As long as the * bitmap is held either by {@link #mBitmapCache} or by a soft reference in * the holder, it will not be necessary to decode the bitmap. *///from ww w. j a v a 2 s. c o m private static void inflateBitmap(BitmapHolder holder, int requestedExtent) { final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent); byte[] bytes = holder.bytes; if (bytes == null || bytes.length == 0) { return; } if (sampleSize == holder.decodedSampleSize) { // Check the soft reference. If will be retained if the bitmap is also // in the LRU cache, so we don't need to check the LRU cache explicitly. if (holder.bitmapRef != null) { holder.bitmap = holder.bitmapRef.get(); if (holder.bitmap != null) { return; } } } try { Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize); // make bitmap mutable and draw size onto it if (DEBUG_SIZES) { Bitmap original = bitmap; bitmap = bitmap.copy(bitmap.getConfig(), true); original.recycle(); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setTextSize(16); paint.setColor(Color.BLUE); paint.setStyle(Style.FILL); canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint); paint.setColor(Color.WHITE); paint.setAntiAlias(true); canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint); } holder.decodedSampleSize = sampleSize; holder.bitmap = bitmap; holder.bitmapRef = new SoftReference<Bitmap>(bitmap); if (DEBUG) { int bCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) ? bitmap.getRowBytes() * bitmap.getHeight() : bitmap.getByteCount(); Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + ", " + btk(bCount)); } } catch (OutOfMemoryError e) { // Do nothing - the photo will appear to be missing } }