public static void loadExperimentImage(Context context, ImageView view, String experimentId, String relativeFilePath) { if (isDestroyed(context)) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Trying to load image for destroyed context"); } // Nothing we can do, return return; } File file = FileMetadataManager.getExperimentFile(context, experimentId, relativeFilePath); // Use last modified time as part of the signature to force a glide cache refresh. GlideApp.with(context) .load(file.getAbsolutePath()) .signature(new ObjectKey(file.getPath() + file.lastModified())) .fitCenter() // caches only the final image, after reducing the resolution .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .into(view); }
public static void loadExperimentOverviewImage(ImageView imageView, String experimentOverviewFilePath) { imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); Context context = imageView.getContext(); String fullPath = PictureUtils.getExperimentOverviewFullImagePath(context, experimentOverviewFilePath); File file = new File(fullPath); GlideApp.with(context) .load(fullPath) // Create a signature based on the last modified time so that cached images will // not be used if the underlying file changes. This may happen if the user has // picked an experiment photo from the "edit experiment" page because there is only // one filename used for that photo. .signature(new ObjectKey(file.getPath() + file.lastModified())) .into(imageView); }
public String getKey(String value) { String safeKey; synchronized (lruCache) { safeKey = lruCache.get(value); } if (safeKey == null) { try { Key key = new ObjectKey(value); MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); key.updateDiskCacheKey(messageDigest); safeKey = Util.sha256BytesToHex(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } synchronized (lruCache) { lruCache.put(value, safeKey); } } return safeKey; }
@Override @Nullable public LoadData<InputStream> buildLoadData(Uri model, int width, int height, Options options) { if (MediaStoreUtil.isThumbnailSize(width, height) && isRequestingDefaultFrame(options)) { // TODO(nnaze): Tighten down this call to just the dependencies neede by buildVideoFetcher return new LoadData<>(new ObjectKey(model), ThumbFetcher.buildVideoFetcher(context, model)); } else { return null; } }
@Override public LoadData<InputStream> buildLoadData(Uri model, int width, int height, Options options) { if (MediaStoreUtil.isThumbnailSize(width, height)) { return new LoadData<>(new ObjectKey(model), ThumbFetcher.buildImageFetcher(context, model)); } else { return null; } }
@Test public void testDifferIfSourceKeyDiffers() throws UnsupportedEncodingException, NoSuchAlgorithmException { mutateAndAssertDifferent(new FactoryMutation() { @Override public void mutate(Factory factory) { factory.sourceKey = new ObjectKey("secondKey"); } }); }
@Test public void testDiffersIfSignatureDiffers() { mutateAndAssertDifferent(new FactoryMutation() { @Override public void mutate(Factory factory) { factory.signature = new ObjectKey("secondSignature"); } }); }
@Override @Nullable public LoadData<InputStream> buildLoadData(Uri model, int width, int height, Options options) { if (MediaStoreUtil.isThumbnailSize(width, height) && isRequestingDefaultFrame(options)) { return new LoadData<>(new ObjectKey(model), ThumbFetcher.buildVideoFetcher(context, model)); } else { return null; } }
@Test public void updateDiskCacheKey_throwsException() throws NoSuchAlgorithmException { // If this test fails, update testEqualsAndHashcode to use KeyTester including regression tests. EngineKey key = new EngineKey( "id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options()); expectedException.expect(UnsupportedOperationException.class); key.updateDiskCacheKey(MessageDigest.getInstance("SHA-1")); }
@Before public void setUp() { dir = RuntimeEnvironment.application.getCacheDir(); cache = DiskLruCacheWrapper.create(dir, 10 * 1024 * 1024); key = new ObjectKey("test" + Math.random()); data = new byte[] { 1, 2, 3, 4, 5, 6 }; }
@Override public LoadData<File> buildLoadData(Uri uri, int width, int height, Options options) { return new LoadData<>(new ObjectKey(uri), new FilePathFetcher(context, uri)); }
@Override public LoadData<ByteBuffer> buildLoadData(File file, int width, int height, Options options) { return new LoadData<>(new ObjectKey(file), new ByteBufferFetcher(file)); }
@Override public LoadData<Data> buildLoadData(Uri model, int width, int height, Options options) { String assetPath = model.toString().substring(ASSET_PREFIX_LENGTH); return new LoadData<>(new ObjectKey(model), factory.buildFetcher(assetManager, assetPath)); }
@Override public LoadData<Data> buildLoadData(String model, int width, int height, Options options) { return new LoadData<>(new ObjectKey(model), new DataUriFetcher<Data>(model, dataDecoder)); }
@Override public LoadData<Model> buildLoadData(Model model, int width, int height, Options options) { return new LoadData<>(new ObjectKey(model), new UnitFetcher<>(model)); }
@Override public LoadData<Data> buildLoadData(File model, int width, int height, Options options) { return new LoadData<>(new ObjectKey(model), new FileFetcher<>(model, fileOpener)); }
@Override public LoadData<Data> buildLoadData(Uri model, int width, int height, Options options) { return new LoadData<>(new ObjectKey(model), factory.build(model)); }
private static Key getFrameSignature() { // Some devices seem to have crypto bugs that throw exceptions when you create a new UUID. // See #1510. return new ObjectKey(Math.random()); }
@Override public LoadData<Data> buildLoadData(String model, int width, int height, Options options) { return new LoadData<>(new ObjectKey(model), new DataUriFetcher<>(model, dataDecoder)); }
@Nullable @Override public LoadData<InputStream> buildLoadData(String category, int width, int height, Options options) { return new LoadData<>(new ObjectKey(category), new ArtworkDataFetcher(category)); }
public Key getGlideSignature() { File file = new File(getPath()); String lastModified = String.valueOf(file.lastModified()); return new ObjectKey(lastModified); }
@Nullable @Override public LoadData<InputStream> buildLoadData( @NonNull AppModel appModel, int width, int height, @NonNull Options options) { return new LoadData<>(new ObjectKey(appModel.pkg()), new AppIconDataFetcher(context, appModel)); }
@Nullable @Override public LoadData<Drawable> buildLoadData(String s, int width, int height, Options options) { return new LoadData<>(new ObjectKey(s), new ApkImageDataFetcher(packageManager, s)); }
/** * Returns a request to load the given byte array. * * <p> Note - by default loads for bytes are not cached in either the memory or the disk cache. * </p> * * @param model the data to load. * @see #load(Object) */ public RequestBuilder<TranscodeType> load(@Nullable byte[] model) { return loadGeneric(model).apply(signatureOf(new ObjectKey(UUID.randomUUID().toString())) .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true /*skipMemoryCache*/)); }
/** * Returns a request to load the given byte array. * * <p> Note - by default loads for bytes are not cached in either the memory or the disk cache. * </p> * * @param model the data to load. * @see #load(Object) */ @CheckResult public RequestBuilder<TranscodeType> load(@Nullable byte[] model) { return loadGeneric(model).apply(signatureOf(new ObjectKey(UUID.randomUUID().toString())) .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true /*skipMemoryCache*/)); }