| Index: remoting/android/java/src/org/chromium/chromoting/Desktop.java
|
| diff --git a/remoting/android/java/src/org/chromium/chromoting/Desktop.java b/remoting/android/java/src/org/chromium/chromoting/Desktop.java
|
| index 9133aa53ac065d3cdc45ca1237536da1f0678465..9cfb8792fbf1770594710127ea79b3196f2bfbfe 100644
|
| --- a/remoting/android/java/src/org/chromium/chromoting/Desktop.java
|
| +++ b/remoting/android/java/src/org/chromium/chromoting/Desktop.java
|
| @@ -93,6 +93,9 @@ public class Desktop
|
| */
|
| private boolean mHasPhysicalKeyboard;
|
|
|
| + /** Tracks whether the activity is in the resumed (running) state. */
|
| + private boolean mIsActivityRunning = false;
|
| +
|
| /** Called when the activity is first created. */
|
| @Override
|
| public void onCreate(Bundle savedInstanceState) {
|
| @@ -132,29 +135,7 @@ public class Desktop
|
| mInputMode = getInitialInputModeValue();
|
|
|
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
| - attachKeyboardVisibilityListener();
|
| -
|
| - // Only create an Autohide task if the system supports immersive fullscreen mode. Older
|
| - // versions of the OS benefit less from this functionality and we don't want to change
|
| - // the experience for them.
|
| - mActionBarAutoHideTask = new Runnable() {
|
| - public void run() {
|
| - if (!mToolbar.isOverflowMenuShowing()) {
|
| - hideSystemUi();
|
| - }
|
| - }
|
| - };
|
| -
|
| - // Suspend the ActionBar timer when the user interacts with the options menu.
|
| - getSupportActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
|
| - public void onMenuVisibilityChanged(boolean isVisible) {
|
| - if (isVisible) {
|
| - stopActionBarAutoHideTimer();
|
| - } else {
|
| - startActionBarAutoHideTimer();
|
| - }
|
| - }
|
| - });
|
| + attachSystemUiResizeListener();
|
| } else {
|
| mRemoteHostDesktop.setFitsSystemWindows(true);
|
| }
|
| @@ -169,19 +150,29 @@ public class Desktop
|
| }
|
|
|
| @Override
|
| - protected void onPause() {
|
| - if (isFinishing()) mActivityLifecycleListener.onActivityPaused(this);
|
| - super.onPause();
|
| - mClient.enableVideoChannel(false);
|
| - stopActionBarAutoHideTimer();
|
| - }
|
| -
|
| - @Override
|
| public void onResume() {
|
| + mIsActivityRunning = true;
|
| super.onResume();
|
| mActivityLifecycleListener.onActivityResumed(this);
|
| mClient.enableVideoChannel(true);
|
| - syncActionBarToSystemUiState();
|
| + if (!inWindowedMode()) {
|
| + setUpAutoHideToolbar();
|
| + syncActionBarToSystemUiState();
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + protected void onPause() {
|
| + if (isFinishing()) mActivityLifecycleListener.onActivityPaused(this);
|
| + super.onPause();
|
| + // The activity is paused in windowed mode when the user switches to another window. In
|
| + // that case we should leave the video channel running so they continue to see updates from
|
| + // their remote machine. The video channel will be stopped when onStop() is called.
|
| + if (!inWindowedMode()) {
|
| + mClient.enableVideoChannel(false);
|
| + }
|
| + stopActionBarAutoHideTimer();
|
| + mIsActivityRunning = false;
|
| }
|
|
|
| @Override
|
| @@ -345,6 +336,45 @@ public class Desktop
|
| });
|
| }
|
|
|
| + private Boolean inWindowedMode() {
|
| + // NOTE: This method should only be called after OnResume() is called, otherwise
|
| + // isInMultiWindowMode() may not be accurate. The value returned by this method is updated
|
| + // on a background thread and there is a race-condition between when the UX changes and this
|
| + // value is updated. Hence, calling this method from onCreate() is not safe and we need to
|
| + // be careful when we query this value.
|
| + Preconditions.isTrue(mIsActivityRunning);
|
| +
|
| + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode();
|
| + }
|
| +
|
| + private void setUpAutoHideToolbar() {
|
| + // Configure the auto-hiding taskbar if the activity is not in multi-window mode and the
|
| + // application is run on an OS which supports fullscreen mode (KitKat or higher).
|
| + Preconditions.isTrue(!inWindowedMode());
|
| + if (mActionBarAutoHideTask != null || Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
| + return;
|
| + }
|
| +
|
| + mActionBarAutoHideTask = new Runnable() {
|
| + public void run() {
|
| + if (!mToolbar.isOverflowMenuShowing()) {
|
| + hideSystemUi();
|
| + }
|
| + }
|
| + };
|
| +
|
| + // Suspend the ActionBar timer when the user interacts with the options menu.
|
| + getSupportActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
|
| + public void onMenuVisibilityChanged(boolean isVisible) {
|
| + if (isVisible) {
|
| + stopActionBarAutoHideTimer();
|
| + } else {
|
| + startActionBarAutoHideTimer();
|
| + }
|
| + }
|
| + });
|
| + }
|
| +
|
| // Posts a deplayed task to hide the ActionBar. If an existing task has already been scheduled,
|
| // then the previous task is removed and the new one scheduled, effectively resetting the timer.
|
| private void startActionBarAutoHideTimer() {
|
| @@ -528,9 +558,9 @@ public class Desktop
|
| return super.onOptionsItemSelected(item);
|
| }
|
|
|
| - private void attachKeyboardVisibilityListener() {
|
| - View keyboardVisibilityDetector = findViewById(R.id.resize_detector);
|
| - keyboardVisibilityDetector.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
| + private void attachSystemUiResizeListener() {
|
| + View systemUiResizeDetector = findViewById(R.id.resize_detector);
|
| + systemUiResizeDetector.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
| // Tracks the maximum 'bottom' value seen during layout changes. This value represents
|
| // the top of the SystemUI displayed at the bottom of the screen.
|
| // Note: This value is a screen coordinate so a larger value means lower on the screen.
|
|
|