/** * Returns the current {@link android.graphics.drawable.Drawable} being displayed in the view * using {@link android.widget.ImageView#getDrawable()}. */ @Override @Nullable public Drawable getCurrentDrawable() { return view.getDrawable(); }
/** * Create or update the drawable on the target {@link ImageView} to display the supplied * placeholder image. */ static void setPlaceholder(ImageView target, @Nullable Drawable placeholderDrawable) { target.setImageDrawable(placeholderDrawable); if (target.getDrawable() instanceof Animatable) { ((Animatable) target.getDrawable()).start(); } }
public boolean setDisplayMatrix(Matrix finalMatrix) { if (finalMatrix == null) { throw new IllegalArgumentException("Matrix cannot be null"); } if (mImageView.getDrawable() == null) { return false; } mSuppMatrix.set(finalMatrix); checkAndDisplayMatrix(); return true; }
@Override public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) { final View progressView = mProgressView; if (progressView.getVisibility() != VISIBLE) { progressView.setVisibility(VISIBLE); Drawable drawable = mProgressView.getDrawable(); if (drawable instanceof Animatable) { ((Animatable) drawable).start(); } else { progressView.animate().rotation(36000).setDuration(100000); } } }
private Bitmap copyFromImageViewDrawable(ImageView imageView) { if (imageView.getDrawable() == null) { fail("Drawable unexpectedly null"); } // Glide mutates Bitmaps, so it's possible that a Bitmap loaded into a View in one place may // be re-used to load a different image later. Create a defensive copy just in case. return Bitmap.createBitmap(((BitmapDrawable) imageView.getDrawable()).getBitmap()); }
public void update() { if (mZoomEnabled) { // Update the base matrix using the current drawable updateBaseMatrix(mImageView.getDrawable()); } else { // Reset the Matrix... resetMatrix(); } }
@Test public void testSetsBitmapOnViewInSetResource() { Bitmap bitmap = Bitmap.createBitmap(100, 75, Bitmap.Config.RGB_565); target.setResource(bitmap); assertEquals(bitmap, ((BitmapDrawable) view.getDrawable()).getBitmap()); } }
private void runTestFileDefaultLoader() { File file = new File("fake"); mockUri(Uri.fromFile(file)); requestManager.load(file).into(target); requestManager.load(file).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Test public void stopPlaceholderAnimationOnError() { Picasso picasso = mock(Picasso.class); AnimationDrawable placeholder = mock(AnimationDrawable.class); ImageView target = mockImageViewTarget(); when(target.getDrawable()).thenReturn(placeholder); ImageViewAction request = new ImageViewAction(picasso, target, null, null, 0, false, null); request.error(new RuntimeException()); verify(placeholder).stop(); } }
@SuppressWarnings("deprecation") @Test public void testUrlDefaultLoader() throws MalformedURLException { URL url = new URL("http://www.google.com"); requestManager.load(url).into(target); requestManager.load(url).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
private void runTestUriDefaultLoader() { Uri uri = Uri.parse("content://test/something"); mockUri(uri); requestManager.load(uri).into(target); requestManager.load(uri).into(imageView); verify(target).onResourceReady(notNull(), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Test public void testByteArrayDefaultLoader() { byte[] bytes = new byte[10]; requestManager.load(bytes).into(target); requestManager.load(bytes).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
private void runTestIntegerDefaultLoader() { int integer = android.R.drawable.star_on; mockUri("android.resource://" + "android" + "/drawable/star_on"); requestManager.load(integer).into(target); requestManager.load(integer).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Test public void clear_withSingleRequest_nullsOutDrawableInView() { concurrency.loadOnMainThread( GlideApp.with(context) .load(ResourceIds.raw.canonical), imageView); assertThat(imageView.getDrawable()).isNotNull(); concurrency.clearOnMainThread(imageView); assertThat(imageView.getDrawable()).isNull(); }
@Test public void testSetsDrawableSetsDrawableOnView() { target.setDrawable(drawable); assertEquals(drawable, view.getDrawable()); }
@Test public void testSetsDrawableOnLoadStarted() { target.onLoadStarted(drawable); assertEquals(drawable, view.getDrawable()); }
@Test public void onStop_withSingleRequest_doesNotNullOutDrawableInView() { concurrency.loadOnMainThread( GlideApp.with(context) .load(ResourceIds.raw.canonical), imageView); assertThat(imageView.getDrawable()).isNotNull(); concurrency.runOnMainThread(new Runnable() { @Override public void run() { GlideApp.with(context).onStop(); } }); assertThat(imageView.getDrawable()).isNotNull(); }
@Test public void testSetDrawableOnLoadFailed() { target.onLoadFailed(drawable); assertEquals(drawable, view.getDrawable()); }
@Test public void testSetsDrawableOnLoadCleared() { target.onLoadCleared(drawable); assertEquals(drawable, view.getDrawable()); }
@Test public void clear_withRequestWithThumbnail_nullsOutDrawableInView() { concurrency.loadOnMainThread( GlideApp.with(context) .load(ResourceIds.raw.canonical) .thumbnail( GlideApp.with(context) .load(ResourceIds.raw.canonical) .override(100, 100)), imageView); assertThat(imageView.getDrawable()).isNotNull(); concurrency.clearOnMainThread(imageView); assertThat(imageView.getDrawable()).isNull(); }