本文整理汇总了Java中android.util.LruCache.get方法的典型用法代码示例。如果您正苦于以下问题:Java LruCache.get方法的具体用法?Java LruCache.get怎么用?Java LruCache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.LruCache
的用法示例。
在下文中一共展示了LruCache.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getThumbnail
import android.util.LruCache; //导入方法依赖的package包/类
public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws FileNotFoundException {
final String uuid = message.getUuid();
final LruCache<String,Bitmap> cache = mXmppConnectionService.getBitmapCache();
Bitmap thumbnail = cache.get(uuid);
if ((thumbnail == null) && (!cacheOnly)) {
synchronized (THUMBNAIL_LOCK) {
thumbnail = cache.get(uuid);
if (thumbnail != null) {
return thumbnail;
}
DownloadableFile file = getFile(message);
final String mime = file.getMimeType();
if (mime.startsWith("video/")) {
thumbnail = getVideoPreview(file, size);
} else {
Bitmap fullsize = getFullsizeImagePreview(file, size);
if (fullsize == null) {
throw new FileNotFoundException();
}
thumbnail = resize(fullsize, size);
thumbnail = rotate(thumbnail, getRotation(file));
if (mime.equals("image/gif")) {
Bitmap withGifOverlay = thumbnail.copy(Bitmap.Config.ARGB_8888,true);
drawOverlay(withGifOverlay,R.drawable.play_gif,1.0f);
thumbnail.recycle();
thumbnail = withGifOverlay;
}
}
this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
}
}
return thumbnail;
}
示例2: getThumbnail
import android.util.LruCache; //导入方法依赖的package包/类
public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws FileNotFoundException {
final String uuid = message.getUuid();
final LruCache<String, Bitmap> cache = mXmppConnectionService.getBitmapCache();
Bitmap thumbnail = cache.get(uuid);
if ((thumbnail == null) && (!cacheOnly)) {
synchronized (THUMBNAIL_LOCK) {
thumbnail = cache.get(uuid);
if (thumbnail != null) {
return thumbnail;
}
DownloadableFile file = getFile(message);
final String mime = file.getMimeType();
if (mime.startsWith("video/")) {
thumbnail = getVideoPreview(file, size);
} else {
Bitmap fullsize = getFullsizeImagePreview(file, size);
if (fullsize == null) {
throw new FileNotFoundException();
}
thumbnail = resize(fullsize, size);
thumbnail = rotate(thumbnail, getRotation(file));
if (mime.equals("image/gif")) {
Bitmap withGifOverlay = thumbnail.copy(Bitmap.Config.ARGB_8888, true);
drawOverlay(withGifOverlay, R.drawable.play_gif, 1.0f);
thumbnail.recycle();
thumbnail = withGifOverlay;
}
}
this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
}
}
return thumbnail;
}
示例3: obtain
import android.util.LruCache; //导入方法依赖的package包/类
public static synchronized <DATA> DATA obtain(Class<DATA> clazz, Object index) {
LruCache dataMap = clazzDataMap.get(clazz);
if (dataMap != null) {
DATA data = (DATA) dataMap.get(index);
if (data != null) {
Log.d(TAG, String.format("%s of %s exist.", clazz.getSimpleName(), String.valueOf(index)));
Log.d(TAG, "Current Size" + dataMap.size());
}
return data;
}
return null;
}
示例4: getThumbnail
import android.util.LruCache; //导入方法依赖的package包/类
public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws FileNotFoundException {
final String uuid = message.getUuid();
final LruCache<String, Bitmap> cache = mXmppConnectionService.getBitmapCache();
Bitmap thumbnail = cache.get(uuid);
if ((thumbnail == null) && (!cacheOnly)) {
synchronized (THUMBNAIL_LOCK) {
thumbnail = cache.get(uuid);
if (thumbnail != null) {
return thumbnail;
}
DownloadableFile file = getFile(message);
final String mime = file.getMimeType();
if (mime.startsWith("video/")) {
thumbnail = getVideoPreview(file, size);
} else {
Bitmap fullsize = getFullsizeImagePreview(file, size);
if (fullsize == null) {
throw new FileNotFoundException();
}
thumbnail = resize(fullsize, size);
thumbnail = rotate(thumbnail, getRotation(file));
if (mime.equals("image/gif")) {
Bitmap withGifOverlay = thumbnail.copy(Bitmap.Config.ARGB_8888, true);
drawOverlay(withGifOverlay, R.drawable.play_gif, 1.0f);
thumbnail.recycle();
thumbnail = withGifOverlay;
}
}
this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
}
}
return thumbnail;
}
示例5: getValue
import android.util.LruCache; //导入方法依赖的package包/类
/**
* Retrieves a value, associated with the given key, from the memory cache. If not found, an
* attempt to fetch the value from the disk store is made. This method call will block until the
* disk store is prepared. On success the value will be put in the memory cache. If no value is
* found neither in the memory, nor on disk, null is returned.
*
* @param storeEnabler
* The callback that will provide the memory and disk stores.
* @param key
* The key for the value to fetch.
* @param classOfValue
* The {@link Class} template to parse the disk store JSON to.
*
* @return The value associated with the key or null if none found.
*
* @throws IOException
* If reading from disk store failed for some reason.
* @throws ClassCastException
* If the value can't be cast to the requested template type.
*/
@SuppressWarnings("unchecked")
private static final <E> E getValue(RuntimeStoreEnabler storeEnabler, Object key, Class<E> classOfValue) throws IOException, ClassCastException {
LruCache<Object, Object> memoryStore = storeEnabler.getMemoryStore();
if (memoryStore == null) {
throw new IllegalStateException("You're trying to fetch content from a closed store.");
}
E value = (E) memoryStore.get(key);
// If nothing found in the memory cache, try to read from disk.
if (value == null) {
// Make sure we wait for the disk store to be ready before we start accessing it.
synchronized (storeEnabler.getDiskStoreLock()) {
File diskStore = storeEnabler.getDiskStore();
if (isReadableDirectory(diskStore) && isValidTemplate(classOfValue)) {
// Read object from disk...
String fileName = getFileName(key);
File file = new File(diskStore, fileName);
value = readObjectFromDisk(file, classOfValue);
// ...and also update in memory.
if (value != null) {
memoryStore.put(key, value);
}
}
}
}
return value;
}
示例6: shotRecyclerView
import android.util.LruCache; //导入方法依赖的package包/类
/**
* RecyclerView截图
*/
public static Bitmap shotRecyclerView(RecyclerView view, int bgColor, int count) {
RecyclerView.Adapter adapter = view.getAdapter();
Bitmap bigBitmap = null;
if (adapter != null) {
int size = Math.min(count, adapter.getItemCount());
int height = 0;
Paint paint = new Paint();
int iHeight = 0;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// Use 1/8th of the available memory for this memory cache.
final int cacheSize = maxMemory / 8;
LruCache<String, Bitmap> bitmapCache = new LruCache<>(cacheSize);
for (int i = 0; i < size; i++) {
RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i));
adapter.onBindViewHolder(holder, i);
holder.itemView.measure(
View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(),
holder.itemView.getMeasuredHeight());
holder.itemView.setDrawingCacheEnabled(true);
holder.itemView.buildDrawingCache();
Bitmap drawingCache = holder.itemView.getDrawingCache();
if (drawingCache != null) {
bitmapCache.put(String.valueOf(i), drawingCache);
}
height += holder.itemView.getMeasuredHeight();
}
bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Bitmap.Config.ARGB_8888);
Canvas bigCanvas = new Canvas(bigBitmap);
bigCanvas.drawColor(bgColor);
Drawable lBackground = view.getBackground();
if (lBackground instanceof ColorDrawable) {
ColorDrawable lColorDrawable = (ColorDrawable) lBackground;
int lColor = lColorDrawable.getColor();
bigCanvas.drawColor(lColor);
}
for (int i = 0; i < size; i++) {
Bitmap bitmap = bitmapCache.get(String.valueOf(i));
bigCanvas.drawBitmap(bitmap, 0f, iHeight, paint);
iHeight += bitmap.getHeight();
bitmap.recycle();
}
}
return bigBitmap;
}
示例7: DisplayItem
import android.util.LruCache; //导入方法依赖的package包/类
/**
* Default Constructor
*
* @param adapter The adapter for this item
* @param item The Item
* @param id The internal id for the item
* @param imageCache The thumbnail image cache
*/
public DisplayItem(final DisplayItemAdapter adapter,
final Item item,
final String id,
final LruCache<String, Bitmap> imageCache) {
mImageCache = imageCache;
mItem = item;
mId = id;
if (hasThumbnail()) {
final BaseApplication base = (BaseApplication)adapter.getContext().getApplicationContext();
mGetThumbnailTask = new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(final Void... params) {
final Bitmap foundImage = imageCache.get(mId);
if (foundImage != null) {
return foundImage;
}
Log.i("DisplayItem", "Getting thumbnail for " + mId);
InputStream in = null;
try {
in = base.getOneDriveClient()
.getDrive()
.getItems(mId)
.getThumbnails("0")
.getThumbnailSize("small")
.getContent()
.buildRequest()
.get();
final Bitmap bitmap = BitmapFactory.decodeStream(in);
imageCache.put(mId, bitmap);
return bitmap;
} catch (final Throwable e) {
Log.e(getClass().getSimpleName(), "Thumbnail download failure", e);
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (final IOException e) {
Log.d(getClass().getSimpleName(), "Problem closing thumbnail stream", e);
}
}
}
}
@Override
protected void onPostExecute(final Bitmap image) {
if (image != null) {
adapter.notifyDataSetChanged();
}
}
};
mGetThumbnailTask.execute();
} else {
mGetThumbnailTask = null;
}
}