@Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { mState = newState; if (newState == RefreshState.None) { mAppreciation = 0; mCloudX1 = mCloudX2 = mCloudX3 = -mCloudDrawable.getBounds().width(); } }
private static int getWidthForMountedContent(Object content) { return content instanceof Drawable ? ((Drawable) content).getBounds().width() : ((View) content).getWidth(); }
private static int getHeightForMountedContent(Object content) { return content instanceof Drawable ? ((Drawable) content).getBounds().height() : ((View) content).getHeight(); }
public static void applyXYToDrawableForAnimation(Drawable drawable, int x, int y) { final Rect bounds = drawable.getBounds(); drawable.setBounds(x, y, bounds.width() + x, bounds.height() + y); } }
public void setGeometricHeight(int height) { final Drawable drawable = PathsDrawable.this; final Rect bounds = drawable.getBounds(); float rate = 1f * height / bounds.height(); setBounds( (int) (bounds.left * rate), (int) (bounds.top * rate), (int) (bounds.right * rate), (int) (bounds.bottom * rate) ); }
public void setGeometricWidth(int width) { final Drawable drawable = PathsDrawable.this; final Rect bounds = drawable.getBounds(); float rate = 1f * width / bounds.width(); setBounds( (int) (bounds.left * rate), (int) (bounds.top * rate), (int) (bounds.right * rate), (int) (bounds.bottom * rate) ); }
public void declareOriginal(int startX, int startY, int width, int height) { this.mStartX = startX; this.mStartY = startY; this.mOriginWidth = mWidth = width; this.mOriginHeight = mHeight = height; final Drawable drawable = PathsDrawable.this; final Rect bounds = drawable.getBounds(); super.setBounds(bounds.left, bounds.top, bounds.left + width, bounds.top + height); }
private void drawSky(Canvas canvas, int width, int height) { Matrix matrix = mMatrix; matrix.reset(); int bWidth = mDrawableSky.getBounds().width();//mSky.getWidth(); int bHeight = mDrawableSky.getBounds().height();//mSky.getHeight(); float townScale = 1f * width / bWidth; float offsetX = 0; float offsetY = height / 2 - bHeight / 2; // matrix.postScale(townScale, townScale); // matrix.postTranslate(offsetX, offsetY); // // canvas.drawBitmap(mSky, matrix, null); final int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(offsetX, offsetY); matrix.postScale(townScale, townScale); mDrawableSky.draw(canvas); canvas.restoreToCount(saveCount); }
public static void applySizeToDrawableForAnimation(Drawable drawable, int width, int height) { final Rect bounds = drawable.getBounds(); drawable.setBounds(bounds.left, bounds.top, bounds.left + width, bounds.top + height); // TODO(t22432769): Remove this after D5965597 lands if (drawable instanceof MatrixDrawable) { ((MatrixDrawable) drawable).bind(width, height); } }
private void drawTown(Canvas canvas, int width, int height) { Matrix matrix = mMatrix; matrix.reset(); int bWidth = mDrawableTown.getBounds().width();//mTown.getWidth(); int bHeight = mDrawableTown.getBounds().height();//mTown.getHeight(); float townScale = 1f * width / bWidth; float amplification = (0.3f * Math.max(mPercent - 1, 0) + 1); float offsetX = width / 2 - (int) (width * amplification) / 2; float offsetY = mHeaderHeight * 0.1f * mPercent; townScale = amplification * townScale; if (offsetY + bHeight * townScale < height) { offsetY = height - bHeight * townScale; } // matrix.postScale(townScale, townScale, mDrawableTown.getBounds().width() / 2, mDrawableTown.getBounds().height() / 2); // matrix.postTranslate(offsetX, offsetY); // canvas.drawBitmap(mTown, matrix, null); final int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(offsetX, offsetY); canvas.scale(townScale, townScale); mDrawableTown.draw(canvas); canvas.restoreToCount(saveCount); }
@Override public void setThumb(Drawable thumb) { Rect localRect = null; if (drawable != null) { localRect = drawable.getBounds(); } super.setThumb(drawable); drawable = thumb; if ((localRect != null) && (drawable != null)) { drawable.setBounds(localRect); } }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); final View thisView = this; final View dropView = mWaterDropView; final Drawable progressDrawable = mProgressDrawable; if (mState == RefreshState.Refreshing) { canvas.save(); canvas.translate( thisView.getWidth()/2-progressDrawable.getBounds().width()/2, mWaterDropView.getMaxCircleRadius() +dropView.getPaddingTop() -progressDrawable.getBounds().height()/2 ); progressDrawable.draw(canvas); canvas.restore(); } }
@Override public void draw(@NonNull Canvas c) { final Drawable thisDrawable = this; final Rect bounds = thisDrawable.getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final View thisView = this; final Drawable drawable = mPathsDrawable; super.setMeasuredDimension( View.resolveSize(drawable.getBounds().width()+thisView.getPaddingLeft()+thisView.getPaddingRight(), widthMeasureSpec), View.resolveSize(drawable.getBounds().height()+thisView.getPaddingTop()+thisView.getPaddingBottom(), heightMeasureSpec)); }
private void calculateFrame(int width) { mCloudX1 += DensityUtil.dp2px(9); mCloudX2 += DensityUtil.dp2px(5); mCloudX3 += DensityUtil.dp2px(12); int cloudWidth = mCloudDrawable.getBounds().width(); if (mCloudX1 > width + cloudWidth) { mCloudX1 = -cloudWidth; } if (mCloudX2 > width + cloudWidth) { mCloudX2 = -cloudWidth; } if (mCloudX3 > width + cloudWidth) { mCloudX3 = -cloudWidth; } mAppreciation += 0.1f; final View thisView = this; thisView.invalidate(); }
@Before public void setup() throws DisplayListException { mDisplayList = Mockito.mock(DisplayList.class); mDrawable = Mockito.mock(Drawable.class); mCanvas = Mockito.mock(Canvas.class); mDlCanvas = Mockito.mock(Canvas.class); when(mDisplayList.isValid()).thenReturn(true); when(mDrawable.getBounds()).thenReturn(new Rect()); when(mDisplayList.start(anyInt(), anyInt())).thenReturn(mDlCanvas); }
@Override public void invalidateDrawable(Drawable who) { logDebug("Invalidating drawable", true); invalidateSelf(); if (mIgnoreInvalidations) { return; } // We need to make sure at this point that the bounds of the {@link DisplayListDrawable} are // equals to the bounds of its content to make sure that the view invalidation works as // expected. setBounds(mDrawable.getBounds()); invalidateDL(); // DL needs to be re-created }
private void unmountDrawable(MountItem mountItem) { assertMainThread(); final Drawable drawable = (Drawable) mountItem.getMountableContent(); drawable.setCallback(null); invalidate(drawable.getBounds()); releaseScrapDataStructuresIfNeeded(); }
@Test public void testMountedDrawableBounds() { final LithoView lithoView = mountComponent( mContext, new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return create(c).widthPx(10).heightPx(10).build(); } }); assertThat(lithoView.getDrawables().get(0).getBounds()).isEqualTo(new Rect(0, 0, 10, 10)); }
@Test public void mutate_createsDeepCopy() throws Exception { BitmapDrawable original = (BitmapDrawable) resources.getDrawable(R.drawable.an_image); Drawable mutated = original.mutate(); assertThat(original).isNotSameAs(mutated); assertThat(mutated instanceof BitmapDrawable).isTrue(); assertThat(mutated.getIntrinsicHeight()).isEqualTo(original.getIntrinsicHeight()); assertThat(mutated.getIntrinsicWidth()).isEqualTo(original.getIntrinsicWidth()); assertThat(mutated.getBounds()).isEqualTo(original.getBounds()); }