| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.res.Configuration; |
| 8 import android.os.Build; | 9 import android.os.Build; |
| 9 import android.os.Bundle; | 10 import android.os.Bundle; |
| 10 import android.os.Handler; | 11 import android.os.Handler; |
| 11 import android.support.v7.app.ActionBar.OnMenuVisibilityListener; | 12 import android.support.v7.app.ActionBar.OnMenuVisibilityListener; |
| 12 import android.support.v7.app.AppCompatActivity; | 13 import android.support.v7.app.AppCompatActivity; |
| 13 import android.support.v7.widget.Toolbar; | 14 import android.support.v7.widget.Toolbar; |
| 14 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
| 15 import android.view.Menu; | 16 import android.view.Menu; |
| 16 import android.view.MenuItem; | 17 import android.view.MenuItem; |
| 17 import android.view.MotionEvent; | 18 import android.view.MotionEvent; |
| 18 import android.view.View; | 19 import android.view.View; |
| 19 import android.view.View.OnLayoutChangeListener; | 20 import android.view.View.OnLayoutChangeListener; |
| 20 import android.view.View.OnTouchListener; | 21 import android.view.View.OnTouchListener; |
| 21 import android.view.inputmethod.InputMethodManager; | 22 import android.view.inputmethod.InputMethodManager; |
| 22 | 23 |
| 23 import org.chromium.chromoting.help.HelpContext; | 24 import org.chromium.chromoting.help.HelpContext; |
| 24 import org.chromium.chromoting.help.HelpSingleton; | 25 import org.chromium.chromoting.help.HelpSingleton; |
| 25 import org.chromium.chromoting.jni.Client; | 26 import org.chromium.chromoting.jni.Client; |
| 27 import org.chromium.ui.UiUtils; |
| 26 | 28 |
| 27 import java.util.List; | 29 import java.util.List; |
| 28 | 30 |
| 29 /** | 31 /** |
| 30 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. | 32 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. |
| 31 */ | 33 */ |
| 32 public class Desktop | 34 public class Desktop |
| 33 extends AppCompatActivity implements View.OnSystemUiVisibilityChangeList
ener, | 35 extends AppCompatActivity implements View.OnSystemUiVisibilityChangeList
ener, |
| 34 CapabilityManager.CapabilitiesChang
edListener { | 36 CapabilityManager.CapabilitiesChang
edListener { |
| 35 /** Used to set/store the selected input mode. */ | 37 /** Used to set/store the selected input mode. */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 73 |
| 72 /** Tracks the current input mode (e.g. trackpad/touch). */ | 74 /** Tracks the current input mode (e.g. trackpad/touch). */ |
| 73 private InputMode mInputMode = InputMode.UNKNOWN; | 75 private InputMode mInputMode = InputMode.UNKNOWN; |
| 74 | 76 |
| 75 /** Indicates whether the remote host supports touch injection. */ | 77 /** Indicates whether the remote host supports touch injection. */ |
| 76 private CapabilityManager.HostCapability mHostTouchCapability = | 78 private CapabilityManager.HostCapability mHostTouchCapability = |
| 77 CapabilityManager.HostCapability.UNKNOWN; | 79 CapabilityManager.HostCapability.UNKNOWN; |
| 78 | 80 |
| 79 private DesktopView mRemoteHostDesktop; | 81 private DesktopView mRemoteHostDesktop; |
| 80 | 82 |
| 83 /** |
| 84 * Indicates whether the device is connected to a non-hidden physical qwerty
keyboard. This is |
| 85 * set by {@link Desktop#setKeyboardState(Configuration)}. DO NOT request a
soft keyboard when a |
| 86 * physical keyboard exists, otherwise the activity will enter an undefined
state where the soft |
| 87 * keyboard never shows up meanwhile request to hide status bar always fails
. |
| 88 */ |
| 89 private boolean mHasPhysicalKeyboard; |
| 90 |
| 81 /** Called when the activity is first created. */ | 91 /** Called when the activity is first created. */ |
| 82 @Override | 92 @Override |
| 83 public void onCreate(Bundle savedInstanceState) { | 93 public void onCreate(Bundle savedInstanceState) { |
| 84 super.onCreate(savedInstanceState); | 94 super.onCreate(savedInstanceState); |
| 85 setContentView(R.layout.desktop); | 95 setContentView(R.layout.desktop); |
| 86 | 96 |
| 87 mClient = Client.getInstance(); | 97 mClient = Client.getInstance(); |
| 88 mInjector = new InputEventSender(mClient); | 98 mInjector = new InputEventSender(mClient); |
| 89 | 99 |
| 90 Preconditions.notNull(mClient); | 100 Preconditions.notNull(mClient); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 225 } |
| 216 } | 226 } |
| 217 }); | 227 }); |
| 218 } | 228 } |
| 219 | 229 |
| 220 ChromotingUtil.tintMenuIcons(this, menu); | 230 ChromotingUtil.tintMenuIcons(this, menu); |
| 221 | 231 |
| 222 // Wait to set the input mode until after the default tinting has been a
pplied. | 232 // Wait to set the input mode until after the default tinting has been a
pplied. |
| 223 setInputMode(mInputMode); | 233 setInputMode(mInputMode); |
| 224 | 234 |
| 235 // Keyboard state must be set after the keyboard icon has been added to
the menu. |
| 236 setKeyboardState(getResources().getConfiguration()); |
| 237 |
| 225 return super.onCreateOptionsMenu(menu); | 238 return super.onCreateOptionsMenu(menu); |
| 226 } | 239 } |
| 227 | 240 |
| 241 @Override |
| 242 public void onConfigurationChanged(Configuration config) { |
| 243 super.onConfigurationChanged(config); |
| 244 setKeyboardState(config); |
| 245 } |
| 246 |
| 247 private void setKeyboardState(Configuration configuration) { |
| 248 mHasPhysicalKeyboard = (configuration.keyboard == Configuration.KEYBOARD
_QWERTY) |
| 249 && (configuration.hardKeyboardHidden == Configuration.HARDKEYBOA
RDHIDDEN_NO); |
| 250 mToolbar.getMenu().findItem(R.id.actionbar_keyboard).setVisible(!mHasPhy
sicalKeyboard); |
| 251 } |
| 252 |
| 228 public Event<SystemUiVisibilityChangedEventParameter> onSystemUiVisibilityCh
anged() { | 253 public Event<SystemUiVisibilityChangedEventParameter> onSystemUiVisibilityCh
anged() { |
| 229 return mOnSystemUiVisibilityChanged; | 254 return mOnSystemUiVisibilityChanged; |
| 230 } | 255 } |
| 231 | 256 |
| 232 public Event<InputModeChangedEventParameter> onInputModeChanged() { | 257 public Event<InputModeChangedEventParameter> onInputModeChanged() { |
| 233 return mOnInputModeChanged; | 258 return mOnInputModeChanged; |
| 234 } | 259 } |
| 235 | 260 |
| 236 private InputMode getInitialInputModeValue() { | 261 private InputMode getInitialInputModeValue() { |
| 237 // Load the previously-selected input mode from Preferences. | 262 // Load the previously-selected input mode from Preferences. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 private static int getLayoutFlags() { | 402 private static int getLayoutFlags() { |
| 378 int flags = 0; | 403 int flags = 0; |
| 379 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | 404 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| 380 flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; | 405 flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 381 flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; | 406 flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 382 flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; | 407 flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; |
| 383 } | 408 } |
| 384 return flags; | 409 return flags; |
| 385 } | 410 } |
| 386 | 411 |
| 412 /** |
| 413 * Shows the soft keyboard if no physical keyboard is attached. |
| 414 */ |
| 415 public void showKeyboard() { |
| 416 if (!mHasPhysicalKeyboard) { |
| 417 UiUtils.showKeyboard(mRemoteHostDesktop); |
| 418 } |
| 419 } |
| 420 |
| 387 public void showSystemUi() { | 421 public void showSystemUi() { |
| 388 // Request exit from any fullscreen mode. The action-bar controls will b
e shown in response | 422 // Request exit from any fullscreen mode. The action-bar controls will b
e shown in response |
| 389 // to the SystemUiVisibility notification. The visibility of the action-
bar should be tied | 423 // to the SystemUiVisibility notification. The visibility of the action-
bar should be tied |
| 390 // to the fullscreen state of the system, so there's no need to explicit
ly show it here. | 424 // to the fullscreen state of the system, so there's no need to explicit
ly show it here. |
| 391 int flags = View.SYSTEM_UI_FLAG_VISIBLE | getLayoutFlags(); | 425 int flags = View.SYSTEM_UI_FLAG_VISIBLE | getLayoutFlags(); |
| 392 getWindow().getDecorView().setSystemUiVisibility(flags); | 426 getWindow().getDecorView().setSystemUiVisibility(flags); |
| 393 | 427 |
| 394 // The OS will not call onSystemUiVisibilityChange() if the soft keyboar
d is visible which | 428 // The OS will not call onSystemUiVisibilityChange() if the soft keyboar
d is visible which |
| 395 // means our ActionBar will not be shown if this function is called in t
hat scenario. | 429 // means our ActionBar will not be shown if this function is called in t
hat scenario. |
| 396 if (mSoftInputVisible) { | 430 if (mSoftInputVisible) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 @Override | 574 @Override |
| 541 public boolean dispatchKeyEvent(KeyEvent event) { | 575 public boolean dispatchKeyEvent(KeyEvent event) { |
| 542 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { | 576 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 543 mClient.destroy(); | 577 mClient.destroy(); |
| 544 return super.dispatchKeyEvent(event); | 578 return super.dispatchKeyEvent(event); |
| 545 } | 579 } |
| 546 | 580 |
| 547 return mInjector.sendKeyEvent(event); | 581 return mInjector.sendKeyEvent(event); |
| 548 } | 582 } |
| 549 } | 583 } |
| OLD | NEW |