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; | |
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
| |
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 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 && (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
| |
203 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.
| |
204 } | |
205 } | |
206 | |
207 /** | |
208 * Sets the given decor {@link View} into an immersive mode. | |
209 * If immersive mode is not supported, this method no-ops. | |
210 */ | |
211 protected void enterImmersiveMode(final View decor) { | |
212 // Immersive mode is only supported in API 19+. | |
213 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return; | |
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 mode. | |
231 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.
| |
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(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.
| |
237 } | |
238 } | |
239 }); | |
240 } | |
241 | |
242 asyncSetImmersive(ENTER_IMMERSIVE_MODE_DELAY_MILLIS); | |
243 mEnteredImmersive = true; | |
244 } | |
245 | |
246 private void asyncSetImmersive(int delayInMills) { | |
247 if (mSetImmersiveRunnable == null) return; | |
248 | |
249 mHandler.removeCallbacks(mSetImmersiveRunnable); | |
250 mHandler.postDelayed(mSetImmersiveRunnable, delayInMills); | |
251 } | |
252 | |
182 /** | 253 /** |
183 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. | 254 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. |
184 */ | 255 */ |
185 protected TabDelegateFactory createTabDelegateFactory() { | 256 protected TabDelegateFactory createTabDelegateFactory() { |
186 return new FullScreenDelegateFactory(); | 257 return new FullScreenDelegateFactory(); |
187 } | 258 } |
188 | 259 |
189 /** | 260 /** |
190 * @return {@link File} pointing at a directory specific for this class. | 261 * @return {@link File} pointing at a directory specific for this class. |
191 */ | 262 */ |
192 protected File getActivityDirectory() { | 263 protected File getActivityDirectory() { |
193 return null; | 264 return null; |
194 } | 265 } |
195 | 266 |
196 @Override | 267 @Override |
197 protected boolean handleBackPressed() { | 268 protected boolean handleBackPressed() { |
198 if (mTab == null) return false; | 269 if (mTab == null) return false; |
199 if (mTab.canGoBack()) { | 270 if (mTab.canGoBack()) { |
200 mTab.goBack(); | 271 mTab.goBack(); |
201 return true; | 272 return true; |
202 } | 273 } |
203 return false; | 274 return false; |
204 } | 275 } |
205 | 276 |
206 @Override | 277 @Override |
207 public void onCheckForUpdate(boolean updateAvailable) { | 278 public void onCheckForUpdate(boolean updateAvailable) { |
208 } | 279 } |
209 } | 280 } |
OLD | NEW |