├── .gitmodules ├── settings.gradle ├── DanmakuFlameMaster ├── src │ ├── main │ │ ├── lint.xml │ │ ├── libs │ │ │ ├── mips │ │ │ │ └── libndkbitmap.so │ │ │ ├── x86 │ │ │ │ └── libndkbitmap.so │ │ │ ├── armeabi │ │ │ │ └── libndkbitmap.so │ │ │ └── armeabi-v7a │ │ │ │ └── libndkbitmap.so │ │ ├── java │ │ │ ├── master │ │ │ │ └── flame │ │ │ │ │ └── danmaku │ │ │ │ │ ├── danmaku │ │ │ │ │ ├── model │ │ │ │ │ │ ├── AlphaValue.java │ │ │ │ │ │ ├── IDanmakuIterator.java │ │ │ │ │ │ ├── android │ │ │ │ │ │ │ ├── DrawingCachePoolManager.java │ │ │ │ │ │ │ ├── BaseCacheStuffer.java │ │ │ │ │ │ │ ├── DrawingCache.java │ │ │ │ │ │ │ ├── SimpleTextCacheStuffer.java │ │ │ │ │ │ │ ├── SpannedCacheStuffer.java │ │ │ │ │ │ │ └── DrawingCacheHolder.java │ │ │ │ │ │ ├── IDrawingCache.java │ │ │ │ │ │ ├── GlobalFlagValues.java │ │ │ │ │ │ ├── Duration.java │ │ │ │ │ │ ├── objectpool │ │ │ │ │ │ │ ├── Pool.java │ │ │ │ │ │ │ ├── PoolableManager.java │ │ │ │ │ │ │ ├── Poolable.java │ │ │ │ │ │ │ ├── SynchronizedPool.java │ │ │ │ │ │ │ ├── Pools.java │ │ │ │ │ │ │ └── FinitePool.java │ │ │ │ │ │ ├── ICacheManager.java │ │ │ │ │ │ ├── AbsDisplayer.java │ │ │ │ │ │ ├── FBDanmaku.java │ │ │ │ │ │ ├── DanmakuTimer.java │ │ │ │ │ │ ├── IDanmakus.java │ │ │ │ │ │ ├── Danmaku.java │ │ │ │ │ │ ├── IDisplayer.java │ │ │ │ │ │ ├── L2RDanmaku.java │ │ │ │ │ │ ├── FTDanmaku.java │ │ │ │ │ │ ├── R2LDanmaku.java │ │ │ │ │ │ ├── BaseDanmaku.java │ │ │ │ │ │ └── SpecialDanmaku.java │ │ │ │ │ ├── util │ │ │ │ │ │ ├── AndroidUtils.java │ │ │ │ │ │ ├── IOUtils.java │ │ │ │ │ │ └── DanmakuUtils.java │ │ │ │ │ ├── loader │ │ │ │ │ │ ├── IllegalDataException.java │ │ │ │ │ │ ├── ILoader.java │ │ │ │ │ │ └── android │ │ │ │ │ │ │ ├── DanmakuLoaderFactory.java │ │ │ │ │ │ │ ├── AcFunDanmakuLoader.java │ │ │ │ │ │ │ └── BiliDanmakuLoader.java │ │ │ │ │ ├── renderer │ │ │ │ │ │ ├── Renderer.java │ │ │ │ │ │ ├── IRenderer.java │ │ │ │ │ │ └── android │ │ │ │ │ │ │ └── DanmakuRenderer.java │ │ │ │ │ └── parser │ │ │ │ │ │ ├── IDataSource.java │ │ │ │ │ │ ├── android │ │ │ │ │ │ ├── JSONSource.java │ │ │ │ │ │ ├── AndroidFileSource.java │ │ │ │ │ │ ├── AcFunDanmakuParser.java │ │ │ │ │ │ └── BiliDanmukuParser.java │ │ │ │ │ │ └── BaseDanmakuParser.java │ │ │ │ │ ├── controller │ │ │ │ │ ├── UpdateThread.java │ │ │ │ │ ├── IDanmakuViewController.java │ │ │ │ │ ├── IDrawTask.java │ │ │ │ │ ├── DrawHelper.java │ │ │ │ │ └── IDanmakuView.java │ │ │ │ │ └── ui │ │ │ │ │ └── widget │ │ │ │ │ └── DanmakuTouchHelper.java │ │ │ └── tv │ │ │ │ └── cjump │ │ │ │ └── jni │ │ │ │ ├── DeviceUtils.java │ │ │ │ └── NativeBitmapFactory.java │ │ ├── .settings │ │ │ └── org.eclipse.jdt.ui.prefs │ │ ├── .classpath │ │ ├── project.properties │ │ ├── proguard-project.txt │ │ ├── .project │ │ ├── AndroidManifest.xml │ │ └── build.xml │ └── androidTest │ │ └── java │ │ └── tv │ │ └── cjump │ │ └── jni │ │ └── NativeBitmapFactoryTest.java ├── gradle.properties └── build.gradle ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle-bintray-upload.gradle └── gradle-mvn-push.gradle ├── Sample ├── src │ └── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── dimens.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ ├── menu │ │ │ └── main.xml │ │ └── layout │ │ │ ├── activity_main.xml │ │ │ └── media_controller.xml │ │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ │ ├── .classpath │ │ ├── project.properties │ │ ├── .project │ │ └── AndroidManifest.xml └── build.gradle ├── .gitignore ├── gradle.properties ├── .travis.yml ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /.gitmodules: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':DanmakuFlameMaster', ':Sample' 2 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Sample/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/Sample/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /DanmakuFlameMaster/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=DanmakuFlameMaster 2 | BINTRAY_POM_NAME=dfm 3 | POM_ARTIFACT_ID=dfm 4 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /Sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/Sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/Sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/Sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/Sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/libs/mips/libndkbitmap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/DanmakuFlameMaster/src/main/libs/mips/libndkbitmap.so -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/libs/x86/libndkbitmap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/DanmakuFlameMaster/src/main/libs/x86/libndkbitmap.so -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/libs/armeabi/libndkbitmap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/DanmakuFlameMaster/src/main/libs/armeabi/libndkbitmap.so -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/libs/armeabi-v7a/libndkbitmap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctiao/DanmakuFlameMaster/HEAD/DanmakuFlameMaster/src/main/libs/armeabi-v7a/libndkbitmap.so -------------------------------------------------------------------------------- /Sample/src/main/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0dp 4 | 0dp 5 | 6 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/AlphaValue.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.model; 3 | 4 | public class AlphaValue { 5 | 6 | public static int MAX = 255; 7 | 8 | public static int TRANSPARENT = 0; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Sample/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | #Sat Feb 01 20:41:29 CET 2014 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip 8 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/IDanmakuIterator.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.model; 2 | 3 | public interface IDanmakuIterator { 4 | 5 | public BaseDanmaku next(); 6 | 7 | public boolean hasNext(); 8 | 9 | public void reset(); 10 | 11 | public void remove(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatter_profile=_AndroidCodeStyle 3 | formatter_settings_version=12 4 | org.eclipse.jdt.ui.ignorelowercasenames=true 5 | org.eclipse.jdt.ui.importorder=android;com;dalvik;gov;junit;libcore;net;org;java;javax; 6 | org.eclipse.jdt.ui.ondemandthreshold=99 7 | org.eclipse.jdt.ui.staticondemandthreshold=99 8 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/util/AndroidUtils.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.util; 3 | 4 | import android.app.ActivityManager; 5 | import android.content.Context; 6 | 7 | public class AndroidUtils { 8 | 9 | public static int getMemoryClass(final Context context) { 10 | return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) 11 | .getMemoryClass(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | *.com 5 | *.class 6 | *.dll 7 | *.exe 8 | *.o 9 | 10 | # files for the dex VM 11 | *.dex 12 | 13 | # Java class files 14 | *.class 15 | 16 | # generated files 17 | bin/ 18 | gen/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Intellij project files 27 | *.iml 28 | *.ipr 29 | *.iws 30 | .idea/ 31 | .DS_Store 32 | .idea/ 33 | .gradle 34 | build/ 35 | *.iml 36 | out/ -------------------------------------------------------------------------------- /Sample/src/main/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/UpdateThread.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.controller; 3 | 4 | public class UpdateThread extends Thread { 5 | 6 | public UpdateThread(String name) { 7 | super(name); 8 | } 9 | 10 | volatile boolean mIsQuited; 11 | 12 | public void quit() { 13 | mIsQuited = true; 14 | } 15 | 16 | public boolean isQuited() { 17 | return mIsQuited; 18 | } 19 | 20 | @Override 21 | public void run() { 22 | if (mIsQuited) 23 | return; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/DrawingCachePoolManager.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.model.android; 3 | 4 | import master.flame.danmaku.danmaku.model.objectpool.PoolableManager; 5 | 6 | public class DrawingCachePoolManager implements PoolableManager { 7 | 8 | @Override 9 | public DrawingCache newInstance() { 10 | return null; 11 | } 12 | 13 | @Override 14 | public void onAcquired(DrawingCache element) { 15 | 16 | } 17 | 18 | @Override 19 | public void onReleased(DrawingCache element) { 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/IDanmakuViewController.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.controller; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * For internal control. DO NOT ACCESS this interface. 7 | */ 8 | public interface IDanmakuViewController { 9 | 10 | public boolean isViewReady(); 11 | 12 | public int getWidth(); 13 | 14 | public int getHeight(); 15 | 16 | public Context getContext(); 17 | 18 | public long drawDanmakus(); 19 | 20 | public void clear(); 21 | 22 | public boolean isHardwareAccelerated(); 23 | 24 | public boolean isDanmakuDrawingCacheEnabled(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/IDrawingCache.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.model; 3 | 4 | public interface IDrawingCache { 5 | 6 | public void build(int w, int h, int density, boolean checkSizeEquals); 7 | 8 | public void erase(); 9 | 10 | public T get(); 11 | 12 | public void destroy(); 13 | 14 | public int size(); 15 | 16 | public int width(); 17 | 18 | public int height(); 19 | 20 | public boolean hasReferences(); 21 | 22 | public void increaseReference(); 23 | 24 | public void decreaseReference(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | source.dir=java 17 | -------------------------------------------------------------------------------- /Sample/src/main/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | android.library.reference.1=../../../DanmakuFlameMaster/src/main 16 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/GlobalFlagValues.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.model; 2 | 3 | public class GlobalFlagValues { 4 | 5 | public int MEASURE_RESET_FLAG = 0; 6 | public int VISIBLE_RESET_FLAG = 0; 7 | public int FILTER_RESET_FLAG = 0; 8 | 9 | public void resetAll() { 10 | VISIBLE_RESET_FLAG = 0; 11 | MEASURE_RESET_FLAG = 0; 12 | FILTER_RESET_FLAG = 0; 13 | } 14 | 15 | public void updateVisibleFlag() { 16 | VISIBLE_RESET_FLAG++; 17 | } 18 | 19 | public void updateMeasureFlag() { 20 | MEASURE_RESET_FLAG++; 21 | } 22 | 23 | public void updateFilterFlag() { 24 | FILTER_RESET_FLAG++; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_CODE=3900 2 | VERSION_NAME=0.3.9 3 | GROUP=com.github.ctiao 4 | POM_NAME=dfm 5 | POM_ARTIFACT_ID=common 6 | POM_PACKAGING=aar 7 | 8 | POM_DESCRIPTION=A Danmaku render library. 9 | POM_URL=https://github.com/ctiao/DanmakuFlameMaster 10 | POM_SCM_URL=https://github.com/ctiao/DanmakuFlameMaster 11 | POM_SCM_CONNECTION=scm:git:git://github.com/ctiao/DanmakuFlameMaster.git 12 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/ctiao/DanmakuFlameMaster.git 13 | 14 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 15 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 16 | POM_LICENCE_DIST=repo 17 | 18 | POM_DEVELOPER_ID=calmer91 19 | POM_DEVELOPER_NAME=Chen Hui 20 | POM_DEVELOPER_EMAIL=calmer91@gmail.com -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk7 3 | env: 4 | matrix: 5 | - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a 6 | 7 | android: 8 | components: 9 | - build-tools-19.1.0 10 | 11 | before_script: 12 | # Create and start emulator 13 | - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI 14 | - emulator -avd test -no-skin -no-audio -no-window & 15 | - adb wait-for-device 16 | - adb shell input keyevent 82 & 17 | 18 | script: 19 | "./gradlew check -i" 20 | 21 | after_failure: 22 | - cat /home/travis/build/Bilibili/DanmakuFlameMaster/DanmakuFlameMaster/build/outputs/lint-results.html 23 | - cat /home/travis/build/Bilibili/DanmakuFlameMaster/DanmakuFlameMaster/build/outputs/lint-results.xml 24 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/loader/IllegalDataException.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.loader; 2 | /** 3 | * Thrown when data is loading which can not be reasonably deal with. 4 | * @author yrom 5 | * 6 | */ 7 | public class IllegalDataException extends Exception { 8 | 9 | private static final long serialVersionUID = 10441759254L; 10 | 11 | public IllegalDataException() { 12 | super(); 13 | } 14 | 15 | public IllegalDataException(String detailMessage, Throwable throwable) { 16 | super(detailMessage, throwable); 17 | } 18 | 19 | public IllegalDataException(String detailMessage) { 20 | super(detailMessage); 21 | } 22 | 23 | public IllegalDataException(Throwable throwable) { 24 | super(throwable); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/Duration.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.model; 3 | 4 | public class Duration { 5 | 6 | private long mInitialDuration; 7 | 8 | private float factor = 1.0f; 9 | 10 | public long value; 11 | 12 | public Duration(long initialDuration) { 13 | mInitialDuration = initialDuration; 14 | value = initialDuration; 15 | } 16 | 17 | public void setValue(long initialDuration) { 18 | mInitialDuration = initialDuration; 19 | value = (long) (mInitialDuration * factor); 20 | } 21 | 22 | public void setFactor(float f) { 23 | if (factor != f) { 24 | factor = f; 25 | value = (long) (mInitialDuration * f); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Danmaku Flame Master 5 | 6 | Settings 7 | 8 | 9 | hide 10 | show 11 | pause 12 | resume 13 | 发送一条(纯文字) 14 | 发送一条(图文) 15 | 定时发送 16 | 取消定时 17 | 18 | release 19 | 旋转屏幕 20 | 21 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/renderer/Renderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.renderer; 18 | 19 | public abstract class Renderer implements IRenderer { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/Pool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | public interface Pool> { 20 | T acquire(); 21 | 22 | void release(T element); 23 | } 24 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/ICacheManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | /** 20 | * Created by ch on 15-11-15. 21 | */ 22 | public interface ICacheManager { 23 | void addDanmaku(BaseDanmaku danmaku); 24 | } 25 | -------------------------------------------------------------------------------- /Sample/src/main/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sample 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/PoolableManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | public interface PoolableManager> { 20 | T newInstance(); 21 | 22 | void onAcquired(T element); 23 | 24 | void onReleased(T element); 25 | } 26 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DanmakuFlameMaster 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/Poolable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | public interface Poolable { 20 | void setNextPoolable(T element); 21 | 22 | T getNextPoolable(); 23 | 24 | boolean isPooled(); 25 | 26 | void setPooled(boolean isPooled); 27 | } 28 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/parser/IDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.parser; 18 | 19 | public interface IDataSource { 20 | String SCHEME_HTTP_TAG = "http"; 21 | String SCHEME_HTTPS_TAG = "https"; 22 | String SCHEME_FILE_TAG = "file"; 23 | 24 | public T data(); 25 | 26 | public void release(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/AbsDisplayer.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.model; 2 | 3 | import master.flame.danmaku.danmaku.model.android.BaseCacheStuffer; 4 | 5 | public abstract class AbsDisplayer implements IDisplayer { 6 | 7 | public abstract T getExtraData(); 8 | 9 | public abstract void setExtraData(T data); 10 | 11 | @Override 12 | public boolean isHardwareAccelerated() { 13 | return false; 14 | } 15 | 16 | public abstract void drawDanmaku(BaseDanmaku danmaku, T canvas, float left, float top, boolean quickly); 17 | 18 | public abstract void clearTextHeightCache(); 19 | 20 | public abstract void setTypeFace(F font); 21 | 22 | public abstract void setFakeBoldText(boolean bold); 23 | 24 | public abstract void setTransparency(int newTransparency); 25 | 26 | public abstract void setScaleTextSizeFactor(float factor); 27 | 28 | public abstract void setCacheStuffer(BaseCacheStuffer cacheStuffer); 29 | 30 | public abstract BaseCacheStuffer getCacheStuffer(); 31 | } 32 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/FBDanmaku.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | public class FBDanmaku extends FTDanmaku { 20 | 21 | public FBDanmaku(Duration duration) { 22 | super(duration); 23 | } 24 | 25 | @Override 26 | public int getType() { 27 | return TYPE_FIX_BOTTOM; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | 19 | dependencies { 20 | compile project(':DanmakuFlameMaster') 21 | } 22 | android { 23 | compileSdkVersion 19 24 | buildToolsVersion "19.1.0" 25 | 26 | defaultConfig { 27 | minSdkVersion 7 28 | targetSdkVersion 19 29 | versionCode 1 30 | versionName "1.0" 31 | } 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_7 34 | targetCompatibility JavaVersion.VERSION_1_7 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/DanmakuTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | public class DanmakuTimer { 20 | public long currMillisecond; 21 | 22 | private long lastInterval; 23 | 24 | public long update(long curr) { 25 | lastInterval = curr - currMillisecond; 26 | currMillisecond = curr; 27 | return lastInterval; 28 | } 29 | 30 | public long add(long mills) { 31 | return update(currMillisecond + mills); 32 | } 33 | 34 | public long lastInterval() { 35 | return lastInterval; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/loader/ILoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.loader; 18 | 19 | import java.io.InputStream; 20 | 21 | import master.flame.danmaku.danmaku.parser.IDataSource; 22 | 23 | public interface ILoader { 24 | /** 25 | * @return data source 26 | */ 27 | IDataSource getDataSource(); 28 | /** 29 | * @param uri 弹幕文件地址(http:// file://) 30 | */ 31 | void load(String uri) throws IllegalDataException; 32 | /** 33 | * 34 | * @param in stream from Internet or local file 35 | */ 36 | void load(InputStream in) throws IllegalDataException; 37 | } 38 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/loader/android/DanmakuLoaderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.loader.android; 18 | 19 | import master.flame.danmaku.danmaku.loader.ILoader; 20 | 21 | public class DanmakuLoaderFactory { 22 | 23 | public static String TAG_BILI = "bili"; 24 | public static String TAG_ACFUN = "acfun"; 25 | 26 | public static ILoader create(String tag) { 27 | if (TAG_BILI.equalsIgnoreCase(tag)) { 28 | return BiliDanmakuLoader.instance(); 29 | } else if(TAG_ACFUN.equalsIgnoreCase(tag)) 30 | return AcFunDanmakuLoader.instance(); 31 | return null; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.OutputStream; 7 | 8 | /** 9 | * Created by MoiTempete. 10 | */ 11 | public class IOUtils { 12 | public static String getString(InputStream in){ 13 | byte[] data = getBytes(in); 14 | return data == null? null:new String(data); 15 | } 16 | public static byte[] getBytes(InputStream in){ 17 | 18 | try { 19 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 20 | byte[] buffer = new byte[8192]; 21 | int len = 0; 22 | while ((len = in.read(buffer)) != -1) 23 | baos.write(buffer, 0, len); 24 | in.close(); 25 | return baos.toByteArray(); 26 | } catch (IOException e) { 27 | return null; 28 | } 29 | } 30 | public static void closeQuietly(InputStream in){ 31 | try { 32 | if(in != null) 33 | in.close(); 34 | } catch (IOException ignore) {} 35 | } 36 | public static void closeQuietly(OutputStream out){ 37 | try { 38 | if(out != null) 39 | out.close(); 40 | } catch (IOException ignore) {} 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/SynchronizedPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | class SynchronizedPool> implements Pool { 20 | private final Pool mPool; 21 | 22 | private final Object mLock; 23 | 24 | public SynchronizedPool(Pool pool) { 25 | mPool = pool; 26 | mLock = this; 27 | } 28 | 29 | public SynchronizedPool(Pool pool, Object lock) { 30 | mPool = pool; 31 | mLock = lock; 32 | } 33 | 34 | public T acquire() { 35 | synchronized (mLock) { 36 | return mPool.acquire(); 37 | } 38 | } 39 | 40 | public void release(T element) { 41 | synchronized (mLock) { 42 | mPool.release(element); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/IDanmakus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | public interface IDanmakus { 20 | 21 | public boolean addItem(BaseDanmaku item); 22 | 23 | public boolean removeItem(BaseDanmaku item); 24 | 25 | public IDanmakus subnew(long startTime, long endTime); 26 | 27 | public IDanmakus sub(long startTime, long endTime); 28 | 29 | public int size(); 30 | 31 | public void clear(); 32 | 33 | public BaseDanmaku first(); 34 | 35 | public BaseDanmaku last(); 36 | 37 | public IDanmakuIterator iterator(); 38 | 39 | public boolean contains(BaseDanmaku item); 40 | 41 | public boolean isEmpty(); 42 | 43 | public void setSubItemsDuplicateMergingEnabled(boolean enable); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/loader/android/AcFunDanmakuLoader.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.loader.android; 2 | 3 | import java.io.InputStream; 4 | 5 | import master.flame.danmaku.danmaku.loader.ILoader; 6 | import master.flame.danmaku.danmaku.loader.IllegalDataException; 7 | import master.flame.danmaku.danmaku.parser.android.JSONSource; 8 | import android.net.Uri; 9 | /** 10 | * Ac danmaku loader 11 | * @author yrom 12 | * 13 | */ 14 | public class AcFunDanmakuLoader implements ILoader{ 15 | private AcFunDanmakuLoader(){} 16 | private static volatile AcFunDanmakuLoader instance; 17 | private JSONSource dataSource; 18 | 19 | public static ILoader instance() { 20 | if(instance == null){ 21 | synchronized (AcFunDanmakuLoader.class){ 22 | if(instance == null) 23 | instance = new AcFunDanmakuLoader(); 24 | } 25 | } 26 | return instance; 27 | } 28 | 29 | @Override 30 | public JSONSource getDataSource() { 31 | return dataSource; 32 | } 33 | 34 | @Override 35 | public void load(String uri) throws IllegalDataException { 36 | try { 37 | dataSource = new JSONSource(Uri.parse(uri)); 38 | } catch (Exception e) { 39 | throw new IllegalDataException(e); 40 | } 41 | } 42 | 43 | @Override 44 | public void load(InputStream in) throws IllegalDataException { 45 | try { 46 | dataSource = new JSONSource(in); 47 | } catch (Exception e) { 48 | throw new IllegalDataException(e); 49 | } 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/Pools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | public class Pools { 20 | private Pools() { 21 | } 22 | 23 | public static > Pool simplePool(PoolableManager manager) { 24 | return new FinitePool(manager); 25 | } 26 | 27 | public static > Pool finitePool(PoolableManager manager, int limit) { 28 | return new FinitePool(manager, limit); 29 | } 30 | 31 | public static > Pool synchronizedPool(Pool pool) { 32 | return new SynchronizedPool(pool); 33 | } 34 | 35 | public static > Pool synchronizedPool(Pool pool, Object lock) { 36 | return new SynchronizedPool(pool, lock); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DanmakuFlameMaster 2 | ================== 3 | 4 | android上开源弹幕解析绘制引擎项目。[![Build Status](https://travis-ci.org/Bilibili/DanmakuFlameMaster.png?branch=master)](https://travis-ci.org/Bilibili/DanmakuFlameMaster) 5 | 6 | ### DFM Inside: 7 | [![bili](https://raw.github.com/ctiao/ctiao.github.io/master/images/apps/bili.png?raw=true)](https://play.google.com/store/apps/details?id=tv.danmaku.bili) 8 | 9 | - libndkbitmap.so(ndk)源码:https://github.com/Bilibili/NativeBitmapFactory 10 | - 开发交流群:314468823 (加入请注明DFM开发交流) 11 | 12 | ### Features 13 | 14 | - 使用多种方式(View/SurfaceView/TextureView)实现高效绘制 15 | 16 | - B站xml弹幕格式解析 17 | 18 | - 基础弹幕精确还原绘制 19 | 20 | - 支持mode7特殊弹幕 21 | 22 | - 多核机型优化,高效的预缓存机制 23 | 24 | - 支持多种显示效果选项实时切换 25 | 26 | - 实时弹幕显示支持 27 | 28 | - 换行弹幕支持/运动弹幕支持 29 | 30 | - 支持自定义字体 31 | 32 | - 支持多种弹幕参数设置 33 | 34 | - 支持多种方式的弹幕屏蔽 35 | 36 | ### TODO: 37 | 38 | - 继续精确/稳定绘帧周期 39 | 40 | - 增加OpenGL ES绘制方式 41 | 42 | - 改进缓存策略和效率 43 | 44 | 45 | ### Download 46 | Download the [latest version][1] or grab via Maven: 47 | 48 | ```xml 49 | 50 | com.github.ctiao 51 | dfm 52 | 0.3.9 53 | 54 | ``` 55 | 56 | or Gradle: 57 | ```groovy 58 | dependencies { 59 | compile 'com.github.ctiao:dfm:0.3.9' 60 | } 61 | ``` 62 | Snapshots of the development version are available in [Sonatype's snapshots repository][2]. 63 | 64 | 65 | ### License 66 | Copyright (C) 2013-2015 Chen Hui 67 | Licensed under the Apache License, Version 2.0 (the "License"); 68 | 69 | 70 | [1]:https://oss.sonatype.org/#nexus-search;gav~com.github.ctiao~dfm~~~ 71 | [2]:https://oss.sonatype.org/content/repositories/snapshots/ 72 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.library' 18 | 19 | def SourcePath = 'src/main/' 20 | 21 | android { 22 | compileSdkVersion 19 23 | buildToolsVersion '19.1.0' 24 | 25 | defaultConfig { 26 | minSdkVersion 7 27 | targetSdkVersion 19 28 | versionName VERSION_NAME 29 | versionCode Integer.parseInt(VERSION_CODE) 30 | } 31 | 32 | sourceSets { 33 | main { 34 | manifest.srcFile "${SourcePath}AndroidManifest.xml" 35 | java.srcDirs = ["${SourcePath}java"] 36 | jniLibs.srcDirs = ["${SourcePath}libs"] 37 | } 38 | androidTest.setRoot("${SourcePath}../androidTest") 39 | } 40 | compileOptions { 41 | sourceCompatibility JavaVersion.VERSION_1_7 42 | targetCompatibility JavaVersion.VERSION_1_7 43 | } 44 | } 45 | if (rootProject.file('gradle/gradle-mvn-push.gradle').exists()) { 46 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 47 | } 48 | if (rootProject.file('gradle/gradle-bintray-upload.gradle').exists()) { 49 | apply from: rootProject.file('gradle/gradle-bintray-upload.gradle') 50 | } -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/Danmaku.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | import master.flame.danmaku.danmaku.util.DanmakuUtils; 20 | 21 | public class Danmaku extends BaseDanmaku { 22 | 23 | public Danmaku(CharSequence text) { 24 | DanmakuUtils.fillText(this, text); 25 | } 26 | 27 | @Override 28 | public boolean isShown() { 29 | return false; 30 | } 31 | 32 | @Override 33 | public void layout(IDisplayer displayer, float x, float y) { 34 | 35 | } 36 | 37 | @Override 38 | public float[] getRectAtTime(IDisplayer displayer, long time) { 39 | return null; 40 | } 41 | 42 | @Override 43 | public float getLeft() { 44 | return 0; 45 | } 46 | 47 | @Override 48 | public float getTop() { 49 | return 0; 50 | } 51 | 52 | @Override 53 | public float getRight() { 54 | return 0; 55 | } 56 | 57 | @Override 58 | public float getBottom() { 59 | return 0; 60 | } 61 | 62 | @Override 63 | public int getType() { 64 | return 0; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/IDisplayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model; 18 | 19 | 20 | public interface IDisplayer { 21 | 22 | int DANMAKU_STYLE_DEFAULT = -1; // 自动 23 | int DANMAKU_STYLE_NONE = 0; // 无 24 | int DANMAKU_STYLE_SHADOW = 1; // 阴影 25 | int DANMAKU_STYLE_STROKEN = 2; // 描边 26 | int DANMAKU_STYLE_PROJECTION = 3; // 投影 27 | 28 | int getWidth(); 29 | 30 | int getHeight(); 31 | 32 | float getDensity(); 33 | 34 | int getDensityDpi(); 35 | 36 | int draw(BaseDanmaku danmaku); 37 | 38 | float getScaledDensity(); 39 | 40 | int getSlopPixel(); 41 | 42 | void measure(BaseDanmaku danmaku, boolean fromWorkerThread); 43 | 44 | float getStrokeWidth(); 45 | 46 | void setHardwareAccelerated(boolean enable); 47 | 48 | boolean isHardwareAccelerated(); 49 | 50 | int getMaximumCacheWidth(); 51 | 52 | int getMaximumCacheHeight(); 53 | 54 | 55 | ////////////////// setter /////////////////////////// 56 | 57 | void resetSlopPixel(float factor); 58 | 59 | void setDensities(float density, int densityDpi, float scaledDensity); 60 | 61 | void setSize(int width, int height); 62 | 63 | void setDanmakuStyle(int style, float[] data); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/loader/android/BiliDanmakuLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.loader.android; 18 | 19 | import java.io.InputStream; 20 | 21 | import master.flame.danmaku.danmaku.loader.ILoader; 22 | import master.flame.danmaku.danmaku.loader.IllegalDataException; 23 | import master.flame.danmaku.danmaku.parser.android.AndroidFileSource; 24 | 25 | public class BiliDanmakuLoader implements ILoader { 26 | 27 | private static BiliDanmakuLoader _instance; 28 | 29 | private AndroidFileSource dataSource; 30 | 31 | private BiliDanmakuLoader() { 32 | 33 | } 34 | 35 | public static BiliDanmakuLoader instance() { 36 | if (_instance == null) { 37 | _instance = new BiliDanmakuLoader(); 38 | } 39 | return _instance; 40 | } 41 | 42 | public void load(String uri) throws IllegalDataException { 43 | try { 44 | dataSource = new AndroidFileSource(uri); 45 | } catch (Exception e) { 46 | throw new IllegalDataException(e); 47 | } 48 | } 49 | 50 | public void load(InputStream stream) { 51 | dataSource = new AndroidFileSource(stream); 52 | } 53 | 54 | @Override 55 | public AndroidFileSource getDataSource() { 56 | return dataSource; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/IDrawTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.controller; 18 | 19 | import master.flame.danmaku.danmaku.model.AbsDisplayer; 20 | import master.flame.danmaku.danmaku.model.BaseDanmaku; 21 | import master.flame.danmaku.danmaku.model.IDanmakus; 22 | import master.flame.danmaku.danmaku.parser.BaseDanmakuParser; 23 | import master.flame.danmaku.danmaku.renderer.IRenderer.RenderingState; 24 | 25 | public interface IDrawTask { 26 | 27 | public void addDanmaku(BaseDanmaku item); 28 | 29 | public void removeAllDanmakus(); 30 | 31 | public void removeAllLiveDanmakus(); 32 | 33 | public void clearDanmakusOnScreen(long currMillis); 34 | 35 | public IDanmakus getVisibleDanmakusOnTime(long time); 36 | 37 | public RenderingState draw(AbsDisplayer displayer); 38 | 39 | public void reset(); 40 | 41 | public void seek(long mills); 42 | 43 | public void start(); 44 | 45 | public void quit(); 46 | 47 | public void prepare(); 48 | 49 | public void requestClear(); 50 | 51 | public void setParser(BaseDanmakuParser parser); 52 | 53 | void invalidateDanmaku(BaseDanmaku item, boolean remeasure); 54 | 55 | public interface TaskListener { 56 | public void ready(); 57 | 58 | public void onDanmakuAdd(BaseDanmaku danmaku); 59 | 60 | public void onDanmakuConfigChanged(); 61 | 62 | public void onDanmakusDrawingFinished(); 63 | } 64 | 65 | public void requestHide(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/parser/android/JSONSource.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.parser.android; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.net.URL; 9 | 10 | import master.flame.danmaku.danmaku.parser.IDataSource; 11 | import master.flame.danmaku.danmaku.util.IOUtils; 12 | 13 | import org.json.JSONArray; 14 | import org.json.JSONException; 15 | 16 | import android.net.Uri; 17 | import android.text.TextUtils; 18 | 19 | /** 20 | * a json file source 21 | * @author yrom 22 | */ 23 | public class JSONSource implements IDataSource{ 24 | private JSONArray mJSONArray; 25 | private InputStream mInput; 26 | public JSONSource(String json) throws JSONException{ 27 | init(json); 28 | } 29 | 30 | public JSONSource(InputStream in) throws JSONException{ 31 | init(in); 32 | } 33 | 34 | private void init(InputStream in) throws JSONException { 35 | if(in == null) 36 | throw new NullPointerException("input stream cannot be null!"); 37 | mInput = in; 38 | String json = IOUtils.getString(mInput); 39 | init(json); 40 | } 41 | 42 | public JSONSource(URL url) throws JSONException, IOException{ 43 | this(url.openStream()); 44 | } 45 | 46 | public JSONSource(File file) throws FileNotFoundException, JSONException{ 47 | init(new FileInputStream(file)); 48 | } 49 | 50 | public JSONSource(Uri uri) throws IOException, JSONException { 51 | String scheme = uri.getScheme(); 52 | if (SCHEME_HTTP_TAG.equalsIgnoreCase(scheme) || SCHEME_HTTPS_TAG.equalsIgnoreCase(scheme)) { 53 | init(new URL(uri.getPath()).openStream()); 54 | } else if (SCHEME_FILE_TAG.equalsIgnoreCase(scheme)) { 55 | init(new FileInputStream(uri.getPath())); 56 | } 57 | } 58 | 59 | private void init(String json) throws JSONException { 60 | if(!TextUtils.isEmpty(json)){ 61 | mJSONArray = new JSONArray(json); 62 | } 63 | } 64 | public JSONArray data(){ 65 | return mJSONArray; 66 | } 67 | 68 | @Override 69 | public void release() { 70 | IOUtils.closeQuietly(mInput); 71 | mInput = null; 72 | mJSONArray = null; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /gradle/gradle-bintray-upload.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Chen Hui 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.github.dcendents.android-maven' 18 | apply plugin: 'com.jfrog.bintray' 19 | 20 | group = GROUP 21 | version = VERSION_NAME 22 | 23 | bintray { 24 | user = project.hasProperty('BINTRAY_USER') ? BINTRAY_USER : '' 25 | key = project.hasProperty('BINTRAY_APIKEY') ? BINTRAY_APIKEY : '' 26 | 27 | configurations = ['archives'] 28 | 29 | dryRun = false 30 | publish = true 31 | 32 | pkg { 33 | repo = 'maven' 34 | name = BINTRAY_POM_NAME 35 | desc = POM_DESCRIPTION 36 | websiteUrl = POM_URL 37 | vcsUrl = POM_SCM_URL 38 | licenses = [POM_LICENCE_NAME] 39 | labels = ['FFmpeg', 'Android', 'player'] 40 | publicDownloadNumbers = true 41 | version { 42 | name = VERSION_NAME 43 | gpg { 44 | sign = true 45 | passphrase = project.hasProperty('GPG_PASSWORD') ? GPG_PASSWORD : '' 46 | } 47 | } 48 | } 49 | } 50 | 51 | install { 52 | repositories.mavenInstaller { 53 | pom.project { 54 | name BINTRAY_POM_NAME 55 | packaging POM_PACKAGING 56 | description POM_DESCRIPTION 57 | url POM_URL 58 | 59 | licenses { 60 | license { 61 | name POM_LICENCE_NAME 62 | url POM_LICENCE_URL 63 | distribution POM_LICENCE_DIST 64 | } 65 | } 66 | 67 | scm { 68 | url POM_SCM_URL 69 | connection POM_SCM_CONNECTION 70 | developerConnection POM_SCM_DEV_CONNECTION 71 | } 72 | 73 | developers { 74 | developer { 75 | id POM_DEVELOPER_ID 76 | name POM_DEVELOPER_NAME 77 | email POM_DEVELOPER_EMAIL 78 | } 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/BaseCacheStuffer.java: -------------------------------------------------------------------------------- 1 | package master.flame.danmaku.danmaku.model.android; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | import android.text.TextPaint; 6 | 7 | import master.flame.danmaku.danmaku.model.BaseDanmaku; 8 | 9 | /** 10 | * Created by ch on 15-7-16. 11 | */ 12 | public abstract class BaseCacheStuffer { 13 | 14 | public static abstract class Proxy { 15 | /** 16 | * 在弹幕显示前使用新的text,使用新的text 17 | * @param danmaku 18 | * @param fromWorkerThread 是否在工作(非UI)线程,在true的情况下可以做一些耗时操作(例如更新Span的drawblae或者其他IO操作) 19 | * @return 如果不需重置,直接返回danmaku.text 20 | */ 21 | public abstract void prepareDrawing(BaseDanmaku danmaku, boolean fromWorkerThread); 22 | 23 | public abstract void releaseResource(BaseDanmaku danmaku); 24 | } 25 | 26 | protected Proxy mProxy; 27 | 28 | /** 29 | * set paintWidth, paintHeight to danmaku 30 | * @param danmaku 31 | * @param fromWorkerThread 32 | */ 33 | public abstract void measure(BaseDanmaku danmaku, TextPaint paint, boolean fromWorkerThread); 34 | 35 | /** 36 | * draw the danmaku-stroke on canvas with the given params 37 | * @param danmaku 38 | * @param lineText 39 | * @param canvas 40 | * @param left 41 | * @param top 42 | * @param paint 43 | */ 44 | public abstract void drawStroke(BaseDanmaku danmaku, String lineText, Canvas canvas, float left, float top, Paint paint); 45 | 46 | /** 47 | * draw the danmaku-text on canvas with the given params 48 | * @param danmaku 49 | * @param lineText 50 | * @param canvas 51 | * @param left 52 | * @param top 53 | * @param paint 54 | * @param fromWorkerThread 55 | */ 56 | public abstract void drawText(BaseDanmaku danmaku, String lineText, Canvas canvas, float left, float top, TextPaint paint, boolean fromWorkerThread); 57 | 58 | /** 59 | * clear caches which created by this stuffer 60 | */ 61 | public abstract void clearCaches(); 62 | 63 | /** 64 | * draw the background in rect (left, top, left + danmaku.paintWidth, top + danmaku.paintHeight) 65 | * @param danmaku 66 | * @param canvas 67 | * @param left 68 | * @param top 69 | */ 70 | public abstract void drawBackground(BaseDanmaku danmaku, Canvas canvas, float left, float top); 71 | 72 | public void clearCache(BaseDanmaku danmaku) { 73 | 74 | } 75 | 76 | public void setProxy(Proxy adapter) { 77 | mProxy = adapter; 78 | } 79 | 80 | public void releaseResource(BaseDanmaku danmaku) { 81 | if (mProxy != null) { 82 | mProxy.releaseResource(danmaku); 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/FinitePool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package master.flame.danmaku.danmaku.model.objectpool; 18 | 19 | class FinitePool> implements Pool { 20 | /** Factory used to create new pool objects */ 21 | private final PoolableManager mManager; 22 | 23 | /** Maximum number of objects in the pool */ 24 | private final int mLimit; 25 | 26 | /** If true, mLimit is ignored */ 27 | private final boolean mInfinite; 28 | 29 | /** Next object to acquire */ 30 | private T mRoot; 31 | 32 | /** Number of objects in the pool */ 33 | private int mPoolCount; 34 | 35 | FinitePool(PoolableManager manager) { 36 | mManager = manager; 37 | mLimit = 0; 38 | mInfinite = true; 39 | } 40 | 41 | FinitePool(PoolableManager manager, int limit) { 42 | if (limit <= 0) { 43 | throw new IllegalArgumentException("The pool limit must be > 0"); 44 | } 45 | 46 | mManager = manager; 47 | mLimit = limit; 48 | mInfinite = false; 49 | } 50 | 51 | public T acquire() { 52 | T element; 53 | 54 | if (mRoot != null) { 55 | element = mRoot; 56 | mRoot = element.getNextPoolable(); 57 | mPoolCount--; 58 | } else { 59 | element = mManager.newInstance(); 60 | } 61 | 62 | if (element != null) { 63 | element.setNextPoolable(null); 64 | element.setPooled(false); 65 | mManager.onAcquired(element); 66 | } 67 | 68 | return element; 69 | } 70 | 71 | public void release(T element) { 72 | if (!element.isPooled()) { 73 | if (mInfinite || mPoolCount < mLimit) { 74 | mPoolCount++; 75 | element.setNextPoolable(mRoot); 76 | element.setPooled(true); 77 | mRoot = element; 78 | } 79 | mManager.onReleased(element); 80 | } else { 81 | System.out.print("[FinitePool] Element is already in pool: " + element); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/DrawingCache.java: -------------------------------------------------------------------------------- 1 | 2 | package master.flame.danmaku.danmaku.model.android; 3 | 4 | import master.flame.danmaku.danmaku.model.IDrawingCache; 5 | import master.flame.danmaku.danmaku.model.objectpool.Poolable; 6 | 7 | public class DrawingCache implements IDrawingCache, Poolable { 8 | 9 | private final DrawingCacheHolder mHolder; 10 | 11 | private int mSize = 0; 12 | 13 | private DrawingCache mNextElement; 14 | 15 | private boolean mIsPooled; 16 | 17 | private int referenceCount = 0; 18 | 19 | public DrawingCache() { 20 | mHolder = new DrawingCacheHolder(); 21 | } 22 | 23 | @Override 24 | public void build(int w, int h, int density, boolean checkSizeEquals) { 25 | final DrawingCacheHolder holder = mHolder; 26 | holder.buildCache(w, h, density, checkSizeEquals); 27 | mSize = mHolder.bitmap.getRowBytes() * mHolder.bitmap.getHeight(); 28 | } 29 | 30 | @Override 31 | public void erase() { 32 | mHolder.erase(); 33 | } 34 | 35 | @Override 36 | public DrawingCacheHolder get() { 37 | final DrawingCacheHolder holder = mHolder; 38 | if (holder.bitmap == null) { 39 | return null; 40 | } 41 | return mHolder; 42 | } 43 | 44 | @Override 45 | public void destroy() { 46 | if (mHolder != null) { 47 | mHolder.recycle(); 48 | } 49 | mSize = 0; 50 | referenceCount = 0; 51 | } 52 | 53 | @Override 54 | public int size() { 55 | return mSize; 56 | } 57 | 58 | @Override 59 | public void setNextPoolable(DrawingCache element) { 60 | mNextElement = element; 61 | } 62 | 63 | @Override 64 | public DrawingCache getNextPoolable() { 65 | return mNextElement; 66 | } 67 | 68 | @Override 69 | public boolean isPooled() { 70 | return mIsPooled; 71 | } 72 | 73 | @Override 74 | public void setPooled(boolean isPooled) { 75 | mIsPooled = isPooled; 76 | } 77 | 78 | @Override 79 | public synchronized boolean hasReferences() { 80 | return referenceCount > 0; 81 | } 82 | 83 | @Override 84 | public synchronized void increaseReference() { 85 | referenceCount++; 86 | } 87 | 88 | @Override 89 | public synchronized void decreaseReference() { 90 | referenceCount--; 91 | } 92 | 93 | @Override 94 | public int width() { 95 | return mHolder.width; 96 | } 97 | 98 | @Override 99 | public int height() { 100 | return mHolder.height; 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /Sample/src/main/res/layout/media_controller.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 | 19 | 20 |