當前位置: 首頁>>代碼示例>>Java>>正文


Java LruCache類代碼示例

本文整理匯總了Java中android.support.v4.util.LruCache的典型用法代碼示例。如果您正苦於以下問題:Java LruCache類的具體用法?Java LruCache怎麽用?Java LruCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LruCache類屬於android.support.v4.util包,在下文中一共展示了LruCache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import android.support.v4.util.LruCache; //導入依賴的package包/類
public static synchronized void initialize(Configuration configuration) {
	if (sIsInitialized) {
		Log.v("ActiveAndroid already initialized.");
		return;
	}

	sContext = configuration.getContext();
	sModelInfo = new ModelInfo(configuration);
	sDatabaseHelper = new DatabaseHelper(configuration);

	// TODO: It would be nice to override sizeOf here and calculate the memory
	// actually used, however at this point it seems like the reflection
	// required would be too costly to be of any benefit. We'll just set a max
	// object size instead.
	sEntities = new LruCache<String, Model>(configuration.getCacheSize());

	openDatabase();

	sIsInitialized = true;

	Log.v("ActiveAndroid initialized successfully.");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:Cache.java

示例2: initMemCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
private void initMemCache() {
    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize =  maxMemory / 8;

    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than
            // number of items.
            return bitmap.getByteCount() / 1024;
        }
    };
}
 
開發者ID:BlueYangDroid,項目名稱:MvpPlus,代碼行數:19,代碼來源:CustomImageLoaderStrategy.java

示例3: EmojiCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
public EmojiCache(int cacheSize) {
		mCache = new LruCache<Integer, Drawable>(cacheSize) {
            @Override
            protected int sizeOf(Integer key, Drawable value) {
                return 1;
            };
            
            @Override
            protected void entryRemoved(boolean evicted, Integer key, Drawable oldValue, Drawable newValue) {
            	//這種情況,可能該drawable還在頁麵使用中,不能隨便recycle。這裏解除引用即可,gc會自動清除
//            	if (oldValue instanceof BitmapDrawable) {
//					((BitmapDrawable)oldValue).getBitmap().recycle();
//				}
            }
        };
	}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:17,代碼來源:EmojiCache.java

示例4: getBitmapCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
private static LruCache<String, Bitmap> getBitmapCache() {
    ThreadUtils.assertOnUiThread();

    LruCache<String, Bitmap> cache = sBitmapCache == null ? null : sBitmapCache.get();
    if (cache != null) return cache;

    // Create a new weakly-referenced cache.
    cache = new LruCache<String, Bitmap>(MAX_CACHE_BYTES) {
        @Override
        protected int sizeOf(String key, Bitmap thumbnail) {
            return thumbnail == null ? 0 : thumbnail.getByteCount();
        }
    };
    sBitmapCache = new WeakReference<>(cache);
    return cache;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:17,代碼來源:ThumbnailProviderImpl.java

示例5: setupCaches

import android.support.v4.util.LruCache; //導入依賴的package包/類
private void setupCaches() {
	// Titles and subtitles are small enough to stay cached, so use a very high max size
	bodyTitleCache = new LruCache<>(10000);
	bodySubtitleCache = new LruCache<>(10000);

	// Every artwork item will be a BitmapDrawable, so use the bitmap byte count for sizing
	bodyArtworkCache = new LruCache<LibraryItem, Drawable>(1000000) {
		@Override
		protected int sizeOf(final LibraryItem key, final Drawable value) {
			return ((BitmapDrawable) value).getBitmap().getByteCount();
		}
	};

	// Header cache will only contain one item
	headerTitleCache = new LruCache<>(2);
	headerSubtitleCache = new LruCache<>(2);
	headerArtworkCache = new LruCache<>(2);
}
 
開發者ID:MatthewTamlin,項目名稱:Mixtape,代碼行數:19,代碼來源:PlaylistActivity.java

示例6: setup

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * Initialises the testing objects and assigns them to member variables.
 */
@Before
public void setup() throws LibraryReadException {
	artwork = mock(Drawable.class);
	when(artwork.getIntrinsicWidth()).thenReturn(100);
	when(artwork.getIntrinsicHeight()).thenReturn(100);

	defaultArtwork = mock(Drawable.class);
	when(defaultArtwork.getIntrinsicWidth()).thenReturn(100);
	when(defaultArtwork.getIntrinsicHeight()).thenReturn(100);

	cachedArtwork = mock(Drawable.class);
	when(cachedArtwork.getIntrinsicWidth()).thenReturn(100);
	when(cachedArtwork.getIntrinsicHeight()).thenReturn(100);

	libraryItem = mock(LibraryItem.class);
	when(libraryItem.getArtwork(anyInt(), anyInt())).thenReturn(artwork);

	cache = new LruCache<>(10);

	displayableDefaults = mock(DisplayableDefaults.class);
	when(displayableDefaults.getArtwork()).thenReturn(defaultArtwork);

	imageView = mock(ImageView.class);
}
 
開發者ID:MatthewTamlin,項目名稱:Mixtape,代碼行數:28,代碼來源:TestArtworkBinder.java

示例7: setup

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * Initialises the testing objects and assigns them to member variables.
 */
@Before
public void setup() throws LibraryReadException {
	subtitle = mock(CharSequence.class);
	defaultSubtitle = mock(CharSequence.class);
	cachedSubtitle = mock(CharSequence.class);

	libraryItem = mock(LibraryItem.class);
	when(libraryItem.getSubtitle()).thenReturn(subtitle);

	cache = new LruCache<>(10);

	displayableDefaults = mock(DisplayableDefaults.class);
	when(displayableDefaults.getSubtitle()).thenReturn(defaultSubtitle);

	textView = mock(TextView.class);
}
 
開發者ID:MatthewTamlin,項目名稱:Mixtape,代碼行數:20,代碼來源:TestSubtitleBinder.java

示例8: setup

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * Initialises the testing objects and assigns them to member variables.
 */
@Before
public void setup() throws LibraryReadException {
	title = mock(CharSequence.class);
	defaultTitle = mock(CharSequence.class);
	cachedTitle = mock(CharSequence.class);

	libraryItem = mock(LibraryItem.class);
	when(libraryItem.getTitle()).thenReturn(title);

	cache = new LruCache<>(10);

	displayableDefaults = mock(DisplayableDefaults.class);
	when(displayableDefaults.getTitle()).thenReturn(defaultTitle);

	textView = mock(TextView.class);
}
 
開發者ID:MatthewTamlin,項目名稱:Mixtape,代碼行數:20,代碼來源:TestTitleBinder.java

示例9: init

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * 初始化<硬盤緩存>和<內存緩存>
 * @param context context
 * @Description:
 */
private void init(Context context)
{
    //設置硬盤緩存
    mImageDiskCache =
            ImageDiskLruCache.openImageCache(context, CacheConfig.Image.DISK_CACHE_NAME, CacheConfig.Image.DISK_CACHE_MAX_SIZE);

    // 設置內存緩存.
    final int imageMemorySize = CacheUtils.getMemorySize(context, CacheConfig.Image.MEMORY_SHRINK_FACTOR);
    LogUtil.d(TAG, "memory size : " + imageMemorySize);
    mMemoryCache = new LruCache<String, Bitmap>(imageMemorySize)
    {
        @Override
        protected int sizeOf(String key, Bitmap bitmap)
        {
            return CacheUtils.getBitmapSize(bitmap);
        }

        @Override
        protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue)
        {
        }
    };
}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:29,代碼來源:ImageCache.java

