Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
james正哥儿
testforfloatingwindow
提交
603f233a
T
testforfloatingwindow
项目概览
james正哥儿
/
testforfloatingwindow
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
testforfloatingwindow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
603f233a
编写于
5月 31, 2018
作者:
D
dongzhong1990
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加视频播放悬浮窗
上级
5da5fdb1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
145 addition
and
0 deletion
+145
-0
app/build.gradle
app/build.gradle
+2
-0
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-0
app/src/main/java/dongzhong/testforfloatingwindow/FloatingVideoService.java
...dongzhong/testforfloatingwindow/FloatingVideoService.java
+103
-0
app/src/main/java/dongzhong/testforfloatingwindow/MainActivity.java
...in/java/dongzhong/testforfloatingwindow/MainActivity.java
+19
-0
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_main.xml
+6
-0
app/src/main/res/layout/video_display.xml
app/src/main/res/layout/video_display.xml
+12
-0
build.gradle
build.gradle
+1
-0
未找到文件。
app/build.gradle
浏览文件 @
603f233a
...
...
@@ -25,4 +25,6 @@ dependencies {
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation
'com.github.dongzhong:VideoPlayer:v1.2'
}
app/src/main/AndroidManifest.xml
浏览文件 @
603f233a
...
...
@@ -3,6 +3,7 @@
package=
"dongzhong.testforfloatingwindow"
>
<uses-permission
android:name=
"android.permission.SYSTEM_ALERT_WINDOW"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:allowBackup=
"true"
...
...
@@ -20,6 +21,7 @@
</activity>
<service
android:name=
".FloatingButtonService"
></service>
<service
android:name=
".FloatingImageDisplayService"
></service>
<service
android:name=
".FloatingVideoService"
></service>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/dongzhong/testforfloatingwindow/FloatingVideoService.java
0 → 100644
浏览文件 @
603f233a
package
dongzhong.testforfloatingwindow
;
import
android.app.Service
;
import
android.content.Intent
;
import
android.graphics.PixelFormat
;
import
android.os.Build
;
import
android.os.IBinder
;
import
android.provider.Settings
;
import
android.support.annotation.Nullable
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.WindowManager
;
import
dongzhong.videoplayer.VideoPlayer
;
/**
* Created by admin on 2018/5/30.
*/
public
class
FloatingVideoService
extends
Service
{
public
static
boolean
isStarted
=
false
;
private
WindowManager
windowManager
;
private
WindowManager
.
LayoutParams
layoutParams
;
private
View
displayView
;
@Override
public
void
onCreate
()
{
super
.
onCreate
();
isStarted
=
true
;
windowManager
=
(
WindowManager
)
getSystemService
(
WINDOW_SERVICE
);
layoutParams
=
new
WindowManager
.
LayoutParams
();
if
(
Build
.
VERSION
.
SDK_INT
>
Build
.
VERSION_CODES
.
O
)
{
layoutParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_APPLICATION_OVERLAY
;
}
else
{
layoutParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_PHONE
;
}
layoutParams
.
format
=
PixelFormat
.
RGBA_8888
;
layoutParams
.
gravity
=
Gravity
.
LEFT
|
Gravity
.
TOP
;
layoutParams
.
flags
=
WindowManager
.
LayoutParams
.
FLAG_NOT_TOUCH_MODAL
|
WindowManager
.
LayoutParams
.
FLAG_NOT_FOCUSABLE
;
layoutParams
.
width
=
800
;
layoutParams
.
height
=
450
;
layoutParams
.
x
=
300
;
layoutParams
.
y
=
300
;
}
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
showFloatingWindow
();
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
private
void
showFloatingWindow
()
{
if
(
Settings
.
canDrawOverlays
(
this
))
{
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
this
);
displayView
=
layoutInflater
.
inflate
(
R
.
layout
.
video_display
,
null
);
VideoPlayer
videoPlayer
=
displayView
.
findViewById
(
R
.
id
.
videoplayer_display
);
videoPlayer
.
preset
(
"https://raw.githubusercontent.com/dongzhong/ImageAndVideoStore/master/Bruno%20Mars%20-%20Treasure.mp4"
,
"Treasure - Bruno Mars"
,
true
);
windowManager
.
addView
(
displayView
,
layoutParams
);
displayView
.
setOnTouchListener
(
new
FloatingOnTouchListener
());
}
}
private
class
FloatingOnTouchListener
implements
View
.
OnTouchListener
{
private
int
x
;
private
int
y
;
@Override
public
boolean
onTouch
(
View
view
,
MotionEvent
event
)
{
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_DOWN
:
x
=
(
int
)
event
.
getRawX
();
y
=
(
int
)
event
.
getRawY
();
break
;
case
MotionEvent
.
ACTION_MOVE
:
int
nowX
=
(
int
)
event
.
getRawX
();
int
nowY
=
(
int
)
event
.
getRawY
();
int
movedX
=
nowX
-
x
;
int
movedY
=
nowY
-
y
;
x
=
nowX
;
y
=
nowY
;
layoutParams
.
x
=
layoutParams
.
x
+
movedX
;
layoutParams
.
y
=
layoutParams
.
y
+
movedY
;
windowManager
.
updateViewLayout
(
view
,
layoutParams
);
break
;
default
:
break
;
}
return
false
;
}
}
}
app/src/main/java/dongzhong/testforfloatingwindow/MainActivity.java
浏览文件 @
603f233a
...
...
@@ -32,6 +32,13 @@ public class MainActivity extends AppCompatActivity {
Toast
.
makeText
(
this
,
"授权成功"
,
Toast
.
LENGTH_SHORT
).
show
();
startService
(
new
Intent
(
MainActivity
.
this
,
FloatingImageDisplayService
.
class
));
}
}
else
if
(
requestCode
==
2
)
{
if
(!
Settings
.
canDrawOverlays
(
this
))
{
Toast
.
makeText
(
this
,
"授权失败"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
Toast
.
makeText
(
this
,
"授权成功"
,
Toast
.
LENGTH_SHORT
).
show
();
startService
(
new
Intent
(
MainActivity
.
this
,
FloatingVideoService
.
class
));
}
}
}
...
...
@@ -58,4 +65,16 @@ public class MainActivity extends AppCompatActivity {
startService
(
new
Intent
(
MainActivity
.
this
,
FloatingImageDisplayService
.
class
));
}
}
public
void
startFloatingVideoService
(
View
view
)
{
if
(
FloatingVideoService
.
isStarted
)
{
return
;
}
if
(!
Settings
.
canDrawOverlays
(
this
))
{
Toast
.
makeText
(
this
,
"当前无权限,请授权"
,
Toast
.
LENGTH_SHORT
);
startActivityForResult
(
new
Intent
(
Settings
.
ACTION_MANAGE_OVERLAY_PERMISSION
,
Uri
.
parse
(
"package:"
+
getPackageName
())),
2
);
}
else
{
startService
(
new
Intent
(
MainActivity
.
this
,
FloatingVideoService
.
class
));
}
}
}
app/src/main/res/layout/activity_main.xml
浏览文件 @
603f233a
...
...
@@ -17,4 +17,10 @@
android:text=
"start floating image display"
android:onClick=
"startFloatingImageDisplayService"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"start floating video player"
android:onClick=
"startFloatingVideoService"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/video_display.xml
0 → 100644
浏览文件 @
603f233a
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<dongzhong.videoplayer.VideoPlayer
android:id=
"@+id/videoplayer_display"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</FrameLayout>
\ No newline at end of file
build.gradle
浏览文件 @
603f233a
...
...
@@ -19,6 +19,7 @@ allprojects {
repositories
{
google
()
jcenter
()
maven
{
url
'https://jitpack.io'
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录