master.flame.danmaku.danmaku.model.BaseDanmaku Java Examples

The following examples show how to use master.flame.danmaku.danmaku.model.BaseDanmaku. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameBaseActivity.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
private void addDanmaku(String content, boolean withBorder) {
    if(danmakuView == null){
        return;
    }
    BaseDanmaku danmaku = danmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    if(content.length() > 7) {
        danmaku = danmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_FIX_TOP);
    }
    danmaku.text = content;
    danmaku.padding = 5;
    danmaku.textSize = sp2px(14);
    danmaku.textColor = Color.WHITE;
    danmaku.textShadowColor = Color.BLACK;
    danmaku.setTime(danmakuView.getCurrentTime());
    if (withBorder) {
        danmaku.borderColor = Color.GREEN;
    }
    danmakuView.addDanmaku(danmaku);
}
 
Example #2
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 6 votes vote down vote up
private void applyPaintConfig(BaseDanmaku danmaku, Paint paint, boolean stroke) {
    if (this.isTranslucent) {
        if (stroke) {
            paint.setStyle(this.HAS_PROJECTION ? Style.FILL : Style.STROKE);
            paint.setColor(danmaku.textShadowColor & ViewCompat.MEASURED_SIZE_MASK);
            paint.setAlpha(this.HAS_PROJECTION ? (int) (((float) this.sProjectionAlpha) * (((float) this.transparency) / ((float) AlphaValue.MAX))) : this.transparency);
            return;
        }
        paint.setStyle(Style.FILL);
        paint.setColor(danmaku.textColor & ViewCompat.MEASURED_SIZE_MASK);
        paint.setAlpha(this.transparency);
    } else if (stroke) {
        paint.setStyle(this.HAS_PROJECTION ? Style.FILL : Style.STROKE);
        paint.setColor(danmaku.textShadowColor & ViewCompat.MEASURED_SIZE_MASK);
        paint.setAlpha(this.HAS_PROJECTION ? this.sProjectionAlpha : AlphaValue.MAX);
    } else {
        paint.setStyle(Style.FILL);
        paint.setColor(danmaku.textColor & ViewCompat.MEASURED_SIZE_MASK);
        paint.setAlpha(AlphaValue.MAX);
    }
}
 
Example #3
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 6 votes vote down vote up
private void clearTimeOutCaches(long time) {
    IDanmakuIterator it = this.mCaches.iterator();
    while (it.hasNext() && !this.mEndFlag) {
        BaseDanmaku val = it.next();
        if (val.isTimeOut()) {
            synchronized (CacheManagingDrawTask.this.mDrawingNotify) {
                try {
                    CacheManagingDrawTask.this.mDrawingNotify.wait(30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    return;
                }
            }
            entryRemoved(false, val, null);
            it.remove();
        } else {
            return;
        }
    }
}
 
Example #4
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean createCache(BaseDanmaku item) {
    if (!item.isMeasured()) {
        item.measure(CacheManagingDrawTask.this.mDisp, true);
    }
    DrawingCache cache = null;
    try {
        cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, (DrawingCache) CacheManager.this.mCachePool.acquire());
        item.cache = cache;
        return true;
    } catch (OutOfMemoryError e) {
        if (cache != null) {
            CacheManager.this.mCachePool.release(cache);
        }
        item.cache = null;
        return false;
    } catch (Exception e2) {
        if (cache != null) {
            CacheManager.this.mCachePool.release(cache);
        }
        item.cache = null;
        return false;
    }
}
 
Example #5
Source File: MainActivity.java    From QSVideoPlayer with Apache License 2.0 6 votes vote down vote up
private void addDanmaku(boolean islive) {
    BaseDanmaku danmaku = DanmakuConfig.getDefaultContext().mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    if (danmaku == null || danmakuControl == null) {
        return;
    }
    // for(int i=0;i<100;i++){
    // }
    danmaku.text = "QSVideoPlayer-" + System.nanoTime();
    danmaku.padding = 5;
    danmaku.priority = 10;  // 可能会被各种过滤器过滤并隐藏显示
    danmaku.isLive = islive;
    danmaku.setTime(demoVideoView.getPosition() + 1200);
    danmaku.textSize = 40;
    danmaku.textColor = Color.RED;
    danmaku.textShadowColor = Color.WHITE;
    // danmaku.underlineColor = Color.GREEN;
    danmaku.borderColor = Color.GREEN;
    danmakuControl.add(danmaku);

}
 
