-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathSplashScreen.java
More file actions
99 lines (86 loc) · 3.1 KB
/
SplashScreen.java
File metadata and controls
99 lines (86 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.devio.rn.splashscreen;
import android.app.Activity;
import android.app.Dialog;
import android.os.Build;
import android.widget.VideoView;
import android.net.Uri;
import android.util.DisplayMetrics;
import java.lang.ref.WeakReference;
import java.net.URI;
/**
* SplashScreen 启动屏 from:http://www.devio.org Author:CrazyCodeBoy
* GitHub:https://github.com/crazycodeboy Email:crazycodeboy@gmail.com
*/
public class SplashScreen {
private static Dialog mSplashDialog;
private static WeakReference<Activity> mActivity;
/**
* 打开启动屏
*/
public static void show(final Activity activity, final int themeResId, final boolean isvideoSplash) {
if (activity == null)
return;
mActivity = new WeakReference<Activity>(activity);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!activity.isFinishing()) {
mSplashDialog = new Dialog(activity, themeResId);
mSplashDialog.setContentView(R.layout.launch_screen);
if (!mSplashDialog.isShowing()) {
mSplashDialog.show();
if(isvideoSplash){
String path = "android.resource://" + activity.getPackageName() + "/" + R.raw.splash_video;
VideoView mVideoView = (VideoView) mSplashDialog.findViewById(R.id.simpleVideoView);
mVideoView.setVideoURI(Uri.parse(path));
mVideoView.start();
mSplashDialog.setCancelable(false);
}
}
}
}
});
}
/**
* 打开启动屏
*/
public static void show(final Activity activity, final boolean fullScreen, final boolean isvideoSplash) {
int resourceId = fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme;
show(activity, resourceId, isvideoSplash);
}
/**
* 打开启动屏
*/
public static void show(final Activity activity) {
show(activity, false, false);
}
/**
* 关闭启动屏
*/
public static void hide(Activity activity) {
if (activity == null) {
if (mActivity == null) {
return;
}
activity = mActivity.get();
}
if (activity == null)
return;
final Activity _activity = activity;
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mSplashDialog != null && mSplashDialog.isShowing()) {
boolean isDestroyed = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
isDestroyed = _activity.isDestroyed();
}
if (!_activity.isFinishing() && !isDestroyed) {
mSplashDialog.dismiss();
}
mSplashDialog = null;
}
}
});
}
}