Ejemplo n.º 1
0
 private IDrawTask createDrawTask(
     boolean useDrwaingCache,
     DanmakuTimer timer,
     Context context,
     int width,
     int height,
     boolean isHardwareAccelerated,
     IDrawTask.TaskListener taskListener) {
   mDisp = mContext.getDisplayer();
   mDisp.setSize(width, height);
   DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
   mDisp.setDensities(
       displayMetrics.density, displayMetrics.densityDpi, displayMetrics.scaledDensity);
   mDisp.resetSlopPixel(mContext.scaleTextSize);
   mDisp.setHardwareAccelerated(isHardwareAccelerated);
   IDrawTask task =
       useDrwaingCache
           ? new CacheManagingDrawTask(
               timer,
               mContext,
               taskListener,
               1024 * 1024 * AndroidUtils.getMemoryClass(context) / 3)
           : new DrawTask(timer, mContext, taskListener);
   task.setParser(mParser);
   task.prepare();
   obtainMessage(NOTIFY_DISP_SIZE_CHANGED, false).sendToTarget();
   return task;
 }
Ejemplo n.º 2
0
  /** 初始化配置 */
  private void initDanmuConfig() {
    // 设置最大显示行数
    HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
    maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 2); // 滚动弹幕最大显示2行
    // 设置是否禁止重叠
    HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
    overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
    overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);

    danmukuContext = DanmakuContext.create();
    danmukuContext
        .setDanmakuStyle(IDisplayer.DANMAKU_STYLE_NONE)
        .setDuplicateMergingEnabled(false)
        .setScrollSpeedFactor(1.2f) // 越大速度越慢
        .setScaleTextSize(1.2f)
        //                .setCacheStuffer(new SimpleTextCacheStuffer(), mCacheStufferAdapter)
        .setCacheStuffer(new BackgroundCacheStuffer(), mCacheStufferAdapter)
        .setMaximumLines(maxLinesPair)
        .preventOverlapping(overlappingEnablePair);
  }