当前位置: 首页>>代码示例>>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;未经允许,请勿转载。