Example #6
Source File: DanmakuVideoPlayer.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 模拟添加弹幕数据
 */
private void addDanmaku(boolean islive) {
    BaseDanmaku danmaku = mDanmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    if (danmaku == null || mDanmakuView == null) {
        return;
    }
    danmaku.text = "这是一条弹幕 " + getCurrentPositionWhenPlaying();
    danmaku.padding = 5;
    danmaku.priority = 8;  // 可能会被各种过滤器过滤并隐藏显示,所以提高等级
    danmaku.isLive = islive;
    danmaku.setTime(mDanmakuView.getCurrentTime() + 500);
    danmaku.textSize = 25f * (mParser.getDisplayer().getDensity() - 0.6f);
    danmaku.textColor = Color.RED;
    danmaku.textShadowColor = Color.WHITE;
    danmaku.borderColor = Color.GREEN;
    mDanmakuView.addDanmaku(danmaku);

}
 
Example #7
Source File: DanmakuConfig.java    From QSVideoPlayer with Apache License 2.0 6 votes vote down vote up
public static DanmakuContext getDefaultContext() {
        if (danmakuContext != null)
            return danmakuContext;

        // 设置最大显示行数
        HashMap<Integer, Integer> maxLinesPair = new HashMap<>();
        maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5); // 滚动弹幕最大显示5行
        // 设置是否禁止重叠
        HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<>();
        overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
        overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);
        danmakuContext = DanmakuContext.create();
        danmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3)
                .setDuplicateMergingEnabled(false)
                .setScrollSpeedFactor(1.2f).setScaleTextSize(1.2f)
//                .setCacheStuffer(new SpannedCacheStuffer(), mCacheStufferAdapter) // 图文混排使用SpannedCacheStuffer
//        .setCacheStuffer(new BackgroundCacheStuffer())  // 绘制背景使用BackgroundCacheStuffer
                .setMaximumLines(maxLinesPair)
                .preventOverlapping(overlappingEnablePair)
                .setDanmakuMargin(40);
        return danmakuContext;
    }
 
Example #8
Source File: Danmakus.java    From letv with Apache License 2.0 6 votes vote down vote up
private Collection<BaseDanmaku> subset(long startTime, long endTime) {
    if (this.mSortType == 4 || this.items == null || this.items.size() == 0) {
        return null;
    }
    if (this.subItems == null) {
        this.subItems = new Danmakus(this.mDuplicateMergingEnabled);
    }
    if (this.startSubItem == null) {
        this.startSubItem = createItem(JarConstant.PLUGIN_WINDOW_PLAYER_STATIC_METHOD_NAME_START);
    }
    if (this.endSubItem == null) {
        this.endSubItem = createItem("end");
    }
    this.startSubItem.time = startTime;
    this.endSubItem.time = endTime;
    return ((SortedSet) this.items).subSet(this.startSubItem, this.endSubItem);
}
 
