com.bumptech.glide.load.data.DataFetcher Java Examples

The following examples show how to use com.bumptech.glide.load.data.DataFetcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlideUtils.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
    return new DataFetcher<InputStream>() {
        @Override
        public InputStream loadData(Priority priority) {
            return null;
        }

        @Override
        public void cleanup() {

        }

        @Override
        public String getId() {
            return model;
        }

        @Override
        public void cancel() {

        }
    };
}
 
Example #2
Source File: DecodeJob.java    From giffun with Apache License 2.0 6 votes vote down vote up
DecodeJob(EngineKey resultKey, int width, int height, DataFetcher<A> fetcher,
        DataLoadProvider<A, T> loadProvider, Transformation<T> transformation, ResourceTranscoder<T, Z> transcoder,
        DiskCacheProvider diskCacheProvider, DiskCacheStrategy diskCacheStrategy, Priority priority, FileOpener
        fileOpener) {
    this.resultKey = resultKey;
    this.width = width;
    this.height = height;
    this.fetcher = fetcher;
    this.loadProvider = loadProvider;
    this.transformation = transformation;
    this.transcoder = transcoder;
    this.diskCacheProvider = diskCacheProvider;
    this.diskCacheStrategy = diskCacheStrategy;
    this.priority = priority;
    this.fileOpener = fileOpener;
}
 
Example #3
Source File: UriLoader.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public final DataFetcher<T> getResourceFetcher(Uri model, int width, int height) {
    final String scheme = model.getScheme();

    DataFetcher<T> result = null;
    if (isLocalUri(scheme)) {
        if (AssetUriParser.isAssetUri(model)) {
            String path = AssetUriParser.toAssetPath(model);
            result = getAssetPathFetcher(context, path);
        } else {
            result = getLocalUriFetcher(context, model);
        }
    } else if (urlLoader != null && ("http".equals(scheme) || "https".equals(scheme))) {
        result = urlLoader.getResourceFetcher(new GlideUrl(model.toString()), width, height);
    }

    return result;
}
 
Example #4
Source File: NetworkDisablingLoader.java    From android-tutorials-glide with MIT License 6 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int width, int height) {
    return new DataFetcher<InputStream>() {
        @Override
        public InputStream loadData(Priority priority) throws Exception {
            throw new IOException("Forced Glide network failure");
        }

        @Override
        public void cleanup() {
        }

        @Override
        public String getId() {
            return model;
        }

        @Override
        public void cancel() {
        }
    };
}
 
Example #5
Source File: ImageVideoModelLoader.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public DataFetcher<ImageVideoWrapper> getResourceFetcher(A model, int width, int height) {
    DataFetcher<InputStream> streamFetcher = null;
    if (streamLoader != null) {
        streamFetcher = streamLoader.getResourceFetcher(model, width, height);
    }
    DataFetcher<ParcelFileDescriptor> fileDescriptorFetcher = null;
    if (fileDescriptorLoader != null) {
        fileDescriptorFetcher = fileDescriptorLoader.getResourceFetcher(model, width, height);
    }

    if (streamFetcher != null || fileDescriptorFetcher != null) {
        return new ImageVideoFetcher(streamFetcher, fileDescriptorFetcher);
    } else {
        return null;
    }
}
 
Example #6
Source File: ResourceLoader.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public DataFetcher<T> getResourceFetcher(Integer model, int width, int height) {
    Uri uri = null;
    try {
      uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
              + resources.getResourcePackageName(model) + '/'
              + resources.getResourceTypeName(model) + '/'
              + resources.getResourceEntryName(model));
    } catch (Resources.NotFoundException e) {
        if (Log.isLoggable(TAG, Log.WARN)) {
            Log.w(TAG, "Received invalid resource id: " + model, e);
        }
    }

    if (uri != null) {
        return uriLoader.getResourceFetcher(uri, width, height);
    } else {
        return null;
    }
}
 
Example #7
Source File: StringLoader.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public DataFetcher<T> getResourceFetcher(String model, int width, int height) {
    Uri uri;
    if (TextUtils.isEmpty(model)) {
        return null;
    } else if (model.startsWith("/")) {
        uri = toFileUri(model);
    } else {
        uri = Uri.parse(model);
        final String scheme = uri.getScheme();
        if (scheme == null) {
            uri = toFileUri(model);
        }
    }

    return uriLoader.getResourceFetcher(uri, width, height);
}
 
Example #8
Source File: GlideImageLoaderStrategy.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * load cache image with Glide
 */
