List of usage examples for android.graphics Rect width
public final int width()
From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }//from w ww . ja v a 2 s . c o m final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Since the view that's being transition to always seems to be on the top (z-order), we have // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out. // There has to be another way to do this, right? Drawable dialogView = null; if (!fromFab) { startValues.view.setDrawingCacheEnabled(true); startValues.view.buildDrawingCache(); Bitmap viewBitmap = startValues.view.getDrawingCache(); dialogView = new BitmapDrawable(view.getResources(), viewBitmap); dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); view.getOverlay().add(dialogView); } // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider(); view.setOutlineProvider(new ViewOutlineProvider() { boolean hasRun = false; @Override public void getOutline(final View view, Outline outline) { final int left = (view.getWidth() - endBounds.width()) / 2; final int top = (view.getHeight() - endBounds.height()) / 2; outline.setOval(left, top, left + endBounds.width(), top + endBounds.height()); if (!hasRun) { hasRun = true; view.setClipToOutline(true); // We have to remove this as soon as it's laid out so we can get the shadow back view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { if (view.getWidth() == endBounds.width() && view.getHeight() == endBounds.height()) { view.setOutlineProvider(fabOutlineProvider); view.setClipToOutline(false); view.getViewTreeObserver().removeOnPreDrawListener(this); return true; } return true; } }); } } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (dialogView != null) { final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0) .setDuration(twoThirdsDuration); dialogViewFade.setInterpolator(fastOutSlowInInterpolator); transition.playTogether(dialogViewFade); } transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); if (!fromFab) { view.setTranslationX(0); view.setTranslationY(0); view.setTranslationZ(0); view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom); } } }); return new AnimUtils.NoPauseAnimator(transition); }
From source file:org.liberty.android.fantastischmemo.ui.QuizLauncherDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setCanceledOnTouchOutside(true); getDialog().setTitle(R.string.quiz_text); View v = inflater.inflate(R.layout.quiz_launcher_dialog, container, false); startQuizButton = (Button) v.findViewById(R.id.start_quiz_button); startQuizButton.setOnClickListener(startQuizButtonOnClickListener); quizByGroupRadio = (RadioButton) v.findViewById(R.id.quiz_by_group_radio); quizByCategoryRadio = (RadioButton) v.findViewById(R.id.quiz_by_category_radio); quizGroupSizeTitle = (TextView) v.findViewById(R.id.quiz_group_size_title); quizGroupSizeEdit = (EditText) v.findViewById(R.id.quiz_group_size); // Make sure the text value is sanity and update other information // about the group size and etc accordingly. quizGroupSizeEdit.addTextChangedListener(editTextWatcher); quizGroupSizeEdit.setOnFocusChangeListener(sanitizeInputListener); quizGroupNumberTitle = (TextView) v.findViewById(R.id.quiz_group_number_title); quizGroupNumberEdit = (EditText) v.findViewById(R.id.quiz_group_number); quizGroupNumberEdit.addTextChangedListener(editTextWatcher); quizGroupNumberEdit.setOnFocusChangeListener(sanitizeInputListener); categoryButton = (Button) v.findViewById(R.id.category_button); categoryButton.setOnClickListener(categoryButtonListener); Rect displayRectangle = new Rect(); Window window = mActivity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle); v.setMinimumWidth((int) (displayRectangle.width() * 0.9f)); return v;/*from www . j av a 2s . co m*/ }
From source file:com.android.gallery3d.data.UriImage.java
public Bitmap drawTextToBitmap(Context gContext, String gText, Bitmap bitmap) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*from w w w . ja va2 s . c om*/ // 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(61, 61, 61)); // text size in pixels paint.setTextSize((int) (25 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.setTextAlign(Align.CENTER); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2; canvas.drawText(gText, x * scale, y * scale, paint); return bitmap; }
From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (null != mViewPager) { if (mViewPager instanceof CircularViewPager) { mPointCount = ((CircularViewPager) mViewPager).getCount(); } else {//from w ww. j a v a2 s. c o m mPointCount = mViewPager.getAdapter().getCount(); } } if (mPointCount <= 0) { return; } final int count = mPointCount; final int margin = mPointMargin; final int height = getHeight(); final int width = getWidth(); final int selIndex = mPosition; final Rect normalRc = mNormalPointRect; final Rect selectRc = mSelectPointRect; final Drawable dNormal = mNormalDrawable; final Drawable dSelect = mSelectDrawable; int left = (width - (margin * (count - 1) + normalRc.width() * (count - 1) + selectRc.width())) / 2; int top = 0; for (int index = 0; index < count; ++index) { if (index == selIndex) { if (null != dSelect) { top = (height - selectRc.height()) / 2; selectRc.offsetTo(left, top); dSelect.setBounds(selectRc); dSelect.draw(canvas); } left += (selectRc.width() + margin); } else { if (null != dNormal) { top = (height - normalRc.height()) / 2; normalRc.offsetTo(left, top); dNormal.setBounds(normalRc); dNormal.draw(canvas); } left += (normalRc.width() + margin); } } }
From source file:com.facebook.imagepipeline.platform.DefaultDecoder.java
/** * Create a bitmap from an input stream. * * @param inputStream the InputStream/* w w w.j a v a2 s. c o m*/ * @param options the {@link android.graphics.BitmapFactory.Options} used to decode the stream * @param regionToDecode optional image region to decode or null to decode the whole image * @param transformToSRGB whether to allow color space transformation to sRGB at load time * @return the bitmap */ private CloseableReference<Bitmap> decodeFromStream(InputStream inputStream, BitmapFactory.Options options, @Nullable Rect regionToDecode, final boolean transformToSRGB) { Preconditions.checkNotNull(inputStream); int targetWidth = options.outWidth; int targetHeight = options.outHeight; if (regionToDecode != null) { targetWidth = regionToDecode.width() / options.inSampleSize; targetHeight = regionToDecode.height() / options.inSampleSize; } int sizeInBytes = getBitmapSize(targetWidth, targetHeight, options); final Bitmap bitmapToReuse = mBitmapPool.get(sizeInBytes); if (bitmapToReuse == null) { throw new NullPointerException("BitmapPool.get returned null"); } options.inBitmap = bitmapToReuse; // Performs transformation at load time to sRGB. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && transformToSRGB) { options.inPreferredColorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } Bitmap decodedBitmap = null; ByteBuffer byteBuffer = mDecodeBuffers.acquire(); if (byteBuffer == null) { byteBuffer = ByteBuffer.allocate(DECODE_BUFFER_SIZE); } try { options.inTempStorage = byteBuffer.array(); if (regionToDecode != null) { BitmapRegionDecoder bitmapRegionDecoder = null; try { bitmapToReuse.reconfigure(targetWidth, targetHeight, options.inPreferredConfig); bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, true); decodedBitmap = bitmapRegionDecoder.decodeRegion(regionToDecode, options); } catch (IOException e) { FLog.e(TAG, "Could not decode region %s, decoding full bitmap instead.", regionToDecode); } finally { if (bitmapRegionDecoder != null) { bitmapRegionDecoder.recycle(); } } } if (decodedBitmap == null) { decodedBitmap = BitmapFactory.decodeStream(inputStream, null, options); } } catch (IllegalArgumentException e) { mBitmapPool.release(bitmapToReuse); // This is thrown if the Bitmap options are invalid, so let's just try to decode the bitmap // as-is, which might be inefficient - but it works. try { // We need to reset the stream first inputStream.reset(); Bitmap naiveDecodedBitmap = BitmapFactory.decodeStream(inputStream); if (naiveDecodedBitmap == null) { throw e; } return CloseableReference.of(naiveDecodedBitmap, SimpleBitmapReleaser.getInstance()); } catch (IOException re) { // We throw the original exception instead since it's the one causing this workaround in the // first place. throw e; } } catch (RuntimeException re) { mBitmapPool.release(bitmapToReuse); throw re; } finally { mDecodeBuffers.release(byteBuffer); } if (bitmapToReuse != decodedBitmap) { mBitmapPool.release(bitmapToReuse); decodedBitmap.recycle(); throw new IllegalStateException(); } return CloseableReference.of(decodedBitmap, mBitmapPool); }
From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) return;//ww w .ja va 2 s. co m final int count = getCount(); if (count == 0) return; Rect areaRect = new Rect(); areaRect.left = getPaddingLeft(); areaRect.right = getWidth() - getPaddingRight(); areaRect.top = getPaddingTop(); areaRect.bottom = getHeight() - getPaddingBottom(); int btnWidth = areaRect.width() / count; Rect tabRect = new Rect(areaRect); tabRect.top = tabRect.height() - mUnderlineHeight; tabRect.left += (mScrollingToPage + mPageOffset) * btnWidth; tabRect.right = tabRect.left + btnWidth; mPaint.setColor(mUnderlineColor); canvas.drawRect(tabRect, mPaint); mPaint.setColor(mTextColor); mPaint.setTextSize(mTextSize); for (int pos = 0; pos < count; pos++) { tabRect.set(areaRect); tabRect.left += pos * btnWidth; tabRect.right = tabRect.left + btnWidth; String pageTitle = getPageTitle(pos); RectF bounds = new RectF(tabRect); bounds.right = mPaint.measureText(pageTitle, 0, pageTitle.length()); bounds.bottom = mPaint.descent() - mPaint.ascent(); bounds.left += (tabRect.width() - bounds.right) / 2.0f; bounds.top += (tabRect.height() - bounds.bottom) / 2.0f; canvas.drawText(pageTitle, bounds.left, bounds.top - mPaint.ascent(), mPaint); } }
From source file:com.android.camera.HighlightView.java
void handleMotion(int edge, float dx, float dy) { Rect r = computeLayout(); if (edge == GROW_NONE) { return;//www . ja v a 2 s. c o m } else if (edge == MOVE) { // Convert to image space before sending to moveBy(). moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height())); } else { if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) { dx = 0; } if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) { dy = 0; } // Convert to image space before sending to growBy(). float xDelta = dx * (mCropRect.width() / r.width()); float yDelta = dy * (mCropRect.height() / r.height()); growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta); } }
From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java
/** * Maps {@link Rect} face bounds from Camera 2 API towards the model used throughout the samples * then passes the RecognisedFace object back * @param faceBounds/* ww w . ja va 2 s . c o m*/ * @param leftEyePosition * @param rightEyePosition */ private Face mapCameraFaceToCanvas(Rect faceBounds, Point leftEyePosition, Point rightEyePosition) { if (isViewAvailable()) { int w = faceBounds.width(); int h = faceBounds.height(); Face face = new Face(faceBounds.centerX() - w, faceBounds.centerY(), w, h); if (leftEyePosition != null) { face.setIrisLeft(leftEyePosition.x, leftEyePosition.y); } return face; } return new Face(); }
From source file:com.example.gatsu.theevent.HighlightView.java
void handleMotion(int edge, float dx, float dy) { Rect r = computeLayout(); if (edge == GROW_NONE) { return;// w w w .ja v a 2 s .c om } else if (edge == MOVE) { // Convert to image space before sending to moveBy(). moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height())); } else { if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) { dx = 0; } if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) { dy = 0; } // Convert to image space before sending to growBy(). float xDelta = dx * (mCropRect.width() / r.width()); float yDelta = dy * (mCropRect.height() / r.height()); growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta); } }
From source file:com.example.gatsu.theevent.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;//from w w w. j a va 2 s. c o m } Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) { canvas.save(); float width = mDrawRect.width(); float height = mDrawRect.height(); path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW); mOutlinePaint.setColor(0xFFEF04D6); canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint); canvas.restore(); } else { Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right, mDrawRect.top); if (topRect.width() > 0 && topRect.height() > 0) { canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right, viewDrawingRect.bottom); if (bottomRect.width() > 0 && bottomRect.height() > 0) { canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top); if (leftRect.width() > 0 && leftRect.height() > 0) { canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top); if (rightRect.width() > 0 && rightRect.height() > 0) { canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } path.addRect(new RectF(mDrawRect), Path.Direction.CW); mOutlinePaint.setColor(0xFFFF8A00); } canvas.drawPath(path, mOutlinePaint); if (mMode == ModifyMode.Grow) { if (mCircle) { int width = mResizeDrawableDiagonal.getIntrinsicWidth(); int height = mResizeDrawableDiagonal.getIntrinsicHeight(); int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D)); int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2; int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2; mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight()); mResizeDrawableDiagonal.draw(canvas); } else { int left = mDrawRect.left + 1; int right = mDrawRect.right + 1; int top = mDrawRect.top + 4; int bottom = mDrawRect.bottom + 3; int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2; int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2; int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2; int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2; int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2); int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2); mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); mResizeDrawableHeight.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); mResizeDrawableHeight.draw(canvas); } } } }