Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 38f684a

Browse files
committed
android splash screen
1 parent d08cbfa commit 38f684a

File tree

20 files changed

+339
-95
lines changed

20 files changed

+339
-95
lines changed

android/app/app-release.apk

1.2 KB
Binary file not shown.

android/app/src/main/assets/index.android.bundle

Lines changed: 33 additions & 31 deletions
Large diffs are not rendered by default.
0 Bytes
Binary file not shown.

android/app/src/main/java/com/gankio/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package com.gankio;
22

3+
import android.os.Bundle;
4+
35
import com.facebook.react.ReactActivity;
6+
import com.gankio.util.SplashScreen;
47

58
public class MainActivity extends ReactActivity {
9+
@Override
10+
protected void onCreate(Bundle savedInstanceState) {
11+
SplashScreen.show(this, true);
12+
super.onCreate(savedInstanceState);
13+
}
614

715
/**
816
* Returns the name of the main component registered from JavaScript.

android/app/src/main/java/com/gankio/MainApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ protected boolean getUseDeveloperSupport() {
2525
protected List<ReactPackage> getPackages() {
2626
return Arrays.<ReactPackage>asList(
2727
new MainReactPackage(),
28-
new VectorIconsPackage()
28+
new VectorIconsPackage(),
29+
new MyReactPackage()
2930
);
3031
}
3132
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.gankio;
2+
3+
import com.facebook.react.ReactPackage;
4+
import com.facebook.react.bridge.JavaScriptModule;
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.uimanager.ViewManager;
8+
import com.gankio.util.SplashScreenModule;
9+
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
14+
/**
15+
* Created by wangdi on 14/11/16.
16+
*/
17+
18+
public class MyReactPackage implements ReactPackage{
19+
@Override
20+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
21+
List<NativeModule> list = new ArrayList<>();
22+
list.add(new SplashScreenModule(reactContext));
23+
return list;
24+
}
25+
26+
@Override
27+
public List<Class<? extends JavaScriptModule>> createJSModules() {
28+
return Collections.emptyList();
29+
}
30+
31+
@Override
32+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
33+
return Collections.emptyList();
34+
}
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.gankio.util;
2+
3+
import android.app.Activity;
4+
import android.app.Dialog;
5+
import java.lang.ref.WeakReference;
6+
7+
import com.gankio.R;
8+
9+
/**
10+
* Created by wangdi on 14/11/16.
11+
*/
12+
13+
public class SplashScreen {
14+
private static Dialog mSplashDialog;
15+
private static WeakReference<Activity> mActivity;
16+
17+
public static void show(final Activity activity, final boolean fullScreen){
18+
if (activity == null) return;
19+
mActivity = new WeakReference<Activity>(activity);
20+
activity.runOnUiThread(new Runnable() {
21+
@Override
22+
public void run() {
23+
if (!activity.isFinishing()) {
24+
25+
mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen: R.style.SplashScreen_SplashTheme);
26+
mSplashDialog.setContentView(R.layout.launch_screen);
27+
mSplashDialog.setCancelable(false);
28+
29+
if (!mSplashDialog.isShowing()) {
30+
mSplashDialog.show();
31+
}
32+
}
33+
}
34+
});
35+
}
36+
37+
public static void hide(Activity activity){
38+
if (activity == null) activity = mActivity.get();
39+
if (activity == null) return;
40+
41+
activity.runOnUiThread(new Runnable() {
42+
@Override
43+
public void run() {
44+
if (mSplashDialog != null && mSplashDialog.isShowing()) {
45+
mSplashDialog.dismiss();
46+
}
47+
}
48+
});
49+
}
50+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.gankio.util;
2+
3+
import android.app.Activity;
4+
import android.app.Dialog;
5+
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
8+
import com.facebook.react.bridge.ReactMethod;
9+
10+
import java.lang.ref.WeakReference;
11+
12+
/**
13+
* Created by wangdi on 14/11/16.
14+
*/
15+
16+
public class SplashScreenModule extends ReactContextBaseJavaModule{
17+
18+
19+
public SplashScreenModule(ReactApplicationContext reactContext) {
20+
super(reactContext);
21+
}
22+
23+
@Override
24+
public String getName() {
25+
return "SplashScreen";
26+
}
27+
28+
@ReactMethod
29+
public void hide(){
30+
SplashScreen.hide(getCurrentActivity());
31+
}
32+
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#fff">
6+
<ImageView
7+
android:layout_width="80dp"
8+
android:layout_height="80dp"
9+
android:src="@drawable/js_assets_icon"
10+
android:id="@+id/logo"
11+
android:layout_centerHorizontal="true"
12+
android:layout_marginTop="130dp"/>
13+
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_below="@id/logo"
18+
android:text="干货集中营"
19+
android:textSize="20dp"
20+
android:layout_centerHorizontal="true"
21+
android:layout_marginTop="10dp"
22+
android:textColor="#000"/>
23+
24+
<TextView
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_centerHorizontal="true"
28+
android:layout_alignParentBottom="true"
29+
android:text="获取每日技术干货"
30+
android:textSize="16dp"
31+
android:textColor="#666"
32+
android:layout_marginBottom="50dp"/>
33+
34+
</RelativeLayout>

android/app/src/main/res/values/styles.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@
55
<!-- Customize your theme here. -->
66
</style>
77

8+
<style name="SplashScreen_SplashAnimation">
9+
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
10+
</style>
11+
12+
<style name="SplashScreen_SplashTheme" parent="Theme.AppCompat.NoActionBar">
13+
<item name="android:windowAnimationStyle">@style/SplashScreen_SplashAnimation</item>
14+
</style>
15+
16+
<style name="SplashScreen_Fullscreen" parent="SplashScreen_SplashTheme">
17+
<item name="android:windowFullscreen">true</item>
18+
</style>
19+
820
</resources>

0 commit comments

Comments
 (0)