private void evictAllNotInScreen(boolean removeAllReferences) { if (mCaches != null) { IDanmakuIterator it = mCaches.iterator(); while (it.hasNext()) { BaseDanmaku danmaku = it.next(); IDrawingCache<?> cache = danmaku.cache; boolean hasReferences = cache != null && cache.hasReferences(); if (removeAllReferences && hasReferences) { if (cache.get() != null) { mRealSize -= cache.size(); cache.destroy(); } entryRemoved(true, danmaku, null); it.remove(); continue; } if (danmaku.hasDrawingCache() == false || danmaku.isOutside()) { entryRemoved(true, danmaku, null); it.remove(); } } // mCaches.clear(); } mRealSize = 0; }
private void evictAll() { if (mCaches != null) { IDanmakuIterator it = mCaches.iterator(); while (it.hasNext()) { BaseDanmaku danmaku = it.next(); entryRemoved(true, danmaku, null); } mCaches.clear(); } mRealSize = 0; }
private void clearTimeOutCaches(long time) { IDanmakuIterator it = mCaches.iterator(); while (it.hasNext() && !mEndFlag) { BaseDanmaku val = it.next(); if (val.isTimeOut()) { synchronized (mDrawingNotify) { try { mDrawingNotify.wait(30); } catch (InterruptedException e) { e.printStackTrace(); break; } } entryRemoved(false, val, null); it.remove(); } else { break; } } }
private BaseDanmaku findReuseableCache( BaseDanmaku refDanmaku, boolean strictMode, int maximumTimes) { IDanmakuIterator it = mCaches.iterator(); int slopPixel = 0; if (!strictMode) { slopPixel = mDisp.getSlopPixel() * 2; } int count = 0; while (it.hasNext() && count++ < maximumTimes) { // limit maximum times BaseDanmaku danmaku = it.next(); if (!danmaku.hasDrawingCache()) { continue; } if (danmaku.paintWidth == refDanmaku.paintWidth && danmaku.paintHeight == refDanmaku.paintHeight && danmaku.underlineColor == refDanmaku.underlineColor && danmaku.borderColor == refDanmaku.borderColor && danmaku.textColor == refDanmaku.textColor && danmaku.text.equals(refDanmaku.text)) { return danmaku; } if (strictMode) { continue; } if (!danmaku.isTimeOut()) { break; } if (danmaku.cache.hasReferences()) { continue; } float widthGap = danmaku.cache.width() - refDanmaku.paintWidth; float heightGap = danmaku.cache.height() - refDanmaku.paintHeight; if (widthGap >= 0 && widthGap <= slopPixel && heightGap >= 0 && heightGap <= slopPixel) { return danmaku; } } return null; }