示例10: EmojiCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
public EmojiCache(int cacheSize) {
		mCache = new LruCache<Integer, Drawable>(cacheSize) {
            @Override
            protected int sizeOf(Integer key, Drawable value) {
                return 1;
            }
            
            @Override
            protected void entryRemoved(boolean evicted, Integer key, Drawable oldValue, Drawable newValue) {
            	//這種情況,可能該drawable還在頁麵使用中,不能隨便recycle。這裏解除引用即可,gc會自動清除
//            	if (oldValue instanceof BitmapDrawable) {
//					((BitmapDrawable)oldValue).getBitmap().recycle();
//				}
            }
        };
	}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:17,代碼來源:EmojiCache.java

示例11: JkImageLoader

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * Constructor
 * @author leibing
 * @createTime 2017/3/2
 * @lastModify 2017/3/2
 * @param context ref
 * @return
 */
private JkImageLoader(Context context){
    // init application conext
    mApplicationContext = context.getApplicationContext();
    // init memory cache(one 8 of the max memory)
    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    int cacheSize = maxMemory / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
        }
    };
    // init disk cache
    initDiskCache();
}
 
開發者ID:leibing8912,項目名稱:JkImageLoader,代碼行數:24,代碼來源:JkImageLoader.java

示例12: init

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * Initialize the cache.
 *
 * @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
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Memory cache created (size = " + memCacheSize + ")");
    }
    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;
        }
    };
}
 
開發者ID:AppLozic,項目名稱:Applozic-Android-Chat-Sample,代碼行數:25,代碼來源:ImageCache.java

示例13: createBitmapCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
/**
 * create thumbnail cache
 */
@SuppressLint("NewApi")
private final void createBitmapCache(final boolean clear) {
	if (clear && (sThumbnailCache != null)) {
		clearBitmapCache(hashCode());
	}
	if (sThumbnailCache == null) {
		// use 1/CACHE_RATE of available memory as memory cache
		final int cacheSize = 1024 * 1024 * mMemClass / CACHE_RATE;	// [MB] => [bytes]
		sThumbnailCache = new LruCache<String, Bitmap>(cacheSize) {
			@Override
			protected int sizeOf(String key, Bitmap bitmap) {
				// control memory usage instead of bitmap counts
				return bitmap.getRowBytes() * bitmap.getHeight();	// [bytes]
			}
		};
	}
	ThreadPool.preStartAllCoreThreads();
}
 
開發者ID:saki4510t,項目名稱:libcommon,代碼行數:22,代碼來源:MediaStoreAdapter.java

示例14: settingCache

import android.support.v4.util.LruCache; //導入依賴的package包/類
public static void settingCache() {
    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;

    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than
            // number of items.
            return bitmap.getByteCount() / 1024;
        }
    };
}
 
開發者ID:benslamajihed,項目名稱:GalleryPictureFirebaseAndroid,代碼行數:19,代碼來源:Utils.java

示例15: MemoryCacheManager

import android.support.v4.util.LruCache; //導入依賴的package包/類
private MemoryCacheManager() {
    // 取本虛擬機可用的最大內存的1/16作為內存緩存區
    int maxMemorySize = (int)Runtime.getRuntime().maxMemory();
    int maxCacheSize = maxMemorySize >> 4;
    mMemoryLruCache = new LruCache<String, T>(maxCacheSize) {
        @Override
        protected int sizeOf(String key, T value) {
            return value.getSize();
        }

        @Override
        protected void entryRemoved(boolean evicted, String key,
                                    T oldValue, T newValue) {
            if (oldValue != null)
                oldValue.release();
        }
    };
}
 
開發者ID:ZeusChan,項目名稱:LittleFreshWeather,代碼行數:19,代碼來源:MemoryCacheManager.java


注:本文中的android.support.v4.util.LruCache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。