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


Java LruCache類代碼示例

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


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

示例1: createLoadingHeader

import android.util.LruCache; //導入依賴的package包/類
/**
 * @param type 數據類型
 * @return 根據type產生loading的頭
 */
private T createLoadingHeader(int type) {

    checkLoadingAdapterBind();

    if (mSingleCache == null) {
        mSingleCache = new LruCache<String, T>(mMaxSingleCacheCount);
    }

    String headerKey = getHeaderKey(type);
    T header = mSingleCache.get(headerKey);

    if (header == null) {
        header = mLoadingEntityAdapter.createLoadingHeaderEntity(type);
        mSingleCache.put(headerKey, header);
    }

    mLoadingEntityAdapter.bindLoadingEntity(header, -1);
    return header;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:RecyclerViewAdapterHelper.java

示例2: MemoryLruCache

import android.util.LruCache; //導入依賴的package包/類
private MemoryLruCache(){

        int maxMemorySize= (int) (Runtime.getRuntime().maxMemory()/16);
        Log.i(GlobalConfig.TAG,"內存可用的大小:"+maxMemorySize/1024 + "K");

        if (maxMemorySize <= 0){
            maxMemorySize = 10*1024*1024;
        }

        lruCache = new LruCache<String, Bitmap>(maxMemorySize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                //一張圖片的大小
                return value.getRowBytes()*value.getHeight();
            }
        };
    }
 
開發者ID:SingleShu,項目名稱:ImageLoaderLibrary,代碼行數:18,代碼來源:MemoryLruCache.java

示例3: getSectionData

import android.util.LruCache; //導入依賴的package包/類
private SparseArray<ArrayList<String>> getSectionData(int section, PageProperty property) {
    SparseArray<ArrayList<String>> pages = null;
    if (map == null) {
        map = new LruCache<>(3);
        pages = loadPages(getPageSource(section), property.textPaint, property.visibleHeight, property.visibleWidth, property.intervalSize, property.paragraphSize);
        map.put(section, pages);
        mPageProperty=property;
    } else {
        if (mPageProperty != null && mPageProperty.equals(property)) {
            pages = map.get(section);
        }
        if (pages == null) {
            pages = loadPages(getPageSource(section), property.textPaint, property.visibleHeight, property.visibleWidth, property.intervalSize, property.paragraphSize);
            map.put(section, pages);
            mPageProperty=property;
        }
    }
    return pages;
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:20,代碼來源:StringAdapter.java

示例4: ImageLoader

import android.util.LruCache; //導入依賴的package包/類
private ImageLoader(Context mContext, String dirNameByRoot) {
    this.mContext = mContext;
    if (dirNameByRoot != null && dirNameByRoot.length() > 0)
        fileUtils = new FileUtils(mContext, dirNameByRoot);
    else
        fileUtils = new FileUtils(mContext);
    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    // 給LruCache分配1/8 4M
    int mCacheSize = maxMemory / 8;
    mMemoryCache = new LruCache<String, Bitmap>(mCacheSize) {
        // 必須重寫此方法,來測量Bitmap的大小
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:18,代碼來源:ImageLoader.java

示例5: ClusterOverlay

import android.util.LruCache; //導入依賴的package包/類
/**
 * 構造函數,批量添加聚合元素時,調用此構造函數
 *
 * @param amap
 * @param clusterItems 聚合元素
 * @param clusterSize
 * @param context
 */
public ClusterOverlay(AMap amap, List<ClusterItem> clusterItems,
                      int clusterSize, Context context) {
    //默認最多會緩存80張圖片作為聚合顯示元素圖片,根據自己顯示需求和app使用內存情況,可以修改數量
    mLruCache = new LruCache<Integer, Drawable>(80) {
    };
    if (clusterItems != null) {
        mClusterItems = clusterItems;
    } else {
        mClusterItems = new ArrayList<ClusterItem>();
    }
    mContext = context;
    mClusters = new ArrayList<Cluster>();
    this.mAMap = amap;
    mClusterSize = clusterSize;
    mPXInMeters = mAMap.getScalePerPixel();
    mClusterDistance = mPXInMeters * mClusterSize;
    amap.setOnCameraChangeListener(this);
    amap.setOnMarkerClickListener(this);
    setClusterRenderer(this);
    setOnClusterClickListener(this);
    initThreadHandler();
    assignClusters();
}
 
開發者ID:sherlockchou86,項目名稱:yphoto,代碼行數:32,代碼來源:ClusterOverlay.java

示例6: AppMuteManager

import android.util.LruCache; //導入依賴的package包/類
public AppMuteManager(NotificationService service) {
    this.service = service;

    googleApiClient = new GoogleApiClient.Builder(service)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    googleApiClient.connect();

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory());
    iconCache = new LruCache<String, Bitmap>(maxMemory / 32) // 1/16th of device's RAM should be far enough for all icons
    {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount();
        }
    };

}
 
開發者ID:matejdro,項目名稱:WearVibrationCenter,代碼行數:21,代碼來源:AppMuteManager.java

示例7: onCreate

import android.util.LruCache; //導入依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    systemApps = getArguments().getBoolean("systemApps", false);

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    iconCache = new LruCache<String, Bitmap>(maxMemory / 16) // 1/16th of device's RAM should be far enough for all icons
    {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount() / 1024;
        }

    };

    adapter = new AppListAdapter();
}
 
開發者ID:matejdro,項目名稱:WearVibrationCenter,代碼行數:19,代碼來源:AppPickerFragment.java

示例8: BitmapLruCache

