master.flame.danmaku.danmaku.util.DanmakuUtils Java Examples

The following examples show how to use master.flame.danmaku.danmaku.util.DanmakuUtils. 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: 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 #2
Source File: QSDanmakuParser.java    From QSVideoPlayer with Apache License 2.0 5 votes vote down vote up
public BaseDanmaku buildDanmaku(String text, int type, long time, float size, int color) {
    item = mContext.mDanmakuFactory.createDanmaku(type, mContext);
    item.setTime(time);
    item.setTimer(getTimer());

    DanmakuUtils.fillText(item, text);//支持换行
    item.textSize = size * density;
    item.textColor = color;
    item.textShadowColor = textShadowColor;
    item.flags = mContext.mGlobalFlagValues;
    item.index = index++;
    return item;
}
 
Example #3
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message msg) {
    switch (msg.what) {
        case 1:
            CacheManager.this.evictAllNotInScreen();
            for (int i = 0; i < 300; i++) {
                CacheManager.this.mCachePool.release(new DrawingCache());
            }
            break;
        case 2:
            addDanmakuAndBuildCache(msg.obj);
            return;
        case 3:
            removeMessages(3);
            boolean repositioned = !(CacheManagingDrawTask.this.mTaskListener == null || CacheManagingDrawTask.this.mReadyState) || this.mSeekedFlag;
            prepareCaches(repositioned);
            if (repositioned) {
                this.mSeekedFlag = false;
            }
            if (CacheManagingDrawTask.this.mTaskListener != null && !CacheManagingDrawTask.this.mReadyState) {
                CacheManagingDrawTask.this.mTaskListener.ready();
                CacheManagingDrawTask.this.mReadyState = true;
                return;
            }
            return;
        case 4:
            CacheManager.this.clearTimeOutCaches();
            return;
        case 5:
            Long seekMills = msg.obj;
            if (seekMills != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(seekMills.longValue());
                this.mSeekedFlag = true;
                CacheManager.this.evictAllNotInScreen();
                resume();
                return;
            }
            return;
        case 6:
            removeCallbacksAndMessages(null);
            this.mPause = true;
            CacheManager.this.evictAll();
            CacheManager.this.clearCachePool();
            getLooper().quit();
            return;
        case 7:
            CacheManager.this.evictAll();
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond - CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
            this.mSeekedFlag = true;
            return;
        case 8:
            CacheManager.this.evictAllNotInScreen(true);
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond);
            return;
        case 9:
            CacheManager.this.evictAllNotInScreen(true);
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond);
            CacheManagingDrawTask.this.requestClear();
            return;
        case 16:
            break;
        case 17:
            Pair<BaseDanmaku, Boolean> pair = msg.obj;
            if (pair != null) {
                BaseDanmaku cacheitem = pair.first;
                if (((Boolean) pair.second).booleanValue()) {
                    cacheitem.requestFlags |= 1;
                }
                cacheitem.requestFlags |= 2;
                if (!((Boolean) pair.second).booleanValue() && cacheitem.hasDrawingCache() && !cacheitem.cache.hasReferences()) {
                    cacheitem.cache = DanmakuUtils.buildDanmakuDrawingCache(cacheitem, CacheManagingDrawTask.this.mDisp, (DrawingCache) cacheitem.cache);
                    CacheManager.this.push(cacheitem, 0, true);
                    return;
                } else if (cacheitem.isLive) {
                    CacheManager.this.clearCache(cacheitem);
                    createCache(cacheitem);
                    return;
                } else {
                    CacheManager.this.entryRemoved(true, cacheitem, null);
                    addDanmakuAndBuildCache(cacheitem);
                    return;
                }
            }
            return;
        default:
            return;
    }
    long delayed = dispatchAction();
    if (delayed <= 0) {
        delayed = CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION / 2;
    }
    sendEmptyMessageDelayed(16, delayed);
}
 
