Esempio n. 1
0
 static BitmapHunter forRequest(
     Context context,
     Picasso picasso,
     Dispatcher dispatcher,
     Cache cache,
     Stats stats,
     Action action,
     Downloader downloader) {
   if (action.getData().resourceId != 0) {
     return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   }
   Uri uri = action.getData().uri;
   String scheme = uri.getScheme();
   if (SCHEME_CONTENT.equals(scheme)) {
     if (Contacts.CONTENT_URI.getHost().equals(uri.getHost()) //
         && !uri.getPathSegments().contains(Contacts.Photo.CONTENT_DIRECTORY)) {
       return new ContactsPhotoBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     } else {
       return new ContentProviderBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     }
   } else if (SCHEME_FILE.equals(scheme)) {
     if (!uri.getPathSegments().isEmpty() && ANDROID_ASSET.equals(uri.getPathSegments().get(0))) {
       return new AssetBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     }
     return new FileBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   } else if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
     return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   } else {
     return new NetworkBitmapHunter(picasso, dispatcher, cache, stats, action, downloader);
   }
 }
 @Test
 public void huntDecodesWhenNotInCache() throws Exception {
   Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget());
   BitmapHunter hunter =
       spy(new TestableBitmapHunter(picasso, dispatcher, cache, stats, action, BITMAP_1));
   Bitmap result = hunter.hunt();
   verify(cache).get(URI_KEY_1);
   verify(hunter).decode(action.getData());
   assertThat(result).isEqualTo(BITMAP_1);
 }
Esempio n. 3
0
 BitmapHunter(Picasso picasso, Dispatcher dispatcher, Cache cache, Stats stats, Action action) {
   this.picasso = picasso;
   this.dispatcher = dispatcher;
   this.cache = cache;
   this.stats = stats;
   this.key = action.getKey();
   this.data = action.getData();
   this.skipMemoryCache = action.skipCache;
   this.actions = new ArrayList<Action>(4);
   attach(action);
 }