List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:org.stockchart.core.Appearance.java
public void applyText(Paint p) { p.reset();//from ww w . j a va 2 s . c om p.setTextSize(fFont.getSize()); p.setColor(fFont.getColor()); p.setTypeface(fFont.getTypeface()); p.setAntiAlias(fIsAntialias); p.setPathEffect(null); p.setStyle(Style.FILL); }
From source file:com.mallapp.utils.ImageLoader.java
/** * Crops a circle out of the thumbnail photo. *//*from w w w . jav a 2 s . c om*/ public Bitmap getCroppedBitmap(final Bitmap bitmap) { Bitmap output = null; try { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); paint.setAntiAlias(true); final int halfWidth = bitmap.getWidth() / 2; final int halfHeight = bitmap.getHeight() / 2; canvas.drawCircle(halfWidth, halfHeight, Math.max(halfWidth, halfHeight), paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); } catch (Exception e) { e.printStackTrace(); } return output; }
From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java
@NonNull private Bitmap buildMarkerBitmap(@NonNull Context c) { // Oh, this is going to be FUN. int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size); float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius); Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation); // Draw the pin line first. That goes from the bottom-center up to // wherever the radius and length take us. float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue(); float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue(); paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke)); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK);/*from w w w . j a v a 2 s . c om*/ canvas.drawLine(dim / 2, dim, topX, topY, paint); // On the top of that line, fill in a circle. paint.setColor(pinData.getColor()); paint.setStyle(Paint.Style.FILL); canvas.drawCircle(topX, topY, radius, paint); // And outline it. paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(topX, topY, radius, paint); return bitmap; }
From source file:potboiler.client.PotsActivity.java
License:asdf
private void createDrawerMenu() { mMenuItems = getResources().getStringArray(R.array.menu_sections); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (LinearLayout) findViewById(R.id.left_drawer); mCommandsList = (ListView) findViewById(R.id.commands); User user = PreferenceUtils.getUser(this); ((TextView) findViewById(R.id.name)).setText(user.username); Bitmap bitmap = ImageUtils.getImageFromFile(this, FileUtils.getImagesPath(this) + user.serverId); if (bitmap != null) { /*Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); /*from w w w . java2 s. c o m*/ BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); int radius = Math.min(h / 2, w / 2); Bitmap circleBitmap = Bitmap.createBitmap(w + 8, h + 8, Bitmap.Config.ARGB_8888); Paint paint = new Paint(); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawARGB(0, 0, 0, 0); paint.setStyle(Paint.Style.FILL); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawBitmap(bitmap, 4, 4, paint); paint.setXfermode(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.WHITE); paint.setStrokeWidth(3); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); ((ImageView) findViewById(R.id.avatar)).setImageBitmap(circleBitmap); } mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent)); DrawerAdapter adapter = new DrawerAdapter(this, R.layout.item_drawer_list, R.id.title, mMenuItems); mCommandsList.setAdapter(adapter); mCommandsList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.pots, R.string.pots) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); syncActionBarArrowState(); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } public void onDrawerOpened(View drawerView) { // super.onDrawerClosed(drawerView); super.onDrawerOpened(drawerView); mDrawerToggle.setDrawerIndicatorEnabled(true); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); float xPositionOpenDrawer = mCommandsList.getWidth(); float xPositionWindowContent = (slideOffset * xPositionOpenDrawer); FrameLayout mHostFragment = (FrameLayout) findViewById(R.id.content_frame); mHostFragment.setX(xPositionWindowContent); getActionBarView().setX(xPositionWindowContent); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener); findViewById(R.id.signout).setOnClickListener(this); }
From source file:org.thoughtcrime.securesms.scribbles.widget.MotionView.java
private void initEntityBorder(@NonNull MotionEntity entity) { // init stroke int strokeSize = getResources().getDimensionPixelSize(R.dimen.scribble_stroke_size); Paint borderPaint = new Paint(); borderPaint.setStrokeWidth(strokeSize); borderPaint.setAntiAlias(true); borderPaint.setColor(getContext().getResources().getColor(R.color.sticker_selected_color)); entity.setBorderPaint(borderPaint);/*from w ww . ja va 2 s .c om*/ }
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. jav a2s . c om*/ 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 } }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
private void drawText(Canvas canvas) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + getSelectedFontName())); int textSize = canvas.getHeight() / 35; paint.setTextSize(textSize);//from www. j ava 2 s. co m int margin = textSize / 5; // Measure date/time String dateTime = mEdtDateTime.getText().toString(); Rect boundsDateTime = new Rect(); paint.getTextBounds(dateTime, 0, dateTime.length(), boundsDateTime); // Measure location String location = mEdtLocation.getText().toString(); Rect boundsLocation = new Rect(); paint.getTextBounds(location, 0, location.length(), boundsLocation); int totalWidth = boundsDateTime.width() + textSize * 2 + boundsLocation.width(); if (totalWidth > canvas.getWidth()) { // Draw on 2 lines // Draw a rectangle paint.setColor(Color.argb(180, 0, 0, 0)); canvas.drawRect(0, 0, canvas.getWidth(), -boundsDateTime.top + boundsDateTime.bottom + -boundsLocation.top + boundsLocation.bottom + margin * 3, paint); // Draw date/time paint.setColor(Color.WHITE); canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint); // Draw location canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin, margin + -boundsDateTime.top + boundsDateTime.bottom + margin + -boundsLocation.top, paint); } else { // Draw on 1 line // Draw a rectangle paint.setColor(Color.argb(180, 0, 0, 0)); canvas.drawRect(0, 0, canvas.getWidth(), margin + Math.max(boundsDateTime.height(), boundsLocation.height()) + margin, paint); // Draw date/time paint.setColor(Color.WHITE); canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint); // Draw location canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin, margin + -boundsLocation.top, paint); } }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) { //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount)); Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); //final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);//from ww w . ja va 2 s. com //y canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); paint.setAntiAlias(true); int Max = 0; if (CritCount > ErrCount && CritCount > WarnCount) Max = CritCount; else if (ErrCount > CritCount && ErrCount > WarnCount) Max = ErrCount; else if (WarnCount > CritCount && WarnCount > ErrCount) Max = WarnCount; else Max = CritCount; if (Max > 0) canvas.drawText(Integer.toString(Max), 0, 10, paint); if (Max > 1) canvas.drawText(Integer.toString(Max / 2), 0, 75, paint); canvas.drawText("0", 0, 148, paint); double divisor = 148 / (double) Max; paint.setAlpha(128); Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148); paint.setColor(Color.argb(200, 208, 0, 0)); //red if (CritCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148); paint.setColor(Color.argb(200, 255, 102, 0));//orange if (ErrCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148); paint.setColor(Color.argb(200, 255, 224, 57)); //yellow if (WarnCount > 0) canvas.drawRect(new RectF(rect), paint); //Return ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void DrawEvents() { Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888); Canvas EventsCanvas = new Canvas(charty); final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(getResources().getColor(R.color.DarkBlue)); paint.setAntiAlias(true); EventsCanvas.drawOval(new RectF(1, 1, 199, 199), paint); RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFF6b7681, 0xFF000000, android.graphics.Shader.TileMode.CLAMP); paint.setDither(true);/*from ww w. j av a 2 s .c o m*/ paint.setShader(gradient); EventsCanvas.drawOval(new RectF(6, 6, 194, 194), paint); //Special Bits int Scale = 100; if (EventCount > 100) ; Scale = EventCount + 50; drawScale(EventsCanvas, true, EventCount, Scale); drawGaugeTitle(EventsCanvas, "Events Count"); drawGaugeNeedle(EventsCanvas, EventCount, Scale); //drawGloss(EventsCanvas); ((ImageView) findViewById(R.id.EventsGauge)).setImageBitmap(charty); }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); if (quoteData != null) { try {// w w w. j a v a2 s.c om JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width, -DY * 3); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }