() {
84 | @Override
85 | public RichMessage createFromParcel(Parcel source) {
86 | return new RichMessage(source);
87 | }
88 |
89 | @Override
90 | public RichMessage[] newArray(int size) {
91 | return new RichMessage[size];
92 | }
93 | };
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/anbetter/danmuku/demo/model/RichTextParse.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.demo.model;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.BitmapDrawable;
7 | import android.text.Spannable;
8 | import android.text.SpannableStringBuilder;
9 | import android.text.Spanned;
10 | import android.text.TextUtils;
11 | import android.text.style.ForegroundColorSpan;
12 |
13 | import androidx.core.content.ContextCompat;
14 |
15 | import com.anbetter.danmuku.demo.R;
16 |
17 | import java.util.ArrayList;
18 |
19 |
20 | /**
21 | * 解析富文本
22 | *
23 | * Created by android_ls on 2016/11/25.
24 | */
25 |
26 | public class RichTextParse {
27 |
28 | public static SpannableStringBuilder parse(final Context context, ArrayList richText,
29 | int textSize, boolean isChatList) {
30 | final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
31 | if (isChatList) {
32 | String name = "直播消息:";
33 | spannableStringBuilder.append(name);
34 |
35 | int nameColor = ContextCompat.getColor(context, R.color.live_yellow);
36 | spannableStringBuilder.setSpan(new ForegroundColorSpan(nameColor),
37 | 0,
38 | name.length(),
39 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
40 | }
41 |
42 | for (RichMessage message : richText) {
43 | final int length = spannableStringBuilder.length();
44 | if ("text".equals(message.getType())) {
45 | String content = message.getContent();
46 | spannableStringBuilder.append(content);
47 |
48 | String textColor = message.getColor();
49 | if (TextUtils.isEmpty(textColor)) {
50 | textColor = "FFFFFF";
51 | }
52 |
53 | spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#" + textColor)),
54 | length,
55 | length + content.length(),
56 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
57 | } else if ("icon_gift".equals(message.getType())) {
58 | // 这里仅用于测试
59 | spannableStringBuilder.append("中奖礼物");
60 | final int imgSize = (int) (textSize * 1.5);
61 | Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.live_gift_cucumber)).getBitmap();
62 | LHImageSpan imageSpan = new LHImageSpan(context, bitmap, imgSize);
63 | spannableStringBuilder.setSpan(imageSpan,
64 | length,
65 | length + 4,
66 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
67 |
68 | // int gifId = message.getGift_id();
69 | // LiveGiftInfo gift = LiveGiftUtils.get().getGift(gifId);
70 | // if (gift != null && !TextUtils.isEmpty(gift.image)) {
71 | // spannableStringBuilder.append("中奖礼物");
72 | // final int imgSize = (int) (textSize * 1.5);
73 | // Phoenix.with(context)
74 | // .setUrl(gift.image)
75 | // .setWidth(imgSize)
76 | // .setHeight(imgSize)
77 | // .setResult(new IResult() {
78 | // @Override
79 | // public void onResult(Bitmap bitmap) {
80 | // LHImageSpan imageSpan = new LHImageSpan(context, bitmap, imgSize);
81 | // spannableStringBuilder.setSpan(imageSpan,
82 | // length,
83 | // length + 4,
84 | // Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
85 | //
86 | // }
87 | // })
88 | // .load();
89 | } else {
90 | String content = message.getContent();
91 | spannableStringBuilder.append(content);
92 |
93 | spannableStringBuilder.setSpan(
94 | new ForegroundColorSpan(ContextCompat.getColor(context,
95 | R.color.light_green)),
96 | length,
97 | length + content.length(),
98 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
99 | }
100 | }
101 |
102 | return spannableStringBuilder;
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_five.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_five.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_four.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_four.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_one.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_one.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_six.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_six.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_three.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_three.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_two.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_two.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_level_stage_zero.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/icon_level_stage_zero.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/live_gift_cucumber.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/drawable-xhdpi/live_gift_cucumber.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/corners_danmu.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
25 |
26 |
27 |
28 |
32 |
33 |
37 |
38 |
39 |
40 |
48 |
49 |
58 |
59 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #FFFFFF
9 | #89F9DF
10 | #E1AF4A
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Danmukulight
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | //./gradlew install
4 | //./gradlew bintrayUpload
5 |
6 | buildscript {
7 | repositories {
8 | jcenter()
9 | mavenCentral()
10 | google()
11 | }
12 |
13 | dependencies {
14 | classpath 'com.android.tools.build:gradle:4.1.2'
15 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
16 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
17 |
18 | // NOTE: Do not place your application dependencies here; they belong
19 | // in the individual module build.gradle files
20 | }
21 | }
22 |
23 | allprojects {
24 | repositories {
25 | jcenter()
26 | mavenCentral()
27 | google()
28 |
29 | maven {
30 | url 'https://dl.bintray.com/hpdx/maven/'
31 | }
32 | }
33 | }
34 |
35 | task clean(type: Delete) {
36 | delete rootProject.buildDir
37 | }
38 |
--------------------------------------------------------------------------------
/danmuku.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/danmuku.apk
--------------------------------------------------------------------------------
/danmukulight/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/danmukulight/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 23
11 | targetSdkVersion 30
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 |
28 | }
29 |
30 | //dependencies {
31 | // implementation 'com.anbetter:MLog:1.1.0'
32 | //}
33 |
34 | // Maven Group ID
35 | group = "com.anbetter"
36 | // library的版本号,后面每次更新都需要更改这个值
37 | version = "1.0.1"
38 |
39 | // 生成jar包的task
40 | task sourcesJar(type: Jar) {
41 | from android.sourceSets.main.java.srcDirs
42 | classifier = 'sources'
43 | }
44 |
45 | // 生成jarDoc的task
46 | task javadoc(type: Javadoc) {
47 | source = android.sourceSets.main.java.srcDirs
48 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
49 | options.encoding = "UTF-8"
50 | failOnError false // 忽略注释语法错误,如果用jdk1.8你的注释写的不规范就编译不过。
51 | }
52 |
53 | // 生成javaDoc的jar
54 | task javadocJar(type: Jar, dependsOn: javadoc) {
55 | classifier = 'javadoc'
56 | from javadoc.destinationDir
57 | }
58 |
59 | artifacts {
60 | archives javadocJar
61 | archives sourcesJar
62 | }
63 |
64 | install {
65 | repositories.mavenInstaller {
66 | pom.project {
67 | name 'danmukulight'
68 | description '基于Fresco的大图浏览库'
69 | url 'https://github.com/hpdx/DanmukuLight'
70 | inceptionYear '2016'
71 |
72 | packaging 'aar'
73 | groupId 'com.anbetter'
74 | artifactId 'danmukulight'
75 | version '1.0.1'
76 |
77 | licenses {
78 | license {
79 | name 'The Apache Software License, Version 2.0'
80 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
81 | distribution 'repo'
82 | }
83 | }
84 |
85 | scm {
86 | connection 'https://github.com/hpdx/DanmukuLight.git' // Git仓库地址。
87 | developerConnection 'https://github.com/hpdx/DanmukuLight.git' // Git仓库地址。
88 | url 'https://github.com/hpdx/DanmukuLight' // 项目主页。
89 | }
90 |
91 | developers {
92 | developer {
93 | id 'android_ls'
94 | name 'android_ls'
95 | email 'android_ls@163.com'
96 | }
97 | }
98 | }
99 | }
100 | }
101 |
102 | Properties properties = new Properties()
103 | // 读取properties的配置信息
104 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
105 |
106 | bintray {
107 | user = properties.getProperty("bintray.user")
108 | key = properties.getProperty("bintray.apikey")
109 | configurations = ['archives']
110 | pkg {
111 | repo = 'maven'
112 | name = 'danmukulight'
113 | userOrg = user
114 | licenses = ['Apache-2.0']
115 | websiteUrl = 'https://github.com/hpdx/DanmukuLight'
116 | vcsUrl = 'https://github.com/hpdx/DanmukuLight.git'
117 | publish = true
118 | publicDownloadNumbers = true
119 | }
120 | }
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/danmukulight/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 /Users/android_ls/Documents/Tool/adt-bundle-mac-x86_64-20130917/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 |
--------------------------------------------------------------------------------
/danmukulight/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/DanMuParentView.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.MotionEvent;
6 | import android.view.View;
7 | import android.widget.RelativeLayout;
8 |
9 | import com.anbetter.danmuku.view.IDanMuParent;
10 |
11 | /**
12 | * 弹幕需要处理事件的,请使用DanMuParentView作为DanMuView的根布局
13 | *
14 | * Created by android_ls on 2016/12/7.
15 | */
16 |
17 | public class DanMuParentView extends RelativeLayout {
18 |
19 | public DanMuParentView(Context context) {
20 | super(context);
21 | }
22 |
23 | public DanMuParentView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | @Override
28 | public boolean onInterceptTouchEvent(MotionEvent ev) {
29 | for (int i = 0; i < getChildCount(); i++) {
30 | View view = getChildAt(i);
31 | if (view instanceof IDanMuParent) {
32 | if (((IDanMuParent) view).hasCanTouchDanMus()) {
33 | view.bringToFront();
34 | view.getParent().requestDisallowInterceptTouchEvent(true);
35 | } else {
36 | moveChildToBack(view);
37 | }
38 | }
39 | }
40 | return super.onInterceptTouchEvent(ev);
41 | }
42 |
43 | public void moveChildToBack(View child) {
44 | int index = indexOfChild(child);
45 | if (index > 0) {
46 | detachViewFromParent(index);
47 | attachViewToParent(child, 0, child.getLayoutParams());
48 | }
49 | }
50 |
51 | @Override
52 | public boolean onTouchEvent(MotionEvent event) {
53 | return super.onTouchEvent(event);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/DanMuSurfaceView.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.PorterDuff;
7 | import android.os.Handler;
8 | import android.os.Message;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.SurfaceHolder;
12 | import android.view.SurfaceView;
13 |
14 | import com.anbetter.danmuku.control.DanMuController;
15 | import com.anbetter.danmuku.model.DanMuModel;
16 | import com.anbetter.danmuku.model.painter.DanMuPainter;
17 | import com.anbetter.danmuku.view.IDanMuParent;
18 | import com.anbetter.danmuku.view.OnDanMuParentViewTouchCallBackListener;
19 | import com.anbetter.danmuku.view.OnDanMuViewTouchListener;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * Created by android_ls on 2016/12/7.
26 | */
27 | public class DanMuSurfaceView extends SurfaceView implements IDanMuParent, SurfaceHolder.Callback {
28 |
29 | private SurfaceHolder mSurfaceHolder;
30 |
31 | private DanMuController danMuController;
32 | private ArrayList onDanMuViewTouchListeners = new ArrayList<>();
33 | private OnDanMuParentViewTouchCallBackListener onDanMuParentViewTouchCallBackListener;
34 |
35 | private boolean isSurfaceCreated = false;
36 |
37 | public DanMuSurfaceView(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | init();
40 | }
41 |
42 | private void init() {
43 | danMuController = new DanMuController(this);
44 | mSurfaceHolder = getHolder();
45 | mSurfaceHolder.addCallback(this);
46 | }
47 |
48 | private void prepare(Canvas canvas) {
49 | danMuController.prepare();
50 | onDanMuViewTouchListeners = new ArrayList<>();
51 | danMuController.initChannels(canvas);
52 | }
53 |
54 | private void addDanMuView(int index, final DanMuModel danMuView) {
55 | if (danMuView == null) {
56 | return;
57 | }
58 | if (danMuController != null) {
59 | if (danMuView.enableTouch()) {
60 | onDanMuViewTouchListeners.add(danMuView);
61 | }
62 | danMuController.addDanMuView(index, danMuView);
63 | }
64 | }
65 |
66 | public void addPainter(DanMuPainter danMuPainter, int key) {
67 | if (danMuController != null) {
68 | danMuController.addPainter(danMuPainter, key);
69 | }
70 | }
71 |
72 | public void setOnDanMuParentViewTouchCallBackListener(OnDanMuParentViewTouchCallBackListener onDanMuParentViewTouchCallBackListener) {
73 | this.onDanMuParentViewTouchCallBackListener = onDanMuParentViewTouchCallBackListener;
74 | }
75 |
76 | @Override
77 | public boolean hasCanTouchDanMus() {
78 | return onDanMuViewTouchListeners.size() > 0;
79 | }
80 |
81 | @Override
82 | public boolean onTouchEvent(MotionEvent event) {
83 | switch (event.getAction() & MotionEvent.ACTION_MASK) {
84 | case MotionEvent.ACTION_DOWN:
85 | break;
86 | case MotionEvent.ACTION_POINTER_DOWN:
87 | break;
88 | case MotionEvent.ACTION_POINTER_UP:
89 | break;
90 | case MotionEvent.ACTION_MOVE:
91 | break;
92 | case MotionEvent.ACTION_UP:
93 | handler.removeMessages(1);
94 | handler.sendEmptyMessage(1);
95 | int size = onDanMuViewTouchListeners.size();
96 | for (int i = 0; i < size; i++) {
97 | OnDanMuViewTouchListener onDanMuViewTouchListener = onDanMuViewTouchListeners.get(i);
98 | boolean onTouched = onDanMuViewTouchListener.onTouch(event.getX(), event.getY());
99 | if (((DanMuModel) onDanMuViewTouchListener).getOnTouchCallBackListener() != null && onTouched) {
100 | ((DanMuModel) onDanMuViewTouchListener).getOnTouchCallBackListener().callBack((DanMuModel) onDanMuViewTouchListener);
101 | return true;
102 | }
103 | }
104 | if (hasCanTouchDanMus()) {
105 | if (onDanMuParentViewTouchCallBackListener != null) {
106 | onDanMuParentViewTouchCallBackListener.hideControlPanel();
107 | }
108 | } else {
109 | if (onDanMuParentViewTouchCallBackListener != null) {
110 | onDanMuParentViewTouchCallBackListener.callBack();
111 | }
112 | }
113 | break;
114 | }
115 | return true;
116 | }
117 |
118 | private Handler handler = new Handler(new Handler.Callback() {
119 | @Override
120 | public boolean handleMessage(Message message) {
121 | switch (message.what) {
122 | case 1:
123 | if (onDanMuViewTouchListeners.size() > 0) {
124 | detectHasCanTouchedDanMus();
125 | handler.sendEmptyMessageDelayed(1, 100);
126 | } else {
127 | if (onDetectHasCanTouchedDanMusListener != null) {
128 | onDetectHasCanTouchedDanMusListener.hasNoCanTouchedDanMus(false);
129 | }
130 | }
131 | break;
132 | }
133 | return false;
134 | }
135 | });
136 |
137 | public void release() {
138 | onDetectHasCanTouchedDanMusListener = null;
139 | onDanMuParentViewTouchCallBackListener = null;
140 | clear();
141 | danMuController.release();
142 | danMuController = null;
143 | if (mSurfaceHolder != null) {
144 | mSurfaceHolder.removeCallback(this);
145 | }
146 | }
147 |
148 | @Override
149 | public void hideNormalDanMuView(boolean hide) {
150 | danMuController.hide(hide);
151 | }
152 |
153 | @Override
154 | public void hideAllDanMuView(boolean hideAll) {
155 | danMuController.hideAll(hideAll);
156 | }
157 |
158 | public interface OnDetectHasCanTouchedDanMusListener {
159 | void hasNoCanTouchedDanMus(boolean hasDanMus);
160 | }
161 |
162 | public OnDetectHasCanTouchedDanMusListener onDetectHasCanTouchedDanMusListener;
163 |
164 | public void setOnDanMuExistListener(OnDetectHasCanTouchedDanMusListener onDetectHasCanTouchedDanMusListener) {
165 | this.onDetectHasCanTouchedDanMusListener = onDetectHasCanTouchedDanMusListener;
166 | }
167 |
168 | public void detectHasCanTouchedDanMus() {
169 | for (int i = 0; i < onDanMuViewTouchListeners.size(); i++) {
170 | if (!((DanMuModel) onDanMuViewTouchListeners.get(i)).isAlive()) {
171 | onDanMuViewTouchListeners.remove(i);
172 | i--;
173 | }
174 | }
175 | if (onDanMuViewTouchListeners.size() == 0) {
176 | if (onDetectHasCanTouchedDanMusListener != null) {
177 | onDetectHasCanTouchedDanMusListener.hasNoCanTouchedDanMus(false);
178 | }
179 | } else {
180 | if (onDetectHasCanTouchedDanMusListener != null) {
181 | onDetectHasCanTouchedDanMusListener.hasNoCanTouchedDanMus(true);
182 | }
183 | }
184 | }
185 |
186 | @Override
187 | public void add(DanMuModel danMuView) {
188 | addDanMuView(-1, danMuView);
189 | }
190 |
191 | @Override
192 | public void add(int index, DanMuModel danMuView) {
193 | addDanMuView(index, danMuView);
194 | }
195 |
196 | @Override
197 | public void jumpQueue(List danMuViews) {
198 | danMuController.jumpQueue(danMuViews);
199 | }
200 |
201 | @Override
202 | public void addAllTouchListener(List danMuViews) {
203 | this.onDanMuViewTouchListeners.addAll(danMuViews);
204 | }
205 |
206 | public void lockDraw() {
207 | if (!isSurfaceCreated) {
208 | return;
209 | }
210 | Canvas canvas = mSurfaceHolder.lockCanvas();
211 | if (canvas == null) {
212 | return;
213 | }
214 |
215 | canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
216 |
217 | if (danMuController != null) {
218 | danMuController.draw(canvas);
219 | }
220 |
221 | if (isSurfaceCreated) {
222 | mSurfaceHolder.unlockCanvasAndPost(canvas);
223 | }
224 | }
225 |
226 | @Override
227 | public void forceSleep() {
228 | danMuController.forceSleep();
229 | }
230 |
231 | @Override
232 | public void forceWake() {
233 | danMuController.forceWake();
234 | }
235 |
236 | @Override
237 | public void clear() {
238 | onDanMuViewTouchListeners.clear();
239 | }
240 |
241 | @Override
242 | public void remove(DanMuModel danMuView) {
243 | onDanMuViewTouchListeners.remove(danMuView);
244 | }
245 |
246 | @Override
247 | protected void onDraw(Canvas canvas) {
248 | super.onDraw(canvas);
249 | }
250 |
251 | @Override
252 | public void surfaceCreated(SurfaceHolder holder) {
253 | isSurfaceCreated = true;
254 | Canvas canvas = mSurfaceHolder.lockCanvas();
255 | prepare(canvas);
256 | mSurfaceHolder.unlockCanvasAndPost(canvas);
257 | }
258 |
259 | @Override
260 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
261 | }
262 |
263 | @Override
264 | public void surfaceDestroyed(SurfaceHolder holder) {
265 | isSurfaceCreated = false;
266 | }
267 |
268 | }
269 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/DanMuView.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.os.Build;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 |
10 | import com.anbetter.danmuku.control.DanMuController;
11 | import com.anbetter.danmuku.control.speed.SpeedController;
12 | import com.anbetter.danmuku.model.DanMuModel;
13 | import com.anbetter.danmuku.view.IDanMuParent;
14 | import com.anbetter.danmuku.view.OnDanMuParentViewTouchCallBackListener;
15 | import com.anbetter.danmuku.view.OnDanMuViewTouchListener;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * Created by android_ls on 2016/12/7.
22 | */
23 | public class DanMuView extends View implements IDanMuParent {
24 |
25 | private DanMuController danMuController;
26 | private volatile ArrayList onDanMuViewTouchListeners;
27 | private OnDanMuParentViewTouchCallBackListener onDanMuParentViewTouchCallBackListener;
28 | private boolean drawFinished = false;
29 |
30 | private Object lock = new Object();
31 |
32 | public DanMuView(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | init(context);
35 | }
36 |
37 | @Override
38 | public void jumpQueue(List danMuViews) {
39 | danMuController.jumpQueue(danMuViews);
40 | }
41 |
42 | @Override
43 | public void addAllTouchListener(List onDanMuTouchCallBackListeners) {
44 | this.onDanMuViewTouchListeners.addAll(onDanMuTouchCallBackListeners);
45 | }
46 |
47 | public DanMuView(Context context, AttributeSet attrs, int defStyle) {
48 | super(context, attrs, defStyle);
49 | init(context);
50 | }
51 |
52 | private void init(Context context) {
53 | onDanMuViewTouchListeners = new ArrayList<>();
54 | if (danMuController == null) {
55 | danMuController = new DanMuController(this);
56 | }
57 | }
58 |
59 | public void prepare() {
60 | prepare(null);
61 | }
62 |
63 | public void prepare(SpeedController speedController) {
64 | if (danMuController != null) {
65 | danMuController.setSpeedController(speedController);
66 | danMuController.prepare();
67 | }
68 | }
69 |
70 | public void release() {
71 | onDetectHasCanTouchedDanMusListener = null;
72 | onDanMuParentViewTouchCallBackListener = null;
73 | clear();
74 | if (danMuController != null) {
75 | danMuController.release();
76 | }
77 | danMuController = null;
78 | }
79 |
80 | private void addDanMuView(final DanMuModel danMuView) {
81 | if (danMuView == null) {
82 | return;
83 | }
84 | if (danMuController != null) {
85 | if (danMuView.enableTouch()) {
86 | onDanMuViewTouchListeners.add(danMuView);
87 | }
88 | danMuController.addDanMuView(-1, danMuView);
89 | }
90 | }
91 |
92 | public void setOnDanMuParentViewTouchCallBackListener(OnDanMuParentViewTouchCallBackListener onDanMuParentViewTouchCallBackListener) {
93 | this.onDanMuParentViewTouchCallBackListener = onDanMuParentViewTouchCallBackListener;
94 | }
95 |
96 | @Override
97 | public boolean hasCanTouchDanMus() {
98 | return onDanMuViewTouchListeners.size() > 0;
99 | }
100 |
101 | @Override
102 | public boolean onTouchEvent(MotionEvent event) {
103 | if (hasCanTouchDanMus()) {
104 | getParent().requestDisallowInterceptTouchEvent(true);
105 | }
106 | switch (event.getAction() & MotionEvent.ACTION_MASK) {
107 | case MotionEvent.ACTION_DOWN:
108 | break;
109 | case MotionEvent.ACTION_POINTER_DOWN:
110 | break;
111 | case MotionEvent.ACTION_POINTER_UP:
112 | break;
113 | case MotionEvent.ACTION_MOVE:
114 | break;
115 | case MotionEvent.ACTION_UP:
116 | int size = onDanMuViewTouchListeners.size();
117 | for (int i = 0; i < size; i++) {
118 | OnDanMuViewTouchListener onDanMuViewTouchListener = onDanMuViewTouchListeners.get(i);
119 | boolean onTouched = onDanMuViewTouchListener.onTouch(event.getX(), event.getY());
120 | if (((DanMuModel) onDanMuViewTouchListener).getOnTouchCallBackListener() != null && onTouched) {
121 | ((DanMuModel) onDanMuViewTouchListener).getOnTouchCallBackListener().callBack((DanMuModel) onDanMuViewTouchListener);
122 | return true;
123 | }
124 | }
125 | if (!hasCanTouchDanMus()) {
126 | if (onDanMuParentViewTouchCallBackListener != null) {
127 | onDanMuParentViewTouchCallBackListener.callBack();
128 | }
129 | } else {
130 | if (onDanMuParentViewTouchCallBackListener != null) {
131 | onDanMuParentViewTouchCallBackListener.hideControlPanel();
132 | }
133 | }
134 | break;
135 | }
136 | return true;
137 | }
138 |
139 | @Override
140 | public void add(DanMuModel danMuView) {
141 | danMuView.enableMoving(true);
142 | addDanMuView(danMuView);
143 | }
144 |
145 | public void lockDraw() {
146 | if (!danMuController.isChannelCreated()) {
147 | return;
148 | }
149 | synchronized (lock) {
150 | if (Build.VERSION.SDK_INT >= 16) {
151 | this.postInvalidateOnAnimation();
152 | } else {
153 | this.postInvalidate();
154 | }
155 | if ((!drawFinished)) {
156 | try {
157 | lock.wait();
158 | } catch (InterruptedException e) {
159 | }
160 | }
161 | drawFinished = false;
162 | }
163 | }
164 |
165 | @Override
166 | public void forceSleep() {
167 | danMuController.forceSleep();
168 | }
169 |
170 | @Override
171 | public void forceWake() {
172 | danMuController.forceWake();
173 | }
174 |
175 | private void unLockDraw() {
176 | synchronized (lock) {
177 | drawFinished = true;
178 | lock.notifyAll();
179 | }
180 | }
181 |
182 | @Override
183 | public void clear() {
184 | onDanMuViewTouchListeners.clear();
185 | }
186 |
187 | @Override
188 | public void remove(DanMuModel danMuView) {
189 | onDanMuViewTouchListeners.remove(danMuView);
190 | }
191 |
192 | public interface OnDetectHasCanTouchedDanMusListener {
193 | void hasNoCanTouchedDanMus(boolean hasDanMus);
194 | }
195 |
196 | public void detectHasCanTouchedDanMus() {
197 | for (int i = 0; i < onDanMuViewTouchListeners.size(); i++) {
198 | if (!((DanMuModel) onDanMuViewTouchListeners.get(i)).isAlive()) {
199 | onDanMuViewTouchListeners.remove(i);
200 | i--;
201 | }
202 | }
203 | if (onDanMuViewTouchListeners.size() == 0) {
204 | if (onDetectHasCanTouchedDanMusListener != null) {
205 | onDetectHasCanTouchedDanMusListener.hasNoCanTouchedDanMus(false);
206 | }
207 | } else {
208 | if (onDetectHasCanTouchedDanMusListener != null) {
209 | onDetectHasCanTouchedDanMusListener.hasNoCanTouchedDanMus(true);
210 | }
211 | }
212 | }
213 |
214 | @Override
215 | public void hideNormalDanMuView(boolean hide) {
216 | danMuController.hide(hide);
217 | }
218 |
219 | @Override
220 | public void hideAllDanMuView(boolean hideAll) {
221 | danMuController.hideAll(hideAll);
222 | }
223 |
224 | @Override
225 | protected void onDraw(Canvas canvas) {
226 | super.onDraw(canvas);
227 | detectHasCanTouchedDanMus();
228 | if (danMuController != null) {
229 | danMuController.initChannels(canvas);
230 | danMuController.draw(canvas);
231 | }
232 | unLockDraw();
233 | }
234 |
235 | @Override
236 | public void add(int index, DanMuModel danMuView) {
237 | danMuController.addDanMuView(index, danMuView);
238 | }
239 |
240 | public OnDetectHasCanTouchedDanMusListener onDetectHasCanTouchedDanMusListener;
241 |
242 | public void setOnDanMuExistListener(OnDetectHasCanTouchedDanMusListener onDetectHasCanTouchedDanMusListener) {
243 | this.onDetectHasCanTouchedDanMusListener = onDetectHasCanTouchedDanMusListener;
244 | }
245 | }
246 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/control/DanMuController.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.control;
2 |
3 | import android.graphics.Canvas;
4 | import android.view.View;
5 |
6 | import com.anbetter.danmuku.control.dispatcher.DanMuDispatcher;
7 | import com.anbetter.danmuku.control.speed.RandomSpeedController;
8 | import com.anbetter.danmuku.control.speed.SpeedController;
9 | import com.anbetter.danmuku.model.DanMuModel;
10 | import com.anbetter.danmuku.model.channel.DanMuPoolManager;
11 | import com.anbetter.danmuku.model.painter.DanMuPainter;
12 | import com.anbetter.danmuku.view.IDanMuParent;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Created by android_ls on 2016/12/7.
18 | */
19 | public final class DanMuController {
20 |
21 | private DanMuPoolManager danMuPoolManager;
22 | private DanMuDispatcher danMuRandomDispatcher;
23 | private SpeedController speedController;
24 | private boolean channelCreated = false;
25 |
26 | public DanMuController(View view) {
27 | if (speedController == null) {
28 | speedController = new RandomSpeedController();
29 | }
30 | if (danMuPoolManager == null) {
31 | danMuPoolManager = new DanMuPoolManager(view.getContext(), (IDanMuParent) view);
32 | }
33 | if (danMuRandomDispatcher == null) {
34 | danMuRandomDispatcher = new DanMuDispatcher(view.getContext());
35 | }
36 | danMuPoolManager.setDispatcher(danMuRandomDispatcher);
37 | }
38 |
39 | public void forceSleep() {
40 | danMuPoolManager.forceSleep();
41 | }
42 |
43 | public void forceWake() {
44 | if (danMuPoolManager != null) {
45 | danMuPoolManager.releaseForce();
46 | }
47 | }
48 |
49 | public void setSpeedController(SpeedController speedController) {
50 | if (speedController != null) {
51 | this.speedController = speedController;
52 | }
53 | }
54 |
55 | public void prepare() {
56 | danMuPoolManager.startEngine();
57 | }
58 |
59 | public void addDanMuView(int index, DanMuModel danMuView) {
60 | danMuPoolManager.addDanMuView(index, danMuView);
61 | }
62 |
63 | public void jumpQueue(List danMuViews) {
64 | danMuPoolManager.jumpQueue(danMuViews);
65 | }
66 |
67 | public void addPainter(DanMuPainter danMuPainter, int key) {
68 | danMuPoolManager.addPainter(danMuPainter, key);
69 | }
70 |
71 | public boolean isChannelCreated() {
72 | return channelCreated;
73 | }
74 |
75 | public void hide(boolean hide) {
76 | if (danMuPoolManager != null) {
77 | danMuPoolManager.hide(hide);
78 | }
79 | }
80 |
81 | public void hideAll(boolean hideAll) {
82 | if (danMuPoolManager != null) {
83 | danMuPoolManager.hideAll(hideAll);
84 | }
85 | }
86 |
87 | public void initChannels(Canvas canvas) {
88 | if (!channelCreated) {
89 | speedController.setWidthPixels(canvas.getWidth());
90 | danMuPoolManager.setSpeedController(speedController);
91 | danMuPoolManager.divide(canvas.getWidth(), canvas.getHeight());
92 | channelCreated = true;
93 | }
94 | }
95 |
96 | public void draw(Canvas canvas) {
97 | danMuPoolManager.drawDanMus(canvas);
98 | }
99 |
100 | public void release() {
101 | if (danMuPoolManager != null) {
102 | danMuPoolManager.release();
103 | danMuPoolManager = null;
104 | }
105 | if (danMuRandomDispatcher != null) {
106 | danMuRandomDispatcher.release();
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/control/dispatcher/DanMuDispatcher.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.control.dispatcher;
2 |
3 | import android.content.Context;
4 | import android.text.Layout;
5 | import android.text.StaticLayout;
6 | import android.text.TextPaint;
7 | import android.text.TextUtils;
8 |
9 | import com.anbetter.danmuku.model.DanMuModel;
10 | import com.anbetter.danmuku.model.channel.DanMuChannel;
11 | import com.anbetter.danmuku.model.utils.PaintUtils;
12 |
13 | import java.util.Random;
14 |
15 | /**
16 | * Created by android_ls on 2016/12/7.
17 | */
18 | public class DanMuDispatcher implements IDanMuDispatcher {
19 |
20 | private Context context;
21 | protected TextPaint paint;
22 | private Random random = new Random();
23 |
24 | public DanMuDispatcher(Context context) {
25 | this.context = context;
26 | paint = PaintUtils.getPaint();
27 | }
28 |
29 | @Override
30 | public synchronized void dispatch(DanMuModel danMuView, DanMuChannel[] danMuChannels) {
31 | if (!danMuView.isAttached() && danMuChannels != null) {
32 | int index = selectChannelRandomly(danMuChannels);
33 | danMuView.selectChannel(index);
34 | DanMuChannel danMuChannel = danMuChannels[index];
35 | if (danMuChannel == null) {
36 | return;
37 | }
38 |
39 | measure(danMuView, danMuChannel);
40 | }
41 | }
42 |
43 | private int selectChannelRandomly(DanMuChannel[] danMuChannels) {
44 | return random.nextInt(danMuChannels.length);
45 | }
46 |
47 | private void measure(DanMuModel danMuView, DanMuChannel danMuChannel) {
48 | if (danMuView.isMeasured()) {
49 | return;
50 | }
51 |
52 | CharSequence text = danMuView.text;
53 | if(!TextUtils.isEmpty(text)) {
54 | paint.setTextSize(danMuView.textSize);
55 | StaticLayout staticLayout = new StaticLayout(text,
56 | paint,
57 | (int) Math.ceil(StaticLayout.getDesiredWidth(text, paint)),
58 | Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
59 |
60 | float textWidth = danMuView.getX()
61 | + danMuView.marginLeft
62 | + danMuView.avatarWidth
63 | + danMuView.levelMarginLeft
64 | + danMuView.levelBitmapWidth
65 | + danMuView.textMarginLeft
66 | + staticLayout.getWidth()
67 | + danMuView.textBackgroundPaddingRight;
68 | danMuView.setWidth((int) textWidth);
69 |
70 | float textHeight = staticLayout.getHeight()
71 | + danMuView.textBackgroundPaddingTop
72 | + danMuView.textBackgroundPaddingBottom;
73 | if(danMuView.avatar != null && danMuView.avatarHeight > textHeight) {
74 | danMuView.setHeight((int)(danMuView.getY() + danMuView.avatarHeight));
75 | } else {
76 | danMuView.setHeight((int)(danMuView.getY() + textHeight));
77 | }
78 | }
79 |
80 | if (danMuView.getDisplayType() == DanMuModel.RIGHT_TO_LEFT) {
81 | danMuView.setStartPositionX(danMuChannel.width);
82 | } else if (danMuView.getDisplayType() == DanMuModel.LEFT_TO_RIGHT) {
83 | danMuView.setStartPositionX(-danMuView.getWidth());
84 | }
85 |
86 | danMuView.setMeasured(true);
87 | danMuView.setStartPositionY(danMuChannel.topY);
88 | danMuView.setAlive(true);
89 | }
90 |
91 | public void release() {
92 | context = null;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/control/dispatcher/IDanMuDispatcher.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.control.dispatcher;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 | import com.anbetter.danmuku.model.channel.DanMuChannel;
5 |
6 | /**
7 | * Created by android_ls on 2016/12/7.
8 | */
9 | public interface IDanMuDispatcher {
10 |
11 | void dispatch(DanMuModel iDanMuView, DanMuChannel[] danMuChannels);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/control/speed/RandomSpeedController.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.control.speed;
2 |
3 | /**
4 | * Created by android_ls on 2016/12/7.
5 | */
6 | public final class RandomSpeedController implements SpeedController {
7 |
8 | private final static int RATE = 1000;
9 |
10 | private static float MAX_SPEED = 3.5f;
11 |
12 | private static float MIN_SPEED = 8.5f;
13 |
14 | private float width;
15 |
16 | @Override
17 | public void setWidthPixels(int width) {
18 | this.width = width;
19 | }
20 |
21 | @Override
22 | public float getSpeed() {
23 | return (float)(((Math.random() * (MAX_SPEED - MIN_SPEED) + MIN_SPEED)) / RATE) * width;
24 | }
25 |
26 | public float getMaxSpeed() {
27 | return MAX_SPEED;
28 | }
29 |
30 | public float getMinSpeed() {
31 | return MIN_SPEED;
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/control/speed/SpeedController.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.control.speed;
2 |
3 | /**
4 | * Created by android_ls on 2016/12/7.
5 | */
6 | public interface SpeedController {
7 |
8 | void setWidthPixels(int width);
9 | float getSpeed();
10 | float getMaxSpeed();
11 | float getMinSpeed();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/DanMuModel.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.anbetter.danmuku.view.OnDanMuTouchCallBackListener;
7 | import com.anbetter.danmuku.view.OnDanMuViewTouchListener;
8 |
9 | /**
10 | * Created by android_ls on 2016/12/7.
11 | */
12 | public class DanMuModel implements OnDanMuViewTouchListener {
13 |
14 | public final static int RIGHT_TO_LEFT = 1;
15 |
16 | public final static int LEFT_TO_RIGHT = 2;
17 |
18 | /**
19 | * priority
20 | */
21 | public final static int SYSTEM = 100;
22 |
23 | public final static int NORMAL = 50;
24 |
25 | /**
26 | * 弹幕左边内间距
27 | */
28 | public int paddingLeft;
29 |
30 | /**
31 | * 弹幕右边内间距
32 | */
33 | public int paddingRight;
34 |
35 | /**
36 | * 弹幕距离左边的外边距
37 | */
38 | public int marginLeft;
39 |
40 | /**
41 | * 弹幕距离右边的外边距
42 | */
43 | public int marginRight;
44 |
45 |
46 | /**
47 | * 用户图像
48 | */
49 | public Bitmap avatar;
50 |
51 | /**
52 | * 用户图像宽
53 | */
54 | public int avatarWidth;
55 |
56 | /**
57 | * 用户图像高
58 | */
59 | public int avatarHeight;
60 |
61 | /**
62 | * 用户图像描边(默认是白色的描边)
63 | */
64 | public boolean avatarStrokes = true;
65 |
66 |
67 | /**
68 | * 用户等级标签
69 | */
70 | public Bitmap levelBitmap;
71 |
72 | /**
73 | * 用户等级标签宽
74 | */
75 | public int levelBitmapWidth;
76 |
77 | /**
78 | * 用户等级标签高
79 | */
80 | public int levelBitmapHeight;
81 |
82 | /**
83 | * 用户等级标签距离左边的外边距
84 | */
85 | public int levelMarginLeft;
86 |
87 |
88 | /**
89 | * 用户等级标签文本
90 | */
91 | public CharSequence levelText;
92 |
93 | /**
94 | * 用户等级标签文本,字体大小
95 | */
96 | public float levelTextSize;
97 |
98 | /**
99 | * 用户等级标签文本,字体颜色
100 | */
101 | public int levelTextColor;
102 |
103 |
104 | /**
105 | * 弹幕文本内容(支持富文本)
106 | */
107 | public CharSequence text;
108 |
109 | /**
110 | * 弹幕文本内容(支持富文本),字体大小
111 | */
112 | public float textSize;
113 |
114 | /**
115 | * 弹幕文本内容(支持富文本),字体颜色
116 | */
117 | public int textColor;
118 |
119 | /**
120 | * 弹幕文本内容(支持富文本),距离左边的外边距
121 | */
122 | public int textMarginLeft;
123 |
124 |
125 | /**
126 | * 弹幕文本背景图
127 | */
128 | public Drawable textBackground;
129 |
130 | /**
131 | * 弹幕文本背景图,距离左边的外边距
132 | */
133 | public int textBackgroundMarginLeft;
134 |
135 | /**
136 | * 弹幕文本背景图,距离上边的内边距
137 | */
138 | public int textBackgroundPaddingTop;
139 |
140 | /**
141 | * 弹幕文本背景图,距离下边的内边距
142 | */
143 | public int textBackgroundPaddingBottom;
144 |
145 | /**
146 | * 弹幕文本背景图,距离左边的内边距
147 | */
148 | public int textBackgroundPaddingLeft;
149 |
150 | /**
151 | * 弹幕文本背景图,距离右边的内边距
152 | */
153 | public int textBackgroundPaddingRight;
154 |
155 | private float startPositionX = -1;
156 | private float startPositionY = -1;
157 | private float speed;
158 |
159 | private int width;
160 | private int height;
161 | private boolean enableTouch;
162 | private int channelIndex;
163 | private boolean isMoving = true;
164 | private boolean isAlive = true;
165 | private OnDanMuTouchCallBackListener onTouchCallBackListener;
166 | private int displayType;
167 | private boolean attached;
168 | private int priority = NORMAL;
169 |
170 | private boolean isMeasured;
171 |
172 | public DanMuModel() {
173 | }
174 |
175 | public float getX() {
176 | return this.startPositionX;
177 | }
178 |
179 | public float getY() {
180 | return this.startPositionY;
181 | }
182 |
183 | public float getSpeed() {
184 | return this.speed;
185 | }
186 |
187 | public void setSpeed(float speed) {
188 | this.speed = speed;
189 | }
190 |
191 | public boolean isAlive() {
192 | return isAlive;
193 | }
194 |
195 | public void setAlive(boolean isAlive) {
196 | if(!isAlive) {
197 | release();
198 | }
199 |
200 | this.isAlive = isAlive;
201 | }
202 |
203 | public int getWidth() {
204 | return this.width;
205 | }
206 |
207 | public void setWidth(int width) {
208 | this.width = width;
209 | }
210 |
211 | public int getHeight() {
212 | return this.height;
213 | }
214 |
215 | public void setHeight(int height) {
216 | this.height = height;
217 | }
218 |
219 | public OnDanMuTouchCallBackListener getOnTouchCallBackListener() {
220 | return this.onTouchCallBackListener;
221 | }
222 |
223 | public void setOnTouchCallBackListener(OnDanMuTouchCallBackListener onTouchCallBackListener) {
224 | this.onTouchCallBackListener = onTouchCallBackListener;
225 | }
226 |
227 | public void enableTouch(boolean enableTouch) {
228 | this.enableTouch = enableTouch;
229 | }
230 |
231 | public boolean enableTouch() {
232 | return this.enableTouch;
233 | }
234 |
235 | public void selectChannel(int index) {
236 | this.channelIndex = index;
237 | }
238 |
239 | public int getChannelIndex() {
240 | return this.channelIndex;
241 | }
242 |
243 | public void enableMoving(boolean isMoving) {
244 | this.isMoving = isMoving;
245 | }
246 |
247 | public boolean isMoving() {
248 | return this.isMoving;
249 | }
250 |
251 | public boolean onTouch(float x, float y) {
252 | if (x >= getX() && x <= getX() + getWidth() && y >= getY() && y <= getY() + getHeight()) {
253 | return true;
254 | } else {
255 | return false;
256 | }
257 | }
258 |
259 | public void release() {
260 | this.avatar = null;
261 | this.levelBitmap = null;
262 | this.textBackground = null;
263 | this.onTouchCallBackListener = null;
264 | }
265 |
266 | public int getDisplayType() {
267 | return displayType;
268 | }
269 |
270 | public void setDisplayType(int displayType) {
271 | this.displayType = displayType;
272 | }
273 |
274 | public void setStartPositionX(float startPositionX) {
275 | this.startPositionX = startPositionX;
276 | }
277 |
278 | public void setStartPositionY(float startPositionY) {
279 | this.startPositionY = startPositionY;
280 | }
281 |
282 | public boolean isAttached() {
283 | return attached;
284 | }
285 |
286 | public void setAttached(boolean attached) {
287 | this.attached = attached;
288 | }
289 |
290 | public int getPriority() {
291 | return priority;
292 | }
293 |
294 | public void setPriority(int priority) {
295 | if (priority != NORMAL && priority != SYSTEM) {
296 | throw new IllegalArgumentException("there's no such number of priority");
297 | }
298 | this.priority = priority;
299 | }
300 |
301 | public boolean isMeasured() {
302 | return isMeasured;
303 | }
304 |
305 | public void setMeasured(boolean measured) {
306 | isMeasured = measured;
307 | }
308 |
309 | }
310 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/channel/DanMuChannel.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.channel;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 |
5 | /**
6 | * Created by android_ls on 2016/12/7.
7 | */
8 | public class DanMuChannel {
9 |
10 | public float speed = 3;
11 | public int width;
12 | public int height;
13 | public int topY;
14 | public int space = 60;
15 |
16 | public DanMuModel r2lReferenceView;
17 | public DanMuModel l2rReferenceView;
18 |
19 | public void dispatch(DanMuModel danMuView) {
20 | if (danMuView.isAttached()) {
21 | return;
22 | }
23 |
24 | danMuView.setSpeed(speed);
25 | if (danMuView.getDisplayType() == DanMuModel.RIGHT_TO_LEFT) {
26 | int mDeltaX = 0;
27 | if (r2lReferenceView != null) {
28 | mDeltaX = (int) (width - r2lReferenceView.getX() - r2lReferenceView.getWidth());
29 | }
30 | if (r2lReferenceView == null || !r2lReferenceView.isAlive() || mDeltaX > space) {
31 | danMuView.setAttached(true);
32 | r2lReferenceView = danMuView;
33 | }
34 | } else if (danMuView.getDisplayType() == DanMuModel.LEFT_TO_RIGHT) {
35 | int mDeltaX = 0;
36 | if (l2rReferenceView != null) {
37 | mDeltaX = (int) l2rReferenceView.getX();
38 | }
39 | if (l2rReferenceView == null || !l2rReferenceView.isAlive() || mDeltaX > space) {
40 | danMuView.setAttached(true);
41 | l2rReferenceView = danMuView;
42 | }
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/channel/DanMuPoolManager.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.channel;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 |
6 | import com.anbetter.danmuku.control.dispatcher.IDanMuDispatcher;
7 | import com.anbetter.danmuku.control.speed.SpeedController;
8 | import com.anbetter.danmuku.model.DanMuModel;
9 | import com.anbetter.danmuku.model.collection.DanMuConsumedPool;
10 | import com.anbetter.danmuku.model.collection.DanMuConsumer;
11 | import com.anbetter.danmuku.model.collection.DanMuProducedPool;
12 | import com.anbetter.danmuku.model.collection.DanMuProducer;
13 | import com.anbetter.danmuku.model.painter.DanMuPainter;
14 | import com.anbetter.danmuku.view.IDanMuParent;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | * Created by android_ls on 2016/12/7.
20 | */
21 | public class DanMuPoolManager implements IDanMuPoolManager {
22 |
23 | private DanMuConsumer danMuConsumer;
24 | private DanMuProducer danMuProducer;
25 |
26 | private DanMuConsumedPool danMuConsumedPool;
27 | private DanMuProducedPool danMuProducedPool;
28 |
29 | private boolean isStart;
30 |
31 | public DanMuPoolManager(Context context, IDanMuParent danMuParent) {
32 | danMuConsumedPool = new DanMuConsumedPool(context);
33 | danMuProducedPool = new DanMuProducedPool(context);
34 | danMuConsumer = new DanMuConsumer(danMuConsumedPool, danMuParent);
35 | danMuProducer = new DanMuProducer(danMuProducedPool, danMuConsumedPool);
36 | }
37 |
38 | public void forceSleep() {
39 | danMuConsumer.forceSleep();
40 | }
41 |
42 | public void releaseForce() {
43 | danMuConsumer.releaseForce();
44 | }
45 |
46 | @Override
47 | public void hide(boolean hide) {
48 | danMuConsumedPool.hide(hide);
49 | }
50 |
51 | @Override
52 | public void hideAll(boolean hideAll) {
53 | danMuConsumedPool.hideAll(hideAll);
54 | }
55 |
56 | @Override
57 | public void startEngine() {
58 | if (!isStart) {
59 | isStart = true;
60 | danMuConsumer.start();
61 | danMuProducer.start();
62 | }
63 | }
64 |
65 | @Override
66 | public void setDispatcher(IDanMuDispatcher iDanMuDispatcher) {
67 | danMuProducedPool.setDanMuDispatcher(iDanMuDispatcher);
68 | }
69 |
70 | @Override
71 | public void setSpeedController(SpeedController speedController) {
72 | danMuConsumedPool.setSpeedController(speedController);
73 | }
74 |
75 | @Override
76 | public void divide(int width, int height) {
77 | danMuProducedPool.divide(width, height);
78 | danMuConsumedPool.divide(width,height);
79 | }
80 |
81 | @Override
82 | public void addDanMuView(int index, DanMuModel danMuView) {
83 | danMuProducer.produce(index, danMuView);
84 | }
85 |
86 | @Override
87 | public void jumpQueue(List danMuViews) {
88 | danMuProducer.jumpQueue(danMuViews);
89 | }
90 |
91 | public void release() {
92 | isStart = false;
93 | danMuConsumer.release();
94 | danMuProducer.release();
95 | danMuConsumedPool = null;
96 | }
97 |
98 | /**
99 | * drawing entrance
100 | *
101 | * @param canvas
102 | */
103 | public void drawDanMus(Canvas canvas) {
104 | danMuConsumer.consume(canvas);
105 | }
106 |
107 | public void addPainter(DanMuPainter danMuPainter, int key) {
108 | danMuConsumedPool.addPainter(danMuPainter, key);
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/channel/IDanMuPoolManager.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.channel;
2 |
3 | import com.anbetter.danmuku.control.dispatcher.IDanMuDispatcher;
4 | import com.anbetter.danmuku.control.speed.SpeedController;
5 | import com.anbetter.danmuku.model.DanMuModel;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by android_ls on 2016/12/7.
11 | */
12 | interface IDanMuPoolManager {
13 | void setSpeedController(SpeedController speedController);
14 |
15 | void addDanMuView(int index, DanMuModel iDanMuView);
16 |
17 | void jumpQueue(List danMuViews);
18 |
19 | void divide(int width, int height);
20 |
21 | void setDispatcher(IDanMuDispatcher iDanMuDispatcher);
22 |
23 | void hide(boolean hide);
24 |
25 | void hideAll(boolean hideAll);
26 |
27 | void startEngine();
28 | }
29 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/collection/DanMuConsumedPool.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.collection;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 |
6 | import com.anbetter.danmuku.control.speed.SpeedController;
7 | import com.anbetter.danmuku.model.DanMuModel;
8 | import com.anbetter.danmuku.model.channel.DanMuChannel;
9 | import com.anbetter.danmuku.model.painter.DanMuPainter;
10 | import com.anbetter.danmuku.model.painter.L2RPainter;
11 | import com.anbetter.danmuku.model.painter.R2LPainter;
12 | import com.anbetter.danmuku.model.utils.DimensionUtil;
13 |
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.Iterator;
17 | import java.util.Set;
18 |
19 | /**
20 | * Created by android_ls on 2016/12/7.
21 | */
22 | public final class DanMuConsumedPool {
23 |
24 | private final static int MAX_COUNT_IN_SCREEN = 30;
25 |
26 | private final static int DEFAULT_SINGLE_CHANNEL_HEIGHT = 40;
27 |
28 | private HashMap danMuPainterHashMap = new HashMap<>();
29 |
30 | private volatile ArrayList mixedDanMuViewQueue = new ArrayList<>();
31 |
32 | private boolean isDrawing;
33 |
34 | private DanMuChannel[] danMuChannels;
35 |
36 | private SpeedController speedController;
37 |
38 | private Context context;
39 |
40 | public DanMuConsumedPool(Context c) {
41 | context = c.getApplicationContext();
42 | initDefaultPainters();
43 | hide(false);
44 | }
45 |
46 | public void setSpeedController(SpeedController speedController) {
47 | this.speedController = speedController;
48 | }
49 |
50 | public void addPainter(DanMuPainter danMuPainter, int key) {
51 | if (danMuPainter == null) {
52 | return;
53 | }
54 | if (!danMuPainterHashMap.containsKey(key)) {
55 | danMuPainterHashMap.put(key, danMuPainter);
56 | } else {
57 | throw new IllegalArgumentException("Already has the key of painter");
58 | }
59 | }
60 |
61 | public void hide(boolean hide) {
62 | Set danMuPainters = danMuPainterHashMap.keySet();
63 | Iterator iterator = danMuPainters.iterator();
64 | while (iterator.hasNext()) {
65 | Integer key = iterator.next();
66 | danMuPainterHashMap.get(key).hideNormal(hide);
67 | }
68 | }
69 |
70 | public void hideAll(boolean hide) {
71 | Set danMuPainters = danMuPainterHashMap.keySet();
72 | Iterator iterator = danMuPainters.iterator();
73 | while (iterator.hasNext()) {
74 | Integer key = iterator.next();
75 | danMuPainterHashMap.get(key).hideAll(hide);
76 | }
77 | }
78 |
79 | public boolean isDrawnQueueEmpty() {
80 | if (mixedDanMuViewQueue == null || mixedDanMuViewQueue.size() == 0) {
81 | isDrawing = false;
82 | return true;
83 | }
84 | return false;
85 | }
86 |
87 | public void put(ArrayList danMuViews) {
88 | // if (!isDrawing) { // 这里的判断是为了控制弹幕的发送数量
89 | if (danMuViews != null && danMuViews.size() > 0) {
90 | mixedDanMuViewQueue.addAll(danMuViews);
91 | }
92 | // }
93 | }
94 |
95 | public void draw(Canvas canvas) {
96 | drawEveryElement(mixedDanMuViewQueue, canvas);
97 | }
98 |
99 | private synchronized void drawEveryElement(ArrayList danMuViewQueue, Canvas canvas) {
100 | isDrawing = true;
101 | if (danMuViewQueue == null || danMuViewQueue.size() == 0) {
102 | return;
103 | }
104 |
105 | for (int i = 0; i < (danMuViewQueue.size() > MAX_COUNT_IN_SCREEN ? MAX_COUNT_IN_SCREEN : danMuViewQueue.size()); i++) {
106 | DanMuModel danMuView = danMuViewQueue.get(i);
107 | if (danMuView.isAlive()) {
108 | DanMuPainter danMuPainter = getPainter(danMuView);
109 | DanMuChannel danMuChannel = danMuChannels[danMuView.getChannelIndex()];
110 | danMuChannel.dispatch(danMuView);
111 | if (danMuView.isAttached()) {
112 | performDraw(danMuView, danMuPainter, canvas, danMuChannel);
113 | }
114 | } else {
115 | danMuViewQueue.remove(i);
116 | i--;
117 | }
118 | }
119 | isDrawing = false;
120 | }
121 |
122 |
123 | private void initDefaultPainters() {
124 | R2LPainter r2LPainter = new R2LPainter();
125 | L2RPainter l2RPainter = new L2RPainter();
126 | danMuPainterHashMap.put(DanMuModel.LEFT_TO_RIGHT, l2RPainter);
127 | danMuPainterHashMap.put(DanMuModel.RIGHT_TO_LEFT, r2LPainter);
128 | }
129 |
130 | private DanMuPainter getPainter(DanMuModel danMuView) {
131 | int painterType = danMuView.getDisplayType();
132 | return danMuPainterHashMap.get(painterType);
133 | }
134 |
135 | private void performDraw(DanMuModel danMuView, DanMuPainter danMuPainter, Canvas canvas, DanMuChannel danMuChannel) {
136 | danMuPainter.execute(canvas, danMuView, danMuChannel);
137 | }
138 |
139 | public void divide(int width, int height) {
140 | int singleHeight = DimensionUtil.dpToPx(context, DEFAULT_SINGLE_CHANNEL_HEIGHT);
141 | int count = height / singleHeight;
142 |
143 | danMuChannels = new DanMuChannel[count];
144 | for (int i = 0; i < count; i++) {
145 | DanMuChannel danMuChannel = new DanMuChannel();
146 | danMuChannel.width = width;
147 | danMuChannel.height = singleHeight;
148 | // danMuChannel.speed = speedController.getSpeed();
149 |
150 | danMuChannel.topY = i * singleHeight;
151 | // danMuChannel.space = selectSpaceRandomly();
152 | danMuChannels[i] = danMuChannel;
153 | }
154 | }
155 |
156 | private int selectSpaceRandomly() {
157 | return (int) (Math.random() * 20 + 15);
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/collection/DanMuConsumer.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.collection;
2 |
3 | import android.graphics.Canvas;
4 |
5 | import com.anbetter.danmuku.view.IDanMuParent;
6 |
7 | import java.lang.ref.WeakReference;
8 | import java.util.concurrent.locks.ReentrantLock;
9 |
10 | /**
11 | * Created by android_ls on 2016/12/7.
12 | */
13 | public class DanMuConsumer extends Thread {
14 |
15 | private final static int SLEEP_TIME = 100;
16 |
17 | private boolean forceSleep = false;
18 |
19 | private boolean isStart;
20 |
21 | private volatile WeakReference danMuViewParent;
22 |
23 | private DanMuConsumedPool danMuSharedPool;
24 |
25 | private ReentrantLock lock = new ReentrantLock();
26 |
27 | public DanMuConsumer(DanMuConsumedPool danMuSharedPool, IDanMuParent danMuParent) {
28 | this.danMuSharedPool = danMuSharedPool;
29 | this.danMuViewParent = new WeakReference<>(danMuParent);
30 | isStart = true;
31 | }
32 |
33 | public void consume(final Canvas canvas) {
34 | if (danMuSharedPool != null) {
35 | danMuSharedPool.draw(canvas);
36 | }
37 | }
38 |
39 | public void release() {
40 | isStart = false;
41 | danMuViewParent.clear();
42 | interrupt();
43 | danMuSharedPool = null;
44 | }
45 |
46 | @Override
47 | public void run() {
48 | super.run();
49 | while (isStart) {
50 | if (danMuSharedPool.isDrawnQueueEmpty() || forceSleep) {
51 | try {
52 | Thread.sleep(SLEEP_TIME);
53 | } catch (InterruptedException e) {
54 | e.printStackTrace();
55 | }
56 | } else {
57 | lock.lock();
58 | try {
59 | if (danMuViewParent != null && danMuViewParent.get() != null) {
60 | danMuViewParent.get().lockDraw();
61 | }
62 | } finally {
63 | lock.unlock();
64 | }
65 | }
66 | }
67 | }
68 |
69 | public void forceSleep() {
70 | forceSleep = true;
71 | }
72 |
73 | public void releaseForce() {
74 | forceSleep = false;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/collection/DanMuProducedPool.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.collection;
2 |
3 | import android.content.Context;
4 |
5 | import com.anbetter.danmuku.control.dispatcher.IDanMuDispatcher;
6 | import com.anbetter.danmuku.model.DanMuModel;
7 | import com.anbetter.danmuku.model.channel.DanMuChannel;
8 | import com.anbetter.danmuku.model.utils.DimensionUtil;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.concurrent.locks.ReentrantLock;
13 |
14 | /**
15 | * Created by android_ls on 2016/12/7.
16 | */
17 | public class DanMuProducedPool {
18 |
19 | private final static int MAX_COUNT_IN_SCREEN = 30;
20 |
21 | private final static int DEFAULT_SINGLE_CHANNEL_HEIGHT = 40;
22 |
23 | private IDanMuDispatcher iDanMuDispatcher;
24 |
25 | private volatile ArrayList mixedDanMuViewPendingQueue = new ArrayList<>();
26 |
27 | private volatile ArrayList fastDanMuViewPendingQueue = new ArrayList<>();
28 |
29 | private ReentrantLock reentrantLock = new ReentrantLock();
30 |
31 | private DanMuChannel[] danMuChannels;
32 |
33 | private Context context;
34 |
35 | public DanMuProducedPool(Context context) {
36 | this.context = context.getApplicationContext();
37 | }
38 |
39 | public void setDanMuDispatcher(IDanMuDispatcher iDanMuDispatcher) {
40 | this.iDanMuDispatcher = iDanMuDispatcher;
41 | }
42 |
43 | public void addDanMuView(int index, DanMuModel danMuView) {
44 | reentrantLock.lock();
45 | try {
46 | if (index > -1) {
47 | mixedDanMuViewPendingQueue.add(index, danMuView);
48 | } else {
49 | mixedDanMuViewPendingQueue.add(danMuView);
50 | }
51 | } finally {
52 | reentrantLock.unlock();
53 | }
54 | }
55 |
56 | public void jumpQueue(List danMuViews) {
57 | reentrantLock.lock();
58 | try {
59 | fastDanMuViewPendingQueue.addAll(danMuViews);
60 | } finally {
61 | reentrantLock.unlock();
62 | }
63 | }
64 |
65 | public synchronized ArrayList dispatch() {
66 | if (isEmpty()) {
67 | return null;
68 | }
69 | ArrayList danMuViews = fastDanMuViewPendingQueue.size() > 0 ? fastDanMuViewPendingQueue : mixedDanMuViewPendingQueue;
70 | ArrayList validateDanMuViews = new ArrayList<>();
71 | for (int i = 0; i < (danMuViews.size() > MAX_COUNT_IN_SCREEN ? MAX_COUNT_IN_SCREEN : danMuViews.size()); i++) {
72 | DanMuModel danMuView = danMuViews.get(i);
73 | iDanMuDispatcher.dispatch(danMuView, danMuChannels);
74 | validateDanMuViews.add(danMuView);
75 | danMuViews.remove(i);
76 | i--;
77 | }
78 |
79 | if (validateDanMuViews.size() > 0) {
80 | return validateDanMuViews;
81 | }
82 | return null;
83 | }
84 |
85 | public boolean isEmpty() {
86 | return fastDanMuViewPendingQueue.size() == 0 && mixedDanMuViewPendingQueue.size() == 0;
87 | }
88 |
89 | public void divide(int width, int height) {
90 | int singleHeight = DimensionUtil.dpToPx(context, DEFAULT_SINGLE_CHANNEL_HEIGHT);
91 | int count = height / singleHeight;
92 |
93 | danMuChannels = new DanMuChannel[count];
94 | for (int i = 0; i < count; i++) {
95 | DanMuChannel danMuChannel = new DanMuChannel();
96 | danMuChannel.width = width;
97 | danMuChannel.height = singleHeight;
98 | danMuChannel.topY = i * singleHeight;
99 | danMuChannels[i] = danMuChannel;
100 | }
101 | }
102 |
103 | public void clear() {
104 | fastDanMuViewPendingQueue.clear();
105 | mixedDanMuViewPendingQueue.clear();
106 | context = null;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/collection/DanMuProducer.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.collection;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import com.anbetter.danmuku.model.DanMuModel;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by android_ls on 2016/12/7.
13 | */
14 | public class DanMuProducer {
15 |
16 | private DanMuConsumedPool danMuConsumedPool;
17 |
18 | private DanMuProducedPool danMuProducedPool;
19 |
20 | private ProducerHandler producerHandler;
21 |
22 | public DanMuProducer(DanMuProducedPool danMuProducedPool, DanMuConsumedPool danMuSharedPool) {
23 | this.danMuConsumedPool = danMuSharedPool;
24 | this.danMuProducedPool = danMuProducedPool;
25 | }
26 |
27 | public void start() {
28 | producerHandler = new ProducerHandler(this);
29 | }
30 |
31 | public void produce(int index, DanMuModel danMuView) {
32 | if (producerHandler != null) {
33 | ProduceMessage produceMessage = new ProduceMessage();
34 | produceMessage.index = index;
35 | produceMessage.danMuView = danMuView;
36 | Message message = producerHandler.obtainMessage();
37 | message.obj = produceMessage;
38 | message.what = 2;
39 | producerHandler.sendMessage(message);
40 | }
41 | }
42 |
43 | public void jumpQueue(List danMuViews) {
44 | danMuProducedPool.jumpQueue(danMuViews);
45 | }
46 |
47 | public void release() {
48 | danMuConsumedPool = null;
49 | if (producerHandler != null) {
50 | producerHandler.removeMessages(1);
51 | producerHandler.release();
52 | }
53 | }
54 |
55 | static class ProducerHandler extends Handler {
56 |
57 | private final int SLEEP_TIME = 100;
58 |
59 | private DanMuProducer danMuProducer;
60 |
61 | ProducerHandler(DanMuProducer danMuProducer) {
62 | this.danMuProducer = danMuProducer;
63 | obtainMessage(1).sendToTarget();
64 | }
65 |
66 | @Override
67 | public void handleMessage(Message msg) {
68 | super.handleMessage(msg);
69 | switch (msg.what) {
70 | case 1:
71 | if (danMuProducer != null && danMuProducer.danMuConsumedPool != null) {
72 | if (danMuProducer.danMuProducedPool != null) {
73 | ArrayList danMuViews = danMuProducer.danMuProducedPool.dispatch();
74 | if (danMuViews != null) {
75 | danMuProducer.danMuConsumedPool.put(danMuViews);
76 | }
77 | }
78 | Message message = obtainMessage();
79 | message.what = 1;
80 | sendMessageDelayed(message, SLEEP_TIME);
81 | }
82 | break;
83 | case 2:
84 | if (danMuProducer != null && msg.obj instanceof ProduceMessage) {
85 | ProduceMessage produceMessage = (ProduceMessage) msg.obj;
86 | danMuProducer.danMuProducedPool.addDanMuView(produceMessage.index, produceMessage.danMuView);
87 | }
88 | break;
89 | }
90 | }
91 |
92 | public void release() {
93 | if (danMuProducer != null) {
94 | if(danMuProducer.danMuProducedPool != null) {
95 | danMuProducer.danMuProducedPool.clear();
96 | }
97 | danMuProducer = null;
98 | }
99 | }
100 |
101 | }
102 |
103 | static class ProduceMessage {
104 | public int index;
105 | public DanMuModel danMuView;
106 | }
107 |
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/painter/DanMuPainter.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.painter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.Rect;
7 | import android.graphics.RectF;
8 | import android.text.Layout;
9 | import android.text.StaticLayout;
10 | import android.text.TextPaint;
11 | import android.text.TextUtils;
12 |
13 | import com.anbetter.danmuku.model.DanMuModel;
14 | import com.anbetter.danmuku.model.channel.DanMuChannel;
15 | import com.anbetter.danmuku.model.utils.PaintUtils;
16 |
17 | /**
18 | * Created by android_ls on 2016/12/7.
19 | */
20 | public class DanMuPainter extends IDanMuPainter {
21 |
22 | protected static TextPaint paint;
23 | protected static RectF rectF;
24 |
25 | private boolean hide;
26 |
27 | private boolean hideAll;
28 |
29 | static {
30 | paint = PaintUtils.getPaint();
31 | rectF = new RectF();
32 | }
33 |
34 | public DanMuPainter() {
35 | }
36 |
37 | protected void layout(DanMuModel danMuView, DanMuChannel danMuChannel) {
38 | }
39 |
40 | private void onLayout(DanMuModel danMuView, DanMuChannel danMuChannel) {
41 | if (danMuView.isMoving()) {
42 | layout(danMuView, danMuChannel);
43 | }
44 | }
45 |
46 | protected void draw(Canvas canvas, DanMuModel danMuView, DanMuChannel danMuChannel) {
47 | if (danMuView.textBackground != null) {
48 | drawTextBackground(danMuView, canvas, danMuChannel);
49 | }
50 |
51 | if (danMuView.avatar != null) {
52 | drawAvatar(danMuView, canvas, danMuChannel);
53 | }
54 |
55 | if(danMuView.avatarStrokes) {
56 | drawAvatarStrokes(danMuView, canvas, danMuChannel);
57 | }
58 |
59 | if (danMuView.levelBitmap != null) {
60 | drawLevel(danMuView, canvas, danMuChannel);
61 | }
62 |
63 | if (!TextUtils.isEmpty(danMuView.levelText)) {
64 | drawLevelText(danMuView, canvas, danMuChannel);
65 | }
66 |
67 | if (!TextUtils.isEmpty(danMuView.text)) {
68 | drawText(danMuView, canvas, danMuChannel);
69 | }
70 | }
71 |
72 | protected void drawAvatar(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
73 | float top = (int) (danMuView.getY()) + danMuChannel.height / 2 - danMuView.avatarHeight / 2;
74 | float x = danMuView.getX() + danMuView.marginLeft;
75 |
76 | rectF.set((int) x, top,
77 | (int) (x + danMuView.avatarWidth),
78 | top + danMuView.avatarHeight);
79 | canvas.drawBitmap(danMuView.avatar, null, rectF, paint);
80 | }
81 |
82 | protected void drawAvatarStrokes(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
83 | float x = danMuView.getX() + danMuView.marginLeft + danMuView.avatarWidth/2;
84 | float top = danMuView.getY() + danMuChannel.height / 2;
85 |
86 | paint.setColor(Color.WHITE);
87 | paint.setStyle(Paint.Style.STROKE);
88 | canvas.drawCircle((int)x , (int)top, danMuView.avatarHeight/2, paint);
89 | }
90 |
91 | protected void drawLevel(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
92 | float top = (int) (danMuView.getY()) + danMuChannel.height / 2 - danMuView.levelBitmapHeight / 2;
93 |
94 | float x = danMuView.getX()
95 | + danMuView.marginLeft
96 | + danMuView.avatarWidth
97 | + danMuView.levelMarginLeft;
98 |
99 | rectF.set((int) x, top,
100 | (int) (x + danMuView.levelBitmapWidth),
101 | top + danMuView.levelBitmapHeight);
102 | canvas.drawBitmap(danMuView.levelBitmap, null, rectF, paint);
103 | }
104 |
105 | protected void drawLevelText(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
106 | if (TextUtils.isEmpty(danMuView.levelText)) {
107 | return;
108 | }
109 |
110 | paint.setTextSize(danMuView.levelTextSize);
111 | paint.setColor(danMuView.levelTextColor);
112 | paint.setStyle(Paint.Style.FILL);
113 |
114 | float top = (int) danMuView.getY()
115 | + danMuChannel.height / 2
116 | - paint.ascent() / 2
117 | - paint.descent() / 2;
118 |
119 | float x = danMuView.getX()
120 | + danMuView.marginLeft
121 | + danMuView.avatarWidth
122 | + danMuView.levelMarginLeft
123 | + danMuView.levelBitmapWidth/2;
124 |
125 | canvas.drawText(danMuView.levelText.toString(), (int) x, top, paint);
126 | }
127 |
128 | protected void drawText(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
129 | if (TextUtils.isEmpty(danMuView.text)) {
130 | return;
131 | }
132 |
133 | paint.setTextSize(danMuView.textSize);
134 | paint.setColor(danMuView.textColor);
135 | paint.setStyle(Paint.Style.FILL);
136 |
137 | CharSequence text = danMuView.text;
138 | StaticLayout staticLayout = new StaticLayout(text,
139 | paint,
140 | (int) Math.ceil(StaticLayout.getDesiredWidth(text, paint)),
141 | Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
142 |
143 | float x = danMuView.getX()
144 | + danMuView.marginLeft
145 | + danMuView.avatarWidth
146 | + danMuView.levelMarginLeft
147 | + danMuView.levelBitmapWidth
148 | + danMuView.textMarginLeft;
149 |
150 | float top = (int) (danMuView.getY())
151 | + danMuChannel.height / 2
152 | - staticLayout.getHeight()/2;
153 |
154 | canvas.save();
155 | canvas.translate((int) x, top);
156 | staticLayout.draw(canvas);
157 | canvas.restore();
158 | }
159 |
160 | protected void drawTextBackground(DanMuModel danMuView, Canvas canvas, DanMuChannel danMuChannel) {
161 | CharSequence text = danMuView.text;
162 | StaticLayout staticLayout = new StaticLayout(text,
163 | paint,
164 | (int) Math.ceil(StaticLayout.getDesiredWidth(text, paint)),
165 | Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
166 |
167 | int textBackgroundHeight = staticLayout.getHeight()
168 | + danMuView.textBackgroundPaddingTop
169 | + danMuView.textBackgroundPaddingBottom;
170 |
171 | float top = danMuView.getY()
172 | + (danMuChannel.height - textBackgroundHeight) / 2;
173 |
174 | float x = danMuView.getX()
175 | + danMuView.marginLeft
176 | + danMuView.avatarWidth
177 | - danMuView.textBackgroundMarginLeft;
178 |
179 | Rect rectF = new Rect((int)x,
180 | (int)top,
181 | (int)(x + danMuView.levelMarginLeft
182 | + danMuView.levelBitmapWidth
183 | + danMuView.textMarginLeft
184 | + danMuView.textBackgroundMarginLeft
185 | + staticLayout.getWidth()
186 | + danMuView.textBackgroundPaddingRight),
187 | (int)(top + textBackgroundHeight));
188 |
189 | danMuView.textBackground.setBounds(rectF);
190 | danMuView.textBackground.draw(canvas);
191 | }
192 |
193 | @Override
194 | public void requestLayout() {
195 | }
196 |
197 | @Override
198 | public void setAlpha(int alpha) {
199 | }
200 |
201 | @Override
202 | public void hideNormal(boolean hide) {
203 | this.hide = hide;
204 | }
205 |
206 | @Override
207 | public void hideAll(boolean hideAll) {
208 | this.hideAll = hideAll;
209 | }
210 |
211 | @Override
212 | public void execute(Canvas canvas, DanMuModel danMuView, DanMuChannel danMuChannel) {
213 | if ((int) danMuView.getSpeed() == 0) {
214 | danMuView.setAlive(false);
215 | }
216 |
217 | onLayout(danMuView, danMuChannel);
218 |
219 | if (hideAll) {
220 | return;
221 | }
222 |
223 | if (danMuView.getPriority() == DanMuModel.NORMAL && hide) {
224 | return;
225 | }
226 |
227 | draw(canvas, danMuView, danMuChannel);
228 | }
229 |
230 | }
231 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/painter/IDanMuPainter.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.painter;
2 |
3 | import android.graphics.Canvas;
4 |
5 | import com.anbetter.danmuku.model.DanMuModel;
6 | import com.anbetter.danmuku.model.channel.DanMuChannel;
7 |
8 | /**
9 | * Created by android_ls on 2016/12/7.
10 | */
11 | abstract class IDanMuPainter {
12 |
13 | public abstract void execute(Canvas canvas, DanMuModel danMuView, DanMuChannel danMuChannel);
14 |
15 | public abstract void requestLayout();
16 |
17 | public abstract void setAlpha(int alpha);
18 |
19 | public abstract void hideNormal(boolean hide);
20 |
21 | public abstract void hideAll(boolean hideAll);
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/painter/L2RPainter.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.painter;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 | import com.anbetter.danmuku.model.channel.DanMuChannel;
5 |
6 | /**
7 | * Created by android_ls on 2016/12/7.
8 | */
9 | public class L2RPainter extends DanMuPainter {
10 |
11 | @Override
12 | protected void layout(DanMuModel danMuView, DanMuChannel danMuChannel) {
13 | if (danMuView.getX() >= (danMuChannel.width + danMuView.getWidth())) {
14 | danMuView.setAlive(false);
15 | return;
16 | }
17 | danMuView.setStartPositionX(danMuView.getX() + danMuView.getSpeed() * (1 + 0.5f));
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/painter/R2LPainter.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.painter;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 | import com.anbetter.danmuku.model.channel.DanMuChannel;
5 |
6 | /**
7 | * Created by android_ls on 2016/12/7.
8 | */
9 | public class R2LPainter extends DanMuPainter {
10 |
11 | @Override
12 | protected void layout(DanMuModel danMuView, DanMuChannel danMuChannel) {
13 | if (danMuView.getX() - danMuView.getSpeed() <= -danMuView.getWidth()) {
14 | danMuView.setAlive(false);
15 | return;
16 | }
17 | danMuView.setStartPositionX(danMuView.getX() - danMuView.getSpeed());
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/utils/DimensionUtil.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.util.TypedValue;
6 |
7 | /**
8 | * Created by android_ls on 2016/12/7.
9 | */
10 | public final class DimensionUtil {
11 |
12 | public static int getDisplayHeight(Context context) {
13 | return context.getResources().getDisplayMetrics().heightPixels;
14 | }
15 |
16 | public static int getDisplayWidth(Context context) {
17 | return context.getResources().getDisplayMetrics().widthPixels;
18 | }
19 |
20 | public static int dpToPx(Context context, int dip) {
21 | Resources r = context.getResources();
22 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
23 | r.getDisplayMetrics());
24 | return (int) px;
25 | }
26 |
27 | public static int dpToPx(Context context, float dip) {
28 | Resources r = context.getResources();
29 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
30 | r.getDisplayMetrics());
31 | return (int) px;
32 | }
33 |
34 | public static int spToPx(Context context, int sp) {
35 | Resources r = context.getResources();
36 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
37 | r.getDisplayMetrics());
38 | return (int) px;
39 | }
40 |
41 | public static int spToPx(Context context, float sp) {
42 | Resources r = context.getResources();
43 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
44 | r.getDisplayMetrics());
45 | return (int) px;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/model/utils/PaintUtils.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.model.utils;
2 |
3 | import android.graphics.Paint;
4 | import android.text.TextPaint;
5 |
6 | /**
7 | * Created by android_ls on 2016/12/12.
8 | */
9 |
10 | public class PaintUtils {
11 |
12 | private static TextPaint paint;
13 |
14 | public static TextPaint getPaint() {
15 | if(paint == null) {
16 | paint = new TextPaint();
17 | paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
18 | paint.setStrokeWidth(3.5f);
19 | }
20 | return paint;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/view/IDanMuParent.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.view;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by android_ls on 2016/12/7.
9 | */
10 | public interface IDanMuParent {
11 | void add(DanMuModel danMuView);
12 |
13 | void add(int index, DanMuModel danMuView);
14 |
15 | void jumpQueue(List danMuViews);
16 |
17 | void addAllTouchListener(List onDanMuTouchCallBackListeners);
18 |
19 | void clear();
20 |
21 | void remove(DanMuModel danMuView);
22 |
23 | void lockDraw();
24 |
25 | void forceSleep();
26 |
27 | void forceWake();
28 |
29 | boolean hasCanTouchDanMus();
30 |
31 | void hideNormalDanMuView(boolean hide);
32 |
33 | void hideAllDanMuView(boolean hideAll);
34 |
35 | void release();
36 | }
37 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/view/OnDanMuParentViewTouchCallBackListener.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.view;
2 |
3 | /**
4 | * Created by android_ls on 2016/12/7.
5 | */
6 | public interface OnDanMuParentViewTouchCallBackListener {
7 |
8 | void callBack();
9 |
10 | void release();
11 |
12 | void hideControlPanel();
13 | }
14 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/view/OnDanMuTouchCallBackListener.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.view;
2 |
3 | import com.anbetter.danmuku.model.DanMuModel;
4 |
5 | /**
6 | * Created by android_ls on 2016/12/7.
7 | */
8 | public interface OnDanMuTouchCallBackListener {
9 |
10 | void callBack(DanMuModel danMuView);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/danmukulight/src/main/java/com/anbetter/danmuku/view/OnDanMuViewTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.anbetter.danmuku.view;
2 |
3 | /**
4 | * Created by android_ls on 2016/12/7.
5 | */
6 | public interface OnDanMuViewTouchListener {
7 |
8 | boolean onTouch(float x, float y);
9 |
10 | void release();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | android.useAndroidX=true
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon May 07 19:39:17 CST 2018
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-6.5-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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/result_image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hpdx/DanmukuLight/eed9b006db7e177e615d63f030fdc570d41a2ee1/result_image.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':danmukulight'
2 |
--------------------------------------------------------------------------------