List of usage examples for android.graphics Rect height
public final int height()
From source file:Main.java
public static void log(String key, Rect rect) { debugOutput.put(key, rect.left + ", " + rect.top + ", " + rect.right + ", " + rect.bottom + " : " + rect.width() + ", " + rect.height()); }
From source file:Main.java
public static Rect getTextBounds(float textSize, String text) { Rect bounds = new Rect(); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(textSize);//from w w w . ja v a2 s . c om paint.getTextBounds(text, 0, text.length(), bounds); bounds.height(); return bounds; }
From source file:Main.java
public static int[] sizeWithTitle(Activity activity) { Rect outRect = new Rect(); int[] size = new int[2]; activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect); size[0] = outRect.width();//from w w w . j a va 2 s .co m size[1] = outRect.height(); return size; }
From source file:Main.java
public static void drawCenterText(Canvas canvas, String text, Paint paint, Rect rect) { paint.getTextBounds(text, 0, text.length(), bounds); int x = (int) (rect.left + rect.width() / 2 - bounds.centerX()); int y = (int) (rect.top + rect.height() / 2 - bounds.centerY()); //Log.v(TAG," x="+x + " y="+y + " "+ text); canvas.drawText(text, x, y, paint);/*from w w w .j av a2 s .c om*/ }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context context, int resId, String text) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, resId); Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null) bitmapConfig = Bitmap.Config.ARGB_8888; bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(context.getResources().getColor(android.R.color.white)); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); paint.setTextSize((int) (12 * scale)); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 4; int y = (bitmap.getHeight() + bounds.height()) / 5; canvas.drawText(text, x * scale, y * scale, paint); return bitmap; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context gContext, String gText, int frontColor, int backColor) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; int w = 1536, h = 1280; Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap android.graphics.Bitmap.Config bitmapConfig = bmp.getConfig(); Canvas canvas = new Canvas(bmp); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(frontColor);//w w w . ja v a2s. c om // text size in pixels paint.setTextSize((int) (400 * scale)); // text shadow //paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center if (backColor != -1) { canvas.drawColor(backColor); } Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bmp.getWidth() - bounds.width()) / 2; int y = (bmp.getHeight() + bounds.height()) / 2; canvas.drawText(gText, x, y, paint); return bmp; }
From source file:Main.java
public static void drawTextCenter(Canvas canvas, RectF rectf, String s, String s1, Paint paint, Paint paint1) { Rect rect = new Rect(); paint.getTextBounds(s, 0, s.length(), rect); float f = rectf.left + (rectf.width() - (float) rect.width()) / 2.0F; float f1 = rectf.top + (rectf.height() + (float) rect.height()) / 2.0F; canvas.drawText(s, f, f1, paint);//from w w w . j a v a2 s .c o m Rect rect1 = new Rect(); paint1.getTextBounds(s, 0, s.length(), rect1); canvas.drawText(s1, 6F + (f + (float) rect.width()), (f1 - (float) rect.height()) + (float) rect1.height(), paint1); }
From source file:Main.java
public static void drawTextCenter(Canvas canvas, RectF rectf, String s, Paint paint) { Rect rect = new Rect(); paint.getTextBounds(s, 0, s.length(), rect); canvas.drawText(s, rectf.left + (rectf.width() - (float) rect.width()) / 2.0F, rectf.top + (rectf.height() + (float) rect.height()) / 2.0F, paint); }
From source file:Main.java
public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight, ScaleType scalingLogic) {// w w w .java 2s. co m Rect srcRect = calculateSrcRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight, scalingLogic); Rect dstRect = calculateDstRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight, scalingLogic); Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(), Config.ARGB_8888); Canvas canvas = new Canvas(scaledBitmap); canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG)); return scaledBitmap; }
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true);// ww w . j a v a 2 s . c o m paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); return new BitmapDrawable(res, buffer); }