本文整理汇总了Java中com.bumptech.glide.load.Key类的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于com.bumptech.glide.load包,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: obtainVersionSignature
import com.bumptech.glide.load.Key; //导入依赖的package包/类
private static Key obtainVersionSignature(Context context) {
PackageInfo pInfo = null;
try {
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
// Should never happen.
e.printStackTrace();
}
final String versionCode;
if (pInfo != null) {
versionCode = String.valueOf(pInfo.versionCode);
} else {
versionCode = UUID.randomUUID().toString();
}
return new ObjectKey(versionCode);
}
示例2: testAddsBitmapsToPoolIfMemoryCacheIsNotFullButCannotFitBitmap
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Test
public void testAddsBitmapsToPoolIfMemoryCacheIsNotFullButCannotFitBitmap() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(cache.getMaxSize()).thenReturn((long) Util.getBitmapByteSize(bitmap) / 2);
PreFillType size =
new PreFillType.Builder(bitmap.getWidth(), bitmap.getHeight()).setConfig(bitmap.getConfig())
.build();
Map<PreFillType, Integer> allocationOrder = new HashMap<>();
allocationOrder.put(size, 1);
getHandler(allocationOrder).run();
verify(cache, never()).put(any(Key.class), anyResource());
// TODO(b/20335397): This code was relying on Bitmap equality which Robolectric removed
//verify(pool).put(eq(bitmap));
//assertThat(addedBitmaps).containsExactly(bitmap);
}
示例3: registerMockModelLoader
import com.bumptech.glide.load.Key; //导入依赖的package包/类
private static <X, Y> void registerMockModelLoader(Class<X> modelClass, Class<Y> dataClass,
Y loadedData, Registry registry) {
DataFetcher<Y> mockStreamFetcher = mock(DataFetcher.class);
when(mockStreamFetcher.getDataClass()).thenReturn(dataClass);
try {
doAnswer(new Util.CallDataReady<>(loadedData))
.when(mockStreamFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
} catch (Exception e) {
throw new RuntimeException(e);
}
ModelLoader<X, Y> mockUrlLoader = mock(ModelLoader.class);
when(mockUrlLoader.buildLoadData(isA(modelClass), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), mockStreamFetcher));
when(mockUrlLoader.handles(isA(modelClass))).thenReturn(true);
ModelLoaderFactory<X, Y> mockUrlLoaderFactory = mock(ModelLoaderFactory.class);
when(mockUrlLoaderFactory.build(isA(MultiModelLoaderFactory.class)))
.thenReturn(mockUrlLoader);
registry.replace(modelClass, dataClass, mockUrlLoaderFactory);
}
示例4: onDataFetcherReady
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Override
public void onDataFetcherReady(Key sourceKey, Object data, DataFetcher<?> fetcher,
DataSource dataSource, Key attemptedKey) {
this.currentSourceKey = sourceKey;
this.currentData = data;
this.currentFetcher = fetcher;
this.currentDataSource = dataSource;
this.currentAttemptingKey = attemptedKey;
if (Thread.currentThread() != currentThread) {
runReason = RunReason.DECODE_DATA;
callback.reschedule(this);
} else {
TraceCompat.beginSection("DecodeJob.decodeFromRetrievedData");
try {
decodeFromRetrievedData();
} finally {
TraceCompat.endSection();
}
}
}
示例5: get
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Override
public File get(Key key) {
String safeKey = safeKeyGenerator.getSafeKey(key);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Get: Obtained: " + safeKey + " for for Key: " + key);
}
File result = null;
try {
// It is possible that the there will be a put in between these two gets. If so that shouldn't
// be a problem because we will always put the same value at the same key so our input streams
// will still represent the same data.
final DiskLruCache.Value value = getDiskCache().get(safeKey);
if (value != null) {
result = value.getFile(0);
}
} catch (IOException e) {
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Unable to get from disk cache", e);
}
}
return result;
}
示例6: release
import com.bumptech.glide.load.Key; //导入依赖的package包/类
void release(Key key) {
WriteLock writeLock;
synchronized (this) {
writeLock = Preconditions.checkNotNull(locks.get(key));
if (writeLock.interestedThreads < 1) {
throw new IllegalStateException("Cannot release a lock that is not held"
+ ", key: " + key
+ ", interestedThreads: " + writeLock.interestedThreads);
}
writeLock.interestedThreads--;
if (writeLock.interestedThreads == 0) {
WriteLock removed = locks.remove(key);
if (!removed.equals(writeLock)) {
throw new IllegalStateException("Removed the wrong lock"
+ ", expected to remove: " + writeLock
+ ", but actually removed: " + removed
+ ", key: " + key);
}
writeLockPool.offer(removed);
}
}
writeLock.lock.unlock();
}
示例7: getCacheKeys
import com.bumptech.glide.load.Key; //导入依赖的package包/类
List<Key> getCacheKeys() {
if (!isCacheKeysSet) {
isCacheKeysSet = true;
cacheKeys.clear();
List<LoadData<?>> loadData = getLoadData();
int size = loadData.size();
for (int i = 0; i < size; i++) {
LoadData<?> data = loadData.get(i);
if (!cacheKeys.contains(data.sourceKey)) {
cacheKeys.add(data.sourceKey);
}
for (int j = 0; j < data.alternateKeys.size(); j++) {
if (!cacheKeys.contains(data.alternateKeys.get(j))) {
cacheKeys.add(data.alternateKeys.get(j));
}
}
}
}
return cacheKeys;
}
示例8: buildLoadData
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Override
public LoadData<Data> buildLoadData(Model model, int width, int height,
Options options) {
Key sourceKey = null;
int size = modelLoaders.size();
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
if (modelLoader.handles(model)) {
LoadData<Data> loadData = modelLoader.buildLoadData(model, width, height, options);
if (loadData != null) {
sourceKey = loadData.sourceKey;
fetchers.add(loadData.fetcher);
}
}
}
return !fetchers.isEmpty()
? new LoadData<>(sourceKey, new MultiFetcher<>(fetchers, exceptionListPool)) : null;
}
示例9: registerFailFactory
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource)
throws Exception {
DataFetcher<Z> failFetcher = mock(DataFetcher.class);
doAnswer(new Util.CallDataReady<>(null))
.when(failFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
when(failFetcher.getDataClass()).thenReturn(failResource);
ModelLoader<T, Z> failLoader = mock(ModelLoader.class);
when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher));
when(failLoader.handles(isA(failModel))).thenReturn(true);
ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class);
when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader);
Glide.get(getContext()).getRegistry().prepend(failModel, failResource, failFactory);
}
示例10: testAddsBitmapsToBitmapPoolIfMemoryCacheIsFull
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Test
public void testAddsBitmapsToBitmapPoolIfMemoryCacheIsFull() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(cache.getMaxSize()).thenReturn(0);
PreFillType size =
new PreFillType.Builder(bitmap.getWidth(), bitmap.getHeight()).setConfig(bitmap.getConfig())
.build();
Map<PreFillType, Integer> allocationOrder = new HashMap<>();
allocationOrder.put(size, 1);
getHandler(allocationOrder).run();
verify(cache, never()).put(any(Key.class), anyResource());
// TODO(b/20335397): This code was relying on Bitmap equality which Robolectric removed
// verify(pool).put(eq(bitmap));
// assertThat(addedBitmaps).containsExactly(bitmap);
}
示例11: testBuildsNewUrlIfNotPresentInCache
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
int width = 10;
int height = 11;
urlLoader.resultUrl = "fakeUrl";
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
.thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
@Override
public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock)
throws Throwable {
GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
return new ModelLoader.LoadData<>(mock(Key.class), fetcher);
}
});
assertEquals(fetcher,
urlLoader.buildLoadData(new GlideUrl(urlLoader.resultUrl), width, height, options).fetcher);
}
示例12: registerFailFactory
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource) {
DataFetcher<Z> failFetcher = mock(DataFetcher.class);
doAnswer(new Util.CallDataReady<>(null))
.when(failFetcher)
.loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class));
when(failFetcher.getDataClass()).thenReturn(failResource);
ModelLoader<T, Z> failLoader = mock(ModelLoader.class);
when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class)))
.thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher));
when(failLoader.handles(isA(failModel))).thenReturn(true);
ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class);
when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader);
Glide.get(context).getRegistry().prepend(failModel, failResource, failFactory);
}
示例13: obtain
import com.bumptech.glide.load.Key; //导入依赖的package包/类
/**
* Returns the signature {@link com.bumptech.glide.load.Key} for version code of the Application
* of the given Context.
*/
public static Key obtain(Context context) {
String packageName = context.getPackageName();
Key result = PACKAGE_NAME_TO_KEY.get(packageName);
if (result == null) {
Key toAdd = obtainVersionSignature(context);
result = PACKAGE_NAME_TO_KEY.putIfAbsent(packageName, toAdd);
// There wasn't a previous mapping, so toAdd is now the Key.
if (result == null) {
result = toAdd;
}
}
return result;
}
示例14: setUp
import com.bumptech.glide.load.Key; //导入依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
doAnswer(new AddBitmapPoolAnswer(addedBitmaps)).when(pool).put(any(Bitmap.class));
when(pool.getDirty(anyInt(), anyInt(), any(Bitmap.Config.class)))
.thenAnswer(new CreateBitmap());
when(cache.put(any(Key.class), anyResource()))
.thenAnswer(new AddBitmapCacheAnswer(addedBitmaps));
}
示例15: addRegressionTestInternal
import com.bumptech.glide.load.Key; //导入依赖的package包/类
private KeyTester addRegressionTestInternal(Key key, String expectedDigest) {
isUsedWithoutCallingTest = true;
String oldValue = regressionTests.put(key, expectedDigest);
if (oldValue != null) {
throw new IllegalArgumentException(
"Given multiple values for: " + key + " old: " + oldValue + " new: " + expectedDigest);
}
return this;
}