Example usage for android.support.v4.util LruCache LruCache

List of usage examples for android.support.v4.util LruCache LruCache

Introduction

In this page you can find the example usage for android.support.v4.util LruCache LruCache.

Prototype

public LruCache(int maxSize) 

Source Link

Usage

From source file:Main.java

public static LruCache<String, SpannableString> getInSize(int size) {
    return new LruCache<String, SpannableString>(size) {
        @Override/*from w ww .  j av a  2s. c om*/
        protected int sizeOf(String key, SpannableString value) {
            return value.length();
        }

        @Override
        protected SpannableString create(String key) {
            return null;
        }
    };
}

From source file:Main.java

public static void init() {
    lruCache = new LruCache<String, Object>(MAX_SIZE);
}

From source file:Main.java

public static void openLrucache() {

    lruCache = new LruCache<String, Bitmap>((int) Runtime.getRuntime().maxMemory() / 8) {
        @Override//from   w  ww .  j a  v a2  s  . com
        protected int sizeOf(String key, Bitmap value) {

            return value.getRowBytes() * value.getHeight();
        }
    };
}

From source file:Main.java

private static void checkBitmapCache() {
    if (bitmapCache == null) {
        bitmapCache = new LruCache<String, Bitmap>((int) Runtime.getRuntime().maxMemory() / 8) {
            @Override//from   ww w.j a  va2 s .  c  o m
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight();
            }
        };
    }
}

From source file:com.onemorecastle.util.ImageCache.java

private static synchronized LruCache<String, Bitmap> getBitmapCache() {
    if (bitmapCache == null) {
        bitmapCache = new LruCache<String, Bitmap>(cacheSize) {
            protected int sizeOf(String key, Bitmap value) {
                return (value.getRowBytes() * value.getHeight());
            }//from   w w  w .  j a  va 2s. c om
        };
    }
    return (bitmapCache);
}

From source file:org.commcare.android.util.StringUtils.java

/**
 * @param input A non-null string// w  w  w. ja  va  2  s .c o  m
 * @return a canonical version of the passed in string that is lower cased and has removed diacritical marks
 * like accents.
 */
@SuppressLint("NewApi")
public synchronized static String normalize(String input) {
    if (normalizationCache == null) {
        normalizationCache = new LruCache<String, String>(cacheSize);

        diacritics = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    }
    String cachedString = normalizationCache.get(input);
    if (cachedString != null) {
        return cachedString;
    }

    //Initialized the normalized string (If we can, we'll use the Normalizer API on it)
    String normalized = input;

    //If we're above gingerbread we'll normalize this in NFD form 
    //which helps a lot. Otherwise we won't be able to clear up some of those
    //issues, but we can at least still eliminate diacritics.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
    } else {
        //TODO: I doubt it's worth it, but in theory we could run
        //some other normalization for the minority of pre-API9
        //devices.
    }

    String output = diacritics.matcher(normalized).replaceAll("").toLowerCase();

    normalizationCache.put(input, output);

    return output;
}

From source file:Main.java

public static String getVlaueFromAnnotation(Annotation annotation, String annName) {
    if (cache == null) {
        cache = new LruCache(500);
    }/*from  ww w  . j a  va2  s  .c  o  m*/
    String annotationString = annotation.toString();
    String cacheKey = "getVlaueByColumnAnnotation:" + annotationString.hashCode() + "," + annName;
    String ret = (String) cache.get(cacheKey);
    if (ret == null || "".equals(ret)) {
        String pattern = annName + "=(.*?),";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(annotation.toString());
        if (m.find()) {
            ret = m.group();
            ret = ret.substring(annName.length() + 1, ret.length() - 1);
        }
        cache.put(cacheKey, ret);
    }
    return ret;
}

From source file:org.commcare.utils.StringUtils.java

/**
 * @param input A non-null string/*www.j  av  a  2s .  c o  m*/
 * @return a canonical version of the passed in string that is lower cased and has removed diacritical marks
 * like accents.
 */
@SuppressLint("NewApi")
public synchronized static String normalize(String input) {
    if (normalizationCache == null) {
        normalizationCache = new LruCache<>(cacheSize);

        diacritics = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    }
    String cachedString = normalizationCache.get(input);
    if (cachedString != null) {
        return cachedString;
    }

    //Initialized the normalized string (If we can, we'll use the Normalizer API on it)
    String normalized = input;

    //If we're above gingerbread we'll normalize this in NFD form 
    //which helps a lot. Otherwise we won't be able to clear up some of those
    //issues, but we can at least still eliminate diacritics.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
    } else {
        //TODO: I doubt it's worth it, but in theory we could run
        //some other normalization for the minority of pre-API9
        //devices.
    }

    String output = diacritics.matcher(normalized).replaceAll("").toLowerCase();

    normalizationCache.put(input, output);

    return output;
}

From source file:com.radioeye.volley.MyVolley.java

public static void init(Context context) {

    mRequestQueue = Volley.newRequestQueue(context);
    mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() {
        private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);

        public void putBitmap(String url, Bitmap bitmap) {
            mCache.put(url, bitmap);/*from   www.  ja va 2 s .c  om*/
        }

        public Bitmap getBitmap(String url) {
            return mCache.get(url);
        }
    });
}

From source file:com.dycody.android.idealnote.models.ThumbnailLruCache.java

public static synchronized ThumbnailLruCache getInstance() {
    if (instance == null) {
        instance = new ThumbnailLruCache(cacheSize);
    }// w ww . java  2s .  c  o m

    mMemoryCache = new LruCache<>(cacheSize);

    return instance;
}