Java源码示例:master.flame.danmaku.danmaku.model.IDanmakus

示例1
private final void removeTimeoutDanmakus(IDanmakus danmakus, long limitTime) {
    IDanmakuIterator it = danmakus.iterator();
    long startTime = SystemClock.uptimeMillis();
    while (it.hasNext()) {
        try {
            if (it.next().isTimeOut()) {
                it.remove();
                if (SystemClock.uptimeMillis() - startTime > limitTime) {
                    return;
                }
            }
            return;
        } catch (Exception e) {
            return;
        }
    }
}
 
示例2
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case 1:
            IDanmakus clickDanmakus = touchHitDanmaku(event.getX(), event.getY());
            BaseDanmaku newestDanmaku = null;
            if (!(clickDanmakus == null || clickDanmakus.isEmpty())) {
                performClick(clickDanmakus);
                newestDanmaku = fetchLatestOne(clickDanmakus);
            }
            if (newestDanmaku != null) {
                performClickWithlatest(newestDanmaku);
                break;
            }
            break;
    }
    return false;
}
 
示例3
public IDanmakus touchHitDanmaku(float x, float y) {
    IDanmakus hitDanmakus = new Danmakus();
    this.mDanmakuBounds.setEmpty();
    IDanmakus danmakus = this.danmakuView.getCurrentVisibleDanmakus();
    if (danmakus != null && !danmakus.isEmpty()) {
        IDanmakuIterator iterator = danmakus.iterator();
        while (iterator.hasNext()) {
            BaseDanmaku danmaku = iterator.next();
            if (danmaku != null) {
                this.mDanmakuBounds.set(danmaku.getLeft(), danmaku.getTop() - 30.0f, danmaku.getRight(), danmaku.getBottom() + 30.0f);
                if (this.mDanmakuBounds.contains(x, y)) {
                    danmaku.clickX = x;
                    danmaku.clickY = y;
                    danmaku.setRectF(this.mDanmakuBounds);
                    hitDanmakus.addItem(danmaku);
                    break;
                }
            }
        }
    }
    return hitDanmakus;
}
 