import android.util.LruCache; //導入依賴的package包/類
public BitmapLruCache(int cacheSize) {
    mCache = new LruCache<T, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(T id, Bitmap value) {
            return value.getByteCount();
        }

        @Override
        protected void entryRemoved(boolean evicted, T key, Bitmap oldValue,
                                    Bitmap newValue) {

            if (oldValue.isMutable()) {
                oldValue.recycle();
            }
        }
    };
}
 
開發者ID:ficklerobot,項目名稱:grid-video-viewer,代碼行數:18,代碼來源:BitmapLruCache.java

示例9: init

import android.util.LruCache; //導入依賴的package包/類
public static void init(Context context) {
    if (sFonts != null) {
        return;
    }

    sCache = new LruCache<String, MemoryFile>(FontProviderSettings.getMaxCache()) {
        @Override
        protected void entryRemoved(boolean evicted, String key, MemoryFile oldValue, MemoryFile newValue) {
            if (evicted) {
                oldValue.close();
            }
        }

        @Override
        protected int sizeOf(String key, MemoryFile value) {
            return value.length();
        }
    };

    sFonts = new ArrayList<>();

    for (int res : FONTS_RES) {
        FontInfo font = new Gson().fromJson(new InputStreamReader(context.getResources().openRawResource(res)), FontInfo.class);
        sFonts.add(font);
    }
}
 
開發者ID:RikkaApps,項目名稱:FontProvider,代碼行數:27,代碼來源:FontManager.java

示例10: ImageCache

import android.util.LruCache; //導入依賴的package包/類
public ImageCache() {
  mReusableBitmaps =
      Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
  long memCacheSize = Runtime.getRuntime().freeMemory() / 8;
  if (memCacheSize <= 0) {
    memCacheSize = 1;
  }
  // If you're running on Honeycomb or newer, create a
  // synchronized HashSet of references to reusable bitmaps.
  mMemoryCache = new LruCache<String, BitmapDrawable>((int) memCacheSize) {

    // // Notify the removed entry that is no longer being cached.
    // @Override
    // protected void entryRemoved(boolean evicted, String key,
    // BitmapDrawable oldValue, BitmapDrawable newValue) {
    // //Log.i("TAG","mReusableBitmaps add2");
    // //mReusableBitmaps.add(new SoftReference<>(oldValue.getBitmap()));
    // }
    @Override
    protected int sizeOf(String key, BitmapDrawable value) {
      return value.getBitmap().getByteCount();
    }
  };
}
 
開發者ID:Mr-wangyong,項目名稱:ImageFrame,代碼行數:25,代碼來源:ImageCache.java

示例11: MemCache

import android.util.LruCache; //導入依賴的package包/類
private MemCache() {
    // Find out maximum memory available to application
    // 1024 is used because LruCache constructor takes int in kilobytes
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/16th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 16;
    Log.d(getClass().getName(), "max memory " + maxMemory + " cache size " + cacheSize);

    this.memCache = new LruCache<String, Entry>(cacheSize) {
        @Override
        protected int sizeOf(String key, Entry value) {
            return super.sizeOf(key, value);
        }
    };
}
 
開發者ID:myntra,項目名稱:ObjectCache,代碼行數:17,代碼來源:MemCache.java

示例12: ImageLoader

import android.util.LruCache; //導入依賴的package包/類
protected ImageLoader() {
    // 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 / LRU_CACHE_SIZE_FACTOR;

    memCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap image) {
            return image.getByteCount()/1024;
        }
    };
}
 
開發者ID:f3401pal,項目名稱:ImageCarouselView,代碼行數:17,代碼來源:ImageLoader.java

示例13: ImageLoader

import android.util.LruCache; //導入依賴的package包/類
private ImageLoader(Context context) {
    mContext = context.getApplicationContext();
    int maxMemory = (int) Runtime.getRuntime().maxMemory();
    int cacheSize = maxMemory / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight() / 1024;
        }
    };
    File diskCacheDir = getDiskCacheDir(mContext, "bitmap");
    if (!diskCacheDir.exists()) {
        diskCacheDir.mkdirs();
    }

    if (getUsableSpace(diskCacheDir) > DISK_CACHE_SIZE) {
        try {
            mDiskLruCache = DiskLruCache.open(diskCacheDir, 1, 1, DISK_CACHE_SIZE);
            mIsDiskLruCacheCreated = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:26,代碼來源:ImageLoader.java

示例14: onCreate

import android.util.LruCache; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

    if (getIntent() != null) {
        handleIntent(getIntent());
    }

    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

    VerticalDividerItemDecoration verticalDividerItemDecoration = new VerticalDividerItemDecoration(10);
    recyclerView.addItemDecoration(verticalDividerItemDecoration);

    this.bitmapLruCache = new LruCache<String, Bitmap>(cacheSize) {
    };

    adapter = new BookAdapter(bookList, bitmapLruCache);
    recyclerView.setAdapter(adapter);

}
 
開發者ID:wangwang4git,項目名稱:ReadInJoy-And-Train,代碼行數:25,代碼來源:RecyclerViewActivity.java

示例15: init

import android.util.LruCache; //導入依賴的package包/類
/**
     * 初始化
     *
     * @param threadCount
     * @param type
     */
    private void init(int threadCount, Type type) {
        initBackThread();

        // 獲取我們應用的最大可用內存
        int maxMemory = (int) Runtime.getRuntime().maxMemory();
        int cacheMemory = maxMemory / 8;
        mLruCache = new LruCache<String, Bitmap>(cacheMemory) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
//                return value.getRowBytes() * value.getHeight();
                return value.getByteCount();
            }

        };

        // 創建線程池
        mThreadPool = Executors.newFixedThreadPool(threadCount);
        mTaskQueue = new LinkedList<Runnable>();
        mType = type;
        mSemaphoreThreadPool = new Semaphore(threadCount);
    }
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:28,代碼來源:ImageLoader.java


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