From 240444c21374d59c97da75134e5e55bd99599cc0 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 10 Jul 2018 15:00:56 +0200 Subject: [PATCH] Android keep screen on --- .../com/brentvatne/react/ReactVideoView.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index 954130a1..6568f860 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -9,6 +9,7 @@ import android.os.Build; import android.os.Handler; import android.util.Log; import android.view.MotionEvent; +import android.view.WindowManager; import android.webkit.CookieManager; import android.widget.MediaController; @@ -89,7 +90,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP private Handler videoControlHandler = new Handler(); private MediaController mediaController; - private String mSrcUriString = null; private String mSrcType = "mp4"; private ReadableMap mRequestHeaders = null; @@ -591,6 +591,15 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mMediaPlayerValid = false; super.onDetachedFromWindow(); + + if (mThemedReactContext != null) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } } @Override @@ -598,6 +607,15 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP super.onAttachedToWindow(); + if (mThemedReactContext != null) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } + if(mMainVer>0) { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); }