List of usage examples for android.graphics Rect isEmpty
public final boolean isEmpty()
From source file:Main.java
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) { final Rect tmpRect = new Rect(); drawable.copyBounds(tmpRect);//from w ww . j av a 2s . co m if (tmpRect.isEmpty()) { tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight())); drawable.setBounds(tmpRect); } Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888); drawable.draw(new Canvas(bitmap)); return bitmap; }
From source file:Main.java
/** * The most useful answer about text drawing ever. http://stackoverflow.com/a/32081250 *///w w w. ja va 2 s. c om @Nullable public static Bitmap createTypefaceBitmap(final Context context, @NonNull final String text, final int color, final float textSizePx) { final Typeface robotoMedium = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(robotoMedium); paint.setStyle(Paint.Style.FILL); paint.setColor(color); paint.setTextSize(textSizePx); final Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); Bitmap bitmap = null; if (!bounds.isEmpty()) { final int width = bounds.width(); final int height = bounds.height(); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); final float x = bounds.left; final float y = height - bounds.bottom; final Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); } return bitmap; }
From source file:com.facebook.litho.utils.IncrementalMountUtils.java
private static void maybePerformIncrementalMountOnView(int scrollingParentWidth, int scrollingParentHeight, View view) {/*from w w w. j a v a 2 s. com*/ final View underlyingView = view instanceof WrapperView ? ((WrapperView) view).getWrappedView() : view; if (!(underlyingView instanceof LithoView)) { return; } final LithoView lithoView = (LithoView) underlyingView; if (!lithoView.isIncrementalMountEnabled()) { return; } if (view != underlyingView && view.getHeight() != underlyingView.getHeight()) { throw new IllegalStateException( "ViewDiagnosticsWrapper must be the same height as the underlying view"); } final int translationX = (int) view.getTranslationX(); final int translationY = (int) view.getTranslationY(); final int top = view.getTop() + translationY; final int bottom = view.getBottom() + translationY; final int left = view.getLeft() + translationX; final int right = view.getRight() + translationX; if (left >= 0 && top >= 0 && right <= scrollingParentWidth && bottom <= scrollingParentHeight && lithoView.getPreviousMountBounds().width() == lithoView.getWidth() && lithoView.getPreviousMountBounds().height() == lithoView.getHeight()) { // View is fully visible, and has already been completely mounted. return; } final Rect rect = acquireRect(); rect.set(Math.max(0, -left), Math.max(0, -top), Math.min(right, scrollingParentWidth) - left, Math.min(bottom, scrollingParentHeight) - top); if (rect.isEmpty()) { // View is not visible at all, nothing to do. release(rect); return; } lithoView.performIncrementalMount(rect); release(rect); }
From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java
/** * Computes whether the specified {@link android.graphics.Rect} intersects with the visible portion of its parent * {@link android.view.View}. Modifies {@code localRect} to contain only the visible portion. * * @param localRect A rectangle in local (parent) coordinates. * @return Whether the specified {@link android.graphics.Rect} is visible on the screen. *///from ww w .ja v a 2 s . c om private boolean intersectVisibleToUser(Rect localRect) { // Missing or empty bounds mean this view is not visible. if ((localRect == null) || localRect.isEmpty()) { return false; } // Attached to invisible window means this view is not visible. if (mParentView.getWindowVisibility() != View.VISIBLE) { return false; } // An invisible predecessor or one with alpha zero means // that this view is not visible to the user. Object current = this; while (current instanceof View) { final View view = (View) current; // We have attach info so this view is attached and there is no // need to check whether we reach to ViewRootImpl on the way up. if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) { return false; } current = view.getParent(); } // If no portion of the parent is visible, this view is not visible. if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) { return false; } // Check if the view intersects the visible portion of the parent. return localRect.intersect(mTempVisibleRect); }
From source file:org.holoeverywhere.widget.datetimepicker.TouchExplorationHelper.java
/** * Computes whether the specified {@link Rect} intersects with the visible * portion of its parent {@link View}. Modifies {@code localRect} to * contain only the visible portion.// w ww . j a va 2 s . c om * * @param localRect A rectangle in local (parent) coordinates. * @return Whether the specified {@link Rect} is visible on the screen. */ private boolean intersectVisibleToUser(Rect localRect) { // Missing or empty bounds mean this view is not visible. if ((localRect == null) || localRect.isEmpty()) { return false; } // Attached to invisible window means this view is not visible. if (mParentView.getWindowVisibility() != View.VISIBLE) { return false; } // An invisible predecessor or one with alpha zero means // that this view is not visible to the user. Object current = this; while (current instanceof View) { final View view = (View) current; // We have attach info so this view is attached and there is no // need to check whether we reach to ViewRootImpl on the way up. if ((ViewHelper.getAlpha(view) <= 0) || (view.getVisibility() != View.VISIBLE)) { return false; } current = view.getParent(); } // If no portion of the parent is visible, this view is not visible. if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) { return false; } // Check if the view intersects the visible portion of the parent. return localRect.intersect(mTempVisibleRect); }
From source file:com.doomonafireball.betterpickers.TouchExplorationHelper.java
/** * Computes whether the specified {@link android.graphics.Rect} intersects * with the visible portion of its parent {@link android.view.View}. * Modifies {@code localRect} to contain only the visible portion. * //from w w w .j ava 2 s. c om * @param localRect * A rectangle in local (parent) coordinates. * @return Whether the specified {@link android.graphics.Rect} is visible on * the screen. */ @SuppressLint("NewApi") private boolean intersectVisibleToUser(Rect localRect) { // Missing or empty bounds mean this view is not visible. if ((localRect == null) || localRect.isEmpty()) { return false; } // Attached to invisible window means this view is not visible. if (mParentView.getWindowVisibility() != View.VISIBLE) { return false; } // An invisible predecessor or one with alpha zero means // that this view is not visible to the user. Object current = this; while (current instanceof View) { final View view = (View) current; // We have attach info so this view is attached and there is no // need to check whether we reach to ViewRootImpl on the way up. if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) { return false; } current = view.getParent(); } // If no portion of the parent is visible, this view is not visible. if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) { return false; } // Check if the view intersects the visible portion of the parent. return localRect.intersect(mTempVisibleRect); }
From source file:android.support.transition.FragmentTransitionSupport.java
@Override public void setEpicenter(Object transitionObj, final Rect epicenter) { if (transitionObj != null) { Transition transition = (Transition) transitionObj; transition.setEpicenterCallback(new Transition.EpicenterCallback() { @Override//from www . j av a 2 s. c om public Rect onGetEpicenter(@NonNull Transition transition) { if (epicenter == null || epicenter.isEmpty()) { return null; } return epicenter; } }); } }
From source file:com.android.utils.ExploreByTouchHelper.java
/** * Computes whether the specified {@link Rect} intersects with the visible * portion of its parent {@link View}. Modifies {@code localRect} to contain * only the visible portion./* w ww. ja va2 s . c om*/ * * @param localRect A rectangle in local (parent) coordinates. * @return Whether the specified {@link Rect} is visible on the screen. */ private boolean intersectVisibleToUser(Rect localRect) { // Missing or empty bounds mean this view is not visible. if ((localRect == null) || localRect.isEmpty()) { return false; } // Attached to invisible window means this view is not visible. if (mHost.getWindowVisibility() != View.VISIBLE) { return false; } // An invisible predecessor or one with alpha zero means // that this view is not visible to the user. Object current = this; while (current instanceof View) { final View view = (View) current; // We have attach info so this view is attached and there is no // need to check whether we reach to ViewRootImpl on the way up. if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) { return false; } current = view.getParent(); } // If no portion of the parent is visible, this view is not visible. if (!mHost.getLocalVisibleRect(mTempVisibleRect)) { return false; } // Check if the view intersects the visible portion of the parent. return localRect.intersect(mTempVisibleRect); }
From source file:com.facebook.litho.LithoView.java
private void maybePerformIncrementalMountOnView() { if (!mIncrementalMountOnOffsetOrTranslationChange && !ComponentsConfiguration.isIncrementalMountOnOffsetOrTranslationChangeEnabled) { return;/*from ww w . j a v a 2 s.co m*/ } if (!isIncrementalMountEnabled() || !(getParent() instanceof View)) { return; } int parentWidth = ((View) getParent()).getWidth(); int parentHeight = ((View) getParent()).getHeight(); final int translationX = (int) getTranslationX(); final int translationY = (int) getTranslationY(); final int top = getTop() + translationY; final int bottom = getBottom() + translationY; final int left = getLeft() + translationX; final int right = getRight() + translationX; if (left >= 0 && top >= 0 && right <= parentWidth && bottom <= parentHeight && mPreviousMountBounds.width() == getWidth() && mPreviousMountBounds.height() == getHeight()) { // View is fully visible, and has already been completely mounted. return; } final Rect rect = ComponentsPools.acquireRect(); rect.set(Math.max(0, -left), Math.max(0, -top), Math.min(right, parentWidth) - left, Math.min(bottom, parentHeight) - top); if (rect.isEmpty()) { // View is not visible at all, nothing to do. ComponentsPools.release(rect); return; } performIncrementalMount(rect); ComponentsPools.release(rect); }
From source file:com.facebook.litho.MountState.java
private static int computeRectArea(Rect rect) { return rect.isEmpty() ? 0 : (rect.width() * rect.height()); }