Example #9
Source File: DanmakuFilters.java    From letv with Apache License 2.0 6 votes vote down vote up
private boolean needFilter(BaseDanmaku danmaku, int orderInScreen, int totalSizeInScreen, DanmakuTimer timer, boolean fromCachingTask, DanmakuContext context) {
    Log.v("XX", "QuantityDanmakuFilter needFilter mMaximumSize : " + this.mMaximumSize + " totalSizeInScreen : " + totalSizeInScreen + " orderInScreen : " + orderInScreen + " danmaku.isTimeOut() " + danmaku.isTimeOut() + " mMaximumSize : " + this.mMaximumSize + " isShown :" + danmaku.isShown());
    if (this.mMaximumSize == 0) {
        return true;
    }
    if (totalSizeInScreen < this.mMaximumSize || (this.mLastSkipped != null && danmaku.time - this.mLastSkipped.time > context.mDanmakuFactory.MAX_DANMAKU_DURATION / 4)) {
        Log.v("xx", " QuantityDanmakuFilter not guolv2222 >>>>>>>>");
        this.mLastSkipped = danmaku;
        return false;
    } else if (orderInScreen <= this.mMaximumSize || danmaku.isTimeOut()) {
        this.mLastSkipped = danmaku;
        Log.v("xx", " QuantityDanmakuFilter not guolv11111 >>>>>>>>");
        return false;
    } else {
        Log.v("xx", " QuantityDanmakuFilter guolv >>>>>>>>");
        return true;
    }
}
 
Example #10
Source File: SimpleTextCacheStuffer.java    From letv with Apache License 2.0 6 votes vote down vote up
public void measure(BaseDanmaku danmaku, TextPaint paint, boolean fromWorkerThread) {
    if (this.mProxy != null) {
        this.mProxy.prepareDrawing(danmaku, fromWorkerThread);
    }
    float w = 0.0f;
    Float textHeight = Float.valueOf(0.0f);
    if (danmaku.lines == null) {
        if (danmaku.text == null) {
            w = 0.0f;
        } else {
            w = paint.measureText(danmaku.text.toString());
            textHeight = getCacheHeight(danmaku, paint);
        }
        danmaku.paintWidth = w;
        danmaku.paintHeight = textHeight.floatValue();
        return;
    }
    textHeight = getCacheHeight(danmaku, paint);
    for (String tempStr : danmaku.lines) {
        if (tempStr.length() > 0) {
            w = Math.max(paint.measureText(tempStr), w);
        }
    }
    danmaku.paintWidth = w;
    danmaku.paintHeight = ((float) danmaku.lines.length) * textHeight.floatValue();
}
 
Example #11
Source File: DanmakuFilters.java    From letv with Apache License 2.0 6 votes vote down vote up
public synchronized boolean needFilter(BaseDanmaku danmaku, int index, int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
    boolean z = true;
    synchronized (this) {
        removeTimeoutDanmakus(this.blockedDanmakus, 2);
        removeTimeoutDanmakus(this.passedDanmakus, 2);
        removeTimeoutDanmakus(this.currentDanmakus, 3);
        if (!this.blockedDanmakus.contains(danmaku) || danmaku.isOutside()) {
            if (this.passedDanmakus.contains(danmaku)) {
                z = false;
            } else if (this.currentDanmakus.containsKey(danmaku.text)) {
                this.currentDanmakus.put(String.valueOf(danmaku.text), danmaku);
                this.blockedDanmakus.removeItem(danmaku);
                this.blockedDanmakus.addItem(danmaku);
            } else {
                this.currentDanmakus.put(String.valueOf(danmaku.text), danmaku);
                this.passedDanmakus.addItem(danmaku);
                z = false;
            }
        }
    }
    return z;
}
 
Example #12
Source File: DanmakuFilters.java    From letv with Apache License 2.0 6 votes vote down vote up
private void removeTimeoutDanmakus(LinkedHashMap<String, BaseDanmaku> danmakus, int limitTime) {
    Iterator<Entry<String, BaseDanmaku>> it = danmakus.entrySet().iterator();
    long startTime = SystemClock.uptimeMillis();
    while (it.hasNext()) {
        try {
            if (((BaseDanmaku) ((Entry) it.next()).getValue()).isTimeOut()) {
                it.remove();
                if (SystemClock.uptimeMillis() - startTime > ((long) limitTime)) {
                    return;
                }
            }
            return;
        } catch (Exception e) {
            return;
        }
    }
}
 
Example #13
Source File: DanmakuTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #14
Source File: Danmakus.java    From letv with Apache License 2.0 5 votes vote down vote up
public BaseDanmaku first() {
    if (this.items == null || this.items.isEmpty()) {
        return null;
    }
    if (this.mSortType == 4) {
        return (BaseDanmaku) ((ArrayList) this.items).get(0);
    }
    return (BaseDanmaku) ((SortedSet) this.items).first();
}
 
