Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added video support for android. Will update the documentation too if needed but first just go through the code once. #547

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
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:[email protected]
* SplashScreen 启动屏 from:http://www.devio.org Author:CrazyCodeBoy
* GitHub:https://github.com/crazycodeboy Email:[email protected]
*/
public class SplashScreen {
private static Dialog mSplashDialog;
Expand All @@ -21,19 +21,25 @@ public class SplashScreen {
/**
* 打开启动屏
*/
public static void show(final Activity activity, final int themeResId) {
if (activity == null) return;
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);
mSplashDialog.setCancelable(false);

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);
}
}
}
}
Expand All @@ -43,17 +49,17 @@ public void run() {
/**
* 打开启动屏
*/
public static void show(final Activity activity, final boolean fullScreen) {
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);
show(activity, resourceId, isvideoSplash);
}

/**
* 打开启动屏
*/
public static void show(final Activity activity) {
show(activity, false);
show(activity, false, false);
}

/**
Expand All @@ -67,7 +73,8 @@ public static void hide(Activity activity) {
activity = mActivity.get();
}

if (activity == null) return;
if (activity == null)
return;

final Activity _activity = activity;

Expand Down
8 changes: 7 additions & 1 deletion android/src/main/res/values/refs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<item type="layout" name="launch_screen">
@layout/launch_screen
</item>
</resources>
<item type="raw" name="splash_video">
@raw/splash_video
</item>
<item type="id" name="simpleVideoView">
@id/simpleVideoView
</item>
</resources>