Example #4
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
private byte buildCache(BaseDanmaku item, boolean forceInsert) {
    if (!item.isMeasured()) {
        item.measure(CacheManagingDrawTask.this.mDisp, true);
    }
    DrawingCache cache = null;
    try {
        BaseDanmaku danmaku = CacheManager.this.findReuseableCache(item, true, 20);
        if (danmaku != null) {
            cache = (DrawingCache) danmaku.cache;
        }
        if (cache != null) {
            cache.increaseReference();
            item.cache = cache;
            CacheManagingDrawTask.this.mCacheManager.push(item, 0, forceInsert);
            return (byte) 0;
        }
        danmaku = CacheManager.this.findReuseableCache(item, false, 50);
        if (danmaku != null) {
            cache = (DrawingCache) danmaku.cache;
        }
        if (cache != null) {
            danmaku.cache = null;
            item.cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, cache);
            CacheManagingDrawTask.this.mCacheManager.push(item, 0, forceInsert);
            return (byte) 0;
        }
        if (!forceInsert) {
            if (CacheManager.this.mRealSize + DanmakuUtils.getCacheSize((int) item.paintWidth, (int) item.paintHeight) > CacheManager.this.mMaxSize) {
                return (byte) 1;
            }
        }
        cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, (DrawingCache) CacheManager.this.mCachePool.acquire());
        item.cache = cache;
        boolean pushed = CacheManagingDrawTask.this.mCacheManager.push(item, CacheManager.this.sizeOf(item), forceInsert);
        if (!pushed) {
            releaseDanmakuCache(item, cache);
        }
        return pushed ? (byte) 0 : (byte) 1;
    } catch (OutOfMemoryError e) {
        releaseDanmakuCache(item, null);
        return (byte) 1;
    } catch (Exception e2) {
        releaseDanmakuCache(item, null);
        return (byte) 1;
    }
}
 
Example #5
Source File: BiliDanmukuParser.java    From letv with Apache License 2.0 4 votes vote down vote up
public void characters(char[] ch, int start, int length) {
    if (this.item != null) {
        DanmakuUtils.fillText(this.item, decodeXmlString(new String(ch, start, length)));
        BaseDanmaku baseDanmaku = this.item;
        int i = this.index;
        this.index = i + 1;
        baseDanmaku.index = i;
        String text = String.valueOf(this.item.text).trim();
        if (this.item.getType() == 7) {
            if (text.startsWith("[")) {
                if (text.endsWith("]")) {
                    int i2;
                    String[] textArr = null;
                    try {
                        JSONArray jSONArray = new JSONArray(text);
                        textArr = new String[jSONArray.length()];
                        for (i2 = 0; i2 < textArr.length; i2++) {
                            textArr[i2] = jSONArray.getString(i2);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (textArr == null || textArr.length < 5) {
                        this.item = null;
                        return;
                    }
                    this.item.text = textArr[4];
                    float beginX = Float.parseFloat(textArr[0]);
                    float beginY = Float.parseFloat(textArr[1]);
                    float endX = beginX;
                    float endY = beginY;
                    String[] alphaArr = textArr[2].split(NetworkUtils.DELIMITER_LINE);
                    int beginAlpha = (int) (((float) AlphaValue.MAX) * Float.parseFloat(alphaArr[0]));
                    int endAlpha = beginAlpha;
                    if (alphaArr.length > 1) {
                        endAlpha = (int) (((float) AlphaValue.MAX) * Float.parseFloat(alphaArr[1]));
                    }
                    long alphaDuraion = (long) (Float.parseFloat(textArr[3]) * 1000.0f);
                    long translationDuration = alphaDuraion;
                    long translationStartDelay = 0;
                    float rotateY = 0.0f;
                    float rotateZ = 0.0f;
                    if (textArr.length >= 7) {
                        rotateZ = Float.parseFloat(textArr[5]);
                        rotateY = Float.parseFloat(textArr[6]);
                    }
                    if (textArr.length >= 11) {
                        endX = Float.parseFloat(textArr[7]);
                        endY = Float.parseFloat(textArr[8]);
                        if (!"".equals(textArr[9])) {
                            translationDuration = (long) Integer.parseInt(textArr[9]);
                        }
                        if (!"".equals(textArr[10])) {
                            translationStartDelay = (long) Float.parseFloat(textArr[10]);
                        }
                    }
                    this.item.duration = new Duration(alphaDuraion);
                    this.item.rotationZ = rotateZ;
                    this.item.rotationY = rotateY;
                    BiliDanmukuParser.this.mContext.mDanmakuFactory.fillTranslationData(this.item, beginX, beginY, endX, endY, translationDuration, translationStartDelay, BiliDanmukuParser.this.mDispScaleX, BiliDanmukuParser.this.mDispScaleY);
                    BiliDanmukuParser.this.mContext.mDanmakuFactory.fillAlphaData(this.item, beginAlpha, endAlpha, alphaDuraion);
                    if (textArr.length >= 12 && !TextUtils.isEmpty(textArr[11]) && "true".equals(textArr[11])) {
                        this.item.textShadowColor = 0;
                    }
                    if (textArr.length >= 13) {
                    }
                    if (textArr.length >= 14) {
                    }
                    if (textArr.length >= 15 && !"".equals(textArr[14])) {
                        String[] pointStrArray = textArr[14].substring(1).split("L");
                        if (pointStrArray != null && pointStrArray.length > 0) {
                            float[][] points = (float[][]) Array.newInstance(Float.TYPE, new int[]{pointStrArray.length, 2});
                            for (i2 = 0; i2 < pointStrArray.length; i2++) {
                                String[] pointArray = pointStrArray[i2].split(",");
                                points[i2][0] = Float.parseFloat(pointArray[0]);
                                points[i2][1] = Float.parseFloat(pointArray[1]);
                            }
                            DanmakuFactory.fillLinePathData(this.item, points, BiliDanmukuParser.this.mDispScaleX, BiliDanmukuParser.this.mDispScaleY);
                        }
                    }
                }
            }
        }
    }
}
 
Example #6
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        float topPos = 0.0f;
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVertialEdge = false;
        boolean shown = drawItem.isShown();
        if (!shown) {
            boolean overwriteInsert;
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            BaseDanmaku insertItem = null;
            BaseDanmaku firstItem = null;
            BaseDanmaku lastItem = null;
            BaseDanmaku minRightRow = null;
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    insertItem = item;
                    lastItem = null;
                    shown = true;
                    willHit = false;
                    overwriteInsert = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                }
                if (drawItem.paintHeight + item.getTop() > ((float) disp.getHeight())) {
                    overwriteInsert = true;
                    break;
                }
                if (minRightRow == null) {
                    minRightRow = item;
                } else if (minRightRow.getRight() >= item.getRight()) {
                    minRightRow = item;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    insertItem = item;
                    overwriteInsert = false;
                    break;
                }
                lastItem = item;
            }
            overwriteInsert = false;
            boolean checkEdge = true;
            if (insertItem != null) {
                if (lastItem != null) {
                    topPos = lastItem.getBottom();
                } else {
                    topPos = insertItem.getTop();
                }
                if (insertItem != drawItem) {
                    this.mVisibleDanmakus.removeItem(insertItem);
                    shown = false;
                }
            } else if (overwriteInsert && minRightRow != null) {
                topPos = minRightRow.getTop();
                checkEdge = false;
                shown = false;
            } else if (lastItem != null) {
                topPos = lastItem.getBottom();
                willHit = false;
            } else if (firstItem != null) {
                topPos = firstItem.getTop();
                this.mVisibleDanmakus.removeItem(firstItem);
                shown = false;
            } else {
                topPos = 0.0f;
            }
            if (checkEdge) {
                isOutOfVertialEdge = isOutVerticalEdge(overwriteInsert, drawItem, disp, topPos, firstItem, lastItem);
            }
            if (isOutOfVertialEdge) {
                topPos = 0.0f;
                willHit = true;
            }
            if (topPos == 0.0f) {
                shown = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVertialEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}
 
Example #7
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        boolean shown = drawItem.isShown();
        float topPos = drawItem.getTop();
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVerticalEdge = false;
        if (topPos < 0.0f) {
            topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
        }
        BaseDanmaku removeItem = null;
        BaseDanmaku firstItem = null;
        if (!shown) {
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    removeItem = null;
                    willHit = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                    if (firstItem.getBottom() != ((float) disp.getHeight())) {
                        break;
                    }
                }
                if (topPos < 0.0f) {
                    removeItem = null;
                    break;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    removeItem = item;
                    break;
                }
                topPos = item.getTop() - drawItem.paintHeight;
            }
            isOutOfVerticalEdge = isOutVerticalEdge(false, drawItem, disp, topPos, firstItem, null);
            if (isOutOfVerticalEdge) {
                topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
                willHit = true;
            } else if (topPos >= 0.0f) {
                willHit = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVerticalEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.removeItem(removeItem);
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}
 
