@Override public void run() { ImageView testImage = findViewById(R.id.test_image_view); Glide.with(InputUrlDetailActivity.this.getApplicationContext()) .load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1525708180755&di=078af5aedf4b44268425be46bf25e407&imgtype=0&src=http%3A%2F%2Fc.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F203fb80e7bec54e78494e3a3bb389b504fc26a17.jpg") .into(testImage); } }, 5000);
@Test public void testLoadBitmap_asBitmap() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); requestManager .asBitmap() .load(bitmap) .into(target); verify(target).onResourceReady(eq(bitmap), any(Transition.class)); }
/** * Lifecycle callback that unregisters for connectivity events (if the * android.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads. */ @Override public synchronized void onStop() { pauseRequests(); targetTracker.onStop(); }
@Test public void testApplicationRequestManagerIsNotReResumedAfterFirstRetrieval() { RequestManager manager = retriever.get(RuntimeEnvironment.application); manager.pauseRequests(); manager = retriever.get(RuntimeEnvironment.application); assertTrue(manager.isPaused()); }
@Test public void removeFromManagers_afterRequestManagerRemoved_clearsRequest() { target = requestManager.load(mockUri("content://uri")).into(new SimpleTarget<Drawable>() { @Override public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { // Do nothing. } }); Request request = Preconditions.checkNotNull(target.getRequest()); requestManager.onDestroy(); requestManager.clear(target); assertThat(target.getRequest()).isNull(); assertThat(request.isCleared()).isTrue(); }
/** * Tests #2262. */ @Test public void clear_withNonOwningRequestManager_afterOwningManagerIsDestroyed_doesNotThrow() { // First destroy our Fragment/Activity RequestManager. requestManager.onDestroy(); final ImageView imageView = new ImageView(context); imageView.measure(100, 100); imageView.layout(0, 0, 100, 100); // Then start a new load with our now destroyed RequestManager. concurrency.loadOnMainThread(requestManager.load(ResourceIds.raw.canonical), imageView); // Finally clear our new load with any RequestManager other than the one we used to start it. concurrency.runOnMainThread(new Runnable() { @Override public void run() { Glide.with(context).clear(imageView); } }); }
@Test public void requestManager_intoImageView_withSameByteArrayAndMemoryCacheEnabled_loadsFromMemory() throws IOException { final byte[] canonicalBytes = getCanonicalBytes(); concurrency.loadOnMainThread( Glide.with(context) .load(canonicalBytes) .apply(skipMemoryCacheOf(false)), imageView); Glide.with(context).clear(imageView); concurrency.loadOnMainThread( Glide.with(context) .load(canonicalBytes) .listener(requestListener) .apply(skipMemoryCacheOf(false)), imageView); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_extends_normal); JzvdStd jzvdStd = findViewById(R.id.videoplayer); jzvdStd.setUp(VideoConstant.videoUrlList[0], "饺子不信" , JzvdStd.SCREEN_WINDOW_NORMAL); Glide.with(this) .load(VideoConstant.videoThumbList[0]) .into(jzvdStd.thumbImageView); }
@Override public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) .apply(new RequestOptions() .override(resize, resize) .placeholder(placeholder) .centerCrop()) .into(imageView); }
@Override public void runTest() { manager.pauseRequests(); } });
@Override public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { Glide.with(context) .load(uri) .override(resizeX, resizeY) .priority(Priority.HIGH) .fitCenter() .into(imageView); }
@Override public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) .apply(new RequestOptions() .override(resize, resize) .placeholder(placeholder) .centerCrop()) .into(imageView); }
/** * Performs {@link #pauseRequests()} recursively for all managers that are contextually descendant * to this manager based on the Activity/Fragment hierarchy: * * <ul> * <li>When pausing on an Activity all attached fragments will also get paused. * <li>When pausing on an attached Fragment all descendant fragments will also get paused. * <li>When pausing on a detached Fragment or the application context only the current * RequestManager is paused. * </ul> * * <p>Note, on pre-Jelly Bean MR1 calling pause on a Fragment will not cause child fragments to * pause, in this case either call pause on the Activity or use a support Fragment. */ // Public API. @SuppressWarnings({"WeakerAccess", "unused"}) public synchronized void pauseRequestsRecursive() { pauseRequests(); for (RequestManager requestManager : treeNode.getDescendants()) { requestManager.pauseRequests(); } }
@Override public void onBindViewHolder(ImageHolder holder, int position) { ImageBean image = mImageList.get(position); holder.originArg.setText(image.getOriginArg()); holder.thumbArg.setText(image.getThumbArg()); Glide.with(mContext) .load(image.getImage()) .into(holder.image); }
private static RequestBuilder<Bitmap> getRequestBuilder( RequestManager requestManager, int width, int height) { return requestManager .asBitmap() .apply( diskCacheStrategyOf(DiskCacheStrategy.NONE) .useAnimationPool(true) .skipMemoryCache(true) .override(width, height)); }
@Test public void testPauseRequestsPausesRequests() { manager.pauseRequests(); verify(requestTracker).pauseRequests(); }
@Test public void testByteData() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 6 }; requestManager.load(data).into(target); }
@Override public void run() throws Throwable { Glide.with(context) .asBitmap() .load(ResourceIds.drawable.shape_drawable) .submit() .get(); } });
@Test(expected = Exception.class) public void testUnregisteredModelThrowsException() { Float unregistered = 0.5f; requestManager.load(unregistered).into(target); }
@Test public void load_withShapeDrawableResourceId_asBitmap_withValidSize_returnsNonNullBitmap() throws ExecutionException, InterruptedException { Bitmap bitmap = Glide.with(context) .asBitmap() .load(ResourceIds.drawable.shape_drawable) .submit(100, 200) .get(); assertThat(bitmap).isNotNull(); assertThat(bitmap.getWidth()).isEqualTo(100); assertThat(bitmap.getHeight()).isEqualTo(200); }