Browse Source

fixed full-screen mode when watching a video in full-screen

master
Anthony Restaino 9 years ago
parent
commit
b8b610347f
  1. 55
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 4
      app/src/main/java/acr/browser/lightning/activity/ThemableActivity.java

55
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -145,6 +145,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
private LightningView mCurrentView; private LightningView mCurrentView;
private WebView mWebView; private WebView mWebView;
// Views
private AnimatedProgressBar mProgressBar; private AnimatedProgressBar mProgressBar;
private AutoCompleteTextView mSearch; private AutoCompleteTextView mSearch;
private ImageView mArrowImage, mBookmarkTitleImage, mBookmarkImage; private ImageView mArrowImage, mBookmarkTitleImage, mBookmarkImage;
@ -166,7 +167,11 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
private Activity mActivity; private Activity mActivity;
// Primatives // Primatives
private boolean mSystemBrowser = false, mIsNewIntent = false, mFullScreen, mColorMode, mDarkTheme; private boolean mFullScreen, mColorMode, mDarkTheme,
mSystemBrowser = false,
mIsNewIntent = false,
mIsFullScreen = false,
mIsImmersive = false;
private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor; private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor;
private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath; private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath;
@ -658,12 +663,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
if (mWebView != null) if (mWebView != null)
mWebView.setTranslationY(0); mWebView.setTranslationY(0);
} }
if (mPreferences.getHideStatusBarEnabled()) { setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
switch (mPreferences.getSearchChoice()) { switch (mPreferences.getSearchChoice()) {
case 0: case 0:
@ -2252,7 +2252,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
mCustomView = view; mCustomView = view;
mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS); mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
setFullscreen(true); setFullscreen(true, true);
mCurrentView.setVisibility(View.GONE); mCurrentView.setVisibility(View.GONE);
if (view instanceof FrameLayout) { if (view instanceof FrameLayout) {
if (((FrameLayout) view).getFocusedChild() instanceof VideoView) { if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
@ -2276,7 +2276,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on"); Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
} }
setFullscreen(mPreferences.getHideStatusBarEnabled()); setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
FrameLayout decor = (FrameLayout) getWindow().getDecorView(); FrameLayout decor = (FrameLayout) getWindow().getDecorView();
if (decor != null) { if (decor != null) {
decor.removeView(mFullscreenContainer); decor.removeView(mFullscreenContainer);
@ -2314,26 +2314,39 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} }
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
setFullscreen(mIsFullScreen, mIsImmersive);
}
}
/** /**
* turns on fullscreen mode in the app * turns on fullscreen mode in the app
* *
* @param enabled whether to enable fullscreen or not * @param enabled whether to enable fullscreen or not
*/ */
private void setFullscreen(boolean enabled) { private void setFullscreen(boolean enabled, boolean immersive) {
Window win = getWindow(); mIsFullScreen = enabled;
WindowManager.LayoutParams winParams = win.getAttributes(); mIsImmersive = immersive;
final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; Window window = getWindow();
View decor = window.getDecorView();
if (enabled) { if (enabled) {
winParams.flags |= bits; window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
} else { WindowManager.LayoutParams.FLAG_FULLSCREEN);
winParams.flags &= ~bits; if (immersive) {
if (mCustomView != null) { decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
} else { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
mBrowserFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
} }
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
} }
win.setAttributes(winParams);
} }
/** /**

4
app/src/main/java/acr/browser/lightning/activity/ThemableActivity.java

@ -33,6 +33,8 @@ public abstract class ThemableActivity extends AppCompatActivity {
} }
private void restart() { private void restart() {
recreate(); Intent intent = getIntent();
finish();
startActivity(intent);
} }
} }

Loading…
Cancel
Save