示例4
public IDanmakus getVisibleDanmakusOnTime(long time) {
    IDanmakus subDanmakus = this.danmakuList.subnew((time - this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION) - 100, time + this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
    IDanmakus visibleDanmakus = new Danmakus();
    if (!(subDanmakus == null || subDanmakus.isEmpty())) {
        IDanmakuIterator iterator = subDanmakus.iterator();
        while (iterator.hasNext()) {
            BaseDanmaku danmaku = iterator.next();
            if (danmaku.isShown() && !danmaku.isOutside()) {
                visibleDanmakus.addItem(danmaku);
            }
        }
    }
    return visibleDanmakus;
}
 
示例5
public IDanmakus getDanmakus() {
    if (this.mDanmakus != null) {
        return this.mDanmakus;
    }
    this.mContext.mDanmakuFactory.resetDurationsData();
    this.mDanmakus = parse();
    releaseDataSource();
    this.mContext.mDanmakuFactory.updateMaxDanmakuDuration();
    return this.mDanmakus;
}
 
示例6
public IDanmakus subnew(long startTime, long endTime) {
    Collection<BaseDanmaku> subset = subset(startTime, endTime);
    if (subset == null || subset.isEmpty()) {
        return null;
    }
    return new Danmakus(new ArrayList(subset));
}
 
示例7
public IDanmakus sub(long startTime, long endTime) {
    if (this.items == null || this.items.size() == 0) {
        return null;
    }
    if (this.subItems == null) {
        if (this.mSortType == 4) {
            this.subItems = new Danmakus(4);
            this.subItems.setItems(this.items);
        } else {
            this.subItems = new Danmakus(this.mDuplicateMergingEnabled);
        }
    }
    if (this.mSortType == 4) {
        return this.subItems;
    }
    if (this.startItem == null) {
        this.startItem = createItem(JarConstant.PLUGIN_WINDOW_PLAYER_STATIC_METHOD_NAME_START);
    }
    if (this.endItem == null) {
        this.endItem = createItem("end");
    }
    if (this.subItems != null && startTime - this.startItem.time >= 0 && endTime <= this.endItem.time) {
        return this.subItems;
    }
    this.startItem.time = startTime;
    this.endItem.time = endTime;
    this.subItems.setItems(((SortedSet) this.items).subSet(this.startItem, this.endItem));
    return this.subItems;
}
 
示例8
private void danmuku(InputStream inputStream) {
        if (mDanmakuView != null) {
            mParser = DanmakuHelper.createParser(inputStream);
            mDanmakuView.setCallback(new DrawHandler.Callback() {
                @Override
                public void updateTimer(DanmakuTimer timer) {
                }

                @Override
                public void danmakuShown(BaseDanmaku danmaku) {

                }

                @Override
                public void drawingFinished() {

                }

                @Override
                public void prepared() {
                    mIsDanmakuReday = true;
                }
            });
            mDanmakuView.setOnDanmakuClickListener(new IDanmakuView.OnDanmakuClickListener() {
                @Override
                public void onDanmakuClick(BaseDanmaku latest) {
//                    Log.d("DFM", "onDanmakuClick text:" + latest.text);
                }

                @Override
                public void onDanmakuClick(IDanmakus danmakus) {
//                    Log.d("DFM", "onDanmakuClick danmakus size:" + danmakus.size());
                }
            });
            mDanmakuView.prepare(mParser, mDanmakuContext);
            mDanmakuView.enableDanmakuDrawingCache(true);
//            mDanmakuView.showFPS(true);
        }
    }
 
示例9
@Override
public IDanmakus getCurrentVisibleDanmakus() {
    if (handler != null) {
        return handler.getCurrentVisibleDanmakus();
    }

    return null;
}
 
示例10
@Override
protected IDanmakus parse() {
    return new Danmakus();
}
 
示例11
@Override
protected IDanmakus parse() {
    return new Danmakus();
}
 
示例12
@Override
protected IDanmakus parse() {
    if (result == null) result = preParse(mContext);
    return result;
}
 
示例13
public IDanmakus getCurrentVisibleDanmakus() {
    if (this.drawTask != null) {
        return this.drawTask.getVisibleDanmakusOnTime(getCurrentTime());
    }
    return null;
}
 
示例14
protected RenderingState drawDanmakus(AbsDisplayer disp, DanmakuTimer timer) {
    if (this.clearRetainerFlag) {
        this.mRenderer.clearRetainer();
        this.clearRetainerFlag = false;
    }
    if (this.danmakuList == null) {
        return null;
    }
    DrawHelper.clearCanvas((Canvas) disp.getExtraData());
    if (this.mIsHidden) {
        return this.mRenderingState;
    }
    long beginMills = (timer.currMillisecond - this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION) - 100;
    long endMills = timer.currMillisecond + this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION;
    if (this.mLastBeginMills > beginMills || timer.currMillisecond > this.mLastEndMills) {
        IDanmakus subDanmakus = this.danmakuList.sub(beginMills, endMills);
        if (subDanmakus != null) {
            this.danmakus = subDanmakus;
        } else {
            this.danmakus.clear();
        }
        this.mLastBeginMills = beginMills;
        this.mLastEndMills = endMills;
    } else {
        beginMills = this.mLastBeginMills;
        endMills = this.mLastEndMills;
    }
    if (this.danmakus == null || this.danmakus.isEmpty()) {
        this.mRenderingState.nothingRendered = true;
        this.mRenderingState.beginTime = beginMills;
        this.mRenderingState.endTime = endMills;
        return this.mRenderingState;
    }
    RenderingState renderingState = this.mRenderer.draw(this.mDisp, this.danmakus, this.mStartRenderTime);
    this.mRenderingState = renderingState;
    if (!renderingState.nothingRendered) {
        return renderingState;
    }
    if (!(this.mTaskListener == null || this.mLastDanmaku == null || !this.mLastDanmaku.isTimeOut())) {
        this.mTaskListener.onDanmakusDrawingFinished();
    }
    if (renderingState.beginTime == -1) {
        renderingState.beginTime = beginMills;
    }
    if (renderingState.endTime != -1) {
        return renderingState;
    }
    renderingState.endTime = endMills;
    return renderingState;
}
 
示例15
private long prepareCaches(boolean repositioned) {
    long curr = CacheManagingDrawTask.this.mCacheTimer.currMillisecond;
    long end = curr + (CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize));
    if (end < CacheManagingDrawTask.this.mTimer.currMillisecond) {
        return 0;
    }
    long startTime = SystemClock.uptimeMillis();
    IDanmakus danmakus = null;
    int tryCount = 0;
    boolean hasException = false;
    do {
        BaseDanmaku first;
        try {
            danmakus = CacheManagingDrawTask.this.danmakuList.subnew(curr, end);
        } catch (Exception e) {
            hasException = true;
            SystemClock.sleep(10);
        }
        tryCount++;
        if (tryCount >= 3 || danmakus != null) {
            if (danmakus != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            first = danmakus.first();
            BaseDanmaku last = danmakus.last();
            if (first != null || last == null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            long sleepTime = Math.min(100, 30 + ((10 * (first.time - CacheManagingDrawTask.this.mTimer.currMillisecond)) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION));
            if (repositioned) {
                sleepTime = 0;
            }
            IDanmakuIterator itr = danmakus.iterator();
            BaseDanmaku item = null;
            int orderInScreen = 0;
            int currScreenIndex = 0;
            int sizeInScreen = danmakus.size();
            while (!this.mPause && !this.mCancelFlag && itr.hasNext()) {
                item = itr.next();
                if (last.time >= CacheManagingDrawTask.this.mTimer.currMillisecond) {
                    if (!item.hasDrawingCache() && (repositioned || (!item.isTimeOut() && item.isOutside()))) {
                        if (!item.hasPassedFilter()) {
                            CacheManagingDrawTask.this.mContext.mDanmakuFilters.filter(item, orderInScreen, sizeInScreen, null, true, CacheManagingDrawTask.this.mContext);
                        }
                        if (!((item.priority == (byte) 0 && item.isFiltered()) || (item.isDanmakuTypeFiltered && item.isFiltered()))) {
                            int screenIndex = (int) ((item.time - curr) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
                            if (currScreenIndex == screenIndex) {
                                orderInScreen++;
                            } else {
                                orderInScreen = 0;
                                currScreenIndex = screenIndex;
                            }
                            if (!repositioned) {
                                try {
                                    synchronized (CacheManagingDrawTask.this.mDrawingNotify) {
                                        CacheManagingDrawTask.this.mDrawingNotify.wait(sleepTime);
                                    }
                                } catch (InterruptedException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            if (buildCache(item, false) != (byte) 1) {
                                if (!repositioned && SystemClock.uptimeMillis() - startTime >= DanmakuFactory.COMMON_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize)) {
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                break;
            }
            long consumingTime = SystemClock.uptimeMillis() - startTime;
            if (item != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(item.time);
                return consumingTime;
            }
            CacheManagingDrawTask.this.mCacheTimer.update(end);
            return consumingTime;
        }
    } while (hasException);
    if (danmakus != null) {
        first = danmakus.first();
        BaseDanmaku last2 = danmakus.last();
        if (first != null) {
        }
        CacheManagingDrawTask.this.mCacheTimer.update(end);
        return 0;
    }
    CacheManagingDrawTask.this.mCacheTimer.update(end);
    return 0;
}
 
示例16
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
    int lastTotalDanmakuCount = this.mRenderingState.totalDanmakuCount;
    this.mRenderingState.reset();
    IDanmakuIterator itr = danmakus.iterator();
    int orderInScreen = 0;
    this.mStartTimer.update(SystemClock.uptimeMillis());
    int sizeInScreen = danmakus.size();
    BaseDanmaku drawItem = null;
    while (itr.hasNext()) {
        drawItem = itr.next();
        if (!drawItem.hasPassedFilter()) {
            this.mContext.mDanmakuFilters.filter(drawItem, orderInScreen, sizeInScreen, this.mStartTimer, false, this.mContext);
        }
        if (drawItem.time >= startRenderTime && (!(drawItem.priority == (byte) 0 && drawItem.isFiltered()) && drawItem.time >= startRenderTime)) {
            if (!drawItem.isDanmakuTypeFiltered || !drawItem.isFiltered()) {
                if (drawItem.isLate()) {
                    if (this.mCacheManager == null || drawItem.hasDrawingCache()) {
                        break;
                    }
                    this.mCacheManager.addDanmaku(drawItem);
                } else {
                    orderInScreen++;
                    if (!drawItem.isMeasured()) {
                        drawItem.measure(disp, false);
                    }
                    this.mDanmakusRetainer.fix(drawItem, disp, this.mVerifier);
                    if (!drawItem.isOutside() && drawItem.isShown()) {
                        if (drawItem.lines != null || drawItem.getBottom() <= ((float) disp.getHeight())) {
                            int renderingType = drawItem.draw(disp);
                            RenderingState renderingState;
                            if (renderingType == 1) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheHitCount++;
                            } else if (renderingType == 2) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheMissCount++;
                                if (this.mCacheManager != null) {
                                    this.mCacheManager.addDanmaku(drawItem);
                                }
                            }
                            this.mRenderingState.addCount(drawItem.getType(), 1);
                            this.mRenderingState.addTotalCount(1);
                            if (!(this.mOnDanmakuShownListener == null || drawItem.firstShownFlag == this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG)) {
                                drawItem.firstShownFlag = this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG;
                                this.mOnDanmakuShownListener.onDanmakuShown(drawItem);
                            }
                        }
                    }
                }
            }
        }
    }
    this.mRenderingState.nothingRendered = this.mRenderingState.totalDanmakuCount == 0;
    this.mRenderingState.endTime = drawItem != null ? drawItem.time : -1;
    if (this.mRenderingState.nothingRendered) {
        this.mRenderingState.beginTime = -1;
    }
    this.mRenderingState.incrementCount = this.mRenderingState.totalDanmakuCount - lastTotalDanmakuCount;
    this.mRenderingState.consumingTime = this.mStartTimer.update(SystemClock.uptimeMillis());
    return this.mRenderingState;
}
 
示例17
public IDanmakus getCurrentVisibleDanmakus() {
    if (this.handler != null) {
        return this.handler.getCurrentVisibleDanmakus();
    }
    return null;
}
 
示例18
private void performClick(IDanmakus danmakus) {
    if (this.danmakuView.getOnDanmakuClickListener() != null) {
        this.danmakuView.getOnDanmakuClickListener().onDanmakuClick(danmakus);
    }
}
 
示例19
private BaseDanmaku fetchLatestOne(IDanmakus danmakus) {
    if (danmakus.isEmpty()) {
        return null;
    }
    return danmakus.last();
}
 
示例20
public IDanmakus getCurrentVisibleDanmakus() {
    if (this.handler != null) {
        return this.handler.getCurrentVisibleDanmakus();
    }
    return null;
}
 
示例21
public boolean isClickDanmukuRange(MotionEvent event) {
    IDanmakus clickDanmakus = this.mTouchHelper.touchHitDanmaku(event.getX(), event.getY());
    return (clickDanmakus == null || clickDanmakus.isEmpty()) ? false : true;
}
 
示例22
public IDanmakus getCurrentVisibleDanmakus() {
    if (this.handler != null) {
        return this.handler.getCurrentVisibleDanmakus();
    }
    return null;
}
 
示例23
@Override
protected IDanmakus parse() {
    return new Danmakus();
}
 
示例24
void onDanmakuClick(IDanmakus iDanmakus); 
示例25
IDanmakus getCurrentVisibleDanmakus(); 
示例26
IDanmakus getVisibleDanmakusOnTime(long j); 
示例27
protected abstract IDanmakus parse(); 
示例28
RenderingState draw(IDisplayer iDisplayer, IDanmakus iDanmakus, long j);