private void loadCache(Context ctx, ImageLoader img) {
    Glide.with(ctx).using(new StreamModelLoader<String>() {
        @Override
        public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
            return new DataFetcher<InputStream>() {
                @Override
                public InputStream loadData(Priority priority) throws Exception {
                    throw new IOException();
                }

                @Override
                public void cleanup() {

                }

                @Override
                public String getId() {
                    return model;
                }

                @Override
                public void cancel() {

                }
            };
        }
    }).load(img.getUrl()).placeholder(img.getPlaceHolder()).diskCacheStrategy(DiskCacheStrategy.ALL).into(img.getImgView());
}
 
Example #9
Source File: HttpUrlGlideUrlLoader.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
    // GlideUrls memoize parsed URLs so caching them saves a few object instantiations and time spent parsing urls.
    GlideUrl url = model;
    if (modelCache != null) {
        url = modelCache.get(model, 0, 0);
        if (url == null) {
            modelCache.put(model, 0, 0, model);
            url = model;
        }
    }
    return new HttpUrlFetcher(url);
}
 
Example #10
Source File: GeneratePassthroughModelLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<GenerateParams> getResourceFetcher(final GenerateParams model, int width, int height) {
	return new DataFetcher<GenerateParams>() {
		@Override public GenerateParams loadData(Priority priority) throws Exception {
			return model;
		}
		@Override public void cleanup() {
		}
		@Override public String getId() {
			return model.getId();
		}
		@Override public void cancel() {
		}
	};
}
 
Example #11
Source File: StethoHttpUrlGlideUrlLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
	// GlideUrls memoize parsed URLs so caching them saves a few object instantiations and time spent parsing urls.
	GlideUrl url = model;
	if (modelCache != null) {
		url = modelCache.get(model, 0, 0);
		if (url == null) {
			modelCache.put(model, 0, 0, model);
			url = model;
		}
	}
	return new StethoHttpUrlFetcher(url);
}
 
Example #12
Source File: ProgressModelLoader.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(String model, int width, int height) {
    String result = null;
    if (modelCache != null) {
        result = modelCache.get(model, width, height);
    }
    if (result == null) {
        result = model;
        if (modelCache != null) {
            modelCache.put(model, width, height, result);
        }
    }
    return new ProgressDataFetcher(result, handler);
}
 
Example #13
Source File: YouTubeModelLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(final YouTubeVideo model, final int width,
		final int height) {
	return new DataFetcher<InputStream>() {
		private DataFetcher<InputStream> fetcher;

		@Override public String getId() {
			return model.id; // assuming that if SDUrl failed once, it'll fail the next time
			// so it's better to cache MDUrl in that case for this video, forever
		}

		@Override public InputStream loadData(Priority priority) throws Exception {
			try {
				fetcher = loader.getResourceFetcher(model.getSDUrl(), width, height);
				return fetcher.loadData(priority);
			} catch (Exception ex) {
				if (fetcher != null) {
					fetcher.cleanup();
				}
				fetcher = loader.getResourceFetcher(model.getMDUrl(), width, height);
				return fetcher.loadData(priority);
			}
		}

		@Override public void cleanup() {
			if (fetcher != null) {
				fetcher.cleanup();
			}
		}
		@Override public void cancel() {
			if (fetcher != null) {
				fetcher.cancel();
			}
		}
	};
}
 
Example #14
Source File: DataUriModelLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(final String model, int width, int height) {
	if (model.startsWith(PREFIX)) { // TODO better matching based on your needs
		return new Base64StreamDataFetcher(model.substring(PREFIX.length()));
	} else {
		return defaultLoader.getResourceFetcher(model, width, height);
	}
}
 
Example #15
Source File: ProgressModelLoader.java    From Simpler with Apache License 2.0 5 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(String model, int width, int height) {
    String result = null;
    if (modelCache != null) {
        result = modelCache.get(model, width, height);
    }
    if (result == null) {
        result = model;
        if (modelCache != null) {
            modelCache.put(model, width, height, result);
        }
    }
    return new ProgressDataFetcher(result, handler);
}
 
Example #16
Source File: FirebaseModelLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(final FirebaseImage model, int width, int height) {
	return new DataFetcher<InputStream>() {
		private Thread decodingThread;
		@Override public InputStream loadData(Priority priority) throws Exception {
			decodingThread = Thread.currentThread();
			// somehow make sure that fb is ready after authWithPassword is called
			String dataUri = model.getDataUri(fb);
			String base64 = dataUri.substring("data:image/jpeg;base64,".length());
			// depending on how you encoded it, the below is just a guess:
			// here the full base64 is decoded into bytes and the bytes will be parsed by Glide
			return new ByteArrayInputStream(Base64.decode(base64, Base64.NO_WRAP | Base64.URL_SAFE));
			// if you don't want to delay decoding you can use something like:
			// Base64InputStream (http://stackoverflow.com/a/19981216/253468)
			// here the base64 bytes are passed to Base64InputStream and that to Glide
			// so base64 decoding will be done later when Glide reads from the stream.
			//return new Base64InputStream(new ByteArrayInputStream(base64.getBytes("utf-8")), Base64.NO_WRAP | Base64.URL_SAFE);
		}
		@Override public String getId() {
			return model.key; // for cache
		}
		@Override public void cancel() {
			// don't do this if it's likely to display in the future (read doc of cancel)
			decodingThread.interrupt(); // should fly out from await()
		}
		@Override public void cleanup() {
			decodingThread = null;
		}
	};
}
 