Example #15
Source File: Danmakus.java    From letv with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #16
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 5 votes vote down vote up
private void setDanmakuPaintWidthAndHeight(BaseDanmaku danmaku, float w, float h) {
    float pw = w + ((float) (danmaku.padding * 2));
    float ph = h + ((float) (danmaku.padding * 2));
    if (danmaku.borderColor != 0) {
        pw += 8.0f;
        ph += 8.0f;
    }
    danmaku.paintWidth = getStrokeWidth() + pw;
    danmaku.paintHeight = ph;
}
 
Example #17
Source File: DanmakuFilters.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask, DanmakuContext config) {
    boolean filtered = danmaku != null && this.mBlackList.contains(danmaku.userHash);
    if (filtered) {
        danmaku.mFilterParam |= 32;
    }
    return filtered;
}
 
Example #18
Source File: Danmakus.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean addItem(BaseDanmaku item) {
    if (this.items != null) {
        try {
            if (this.items.add(item)) {
                this.mSize++;
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
Example #19
Source File: DanmakuFilters.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean filterSecondary(BaseDanmaku danmaku, int lines, int totalsizeInScreen, DanmakuTimer timer, boolean willHit, DanmakuContext context) {
    for (IDanmakuFilter<?> f : this.mFilterArraySecondary) {
        if (f != null) {
            boolean filtered = f.filter(danmaku, lines, totalsizeInScreen, timer, willHit, context);
            danmaku.filterResetFlag = context.mGlobalFlagValues.FILTER_RESET_FLAG;
            if (filtered) {
                return true;
            }
        }
    }
    return false;
}
 
Example #20
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
private long clearCache(BaseDanmaku oldValue) {
    if (oldValue.cache.hasReferences()) {
        oldValue.cache.decreaseReference();
        oldValue.cache = null;
        return 0;
    }
    long size = (long) sizeOf(oldValue);
    oldValue.cache.destroy();
    oldValue.cache = null;
    return size;
}
 
Example #21
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public void invalidateDanmaku(BaseDanmaku item, boolean remeasure) {
    if (this.mCacheManager == null) {
        super.invalidateDanmaku(item, remeasure);
    } else {
        this.mCacheManager.invalidateDanmaku(item, remeasure);
    }
}
 
Example #22
Source File: DanmakuUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static DrawingCache buildDanmakuDrawingCache(BaseDanmaku danmaku, IDisplayer disp, DrawingCache cache) {
    if (cache == null) {
        cache = new DrawingCache();
    }
    cache.build((int) Math.ceil((double) danmaku.paintWidth), (int) Math.ceil((double) danmaku.paintHeight), disp.getDensityDpi(), false);
    DrawingCacheHolder holder = cache.get();
    if (holder != null) {
        ((AbsDisplayer) disp).drawDanmaku(danmaku, holder.canvas, 0.0f, 0.0f, true);
        if (disp.isHardwareAccelerated()) {
            holder.splitWith(disp.getWidth(), disp.getHeight(), disp.getMaximumCacheWidth(), disp.getMaximumCacheHeight());
        }
    }
    return cache;
}
 
Example #23
Source File: Danmakus.java    From letv with Apache License 2.0 5 votes vote down vote up
public BaseDanmaku last() {
    if (this.items == null || this.items.isEmpty()) {
        return null;
    }
    if (this.mSortType == 4) {
        return (BaseDanmaku) ((ArrayList) this.items).get(this.items.size() - 1);
    }
    return (BaseDanmaku) ((SortedSet) this.items).last();
}
 
Example #24
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 5 votes vote down vote up
private void applyTextScaleConfig(BaseDanmaku danmaku, Paint paint) {
    if (this.isTextScaled) {
        Float size = (Float) this.sCachedScaleSize.get(Float.valueOf(danmaku.textSize));
        if (size == null || this.sLastScaleTextSize != this.scaleTextSize) {
            this.sLastScaleTextSize = this.scaleTextSize;
            size = Float.valueOf(danmaku.textSize * this.scaleTextSize);
            this.sCachedScaleSize.put(Float.valueOf(danmaku.textSize), size);
        }
        paint.setTextSize(size.floatValue());
    }
}
 
Example #25
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public synchronized void removeAllLiveDanmakus() {
    if (!(this.danmakus == null || this.danmakus.isEmpty())) {
        synchronized (this.danmakus) {
            IDanmakuIterator it = this.danmakus.iterator();
            while (it.hasNext()) {
                BaseDanmaku danmaku = it.next();
                if (danmaku.isLive) {
                    it.remove();
                    onDanmakuRemoved(danmaku);
                }
            }
        }
    }
}
 
Example #26
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public void invalidateDanmaku(BaseDanmaku item, boolean remeasure) {
    this.mContext.getDisplayer().getCacheStuffer().clearCache(item);
    if (remeasure) {
        item.paintWidth = -1.0f;
        item.paintHeight = -1.0f;
    }
}
 
Example #28
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public synchronized void addDanmaku(BaseDanmaku item) {
    if (this.danmakuList != null) {
        boolean added;
        if (item.isLive) {
            removeUnusedLiveDanmakusIn(10);
        }
        item.index = this.danmakuList.size();
        if (this.mLastBeginMills <= item.time && item.time <= this.mLastEndMills) {
            synchronized (this.danmakus) {
                added = this.danmakus.addItem(item);
            }
        } else if (item.isLive) {
            this.mLastEndMills = 0;
            this.mLastBeginMills = 0;
        }
        synchronized (this.danmakuList) {
            added = this.danmakuList.addItem(item);
        }
        if (added) {
            if (this.mTaskListener != null) {
                this.mTaskListener.onDanmakuAdd(item);
            }
        }
        if (this.mLastDanmaku == null || !(item == null || this.mLastDanmaku == null || item.time <= this.mLastDanmaku.time)) {
            this.mLastDanmaku = item;
        }
    }
}
 
Example #29
Source File: SimpleTextCacheStuffer.java    From letv with Apache License 2.0 5 votes vote down vote up
public void drawText(BaseDanmaku danmaku, String lineText, Canvas canvas, float left, float top, TextPaint paint, boolean fromWorkerThread) {
    if (lineText != null) {
        canvas.drawText(lineText, left, top, paint);
    } else {
        canvas.drawText(danmaku.text.toString(), left, top, paint);
    }
}
 
Example #30
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public DrawTask(DanmakuTimer timer, DanmakuContext context, TaskListener taskListener) {
    boolean z = false;
    if (context == null) {
        throw new IllegalArgumentException("context is null");
    }
    this.mContext = context;
    this.mDisp = context.getDisplayer();
    this.mTaskListener = taskListener;
    this.mRenderer = new DanmakuRenderer(context);
    this.mRenderer.setOnDanmakuShownListener(new OnDanmakuShownListener() {
        public void onDanmakuShown(BaseDanmaku danmaku) {
            if (DrawTask.this.mTaskListener != null) {
                DrawTask.this.mTaskListener.onDanmakuShown(danmaku);
            }
        }
    });
    IRenderer iRenderer = this.mRenderer;
    if (this.mContext.isPreventOverlappingEnabled() || this.mContext.isMaxLinesLimited()) {
        z = true;
    }
    iRenderer.setVerifierEnabled(z);
    initTimer(timer);
    Boolean enable = Boolean.valueOf(this.mContext.isDuplicateMergingEnabled());
    if (enable == null) {
        return;
    }
    if (enable.booleanValue()) {
        this.mContext.mDanmakuFilters.registerFilter(DanmakuFilters.TAG_DUPLICATE_FILTER);
    } else {
        this.mContext.mDanmakuFilters.unregisterFilter(DanmakuFilters.TAG_DUPLICATE_FILTER);
    }
}