List of usage examples for android.graphics RectF RectF
public RectF()
From source file:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java
/** * /*from ww w .ja v a 2 s. co m*/ * * @param index * @param paint * @return */ private RectF calcBounds(int index, Paint paint) { // Calculate the text bounds RectF bounds = new RectF(); bounds.right = paint.measureText(mTitleProvider.getPageTitle(index).toString()); bounds.bottom = paint.descent() - paint.ascent(); return bounds; }
From source file:com.pdftron.pdf.controls.UserCropDialogFragment.java
private void SetCropRectOnView() { if (mPageProperties[mCurrentPage].mUserCropBox != null) { try {/*from ww w. j ava 2 s.c om*/ Rect cropBox = mPageProperties[mCurrentPage].mCropBox; if (cropBox.getWidth() > 0 && cropBox.getHeight() > 0) { Rect userCropBox = mPageProperties[mCurrentPage].mUserCropBox; RectF cropPercentageRect = new RectF(); cropPercentageRect.left = (float) ((userCropBox.getX1() - cropBox.getX1()) / cropBox.getWidth()); cropPercentageRect.right = (float) ((cropBox.getX2() - userCropBox.getX2()) / cropBox.getWidth()); cropPercentageRect.bottom = (float) ((userCropBox.getY1() - cropBox.getY1()) / cropBox.getHeight()); cropPercentageRect.top = (float) ((cropBox.getY2() - userCropBox.getY2()) / cropBox.getHeight()); rotateRectangle(cropPercentageRect, mPageProperties[mCurrentPage].mRotation); //mCropImageView.setCropRectPercentageMargins(cropPercentageRect); } } catch (com.pdftron.common.PDFNetException e) { } } }
From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //Measure our width in whatever mode specified final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); //Determine our height float height = 0; final int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); if (heightSpecMode == MeasureSpec.EXACTLY) { //We were told how big to be height = MeasureSpec.getSize(heightMeasureSpec); } else {/*from w w w . jav a 2s .c o m*/ //Calculate the text bounds RectF bounds = new RectF(); bounds.bottom = mPaintText.descent() - mPaintText.ascent(); height = bounds.bottom - bounds.top + mFooterLineHeight + mFooterPadding + mTopPadding; if (mFooterIndicatorStyle != IndicatorStyle.None) { height += mFooterIndicatorHeight; } } final int measuredHeight = (int) height; setMeasuredDimension(measuredWidth, measuredHeight); }
From source file:com.progekt.webtools.viewpagerindicator.TitlePageIndicator.java
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //Measure our width in whatever mode specified final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); //Determine our height float height = 0; final int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); if (heightSpecMode == MeasureSpec.EXACTLY) { //We were told how big to be height = MeasureSpec.getSize(heightMeasureSpec); } else {//from w ww.ja va2s. co m //Calculate the text bounds RectF bounds = new RectF(); bounds.bottom = mPaintText.descent() - mPaintText.ascent(); height = bounds.bottom - bounds.top + mFooterLineHeight + mFooterPadding + mTopPadding; if (mFooterIndicatorStyle != IndicatorStyle.None) { height += mFooterIndicatorHeight; } } final int measuredHeight = (int) height; setMeasuredDimension(measuredWidth, measuredHeight); }
From source file:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java
/** * View/*from ww w .j a v a2 s .c om*/ * * @param measureSpec * A measureSpec packed into an int * @return */ private int measureHeight(int measureSpec) { float result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { // result = specSize; } else { // RectF bounds = new RectF(); // =- bounds.bottom = mPaintText.descent() - mPaintText.ascent(); result = bounds.bottom - bounds.top + mFooterLineHeight + mFooterPadding + mTopPadding; // if (mFooterIndicatorStyle != IndicatorStyle.None) { result += mFooterIndicatorHeight; } } return (int) result; }
From source file:com.juce.JuceAppActivity.java
public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds (boundsF, true);/*w w w . j av a 2 s .c o m*/ matrix.mapRect (boundsF); boundsF.roundOut (bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max (1, bounds.height()); Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); matrix.postTranslate (-bounds.left, -bounds.top); c.setMatrix (matrix); c.drawPath (p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int [sizeNeeded]; bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:kr.wdream.storyshop.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;//from w w w . j a v a2 s.c o m TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e("tmessages", e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.android.launcher3.Utilities.java
/** * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually * normalized with other icons and has enough spacing to add shadow. *//*from ww w.j a v a2s . c o m*/ public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) { RectF iconBounds = new RectF(); float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ? 1 : IconNormalizer.getInstance().getScale(icon, iconBounds); scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds)); return createIconBitmap(icon, context, scale); }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/*from w ww . j ava 2 s .c o m*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e(e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:org.akop.crosswords.view.CrosswordView.java
private void bringIntoView(Crossword.Word word, int selectedCell) { if (word == null) { return;//from www .j a va2 s.co m } RectF wordRect = new RectF(); wordRect.left = word.getStartColumn() * mScaledCellSize - mContentRect.left; wordRect.top = word.getStartRow() * mScaledCellSize - mContentRect.top; if (word.getDirection() == Crossword.Word.DIR_ACROSS) { wordRect.right = wordRect.left + word.getLength() * mScaledCellSize; wordRect.bottom = wordRect.top + mScaledCellSize; } else if (word.getDirection() == Crossword.Word.DIR_DOWN) { wordRect.right = wordRect.left + mScaledCellSize; wordRect.bottom = wordRect.top + word.getLength() * mScaledCellSize; } RectF objectRect = new RectF(wordRect); RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(), -mBitmapOffset.y + mContentRect.height()); if (visibleArea.contains(objectRect)) { return; // Already visible } if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) { // Available area isn't large enough to fit the entire word // Is the selected cell visible? If not, bring it into view CellOffset co = getCellOffset(word, selectedCell); RectF cellRect = new RectF(); cellRect.left = co.mColumn * mScaledCellSize; cellRect.top = co.mRow * mScaledCellSize; cellRect.right = cellRect.left + mScaledCellSize; cellRect.bottom = cellRect.top + mScaledCellSize; if (visibleArea.contains(cellRect)) { return; // Already visible } objectRect.set(cellRect); } // Compute view that includes the object in the center PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left, (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top); // Clamp the values clampPointF(end, mTranslationBounds); // Compute the distance to travel from current location float distanceX = end.x - mBitmapOffset.x; float distanceY = end.y - mBitmapOffset.y; // Scroll the point into view mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY, NAVIGATION_SCROLL_DURATION_MS); }