public void recycle() { for (BmpCacheEntry ce : m_cache) { ce.recycle(); } m_cache.clear(); caches.remove(m_cache); }
public static void clearAllCache() { for (Vector<BmpCacheEntry> cache : caches) { for (BmpCacheEntry be : cache) { be.recycle(); } cache.clear(); } caches.clear(); System.gc(); }
@Override protected void onResize(float width, float height) { int w = (int) width, h = (int) height; m_curEntry = searchEntry((int) width, (int) height); if (m_curEntry != null) { if (m_curEntry.isValid()) { return; } m_cache.remove(m_curEntry); } super.onResize((int) width, (int) height); if (m_cache.size() == 0) { caches.add(m_cache); } m_curEntry = new BmpCacheEntry(); m_curEntry.w = w; m_curEntry.h = h; m_curEntry.bmpNormal = Bitmap.createBitmap(w, h, Config.ARGB_8888); boolean press = m_bPressed; boolean ch = m_bCheckable; m_bCheckable = false; m_bPressed = false; super.draw(new Canvas(m_curEntry.bmpNormal), null); m_bPressed = true; m_curEntry.bmpPress = Bitmap.createBitmap(w, h, Config.ARGB_8888); super.draw(new Canvas(m_curEntry.bmpPress), null); if (m_cache.size() == m_cacheSize) { m_cache.remove(0); } m_cache.add(m_curEntry); m_bPressed = press; m_bCheckable = ch; // try { // File f = new // File(Environment.getExternalStorageDirectory()+"/test"+System.currentTimeMillis()+".jpg"); // f.createNewFile(); // boolean ok = m_curEntry.bmpNormal.compress(CompressFormat.JPEG, 100, new // FileOutputStream(f)); // if(!ok||!f.exists()) // { // long aa = 1; // long bb = aa; // } // } catch (Throwable e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
@Override public void draw(Canvas canvas, Paint paint) { if (m_curEntry == null) { return; } if (!m_curEntry.isValid()) { onResize(m_curEntry.w, m_curEntry.h); } Bitmap bmp = m_bPressed ? m_curEntry.bmpPress : m_curEntry.bmpNormal; canvas.drawBitmap(bmp, 0, 0, null); if (m_bCheckable || m_bChecked) { onDrawCheckMark(canvas, m_bChecked, m_rect); } };