Java tutorial
/* * Copyright (C) 2014 ChatWing * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.chatwingsdk.utils; import android.annotation.TargetApi; import android.graphics.Bitmap; import android.os.Build; import android.support.v4.util.LruCache; import com.android.volley.toolbox.ImageLoader.ImageCache; /** * Author: Huy Nguyen * Date: 5/30/13 * Time: 2:16 AM */ public class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache { /** * Constructs a new cache * * @param maxSize * in kilobytes */ public BitmapLruCache(int maxSize) { super(maxSize); } @Override @TargetApi(12) protected int sizeOf(String key, Bitmap value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { return value.getByteCount() / 1024; } else { return (value.getRowBytes() * value.getHeight()) / 1024; } } @Override public Bitmap getBitmap(String url) { return get(url); } @Override public void putBitmap(String url, Bitmap bitmap) { put(url, bitmap); } }