-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathSplashScreen.java
99 lines (84 loc) · 2.66 KB
/
SplashScreen.java
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 java.lang.ref.WeakReference;
/**
* SplashScreen
* 启动屏
* from:http://www.devio.org
* Author:CrazyCodeBoy
* GitHub:https://github.com/crazycodeboy
* Email:[email protected]
*/
public class SplashScreen {
protected static Dialog mSplashDialog;
protected static WeakReference<Activity> mActivity;
public static Dialog getSplashDialog() {
return mSplashDialog;
}
public static WeakReference<Activity> getActivity() {
return mActivity;
}
/**
* 打开启动屏
*/
public static void show(final Activity activity, final int themeResId) {
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);
mSplashDialog.setCancelable(false);
if (!mSplashDialog.isShowing()) {
mSplashDialog.show();
}
}
}
});
}
/**
* 打开启动屏
*/
public static void show(final Activity activity, final boolean fullScreen) {
int resourceId = fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme;
show(activity, resourceId);
}
/**
* 打开启动屏
*/
public static void show(final Activity activity) {
show(activity, 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;
}
}
});
}
}