private Bitmap getVideoThumbToCache(String path) { return lruCache.get(path); }
@Override @Nullable <T> T get(int key) { return (T) mCache.get(key); }
@Nullable private static Info getInfo(@NonNull final String key) { final CacheData data = InfoCache.lruCache.get(key); if (data == null) return null; if (data.isExpired()) { InfoCache.lruCache.remove(key); return null; } return data.info; }
@Nullable public <T> T get(@NonNull final String key, @NonNull final Class<T> type) { if (DEBUG) Log.d(TAG, "get() called with: key = [" + key + "]"); synchronized (lruCache) { final CacheData data = lruCache.get(key); return data != null ? getItem(data, type) : null; } }
@Nullable public <T> T take(@NonNull final String key, @NonNull final Class<T> type) { if (DEBUG) Log.d(TAG, "take() called with: key = [" + key + "]"); synchronized (lruCache) { return lruCache.get(key) != null ? getItem(lruCache.remove(key), type) : null; } }
public static int parseColor(String colorString, int defaultColor) { try { Integer integer = colorCache.get(colorString); if (integer != null) { return integer.intValue(); } else { integer = Color.parseColor(colorString); colorCache.put(colorString, integer); return integer.intValue(); } } catch (Exception e) { return defaultColor; } }
public static int parseColor(String colorString, int defaultColor) { try { Integer integer = colorCache.get(colorString); if (integer != null) { return integer.intValue(); } else { integer = Color.parseColor(colorString); colorCache.put(colorString, integer); return integer.intValue(); } } catch (Exception e) { return defaultColor; } }
/** * Sets the marker icon if there was a url that was found * * @param styleUrl The style which we retrieve the icon url from * @param markerOptions The marker which is displaying the icon */ private void addMarkerIcons(String styleUrl, MarkerOptions markerOptions) { if (mImagesCache.get(styleUrl) != null) { // Bitmap stored in cache Bitmap bitmap = mImagesCache.get(styleUrl); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap)); } else if (!mMarkerIconUrls.contains(styleUrl)) { mMarkerIconUrls.add(styleUrl); } }
private Set<? extends Cluster<T>> getClustersInternal(int discreteZoom) { Set<? extends Cluster<T>> results; mCacheLock.readLock().lock(); results = mCache.get(discreteZoom); mCacheLock.readLock().unlock(); if (results == null) { mCacheLock.writeLock().lock(); results = mCache.get(discreteZoom); if (results == null) { results = mAlgorithm.getClusters(discreteZoom); mCache.put(discreteZoom, results); } mCacheLock.writeLock().unlock(); } return results; }
@Override public Set<? extends Cluster<T>> getClusters(double zoom) { int discreteZoom = (int) zoom; Set<? extends Cluster<T>> results = getClustersInternal(discreteZoom); // TODO: Check if requests are already in-flight. if (mCache.get(discreteZoom + 1) == null) { new Thread(new PrecacheRunnable(discreteZoom + 1)).start(); } if (mCache.get(discreteZoom - 1) == null) { new Thread(new PrecacheRunnable(discreteZoom - 1)).start(); } return results; }
/** * Adds all given ground overlays to the map * * @param groundOverlays hashmap of ground overlays to add to the map */ private void addGroundOverlays(HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays) { for (KmlGroundOverlay groundOverlay : groundOverlays.keySet()) { String groundOverlayUrl = groundOverlay.getImageUrl(); if (groundOverlayUrl != null && groundOverlay.getLatLngBox() != null) { // Can't draw overlay if url and coordinates are missing if (getImagesCache().get(groundOverlayUrl) != null) { addGroundOverlayToMap(groundOverlayUrl, mGroundOverlays, true); } else if (!mGroundOverlayUrls.contains(groundOverlayUrl)) { mGroundOverlayUrls.add(groundOverlayUrl); } } } }
/** * Enlarges or shrinks a bitmap image based on the scale provided * @param style Style to retrieve iconUrl and scale from * @param placemarks * @param placemark Placemark object to set the image to */ private void scaleBitmap(KmlStyle style, HashMap<KmlPlacemark, Object> placemarks, KmlPlacemark placemark) { double bitmapScale = style.getIconScale(); String bitmapUrl = style.getIconUrl(); Bitmap bitmapImage = getImagesCache().get(bitmapUrl); BitmapDescriptor scaledBitmap = scaleIcon(bitmapImage, bitmapScale); ((Marker) placemarks.get(placemark)).setIcon(scaledBitmap); }
@Override public void onSuccess(RateGalleryParser.Result result) { showTip(R.string.rate_successfully, LENGTH_SHORT); GalleryDetailScene scene = getScene(); if (scene != null) { scene.onRateGallerySuccess(result); } else { // Update rating in cache GalleryDetail gd = EhApplication.getGalleryDetailCache(getApplication()).get(mGid); if (gd != null) { gd.rating = result.rating; gd.ratingCount = result.ratingCount; } } }
/** * Adds ground overlays from a given URL onto the map * * @param groundOverlayUrl url of ground overlay * @param groundOverlays hashmap of ground overlays to add to the map */ private void addGroundOverlayToMap(String groundOverlayUrl, HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays, boolean containerVisibility) { BitmapDescriptor groundOverlayBitmap = BitmapDescriptorFactory .fromBitmap(getImagesCache().get(groundOverlayUrl)); for (KmlGroundOverlay kmlGroundOverlay : groundOverlays.keySet()) { if (kmlGroundOverlay.getImageUrl().equals(groundOverlayUrl)) { GroundOverlayOptions groundOverlayOptions = kmlGroundOverlay.getGroundOverlayOptions() .image(groundOverlayBitmap); GroundOverlay mapGroundOverlay = attachGroundOverlay(groundOverlayOptions); if (!containerVisibility) { mapGroundOverlay.setVisible(false); } groundOverlays.put(kmlGroundOverlay, mapGroundOverlay); } } }
@Nullable public Drawable get(int resId, Resources resources, @Nullable Resources.Theme theme) { SimplePoolWithCount<Drawable> drawablesPool = mDrawableCache.get(resId); if (drawablesPool == null) { drawablesPool = new SimplePoolWithCount<>(DRAWABLES_POOL_MAX_ITEMS); mDrawableCache.put(resId, drawablesPool); } Drawable drawable = drawablesPool.acquire(); if (drawable == null) { drawable = ResourcesCompat.getDrawable(resources, resId, theme); } // We never want this pool to remain empty otherwise we would risk to resolve a new drawable // when get is called again. So if the pool is about to drain we just put a new Drawable in it // to keep it warm. if (drawable != null && drawablesPool.getPoolSize() == 0) { drawablesPool.release(drawable.getConstantState().newDrawable()); } return drawable; }
public Where build(Constraint constraint, StringBuilder stringBuilder) { final boolean cacheable = isCacheable(constraint); final long cacheKey = cacheKey(constraint); Where where = cacheable ? queryCache.get(cacheKey) : null; if (where == null) { // build it where = createWhere(cacheKey, constraint, stringBuilder); if (cacheable) { queryCache.put(cacheKey, where); } } fillWhere(constraint, where); return where; }
private boolean prepareData() { Context context = getContext2(); AssertUtils.assertNotNull(context); if (mGalleryDetail != null) { return true; } long gid = getGid(); if (gid == -1) { return false; } // Get from cache mGalleryDetail = EhApplication.getGalleryDetailCache(context).get(gid); if (mGalleryDetail != null) { return true; } EhApplication application = (EhApplication) context.getApplicationContext(); if (application.containGlobalStuff(mRequestId)) { // request exist return true; } // Do request return request(); }
public void release(Drawable drawable, int resId) { SimplePoolWithCount<Drawable> drawablesPool = mDrawableCache.get(resId); if (drawablesPool == null) { drawablesPool = new SimplePoolWithCount<>(DRAWABLES_POOL_MAX_ITEMS); mDrawableCache.put(resId, drawablesPool); } // Reset a stateful drawable, and its animations, before being released. if (drawable.isStateful()) { drawable.setState(StateSet.WILD_CARD); if (SDK_INT >= HONEYCOMB) { drawable.jumpToCurrentState(); } } drawablesPool.release(drawable); }
@Test public void testCachingSpannableString() { SpannableStringBuilder spannable = new SpannableStringBuilder("This is a bold text"); spannable.setSpan(new StyleSpan(Typeface.BOLD), 10, 13, Spanned.SPAN_INCLUSIVE_INCLUSIVE); mLayout = mBuilder.setText(spannable).setShouldCacheLayout(true).build(); assertEquals(mBuilder.sCache.size(), 1); assertEquals(mBuilder.sCache.get(mBuilder.mParams.hashCode()), mLayout); }
@Test public void testCaching() { mLayout = mBuilder.setShouldCacheLayout(true).build(); Layout newLayout = mBuilder.build(); assertEquals(mLayout, newLayout); assertEquals(mBuilder.sCache.size(), 1); assertEquals(mBuilder.sCache.get(mBuilder.mParams.hashCode()), mLayout); }