List of usage examples for android.support.v4.util LruCache LruCache
public LruCache(int maxSize)
From source file:com.lurencun.cfuture09.androidkit.cache.ObjectLruCache.java
/** * ????mMemCache?// ww w.j av a2 s . c o m */ protected void initMemoryCache() { mMemoryCache = new LruCache<String, T>(mCacheParams.getMemCacheSize()) { /** * Measure item size in bytes rather than units which is more * practical for a bitmap cache */ @Override protected int sizeOf(String key, T t) { return 1; } }; }
From source file:io.mapsquare.osmcontributor.ui.utils.BitmapHandler.java
@Inject public BitmapHandler(Application osmTemplateApplication) { context = osmTemplateApplication.getApplicationContext(); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/5th of the available memory for this memory cache. final int cacheSize = maxMemory / 5; cache = new LruCache<String, Bitmap>(cacheSize) { @Override//from w w w. j a v a 2 s . c om protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in kilobytes rather than items count return bitmap.getByteCount() / 1024; } }; icons.put("administrative", R.drawable.administrative); icons.put("animal_shelter", R.drawable.pet2); icons.put("antique", R.drawable.archaeological); icons.put("gallery", R.drawable.art_gallery2); icons.put("boat_sharing", R.drawable.sailing); icons.put("books", R.drawable.library); icons.put("boutique", R.drawable.convenience); icons.put("brothel", R.drawable.hotel2); icons.put("bureau_de_change", R.drawable.currency_exchange); icons.put("camp_site", R.drawable.camping); icons.put("car_wash", R.drawable.ford); icons.put("car_sharing", R.drawable.car_share); icons.put("clinic", R.drawable.doctors2); icons.put("arts_centre", R.drawable.art_gallery2); icons.put("dry_cleaning", R.drawable.laundrette); icons.put("archaeological_site", R.drawable.archaeological2); icons.put("farm", R.drawable.marketplace); icons.put("variety_store", R.drawable.convenience); icons.put("food_court", R.drawable.marketplace); icons.put("fort", R.drawable.castle2); icons.put("general", R.drawable.department_store); icons.put("hardware", R.drawable.mine); icons.put("doityourself", R.drawable.diy); icons.put("organic", R.drawable.greengrocer); icons.put("laundry", R.drawable.laundrette); icons.put("kindergarten", R.drawable.nursery3); icons.put("manor", R.drawable.house); icons.put("alpine_hut", R.drawable.alpinehut); icons.put("wilderness_hut", R.drawable.alpinehut); icons.put("ship", R.drawable.sailing); icons.put("music_venue", R.drawable.music); icons.put("music_venue", R.drawable.music); icons.put("nursing_home", R.drawable.hotel2); icons.put("optician", R.drawable.opticians); icons.put("viewpoint", R.drawable.photo); icons.put("crossing", R.drawable.zebra_crossing); icons.put("guest_house", R.drawable.bed_and_breakfast2); icons.put("photo_booth", R.drawable.photo); icons.put("picnic_site", R.drawable.picnic); icons.put("services", R.drawable.picnic); icons.put("public_bookcase", R.drawable.library); icons.put("register_office", R.drawable.administrative); icons.put("mini_roundabout", R.drawable.roundabout_anticlockwise); icons.put("ruins", R.drawable.ruin); icons.put("caravan_site", R.drawable.caravan_park); icons.put("tailor", R.drawable.clothes); icons.put("taxi", R.drawable.taxi_rank); icons.put("tomb", R.drawable.memorial); icons.put("travel_agency", R.drawable.aerodrome); icons.put("video", R.drawable.video_rental); icons.put("waste_basket", R.drawable.waste_bin); icons.put("waste_basket", R.drawable.waste_bin); icons.put("artwork", R.drawable.art_gallery); icons.put("aerodrome", R.drawable.aerodrome); icons.put("aircraft", R.drawable.aerodrome); icons.put("alcohol", R.drawable.bar); icons.put("atm", R.drawable.atm); icons.put("attraction", R.drawable.attraction); icons.put("bank", R.drawable.bank); icons.put("bar", R.drawable.bar); icons.put("bus_stop", R.drawable.bus_stop); icons.put("bicycle_parking", R.drawable.bicycle_parking); icons.put("bicycle_rental", R.drawable.bicycle_rental); icons.put("biergarten", R.drawable.biergarten); icons.put("cafe", R.drawable.cafe); icons.put("car_rental", R.drawable.car_rental); icons.put("church", R.drawable.place_of_worship); icons.put("cinema", R.drawable.cinema); icons.put("city", R.drawable.town); icons.put("commercial", R.drawable.mall); icons.put("courthouse", R.drawable.courthouse); icons.put("dentist", R.drawable.dentist); icons.put("doctors", R.drawable.doctors); icons.put("drinking_water", R.drawable.drinking_water); icons.put("embassy", R.drawable.embassy); icons.put("entrance", R.drawable.entrance); icons.put("fast_food", R.drawable.fast_food); icons.put("fire_station", R.drawable.fire_station); icons.put("fuel", R.drawable.fuel); icons.put("hamlet", R.drawable.town); icons.put("hospital", R.drawable.hospital); icons.put("hotel", R.drawable.hotel); icons.put("house", R.drawable.house); icons.put("housenumber", R.drawable.house); icons.put("hunting_stand", R.drawable.hunting_stand); icons.put("locality", R.drawable.town); icons.put("mall", R.drawable.mall); icons.put("nightclub", R.drawable.nightclub); icons.put("neighbourhood", R.drawable.house); icons.put("parking", R.drawable.parking); icons.put("pharmacy", R.drawable.pharmacy); icons.put("place_of_worship", R.drawable.place_of_worship); icons.put("police", R.drawable.police); icons.put("political", R.drawable.administrative); icons.put("primary", R.drawable.street); icons.put("prison", R.drawable.prison); icons.put("pub", R.drawable.pub); icons.put("recycling", R.drawable.recycling); icons.put("religious_administrative", R.drawable.place_of_worship); icons.put("residential", R.drawable.house); icons.put("restaurant", R.drawable.restaurant); icons.put("retail", R.drawable.mall); icons.put("road", R.drawable.street); icons.put("secondary", R.drawable.street); icons.put("stadium", R.drawable.stadium); icons.put("station", R.drawable.bus_stop); icons.put("street", R.drawable.street); icons.put("suburb", R.drawable.town); icons.put("subway_entrance", R.drawable.bus_stop); icons.put("supermarket", R.drawable.mall); icons.put("terminal", R.drawable.aerodrome); icons.put("tertiary", R.drawable.street); icons.put("theatre", R.drawable.theatre); icons.put("toilets", R.drawable.toilets); icons.put("town", R.drawable.town); icons.put("townhall", R.drawable.townhall); icons.put("track", R.drawable.street); icons.put("village", R.drawable.town); icons.put("phone", R.drawable.sos); }
From source file:io.github.mkjung.ivi.gui.helpers.BitmapCache.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private BitmapCache() { // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext() .getSystemService(Context.ACTIVITY_SERVICE)); final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass(); // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.i(TAG, "LRUCache size set to " + cacheSize); mMemCache = new LruCache<String, CacheableBitmap>(cacheSize) { @Override//from w w w . ja va2 s . c o m protected int sizeOf(String key, CacheableBitmap value) { return value.getSize(); } }; }
From source file:com.yanzhenjie.album.task.LocalImageLoader.java
public LocalImageLoader() { mExecutorService = Executors.newFixedThreadPool(6); int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 4); mLruCache = new LruCache<String, Bitmap>(maxMemory) { @Override/*from w ww . ja va2s . c om*/ protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:org.i_chera.wolfensteineditor.document.VSwapContainer.java
/** * Gets a 64x64 bitmap from a given sprite * @param n Index of sprite// w ww. j av a 2 s . c o m * @return Null if invalid or out of bounds, the bitmap otherwise */ public Bitmap getSpriteBitmap(int n) { if (n < 0 || n >= mSoundStart - mSpriteStart) return null; if (mSpriteBitmapCache == null) { mSpriteBitmapCache = new LruCache<Integer, Bitmap>(mSoundStart - mSpriteStart); } Bitmap bmp = mSpriteBitmapCache.get(n); if (bmp == null) { bmp = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888); byte[] data = mPages.get(mSpriteStart + n); int leftPixel = FileUtil.readUInt16(data, 0); int rightPixel = FileUtil.readUInt16(data, 2); if (leftPixel < 0 || leftPixel >= 64 || rightPixel < 0 || rightPixel >= 64 || rightPixel < leftPixel) return null; int directoryOffset; int x, y, i, j, topPixel, bottomPixel, postStart; for (x = leftPixel, i = 4; x <= rightPixel; ++x, i += 2) { directoryOffset = FileUtil.readUInt16(data, i); j = directoryOffset; for (;;) { bottomPixel = FileUtil.readUInt16(data, j) / 2; j += 2; if (bottomPixel == 0) break; postStart = FileUtil.readInt16(data, j); j += 2; topPixel = FileUtil.readUInt16(data, j) / 2; j += 2; if (bottomPixel < 0 || bottomPixel > 64 || topPixel < 0 || topPixel >= 64 || bottomPixel <= topPixel) return null; for (y = topPixel; y < bottomPixel; ++y) { bmp.setPixel(x, y, Palette.WL6[data[postStart + y] & 0xff]); } } } mSpriteBitmapCache.put(n, bmp); } return bmp; }
From source file:com.nttec.everychan.cache.BitmapCache.java
/** * ?/*from w ww . j ava 2s . co m*/ * @param maxSize ? ? ? * @param fileCache ? */ public BitmapCache(int maxSize, FileCache fileCache) { this.fileCache = fileCache; this.lru = new LruCache<String, Bitmap>(maxSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; this.currentDownloads = new HashSet<String>(); }
From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java
@Inject public BitmapHandler(Application osmTemplateApplication) { context = osmTemplateApplication.getApplicationContext(); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/5th of the available memory for this memory cache. final int cacheSize = maxMemory / 5; cache = new LruCache<String, Bitmap>(cacheSize) { @Override/*from w w w . ja v a2 s. c o m*/ protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in kilobytes rather than items count return bitmap.getByteCount() / 1024; } }; icons.put("administrative", R.drawable.administrative); icons.put("animal_shelter", R.drawable.pet2); icons.put("antique", R.drawable.archaeological); icons.put("gallery", R.drawable.art_gallery2); icons.put("boat_sharing", R.drawable.sailing); icons.put("books", R.drawable.library); icons.put("boutique", R.drawable.convenience); icons.put("brothel", R.drawable.hotel2); icons.put("bureau_de_change", R.drawable.currency_exchange); icons.put("camp_site", R.drawable.camping); icons.put("car_wash", R.drawable.ford); icons.put("car_sharing", R.drawable.car_share); icons.put("clinic", R.drawable.doctors2); icons.put("arts_centre", R.drawable.art_gallery2); icons.put("dry_cleaning", R.drawable.laundrette); icons.put("archaeological_site", R.drawable.archaeological2); icons.put("farm", R.drawable.marketplace); icons.put("variety_store", R.drawable.convenience); icons.put("food_court", R.drawable.marketplace); icons.put("fort", R.drawable.castle2); icons.put("general", R.drawable.department_store); icons.put("hardware", R.drawable.mine); icons.put("doityourself", R.drawable.diy); icons.put("organic", R.drawable.greengrocer); icons.put("laundry", R.drawable.laundrette); icons.put("kindergarten", R.drawable.nursery3); icons.put("manor", R.drawable.house); icons.put("alpine_hut", R.drawable.alpinehut); icons.put("wilderness_hut", R.drawable.alpinehut); icons.put("ship", R.drawable.sailing); icons.put("music_venue", R.drawable.music); icons.put("music_venue", R.drawable.music); icons.put("nursing_home", R.drawable.hotel2); icons.put("optician", R.drawable.opticians); icons.put("viewpoint", R.drawable.photo); icons.put("crossing", R.drawable.zebra_crossing); icons.put("guest_house", R.drawable.bed_and_breakfast2); icons.put("photo_booth", R.drawable.photo); icons.put("picnic_site", R.drawable.picnic); icons.put("services", R.drawable.picnic); icons.put("public_bookcase", R.drawable.library); icons.put("register_office", R.drawable.administrative); icons.put("mini_roundabout", R.drawable.roundabout_anticlockwise); icons.put("ruins", R.drawable.ruin); icons.put("caravan_site", R.drawable.caravan_park); icons.put("tailor", R.drawable.clothes); icons.put("taxi", R.drawable.taxi_rank); icons.put("tomb", R.drawable.memorial); icons.put("travel_agency", R.drawable.aerodrome); icons.put("video", R.drawable.video_rental); icons.put("waste_basket", R.drawable.waste_bin); icons.put("waste_basket", R.drawable.waste_bin); icons.put("artwork", R.drawable.art_gallery); icons.put("aerodrome", R.drawable.aerodrome); icons.put("aircraft", R.drawable.aerodrome); icons.put("alcohol", R.drawable.bar); icons.put("atm", R.drawable.atm); icons.put("attraction", R.drawable.attraction); icons.put("bank", R.drawable.bank); icons.put("bar", R.drawable.bar); icons.put("bus_stop", R.drawable.bus_stop); icons.put("bicycle_parking", R.drawable.bicycle_parking); icons.put("bicycle_rental", R.drawable.bicycle_rental); icons.put("biergarten", R.drawable.biergarten); icons.put("cafe", R.drawable.cafe); icons.put("car_rental", R.drawable.car_rental); icons.put("church", R.drawable.place_of_worship); icons.put("cinema", R.drawable.cinema); icons.put("city", R.drawable.town); icons.put("commercial", R.drawable.mall); icons.put("courthouse", R.drawable.courthouse); icons.put("dentist", R.drawable.dentist); icons.put("doctors", R.drawable.doctors); icons.put("drinking_water", R.drawable.drinking_water); icons.put("embassy", R.drawable.embassy); icons.put("entrance", R.drawable.entrance); icons.put("fast_food", R.drawable.fast_food); icons.put("fire_station", R.drawable.fire_station); icons.put("fuel", R.drawable.fuel); icons.put("hamlet", R.drawable.town); icons.put("hospital", R.drawable.hospital); icons.put("hotel", R.drawable.hotel); icons.put("house", R.drawable.house); icons.put("housenumber", R.drawable.house); icons.put("hunting_stand", R.drawable.hunting_stand); icons.put("locality", R.drawable.town); icons.put("mall", R.drawable.mall); icons.put("nightclub", R.drawable.nightclub); icons.put("neighbourhood", R.drawable.house); icons.put("parking", R.drawable.parking); icons.put("pharmacy", R.drawable.pharmacy); icons.put("place_of_worship", R.drawable.place_of_worship); icons.put("police", R.drawable.police); icons.put("political", R.drawable.administrative); icons.put("primary", R.drawable.street); icons.put("prison", R.drawable.prison); icons.put("pub", R.drawable.pub); icons.put("recycling", R.drawable.recycling); icons.put("religious_administrative", R.drawable.place_of_worship); icons.put("residential", R.drawable.house); icons.put("restaurant", R.drawable.restaurant); icons.put("retail", R.drawable.mall); icons.put("road", R.drawable.street); icons.put("secondary", R.drawable.street); icons.put("stadium", R.drawable.stadium); icons.put("station", R.drawable.bus_stop); icons.put("street", R.drawable.street); icons.put("suburb", R.drawable.town); icons.put("subway_entrance", R.drawable.bus_stop); icons.put("platform", R.drawable.bus_stop); icons.put("supermarket", R.drawable.mall); icons.put("terminal", R.drawable.aerodrome); icons.put("tertiary", R.drawable.street); icons.put("theatre", R.drawable.theatre); icons.put("toilets", R.drawable.toilets); icons.put("town", R.drawable.town); icons.put("townhall", R.drawable.townhall); icons.put("track", R.drawable.street); icons.put("village", R.drawable.town); icons.put("phone", R.drawable.sos); }
From source file:com.gsma.rcs.ri.utils.RcsContactUtil.java
/** * Constructor//w ww .jav a 2 s . c o m * * @param context the context */ private RcsContactUtil(Context context) { mService = ConnectionManager.getInstance().getContactApi(); mResolver = context.getContentResolver(); mDefaultDisplayName = context.getString(R.string.label_no_contact); mDisplayNameAndroidCache = new LruCache<>(MAX_DISPLAY_NAME_IN_CACHE); mPhotoContactCache = new LruCache<>(MAX_DISPLAY_NAME_IN_CACHE); }
From source file:co.tinode.tindroid.ImageLoader.java
protected ImageLoader(Context context, int imageSize, FragmentManager fm) { mResources = context.getResources(); mImageSize = imageSize;/*from w w w. ja v a 2 s. c o m*/ final RetainFragment mRetainFragment = findOrCreateRetainFragment(fm); // See if we already have an ImageCache stored in RetainFragment mBitmapCache = (LruCache<String, Bitmap>) mRetainFragment.getObject(); // No existing ImageCache, create one and store it in RetainFragment if (mBitmapCache == null) { int maxSize = Math.round(MEMORY_PERCENT * Runtime.getRuntime().maxMemory() / 1024); mBitmapCache = new LruCache<String, Bitmap>(maxSize) { /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = bitmap.getByteCount() / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; mRetainFragment.saveObject(mBitmapCache); } }
From source file:com.chris.ni.omw.util.ImageCache.java
/** * Initialize the cache.//w ww . j a va 2s. c o m * * @param memCacheSizePercent The cache size as a percent of available app memory. */ private void init(float memCacheSizePercent) { int memCacheSize = calculateMemCacheSize(memCacheSizePercent); // Set up memory cache mMemoryCache = new LruCache<String, Bitmap>(memCacheSize) { /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = getBitmapSize(bitmap) / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; }