├── .gitignore
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── opendanmaku
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── opendanmaku
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── opendanmaku
│ │ ├── DanmakuItem.java
│ │ ├── DanmakuView.java
│ │ └── IDanmakuItem.java
│ └── res
│ └── values
│ ├── danmaku_attrs.xml
│ └── strings.xml
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── opendanmaku
│ │ └── sample
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── opendanmaku
│ │ └── sample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ └── em.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── screenshot
└── screenshot.jpg
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /captures
3 |
4 | .gradle
5 | .DS_Store
6 |
7 | /build
8 | /**/*/build
9 |
10 | .idea/
11 |
12 | # built application files
13 | *.apk
14 | *.ap_
15 | # files for the dex VM
16 | *.dex
17 | # Java class files
18 | *.class
19 | # generated files
20 | bin/
21 | gen/
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Open Danmaku
2 |
3 | [中文版说明请点击这里](http://my.oschina.net/u/1403288/blog/521343)
4 |
5 | 一个Android的弹幕控件.
6 | Open Danmaku is a Android widget which shows danmaku animation(https://github.com/linsea/OpenDanmaku).
7 |
8 | 
9 |
10 | # Usage
11 |
12 | *For a working implementation of this project see the sample app.*
13 |
14 | 1. add library dependency to your `build.gradle` file.
15 | ```groovy
16 | dependencies {
17 | compile 'com.linsea:opendanmaku:1.0.0@aar'
18 | }
19 | ```
20 | 2. Include the `DanmakuView` in your layout.
21 | ```xml
22 |
32 | ```
33 | 3. In your `Activity`:
34 | ```java
35 | mDanmakuView = (DanmakuView) findViewById(R.id.danmakuView);
36 |
37 | // add danmaku items:
38 | mDanmakuView.addItem(list, true);
39 | mDanmakuView.addItem(new DanmakuItem(this, "Hello World", mDanmakuView.getWidth());
40 |
41 | //show danmaku and play animation:
42 | mDanmakuView.show();
43 |
44 | //hide and pause playing:
45 | mDanmakuView.hide();
46 |
47 | //release all playing and waiting items:
48 | mDanmakuView.clear();
49 | ```
50 | # Customization
51 |
52 | * `start_Y_offset` first channel offset to the view top edge.
53 | * `end_Y_offset` last channel offset to the view top edge.
54 | * `max_row` max running channels on Y axis.
55 | * `max_running_per_row` max concurrent running items in one channel.
56 | * `pick_interval` interval millisecond picking up an item in the backing queue to play.
57 | * `show_debug` show debug info like FPS and lines between channels.
58 |
59 |
60 | # You might also like
61 | - [UniversalVideoView](https://github.com/linsea/UniversalVideoView) VideoView like Widget with more features.
62 |
63 |
64 | # License
65 |
66 | Copyright 2015 the OpenDanmaku Author
67 |
68 | Licensed under the Apache License, Version 2.0 (the "License");
69 | you may not use this file except in compliance with the License.
70 | You may obtain a copy of the License at
71 |
72 | http://www.apache.org/licenses/LICENSE-2.0
73 |
74 | Unless required by applicable law or agreed to in writing, software
75 | distributed under the License is distributed on an "AS IS" BASIS,
76 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77 | See the License for the specific language governing permissions and
78 | limitations under the License.
79 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 | classpath 'com.github.dcendents:android-maven-plugin:1.2'
10 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 16 12:47:14 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/opendanmaku/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/opendanmaku/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: "com.jfrog.bintray"
4 |
5 | // This is the library version used when deploying the artifact
6 | version = "1.0.0"
7 |
8 | android {
9 | compileSdkVersion 22
10 | buildToolsVersion "22.0.1"
11 |
12 | defaultConfig {
13 | minSdkVersion 10
14 | targetSdkVersion 22
15 | versionCode 1
16 | versionName "1.0.0"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | tasks.withType(JavaCompile) {
27 | options.encoding = "UTF-8"
28 | }
29 |
30 | /*javadoc {
31 | options.charSet = 'UTF-8'
32 | }*/
33 |
34 | dependencies {
35 | compile fileTree(dir: 'libs', include: ['*.jar'])
36 | compile 'com.android.support:appcompat-v7:22.2.0'
37 | }
38 |
39 |
40 | def siteUrl = 'https://github.com/linsea/OpenDanmaku' // Homepage URL of the library
41 | def gitUrl = 'https://github.com/linsea/OpenDanmaku.git' // Git repository URL
42 | group = "com.linsea" // Maven Group ID for the artifact
43 |
44 | //distribute library to Jcenter guide :
45 | // http://blog.csdn.net/u013308121/article/details/46360703
46 | // https://github.com/danielemaddaluno/gradle-jcenter-publish
47 | install {
48 | repositories.mavenInstaller {
49 | // This generates POM.xml with proper parameters
50 | pom {
51 | project {
52 | packaging 'aar'
53 |
54 | // Add your description here
55 | name 'Android Open Danmaku'
56 | description = '一个Android的弹幕控件.Open Danmaku is a Android widget which shows danmaku.'
57 | url siteUrl
58 |
59 | // Set your license
60 | licenses {
61 | license {
62 | name 'The Apache Software License, Version 2.0'
63 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
64 | }
65 | }
66 | developers {
67 | developer {
68 | id 'linsea'
69 | name 'linsea'
70 | email 'dictfb@gmail.com'
71 | }
72 | }
73 | scm {
74 | connection gitUrl
75 | developerConnection gitUrl
76 | url siteUrl
77 |
78 | }
79 | }
80 | }
81 | }
82 | }
83 |
84 | task sourcesJar(type: Jar) {
85 | from android.sourceSets.main.java.srcDirs
86 | classifier = 'sources'
87 | }
88 |
89 | task javadoc(type: Javadoc) {
90 | options.encoding = "utf-8"
91 | source = android.sourceSets.main.java.srcDirs
92 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
93 | }
94 |
95 | task javadocJar(type: Jar, dependsOn: javadoc) {
96 | classifier = 'javadoc'
97 | from javadoc.destinationDir
98 | }
99 | artifacts {
100 | archives javadocJar
101 | archives sourcesJar
102 | }
103 |
104 | Properties properties = new Properties()
105 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
106 |
107 | // https://github.com/bintray/gradle-bintray-plugin
108 | bintray {
109 | user = properties.getProperty("bintray.user")
110 | key = properties.getProperty("bintray.apikey")
111 |
112 | configurations = ['archives']
113 | pkg {
114 | repo = "maven"
115 | // it is the name that appears in bintray when logged
116 | name = "AndroidOpenDanmaku"
117 | websiteUrl = siteUrl
118 | vcsUrl = gitUrl
119 | licenses = ["Apache-2.0"]
120 | publish = true
121 | version {
122 | gpg {
123 | sign = true //Determines whether to GPG sign the files. The default is false
124 | passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
125 | }
126 | // mavenCentralSync {
127 | // sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
128 | // user = properties.getProperty("bintray.oss.user") //OSS user token
129 | // password = properties.getProperty("bintray.oss.password") //OSS user password
130 | // close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
131 | // }
132 | }
133 | }
134 | }
135 |
136 |
--------------------------------------------------------------------------------
/opendanmaku/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\AndroidDev\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/opendanmaku/src/androidTest/java/com/opendanmaku/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/opendanmaku/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/opendanmaku/src/main/java/com/opendanmaku/DanmakuItem.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.text.Layout;
8 | import android.text.SpannableString;
9 | import android.text.StaticLayout;
10 | import android.text.TextPaint;
11 |
12 | public class DanmakuItem implements IDanmakuItem {
13 |
14 | /** X axis base speed*/
15 | private static int sBaseSpeed = 3;
16 |
17 | private Context mContext;
18 |
19 | /**DanmakuView width, height*/
20 | private int mContainerWidth, mContainerHeight;
21 |
22 | private int mTextSize;
23 |
24 | private int mTextColor = Color.WHITE;
25 |
26 | private SpannableString mContent;
27 |
28 | private int mCurrX, mCurrY;
29 |
30 | /** X axis speed factor*/
31 | private float mFactor;
32 |
33 | private StaticLayout staticLayout;
34 | private StaticLayout borderStaticLayout;
35 | private static TextPaint strokePaint = new TextPaint();
36 |
37 | private int mContentWidth , mContentHeight;
38 |
39 |
40 | static {
41 | strokePaint.setARGB(255, 0, 0, 0);
42 | // strokePaint.setTextAlign(Paint.Align.CENTER);
43 | // strokePaint.setTextSize(16);
44 | // strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
45 | strokePaint.setStyle(Paint.Style.STROKE);
46 | strokePaint.setStrokeWidth(4);
47 | strokePaint.setAntiAlias(true);
48 |
49 | }
50 | /**
51 | * construct a DanmakuItem
52 | * @param context Context
53 | * @param content paint text as content
54 | * @param startX start position of X axis,
55 | * normally should be the screen width, e.g. right side of the view).
56 | * the Y axis position will be assigned a channel by the DanmakuView randomly.
57 | */
58 | public DanmakuItem(Context context, CharSequence content, int startX) {
59 | this(context, new SpannableString(content), startX, 0, 0, 0, 1f);
60 | }
61 |
62 | public DanmakuItem(Context context, CharSequence content, int startX, int startY) {
63 | this(context, new SpannableString(content), startX, startY, 0, 0, 1f);
64 | }
65 |
66 |
67 | public DanmakuItem(Context context, SpannableString content, int startX, int startY,
68 | int textColorResId, int textSizeInDip, float speedFactor) {
69 | this.mContext = context;
70 | this.mContent = content;
71 | this.mCurrX = startX;
72 | this.mCurrY = startY;
73 | setTextColor(textColorResId);
74 | setTextSize(textSizeInDip);
75 | mFactor = speedFactor;
76 | measure();
77 | }
78 |
79 | private void measure() {
80 | TextPaint tp = new TextPaint();
81 | tp.setAntiAlias(true);
82 | tp.setColor(mTextColor);
83 | tp.setTextSize(mTextSize);
84 | strokePaint.setTextSize(mTextSize);
85 | // tp.setShadowLayer(4, 0, 0, Color.BLACK);
86 | mContentHeight = getFontHeight(tp);
87 | staticLayout = new StaticLayout(mContent,
88 | tp,
89 | (int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
90 | Layout.Alignment.ALIGN_NORMAL,
91 | 1.0f,
92 | 0.0f,
93 | false);
94 | mContentWidth = staticLayout.getWidth();
95 | borderStaticLayout = new StaticLayout(mContent,
96 | strokePaint,
97 | (int) Layout.getDesiredWidth(mContent, 0, mContent.length(), tp) + 1,
98 | Layout.Alignment.ALIGN_NORMAL,
99 | 1.0f,
100 | 0.0f,
101 | false);
102 | }
103 |
104 | @Override
105 | public void doDraw(Canvas canvas) {
106 | int canvasWidth = canvas.getWidth();
107 | int canvasHeight = canvas.getHeight();
108 |
109 | if (canvasWidth != this.mContainerWidth || canvasHeight != this.mContainerHeight) {//phone rotated !
110 | this.mContainerWidth = canvasWidth;
111 | this.mContainerHeight = canvasHeight;
112 | }
113 | canvas.save();
114 | canvas.translate(mCurrX,mCurrY);
115 | // for (int i = 0; i < 4; i++) { //加深阴影,产生描边效果. stroke/outline effect
116 | // staticLayout.draw(canvas);
117 | // }
118 | borderStaticLayout.draw(canvas);
119 | staticLayout.draw(canvas);
120 | canvas.restore();
121 | mCurrX = (int) (mCurrX - sBaseSpeed * mFactor);//only support moving along X axis
122 | }
123 |
124 | @Override
125 | public void setTextSize(int textSizeInDip) {
126 | if (textSizeInDip > 0) {
127 | this.mTextSize = dip2px(mContext, textSizeInDip);
128 | measure();
129 | } else {
130 | this.mTextSize = dip2px(mContext, 12); // textSize default to 12 dp
131 | }
132 |
133 | }
134 |
135 | @Override
136 | public void setTextColor(int textColorResId) {
137 | if (textColorResId > 0) {
138 | this.mTextColor = mContext.getResources().getColor(textColorResId);
139 | measure();
140 | }
141 | }
142 |
143 | @Override
144 | public void setStartPosition(int x, int y) {
145 | this.mCurrX = x;
146 | this.mCurrY = y;
147 | }
148 |
149 | @Override
150 | public void setSpeedFactor(float factor) {
151 | this.mFactor = factor;
152 | }
153 |
154 | @Override
155 | public float getSpeedFactor() {
156 | return mFactor;
157 | }
158 |
159 | @Override
160 | public boolean isOut() {
161 | return mCurrX < 0 && Math.abs(mCurrX) > mContentWidth;
162 | }
163 |
164 | @Override
165 | public void release() {
166 | mContext = null;
167 | }
168 |
169 | @Override
170 | public int getWidth() {
171 | return mContentWidth;
172 | }
173 |
174 | @Override
175 | public int getHeight() {
176 | return mContentHeight;
177 | }
178 |
179 | @Override
180 | public int getCurrX() {
181 | return mCurrX;
182 | }
183 |
184 | @Override
185 | public int getCurrY() {
186 | return mCurrY;
187 | }
188 |
189 | /***
190 | * test whether this Danmaku Item would be hit the already running one or not
191 | * if it to be run on the same channel
192 | * @param runningItem item is already moving on the channel
193 | * @return hit or not
194 | */
195 | public boolean willHit(IDanmakuItem runningItem) {
196 | if (runningItem.getWidth() + runningItem.getCurrX() > mContainerWidth) {
197 | return true;
198 | }
199 |
200 | if (runningItem.getSpeedFactor()>= mFactor) {
201 | return false;
202 | }
203 |
204 | float len1 = runningItem.getCurrX() + runningItem.getWidth();
205 | float t1 = len1 / (runningItem.getSpeedFactor() * DanmakuItem.sBaseSpeed);
206 | float len2 = t1 * mFactor * DanmakuItem.sBaseSpeed;
207 | if (len2 > len1) {
208 | return true;
209 | } else {
210 | return false;
211 | }
212 |
213 | }
214 |
215 |
216 | public static int getBaseSpeed() {
217 | return sBaseSpeed;
218 | }
219 |
220 | public static void setBaseSpeed(int baseSpeed) {
221 | DanmakuItem.sBaseSpeed = baseSpeed;
222 | }
223 |
224 |
225 | private static int dip2px(Context context, float dipValue) {
226 | final float scale = context.getResources().getDisplayMetrics().density;
227 | return (int) (dipValue * scale + 0.5f);
228 | }
229 |
230 | private static int getFontHeight(TextPaint paint){
231 | Paint.FontMetrics fm = paint.getFontMetrics();
232 | return (int) Math.ceil(fm.descent - fm.top) + 2;
233 | }
234 | }
235 |
--------------------------------------------------------------------------------
/opendanmaku/src/main/java/com/opendanmaku/DanmakuView.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.PorterDuff;
9 | import android.text.TextPaint;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 |
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.Iterator;
17 | import java.util.LinkedList;
18 | import java.util.List;
19 | import java.util.Random;
20 |
21 | /**
22 | * 弹幕View
23 | */
24 | public class DanmakuView extends View {
25 |
26 | public static final String TAG = "DanmakuView";
27 |
28 | private final Context mContext;
29 |
30 | private int mMaxRow = 1; //最多几条弹道
31 | private int mPickItemInterval = 1000;//每隔多长时间取出一条弹幕来播放.
32 | private int mMaxRunningPerRow = 1; //每条弹道上最多同时有几个弹幕在屏幕上运行
33 | private float mStartYOffset = 0.1f; //第一个弹道在Y轴上的偏移占整个View的百分比
34 | private float mEndYOffset = 0.9f;//最后一个弹道在Y轴上的偏移占整个View的百分比
35 |
36 |
37 |
38 | private HashMap> mChannelMap;
39 | private final java.util.Deque mWaitingItems = new LinkedList<>();
40 | private int[] mChannelY; //每条弹道的Y坐标
41 | private static final float mPartition = 0.95f; //仅View顶部的部分可以播放弹幕百分比
42 |
43 | private static final int STATUS_RUNNING = 1;
44 | private static final int STATUS_PAUSE = 2;
45 | private static final int STATUS_STOP = 3;
46 |
47 | private volatile int status = STATUS_STOP;
48 |
49 | private static Random random = new Random();
50 |
51 | private boolean mShowDebug = false;
52 | private LinkedList times;
53 | private Paint fpsPaint;
54 | private long previousTime = 0;
55 | private LinkedList lines;
56 |
57 |
58 | public DanmakuView(Context context) {
59 | this(context, null);
60 | }
61 |
62 | public DanmakuView(Context context, AttributeSet attrs) {
63 | this(context, attrs, 0);
64 | }
65 |
66 | public DanmakuView(Context context, AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | mContext = context;
69 | TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.DanmakuView, 0, 0);
70 | mMaxRow = a.getInteger(R.styleable.DanmakuView_max_row, 1);
71 | mPickItemInterval = a.getInteger(R.styleable.DanmakuView_pick_interval, 1000);
72 | mMaxRunningPerRow = a.getInteger(R.styleable.DanmakuView_max_running_per_row, 1);
73 | mShowDebug = a.getBoolean(R.styleable.DanmakuView_show_debug, false);
74 | mStartYOffset = a.getFloat(R.styleable.DanmakuView_start_Y_offset, 0.1f);
75 | mEndYOffset = a.getFloat(R.styleable.DanmakuView_end_Y_offset, 0.9f);
76 | a.recycle();
77 | checkYOffset(mStartYOffset, mEndYOffset);
78 | init();
79 | }
80 |
81 | private void checkYOffset(float start, float end) {
82 | if (start >= end ){
83 | throw new IllegalArgumentException("start_Y_offset must < end_Y_offset");
84 | }
85 | if (start < 0f || start >= 1f || end < 0f || end > 1f) {
86 | throw new IllegalArgumentException("start_Y_offset and end_Y_offset must between 0 and 1)");
87 | }
88 | }
89 |
90 | private void init() {
91 | setBackgroundColor(Color.TRANSPARENT);
92 | setDrawingCacheBackgroundColor(Color.TRANSPARENT);
93 | calculation();
94 | }
95 |
96 | private void calculation() {
97 | if (mShowDebug) {
98 | fpsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
99 | fpsPaint.setColor(Color.YELLOW);
100 | fpsPaint.setTextSize(20);
101 | times = new LinkedList<>();
102 | lines = new LinkedList<>();
103 | }
104 | initChannelMap();
105 | initChannelY();
106 | }
107 |
108 | private void initChannelMap(){
109 | mChannelMap = new HashMap<>(mMaxRow);
110 | for (int i = 0; i < mMaxRow; i++) {
111 | ArrayList runningRow= new ArrayList(mMaxRunningPerRow);
112 | mChannelMap.put(i, runningRow);
113 | }
114 | }
115 |
116 | private void initChannelY() {
117 | if (mChannelY == null){
118 | mChannelY = new int[mMaxRow];
119 | }
120 |
121 | float rowHeight = getHeight() * (mEndYOffset - mStartYOffset) / mMaxRow;
122 | float baseOffset = getHeight() * mStartYOffset;
123 | for (int i = 0; i < mMaxRow; i++) {
124 | mChannelY[i] = (int) (baseOffset + rowHeight * (i + 1) - rowHeight * 3 / 4);//每一行空间顶部留1/4,剩下3/4显示文字
125 |
126 | }
127 | if (mShowDebug) {
128 | lines.add(baseOffset);
129 | for (int i = 0; i < mMaxRow; i++) {
130 | lines.add(baseOffset + rowHeight * (i + 1));
131 | }
132 | }
133 | }
134 |
135 | @Override
136 | protected void onDraw(Canvas canvas) {
137 | super.onDraw(canvas);
138 | if (status == STATUS_RUNNING) {
139 | try {
140 | canvas.drawColor(Color.TRANSPARENT);
141 |
142 | //先绘制正在播放的弹幕
143 | for (int i = 0; i < mChannelMap.size(); i++) {
144 | ArrayList list = mChannelMap.get(i);
145 | for (Iterator it = list.iterator(); it.hasNext(); ) {
146 | IDanmakuItem item = it.next();
147 | if (item.isOut()) {
148 | it.remove();
149 | } else {
150 | item.doDraw(canvas);
151 | }
152 | }
153 | }
154 |
155 | //检查是否需要加载播放下一个弹幕
156 | if (System.currentTimeMillis() - previousTime > mPickItemInterval) {
157 | previousTime = System.currentTimeMillis();
158 | // Log.d(TAG, "start pick new item..");
159 | IDanmakuItem di = mWaitingItems.pollFirst();
160 | if (di != null) {
161 | int indexY = findVacant(di);
162 | if (indexY >= 0) {
163 | // Log.d(TAG, "find vacant channel");
164 | di.setStartPosition(canvas.getWidth() - 2, mChannelY[indexY]);
165 | // Log.d(TAG, "draw new, text:" + di.getText());
166 | //Log.d(TAG, String.format("doDraw, position,x=%s,y=%s", c.getWidth() - 1, mChannelY[indexY]));
167 | di.doDraw(canvas);
168 | mChannelMap.get(indexY).add(di);//不要忘记加入正运行的维护的列表中
169 |
170 | } else {
171 | // Log.d(TAG, "Not find vacant channel, add it back");
172 | addItemToHead(di);//找不到可以播放的弹道,则把它放回列表中
173 | }
174 |
175 | } else {
176 | //no item 弹幕播放完毕,
177 | }
178 |
179 | }
180 |
181 | if (mShowDebug) {
182 | int fps = (int) fps();
183 | canvas.drawText("FPS:" + fps, 5f, 20f, fpsPaint);
184 | for (float yp : lines) {
185 | canvas.drawLine(0f, yp, getWidth(), yp, fpsPaint);
186 | }
187 | }
188 |
189 | } catch (Exception e) {
190 | e.printStackTrace();
191 | }
192 | invalidate();
193 |
194 | } else {//暂停或停止,隐藏弹幕内容
195 | canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
196 | }
197 | }
198 |
199 |
200 | /**随机寻找一个可以播放弹幕而不会发生碰撞的弹道,返回弹道的Y坐标在mChannelY上的index,如果没有找到则返回-1*/
201 | private int findVacant(IDanmakuItem item) {
202 | try {//fix NPT exception
203 | for (int i = 0; i < mMaxRow; i++) {
204 | ArrayList list = mChannelMap.get(i);
205 | if (list.size() == 0) {
206 | return i;
207 | }
208 | }
209 | int ind = random.nextInt(mMaxRow);
210 | for (int i = 0; i < mMaxRow; i++) {
211 | ArrayList list = mChannelMap.get((i + ind) % mMaxRow);
212 | if (list.size() > mMaxRunningPerRow) {//每个弹道最多mMaxRunning个弹幕
213 | continue;
214 | }
215 | IDanmakuItem di = list.get(list.size() - 1);
216 | if (!item.willHit(di)) {
217 | return (i + ind) % mMaxRow;
218 | }
219 | }
220 | } catch (Exception e) {
221 | Log.w(TAG, "findVacant,Exception:" + e.toString());
222 | // e.printStackTrace();
223 | }
224 |
225 | return -1;
226 | }
227 |
228 | private void clearPlayingItems() {
229 | if (mChannelMap != null) {
230 | synchronized (mChannelMap) {
231 | for (int i = 0; i < mChannelMap.size(); i++) {
232 | ArrayList list = mChannelMap.get(i);
233 | if (list != null) {
234 | list.clear();
235 | }
236 | }
237 | }
238 | }
239 | }
240 |
241 | @Override
242 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
243 | super.onSizeChanged(w, h, oldw, oldh);
244 | initChannelY();//可能屏幕方向切换了,得重新计算坐标
245 | }
246 |
247 | public boolean isPaused() {
248 | return STATUS_PAUSE == status;
249 | }
250 |
251 |
252 | /**播放显示弹幕*/
253 | public void show() {
254 | status = STATUS_RUNNING;
255 | invalidate();
256 | }
257 |
258 | /**隐藏弹幕,暂停播放*/
259 | public void hide() {
260 | status = STATUS_PAUSE;
261 | invalidate();
262 | }
263 |
264 | /**清空正在播放和等待播放的弹幕*/
265 | public void clear() {
266 | status = STATUS_STOP;
267 | clearItems();
268 | invalidate();
269 | }
270 |
271 | // /**清空弹幕等待队列,暂停播放*/
272 | // public void pauseAndClear() {
273 | // if (mWaitingItems != null) {
274 | // synchronized (mWaitingItems) {
275 | // mWaitingItems.clear();
276 | // }
277 | // }
278 | // clearPlayingItems();
279 | // }
280 |
281 | private void clearItems() {
282 | clearRunning();
283 | clearWaiting();
284 | }
285 |
286 | private void clearRunning() {
287 | if (null != mChannelMap && !mChannelMap.isEmpty()) {
288 | mChannelMap.clear();
289 | }
290 | }
291 |
292 | private void clearWaiting(){
293 | if (null != mWaitingItems && !mWaitingItems.isEmpty()) {
294 | mWaitingItems.clear();
295 | }
296 | }
297 |
298 | public void setMaxRow(int maxRow) {
299 | this.mMaxRow = maxRow;
300 | calculation();
301 | clearRunning();
302 | }
303 |
304 | public void setPickItemInterval(int pickItemInterval) {
305 | this.mPickItemInterval = pickItemInterval;
306 | }
307 |
308 | public void setMaxRunningPerRow(int maxRunningPerRow) {
309 | this.mMaxRunningPerRow = maxRunningPerRow;
310 | }
311 |
312 | public void setStartYOffset(float startYOffset, float endYOffset) {
313 | checkYOffset(startYOffset, endYOffset);
314 | clearRunning();
315 | this.mStartYOffset = startYOffset;
316 | this.mEndYOffset = endYOffset;
317 | calculation();
318 | }
319 |
320 |
321 | public void addItem(IDanmakuItem item) {
322 | synchronized (mWaitingItems) {
323 | this.mWaitingItems.add(item);
324 | }
325 | }
326 |
327 | public void addItemToHead(IDanmakuItem item) {
328 | synchronized (mWaitingItems) {
329 | this.mWaitingItems.offerFirst(item);
330 | }
331 | }
332 |
333 | /**是否新建后台线程来执行添加任务*/
334 | public void addItem(final List list, boolean backgroundLoad) {
335 | if (backgroundLoad) {
336 | new Thread(){
337 | @Override
338 | public void run() {
339 | synchronized (mWaitingItems) {
340 | mWaitingItems.addAll(list);
341 | }
342 | postInvalidate();
343 | }
344 | }.start();
345 | } else {
346 | this.mWaitingItems.addAll(list);
347 | }
348 | }
349 |
350 |
351 | /** Calculates and returns frames per second */
352 | private double fps() {
353 | long lastTime = System.nanoTime();
354 | times.addLast(lastTime);
355 | double NANOS = 1000000000.0;
356 | double difference = (lastTime - times.getFirst()) / NANOS;
357 | int size = times.size();
358 | int MAX_SIZE = 100;
359 | if (size > MAX_SIZE) {
360 | times.removeFirst();
361 | }
362 | return difference > 0 ? times.size() / difference : 0.0;
363 | }
364 | }
365 |
--------------------------------------------------------------------------------
/opendanmaku/src/main/java/com/opendanmaku/IDanmakuItem.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku;
2 |
3 | import android.graphics.Canvas;
4 |
5 | public interface IDanmakuItem {
6 |
7 | void doDraw(Canvas canvas);
8 |
9 | void setTextSize(int sizeInDip);
10 |
11 | void setTextColor(int colorResId);
12 |
13 | void setStartPosition(int x, int y);
14 |
15 | void setSpeedFactor(float factor);
16 |
17 | float getSpeedFactor();
18 |
19 | boolean isOut();
20 |
21 | boolean willHit(IDanmakuItem runningItem);
22 |
23 | void release();
24 |
25 | int getWidth();
26 |
27 | int getHeight();
28 |
29 | int getCurrX();
30 |
31 | int getCurrY();
32 | }
33 |
--------------------------------------------------------------------------------
/opendanmaku/src/main/res/values/danmaku_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/opendanmaku/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.opendanmaku.sample"
9 | minSdkVersion 10
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:22.2.0'
25 | compile project(':opendanmaku')
26 | }
27 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\AndroidDev\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/opendanmaku/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/opendanmaku/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.opendanmaku.sample;
2 |
3 | import android.graphics.Color;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.text.Spannable;
7 | import android.text.SpannableString;
8 | import android.text.TextUtils;
9 | import android.text.style.ImageSpan;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 |
15 | import com.opendanmaku.DanmakuItem;
16 | import com.opendanmaku.DanmakuView;
17 | import com.opendanmaku.IDanmakuItem;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 |
23 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
24 |
25 | private DanmakuView mDanmakuView;
26 | private Button switcherBtn;
27 | private Button sendBtn;
28 | private EditText textEditText;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 | mDanmakuView = (DanmakuView) findViewById(R.id.danmakuView);
36 | switcherBtn = (Button) findViewById(R.id.switcher);
37 | sendBtn = (Button) findViewById(R.id.send);
38 | textEditText = (EditText) findViewById(R.id.text);
39 |
40 | List list = initItems();
41 | Collections.shuffle(list);
42 | mDanmakuView.addItem(list, true);
43 |
44 | switcherBtn.setOnClickListener(this);
45 | sendBtn.setOnClickListener(this);
46 | }
47 |
48 | private List initItems() {
49 | List list = new ArrayList<>();
50 | for (int i = 0; i < 100; i++) {
51 | IDanmakuItem item = new DanmakuItem(this, i + " : plain text danmuku", mDanmakuView.getWidth());
52 | list.add(item);
53 | }
54 |
55 | String msg = " : text with image ";
56 | for (int i = 0; i < 100; i++) {
57 | ImageSpan imageSpan = new ImageSpan(this, R.drawable.em);
58 | SpannableString spannableString = new SpannableString(i + msg);
59 | spannableString.setSpan(imageSpan, spannableString.length() - 2, spannableString.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
60 | IDanmakuItem item = new DanmakuItem(this, spannableString, mDanmakuView.getWidth(), 0, 0, 0, 1.5f);
61 | list.add(item);
62 | }
63 | return list;
64 | }
65 |
66 | @Override
67 | protected void onResume() {
68 | super.onResume();
69 | mDanmakuView.show();
70 | }
71 |
72 | @Override
73 | protected void onPause() {
74 | super.onPause();
75 | mDanmakuView.hide();
76 | }
77 |
78 | @Override
79 | protected void onDestroy() {
80 | super.onDestroy();
81 | mDanmakuView.clear();
82 | }
83 |
84 | @Override
85 | public void onClick(View v) {
86 | switch (v.getId()) {
87 | case R.id.switcher:
88 | if (mDanmakuView.isPaused()) {
89 | switcherBtn.setText(R.string.hide);
90 | mDanmakuView.show();
91 | } else {
92 | switcherBtn.setText(R.string.show);
93 | mDanmakuView.hide();
94 | }
95 | break;
96 | case R.id.send:
97 | String input = textEditText.getText().toString();
98 | if (TextUtils.isEmpty(input)) {
99 | Toast.makeText(MainActivity.this, R.string.empty_prompt, Toast.LENGTH_SHORT).show();
100 | } else {
101 | IDanmakuItem item = new DanmakuItem(this, new SpannableString(input), mDanmakuView.getWidth(),0,R.color.my_item_color,0,1);
102 | // IDanmakuItem item = new DanmakuItem(this, input, mDanmakuView.getWidth());
103 | // item.setTextColor(getResources().getColor(R.color.my_item_color));
104 | // item.setTextSize(14);
105 | // item.setTextColor(textColor);
106 | mDanmakuView.addItemToHead(item);
107 | }
108 | textEditText.setText("");
109 | break;
110 | }
111 | }
112 |
113 | }
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/em.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/sample/src/main/res/drawable/em.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
14 |
15 |
16 |
21 |
22 |
32 |
33 |
34 |
35 |
42 |
43 |
44 |
49 |
50 |
57 |
58 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 | #FF666666
3 | #ff0000
4 | #979b9a
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Danmaku Sample
3 |
4 | action_settings
5 | show
6 | hide
7 | send
8 | input text here
9 | please input text
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/screenshot/screenshot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linsea/OpenDanmaku/623af2dac8d7276ecf7d074bec8c3e6245c552fd/screenshot/screenshot.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':opendanmaku', ':sample'
2 |
--------------------------------------------------------------------------------