Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java

Issue 2636833003: Support "display": "fullscreen" for sites added to the home screen. (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java
index 901b62b51f70f11bef575b192284684282548dd1..dc4f65203a0e269c0e2da5c0a5396d50971c0d44 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java
@@ -5,8 +5,10 @@
package org.chromium.chrome.browser.webapps;
import android.content.Intent;
+import android.os.Build;
import android.util.Pair;
import android.view.View;
+import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.ViewGroup;
import org.chromium.base.annotations.SuppressFBWarnings;
@@ -46,6 +48,20 @@ public abstract class FullScreenActivity extends ChromeActivity {
protected static final String BUNDLE_TAB_URL = "tabUrl";
private static final String TAG = "FullScreenActivity";
+ private static final int ENTER_IMMERSIVE_MODE_DELAY_MILLIS = 300;
Ted C 2017/01/20 05:47:07 any reason all of this logic isn't in WebappActivi
Leo 2017/01/23 01:14:27 Original changes was in WebappActivity. Somehow I
Ted C 2017/01/23 19:01:08 Fullscreen in the name of this activity means that
Leo 2017/02/07 07:52:49 Thanks for the advice. Moved all changes to Webapp
+ private static final int RESTORE_IMMERSIVE_MODE_DELAY_MILLIS = 3000;
+ private static final int IMMERSIVE_MODE_UI_FLAGS =
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
+ | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
+ | View.SYSTEM_UI_FLAG_LOW_PROFILE
+ | View.SYSTEM_UI_FLAG_IMMERSIVE;
+
+ private boolean mEnteredImmersive;
+ private Runnable mSetImmersiveRunnable;
+
private Tab mTab;
private WebContents mWebContents;
@@ -179,6 +195,61 @@ public abstract class FullScreenActivity extends ChromeActivity {
};
}
+ @Override
+ public void onWindowFocusChanged(boolean hasFocus) {
+ super.onWindowFocusChanged(hasFocus);
+
+ if (hasFocus && (mSetImmersiveRunnable != null)) {
Ted C 2017/01/20 05:47:07 the () around the null check aren't needed
Leo 2017/01/23 01:14:27 Thanks for the catch. Use asyncSetImmersive here
+ enterImmersiveMode(getWindow().getDecorView());
Ted C 2017/01/20 05:47:07 looks like both call sites just pass in getWindow(
Leo 2017/01/23 01:14:27 Sure, getWindow().getDecorView() can be used inter
Ted C 2017/01/23 19:01:08 I would just remove the variable. getDecorView()
Leo 2017/02/07 07:52:48 Done.
+ }
+ }
+
+ /**
+ * Sets the given decor {@link View} into an immersive mode.
+ * If immersive mode is not supported, this method no-ops.
+ */
+ protected void enterImmersiveMode(final View decor) {
+ // Immersive mode is only supported in API 19+.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
+
+ if (mSetImmersiveRunnable == null) {
+ mSetImmersiveRunnable = new Runnable() {
+ @Override
+ public void run() {
+ int currentFlags = decor.getSystemUiVisibility();
+ int desiredFlags = currentFlags | IMMERSIVE_MODE_UI_FLAGS;
+ if (currentFlags != desiredFlags) {
+ decor.setSystemUiVisibility(desiredFlags);
+ }
+ }
+ };
+ }
+
+ // When we enter immersive mode for the first time, register a
+ // SystemUiVisibilityChangeListener that restores immersive mode. This is necessary
+ // because user actions like focusing a keyboard will break out of immersive mode.
+ if (!mEnteredImmersive) {
Ted C 2017/01/20 05:47:07 can we just put this block in the mSetImmersiveRun
Leo 2017/01/23 01:14:27 Thanks for the tips, Done.
+ decor.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
+ @Override
+ public void onSystemUiVisibilityChange(int newFlags) {
+ if ((newFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
+ asyncSetImmersive(RESTORE_IMMERSIVE_MODE_DELAY_MILLIS);
Ted C 2017/01/20 05:47:07 3 seconds seems like a very long time. Why does i
Leo 2017/01/23 01:14:27 In most scenarios, immersive mode will be restored
Ted C 2017/01/23 19:01:08 That video looks good to me. Good to know the con
Leo 2017/02/07 07:52:49 Acknowledged.
+ }
+ }
+ });
+ }
+
+ asyncSetImmersive(ENTER_IMMERSIVE_MODE_DELAY_MILLIS);
+ mEnteredImmersive = true;
+ }
+
+ private void asyncSetImmersive(int delayInMills) {
+ if (mSetImmersiveRunnable == null) return;
+
+ mHandler.removeCallbacks(mSetImmersiveRunnable);
+ mHandler.postDelayed(mSetImmersiveRunnable, delayInMills);
+ }
+
/**
* @return {@link TabDelegateFactory} to be used while creating the associated {@link Tab}.
*/
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698