Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.os.Build; | |
| 8 import android.util.Pair; | 9 import android.util.Pair; |
| 9 import android.view.View; | 10 import android.view.View; |
| 11 import android.view.View.OnSystemUiVisibilityChangeListener; | |
| 10 import android.view.ViewGroup; | 12 import android.view.ViewGroup; |
| 11 | 13 |
| 12 import org.chromium.base.annotations.SuppressFBWarnings; | 14 import org.chromium.base.annotations.SuppressFBWarnings; |
| 13 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ChromeActivity; | 16 import org.chromium.chrome.browser.ChromeActivity; |
| 15 import org.chromium.chrome.browser.TabState; | 17 import org.chromium.chrome.browser.TabState; |
| 16 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; | 18 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; |
| 17 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 19 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 18 import org.chromium.chrome.browser.tab.Tab; | 20 import org.chromium.chrome.browser.tab.Tab; |
| 19 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 21 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 39 * Activity would be webapps and streaming media activities - anything where use r interaction with | 41 * Activity would be webapps and streaming media activities - anything where use r interaction with |
| 40 * the regular browser's UI is either unnecessary or undesirable. | 42 * the regular browser's UI is either unnecessary or undesirable. |
| 41 * Subclasses can override {@link #createUI()} if they need something more exoti c. | 43 * Subclasses can override {@link #createUI()} if they need something more exoti c. |
| 42 */ | 44 */ |
| 43 @SuppressFBWarnings("URF_UNREAD_FIELD") | 45 @SuppressFBWarnings("URF_UNREAD_FIELD") |
| 44 public abstract class FullScreenActivity extends ChromeActivity { | 46 public abstract class FullScreenActivity extends ChromeActivity { |
| 45 protected static final String BUNDLE_TAB_ID = "tabId"; | 47 protected static final String BUNDLE_TAB_ID = "tabId"; |
| 46 protected static final String BUNDLE_TAB_URL = "tabUrl"; | 48 protected static final String BUNDLE_TAB_URL = "tabUrl"; |
| 47 private static final String TAG = "FullScreenActivity"; | 49 private static final String TAG = "FullScreenActivity"; |
| 48 | 50 |
| 51 private static final int ENTER_IMMERSIVE_MODE_DELAY_MILLIS = 300; | |
| 52 private static final int RESTORE_IMMERSIVE_MODE_DELAY_MILLIS = 3000; | |
| 53 private static final int IMMERSIVE_MODE_UI_FLAGS = | |
| 54 View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
| 55 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| 56 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | |
| 57 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar | |
| 58 | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | |
| 59 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 60 | View.SYSTEM_UI_FLAG_IMMERSIVE; | |
| 61 | |
| 62 private boolean mEnableImmersive; | |
| 63 private boolean mEnteredImmersive; | |
| 64 | |
| 49 private Tab mTab; | 65 private Tab mTab; |
| 50 | 66 |
| 51 private WebContents mWebContents; | 67 private WebContents mWebContents; |
| 52 @SuppressWarnings("unused") // Reference needed to prevent GC. | 68 @SuppressWarnings("unused") // Reference needed to prevent GC. |
| 53 private WebContentsObserver mWebContentsObserver; | 69 private WebContentsObserver mWebContentsObserver; |
| 54 | 70 |
| 55 @Override | 71 @Override |
| 56 protected void onNewIntent(Intent intent) { | 72 protected void onNewIntent(Intent intent) { |
| 57 super.onNewIntent(intent); | 73 super.onNewIntent(intent); |
| 58 setIntent(intent); | 74 setIntent(intent); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 public void didCommitProvisionalLoadForFrame( | 188 public void didCommitProvisionalLoadForFrame( |
| 173 long frameId, boolean isMainFrame, String url, int transitio nType) { | 189 long frameId, boolean isMainFrame, String url, int transitio nType) { |
| 174 if (!isMainFrame) return; | 190 if (!isMainFrame) return; |
| 175 // Notify the renderer to permanently hide the top controls sinc e they do | 191 // Notify the renderer to permanently hide the top controls sinc e they do |
| 176 // not apply to fullscreen content views. | 192 // not apply to fullscreen content views. |
| 177 mTab.updateBrowserControlsState(mTab.getBrowserControlsStateCons traints(), true); | 193 mTab.updateBrowserControlsState(mTab.getBrowserControlsStateCons traints(), true); |
| 178 } | 194 } |
| 179 }; | 195 }; |
| 180 } | 196 } |
| 181 | 197 |
| 198 @Override | |
| 199 public void onWindowFocusChanged(boolean hasFocus) { | |
| 200 super.onWindowFocusChanged(hasFocus); | |
| 201 | |
| 202 if (hasFocus && mEnableImmersive) { | |
| 203 enterImmersiveMode(getWindow().getDecorView()); | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 /** | |
| 208 * Ensure the given {@link View} is in fullscreen immersion if this device s upports. | |
| 209 */ | |
| 210 protected void enterImmersiveMode(final View decor) { | |
| 211 if (!supportsImmersiveMode()) { | |
| 212 return; | |
| 213 } | |
| 214 mEnableImmersive = true; | |
| 215 | |
| 216 // Register a SystemUiVisibilityChangeListener to restore immersive mode . | |
|
dominickn
2017/01/16 22:49:01
Can these comments be a little more descriptive? S
| |
| 217 if (!mEnteredImmersive) { | |
| 218 decor.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibility ChangeListener() { | |
| 219 @Override | |
| 220 public void onSystemUiVisibilityChange(int newFlags) { | |
| 221 delaySetImmersive(decor, newFlags, RESTORE_IMMERSIVE_MODE_DE LAY_MILLIS); | |
| 222 } | |
| 223 }); | |
| 224 } | |
| 225 // Set Immersive mode on demand. | |
|
dominickn
2017/01/16 22:49:01
Nit: add a newline above this comment, and explain
Leo
2017/01/18 05:09:40
Actually I just follow the sample codes created by
dominickn
2017/01/18 05:56:17
Ah, I see, that makes sense.
| |
| 226 delaySetImmersive(decor, decor.getSystemUiVisibility(), ENTER_IMMERSIVE_ MODE_DELAY_MILLIS); | |
| 227 mEnteredImmersive = true; | |
| 228 } | |
| 229 | |
| 230 private void delaySetImmersive(final View decor, final int flags, int delayI nMills) { | |
| 231 mHandler.postDelayed(new Runnable() { | |
| 232 @Override | |
| 233 public void run() { | |
| 234 int desiredFlags = flags | IMMERSIVE_MODE_UI_FLAGS; | |
| 235 if (flags != desiredFlags) { | |
| 236 decor.setSystemUiVisibility(desiredFlags); | |
| 237 } | |
| 238 } | |
| 239 }, delayInMills); | |
| 240 } | |
| 241 | |
| 182 /** | 242 /** |
| 183 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. | 243 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. |
| 184 */ | 244 */ |
| 185 protected TabDelegateFactory createTabDelegateFactory() { | 245 protected TabDelegateFactory createTabDelegateFactory() { |
| 186 return new FullScreenDelegateFactory(); | 246 return new FullScreenDelegateFactory(); |
| 187 } | 247 } |
| 188 | 248 |
| 189 /** | 249 /** |
| 190 * @return {@link File} pointing at a directory specific for this class. | 250 * @return {@link File} pointing at a directory specific for this class. |
| 191 */ | 251 */ |
| 192 protected File getActivityDirectory() { | 252 protected File getActivityDirectory() { |
| 193 return null; | 253 return null; |
| 194 } | 254 } |
| 195 | 255 |
| 196 @Override | 256 @Override |
| 197 protected boolean handleBackPressed() { | 257 protected boolean handleBackPressed() { |
| 198 if (mTab == null) return false; | 258 if (mTab == null) return false; |
| 199 if (mTab.canGoBack()) { | 259 if (mTab.canGoBack()) { |
| 200 mTab.goBack(); | 260 mTab.goBack(); |
| 201 return true; | 261 return true; |
| 202 } | 262 } |
| 203 return false; | 263 return false; |
| 204 } | 264 } |
| 205 | 265 |
| 206 @Override | 266 @Override |
| 207 public void onCheckForUpdate(boolean updateAvailable) { | 267 public void onCheckForUpdate(boolean updateAvailable) { |
| 208 } | 268 } |
| 269 | |
| 270 /** | |
| 271 ** @return true if this device supports immersive mode functionality. | |
| 272 **/ | |
| 273 public static boolean supportsImmersiveMode() { | |
| 274 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; | |
| 275 } | |
| 209 } | 276 } |
| OLD | NEW |