public long getFirstCacheTime() {
   if (mCaches != null && mCaches.size() > 0) {
     BaseDanmaku firstItem = mCaches.first();
     if (firstItem == null) return 0;
     return firstItem.time;
   }
   return 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;
 }
Example #3
0
  @Override
  public IDanmakus sub(long startTime, long endTime) {
    if (mSortType == ST_BY_LIST || items == null || items.size() == 0) {
      return null;
    }
    if (subItems == null) {
      subItems = new Danmakus(mDuplicateMergingEnabled);
    }
    if (startItem == null) {
      startItem = createItem("start");
    }
    if (endItem == null) {
      endItem = createItem("end");
    }

    if (subItems != null) {
      long dtime = startTime - startItem.time;
      if (dtime >= 0 && endTime <= endItem.time) {
        return subItems;
      }
    }

    startItem.time = startTime;
    endItem.time = endTime;
    subItems.setItems(((SortedSet<BaseDanmaku>) items).subSet(startItem, endItem));
    return subItems;
  }
 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;
 }
Example #5
0
 @Override
 public void setSubItemsDuplicateMergingEnabled(boolean enable) {
   mDuplicateMergingEnabled = enable;
   startItem = endItem = null;
   if (subItems == null) {
     subItems = new Danmakus(enable);
   }
   subItems.setDuplicateMergingEnabled(enable);
 }
Example #6
0
 @Override
 public void clear() {
   if (items != null) {
     items.clear();
     mSize = 0;
   }
   if (subItems != null) {
     subItems.clear();
   }
 }
 private boolean push(BaseDanmaku item, int itemSize, boolean forcePush) {
   int size = itemSize; // sizeOf(item);
   while (mRealSize + size > mMaxSize && mCaches.size() > 0) {
     BaseDanmaku oldValue = mCaches.first();
     if (oldValue.isTimeOut()) {
       entryRemoved(false, oldValue, item);
       mCaches.removeItem(oldValue);
     } else {
       if (forcePush) {
         break;
       }
       return false;
     }
   }
   this.mCaches.addItem(item);
   mRealSize += size;
   // Log.e("CACHE", "realsize:"+mRealSize + ",size" + size);
   return true;
 }
 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;
 }