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

Side by Side 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: refactoring code for performance 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 unified diff | Download patch
OLDNEW
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
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 mEnteredImmersive;
63 private Runnable mSetImmersiveRunnable;
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
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 && (mSetImmersiveRunnable != null)) {
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()) {
dominickn 2017/01/18 05:56:17 Minor nit: the style guide lets you do this for sh
Leo 2017/01/18 23:03:12 Done.
212 return;
213 }
214
215 if (mSetImmersiveRunnable == null) {
216 mSetImmersiveRunnable = new Runnable() {
217 @Override
218 public void run() {
219 int currentFlags = decor.getSystemUiVisibility();
220 int desiredFlags = currentFlags | IMMERSIVE_MODE_UI_FLAGS;
221 if (currentFlags != desiredFlags) {
222 decor.setSystemUiVisibility(desiredFlags);
223 }
224 }
225 };
226 }
227
228 // When we enter immersive mode for the first time, register a
229 // SystemUiVisibilityChangeListener that restores immersive mode. This i s necessary
230 // because user actions like focusing a keyboard will break out of immer sive.
231 if (!mEnteredImmersive) {
232 decor.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibility ChangeListener() {
233 @Override
234 public void onSystemUiVisibilityChange(int newFlags) {
235 if ((newFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
236 asyncSetImmersive(decor, RESTORE_IMMERSIVE_MODE_DELAY_MI LLIS);
237 }
238 }
239 });
240 }
241 // Set immersive mode asynchronously.
dominickn 2017/01/18 05:56:17 Minor nit: you can probably remove this comment be
Leo 2017/01/18 23:03:12 Done.
242 asyncSetImmersive(decor, ENTER_IMMERSIVE_MODE_DELAY_MILLIS);
243 mEnteredImmersive = true;
244 }
245
246 private void asyncSetImmersive(final View decor, int delayInMills) {
247 if (mSetImmersiveRunnable == null) {
dominickn 2017/01/18 05:56:17 Minor style nit: you can inline the return here.
Leo 2017/01/18 23:03:12 Done. And remove unused decor.
248 return;
249 }
250 mHandler.removeCallbacks(mSetImmersiveRunnable);
251 mHandler.postDelayed(mSetImmersiveRunnable, delayInMills);
252 }
253
182 /** 254 /**
183 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. 255 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}.
184 */ 256 */
185 protected TabDelegateFactory createTabDelegateFactory() { 257 protected TabDelegateFactory createTabDelegateFactory() {
186 return new FullScreenDelegateFactory(); 258 return new FullScreenDelegateFactory();
187 } 259 }
188 260
189 /** 261 /**
190 * @return {@link File} pointing at a directory specific for this class. 262 * @return {@link File} pointing at a directory specific for this class.
191 */ 263 */
192 protected File getActivityDirectory() { 264 protected File getActivityDirectory() {
193 return null; 265 return null;
194 } 266 }
195 267
196 @Override 268 @Override
197 protected boolean handleBackPressed() { 269 protected boolean handleBackPressed() {
198 if (mTab == null) return false; 270 if (mTab == null) return false;
199 if (mTab.canGoBack()) { 271 if (mTab.canGoBack()) {
200 mTab.goBack(); 272 mTab.goBack();
201 return true; 273 return true;
202 } 274 }
203 return false; 275 return false;
204 } 276 }
205 277
206 @Override 278 @Override
207 public void onCheckForUpdate(boolean updateAvailable) { 279 public void onCheckForUpdate(boolean updateAvailable) {
208 } 280 }
281
282 /**
283 ** @return true if this device supports immersive mode functionality.
dominickn 2017/01/18 05:56:17 Minor style nit: single * after the first line of
Leo 2017/01/18 23:03:12 Thanks for the correction. I found this method is
284 **/
285 public static boolean supportsImmersiveMode() {
286 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
287 }
209 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698