List of usage examples for android.graphics Rect Rect
public Rect()
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);/*from w ww .ja v a2s. c o m*/ // 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
/** * Returns the node's bounds clipped to the size of the display * * @param node//from w w w .j ava 2 s.c om * @param width pixel width of the display * @param height pixel height of the display * @return null if node is null, else a Rect containing visible bounds */ static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) { if (node == null) { return null; } // targeted node's bounds Rect nodeRect = new Rect(); node.getBoundsInScreen(nodeRect); Rect displayRect = new Rect(); displayRect.top = 0; displayRect.left = 0; displayRect.right = width; displayRect.bottom = height; final boolean intersect = nodeRect.intersect(displayRect); return nodeRect; }
From source file:Main.java
/** * Returns the node's bounds clipped to the size of the display * * @param node// w ww. j av a 2s.c o m * @param width pixel width of the display * @param height pixel height of the display * @return null if node is null, else a Rect containing visible bounds */ static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) { if (node == null) { return null; } // targeted node's bounds Rect nodeRect = new Rect(); node.getBoundsInScreen(nodeRect); Rect displayRect = new Rect(); displayRect.top = 0; displayRect.left = 0; displayRect.right = width; displayRect.bottom = height; nodeRect.intersect(displayRect); return nodeRect; }
From source file:Main.java
public static Rect getBoundsInScreen(AccessibilityNodeInfoCompat nodeInfo) { Rect rect = new Rect(); nodeInfo.getBoundsInScreen(rect); return rect; }
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);// w w w . ja v a2s. co 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); }
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);//www . ja v a2 s .co 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); BitmapDrawable bitmapDrawable = new BitmapDrawable(res, buffer); bitmapDrawable.setTargetDensity(canvas); return bitmapDrawable; }
From source file:Main.java
/** * Internal helper method to show the cheat sheet toast. *//* w ww . j a v a 2s . c o m*/ private static boolean show(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; } final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density); Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up // its height isn't factored in. cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight); } cheatSheet.show(); return true; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }//from w w w .j av a 2s . c o m // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #808080 paint.setColor(Color.rgb(127, 127, 127)); // text size in pixels paint.setTextSize((int) (14 * scale * 5)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); // int x = (bitmap.getWidth() - bounds.width()) / 2; // int y = (bitmap.getHeight() + bounds.height()) / 2; //draw text to the bottom int x = (bitmap.getWidth() - bounds.width()) / 10 * 9; int y = (bitmap.getHeight() + bounds.height()) / 10 * 9; canvas.drawText(gText, x, y, paint); return bitmap; }
From source file:Main.java
private static Rect getIntrinsicCropRegion(Point imageDimen, Rect cropRect, float scale) { Rect cropRegion = new Rect(); cropRegion.left = (int) (cropRect.left * scale); cropRegion.top = (int) (cropRect.top * scale); cropRegion.right = (int) (cropRect.right * scale + cropRegion.left); cropRegion.bottom = (int) (cropRect.bottom * scale + cropRegion.top); checkBoundaryCondition(imageDimen, cropRegion); return cropRegion; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context mContext, int resourceId, String mText) { try {//from w ww .ja v a 2s. c o m Resources resources = mContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, resourceId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; } // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(77, 77, 77)); // text size in pixels paint.setTextSize((int) (13 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(mText, 0, mText.length(), bounds); int x = (int) ((bitmap.getWidth() - bounds.width()) / 4); int y = (int) ((bitmap.getHeight() + bounds.height()) / 4); canvas.drawText(mText, x * scale, y * scale, paint); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; }