Example #8
Source File: Danmakus.java    From letv with Apache License 2.0 4 votes vote down vote up
public int compare(BaseDanmaku obj1, BaseDanmaku obj2) {
    if (this.mDuplicateMergingEnable && DanmakuUtils.isDuplicate(obj1, obj2)) {
        return 0;
    }
    return DanmakuUtils.compare(obj1, obj2);
}
 
Example #9
Source File: Danmakus.java    From letv with Apache License 2.0 4 votes vote down vote up
public int compare(BaseDanmaku obj1, BaseDanmaku obj2) {
    if (this.mDuplicateMergingEnable && DanmakuUtils.isDuplicate(obj1, obj2)) {
        return 0;
    }
    return Float.compare(obj1.getTop(), obj2.getTop());
}
 
Example #10
Source File: Danmakus.java    From letv with Apache License 2.0 4 votes vote down vote up
public int compare(BaseDanmaku obj1, BaseDanmaku obj2) {
    if (this.mDuplicateMergingEnable && DanmakuUtils.isDuplicate(obj1, obj2)) {
        return 0;
    }
    return Float.compare(obj2.getTop(), obj1.getTop());
}
 
Example #11
Source File: Danmaku.java    From letv with Apache License 2.0 4 votes vote down vote up
public Danmaku(CharSequence text) {
    DanmakuUtils.fillText(this, text);
}