Example #17
Source File: GenericRequest.java    From giffun with Apache License 2.0 5 votes vote down vote up
/**
 * A callback method that should never be invoked directly.
 */
@Override
public void onSizeReady(int width, int height) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        logV("Got onSizeReady in " + LogTime.getElapsedMillis(startTime));
    }
    if (status != Status.WAITING_FOR_SIZE) {
        return;
    }
    status = Status.RUNNING;

    width = Math.round(sizeMultiplier * width);
    height = Math.round(sizeMultiplier * height);

    ModelLoader<A, T> modelLoader = loadProvider.getModelLoader();
    final DataFetcher<T> dataFetcher = modelLoader.getResourceFetcher(model, width, height);

    if (dataFetcher == null) {
        onException(new Exception("Failed to load model: \'" + model + "\'"));
        return;
    }
    ResourceTranscoder<Z, R> transcoder = loadProvider.getTranscoder();
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        logV("finished setup for calling load in " + LogTime.getElapsedMillis(startTime));
    }
    loadedFromMemoryCache = true;
    loadStatus = engine.load(signature, width, height, dataFetcher, loadProvider, transformation, transcoder,
            priority, isMemoryCacheable, diskCacheStrategy, this);
    loadedFromMemoryCache = resource != null;
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        logV("finished onSizeReady in " + LogTime.getElapsedMillis(startTime));
    }
}
 
Example #18
Source File: OkHttpFetcher.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
@Override
public void loadData(@NonNull Priority priority,
                     @NonNull final DataFetcher.DataCallback<? super InputStream> callback) {
    Request.Builder requestBuilder = new Request.Builder().url(mGlideUrl.toStringUrl());
    for (Map.Entry<String, String> headerEntry : mGlideUrl.getHeaders().entrySet()) {
        String key = headerEntry.getKey();
        requestBuilder.addHeader(key, headerEntry.getValue());
    }
    Request request = requestBuilder.build();
    mDataCallback = callback;

    mCall = mCallFactory.newCall(request);
    mCall.enqueue(this);
}
 
Example #19
Source File: WifiOnlyLoader.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
	SharedPreferences prefs = App.getPrefs();
	if (prefs.getBoolean("wifi_only", false)) {
		return new NetworkDisablingFetcher(model);
	} else {
		return defaultLoader.getResourceFetcher(model, width, height);
	}
}
 
Example #20
Source File: NetworkDisablingLoader.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(final T model, int width, int height) {
	return new NetworkDisablingFetcher(model);
}
 
Example #21
Source File: ImageModelLoader.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(final Image model, int width, int height) {
	return new JSONImageFetcher(model);
}
 
Example #22
Source File: ContactPhotoUriLoader.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(ContactPhotoUri model, int width, int height) {
  return new ContactPhotoLocalUriFetcher(context, model.uri);
}
 
Example #23
Source File: OkHttpUrlLoader.java    From android-tutorials-glide with MIT License 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
    return new OkHttpStreamFetcher(client, model);
}
 
Example #24
Source File: DelegatingModelLoader.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(From model, int width, int height) {
	return loader.getResourceFetcher(convertModel(model), width, height);
}
 
Example #25
Source File: FlickrModelLoader2.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(PhotoModel model, int width, int height) {
	return loader.getResourceFetcher(new File(model.getOriginalPath()), width, height);
}
 
Example #26
Source File: OkHttpUrlLoader.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(GlideUrl model, int width, int height) {
    return new OkHttpStreamFetcher(client, model);
}
 
Example #27
Source File: FlickrModelLoader.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DataFetcher<InputStream> getResourceFetcher(PhotoModel model, int width, int height) {
	return loader.getResourceFetcher(new File(model.getOriginalPath()), width, height);
}
 
Example #28
Source File: OkHttpViewModelUrlLoader.java    From KinoCast with MIT License 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(ViewModelGlideRequest model, int width, int height) {
    return new OkHttpViewModelStreamFetcher(client, model, tmdbCache);
}
 
Example #29
Source File: ArtistImageLoader.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(ArtistImage model, int width, int height) {
    return new ArtistImageFetcher(context, lastFMClient, model, urlLoader, width, height);
}
 
Example #30
Source File: AttachmentStreamUriLoader.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DataFetcher<InputStream> getResourceFetcher(AttachmentModel model, int width, int height) {
  return new AttachmentStreamLocalUriFetcher(model.attachment, model.key);
}