Chromium Code Reviews| 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 private boolean mHasPhysicalKeyboard; | |
|
joedow
2016/10/05 22:50:59
Can you add a comment on how you detect a physical
Yuwei
2016/10/06 00:26:50
Done.
| |
| 84 | |
| 81 /** Called when the activity is first created. */ | 85 /** Called when the activity is first created. */ |
| 82 @Override | 86 @Override |
| 83 public void onCreate(Bundle savedInstanceState) { | 87 public void onCreate(Bundle savedInstanceState) { |
| 84 super.onCreate(savedInstanceState); | 88 super.onCreate(savedInstanceState); |
| 85 setContentView(R.layout.desktop); | 89 setContentView(R.layout.desktop); |
| 86 | 90 |
| 87 mClient = Client.getInstance(); | 91 mClient = Client.getInstance(); |
| 88 mInjector = new InputEventSender(mClient); | 92 mInjector = new InputEventSender(mClient); |
| 89 | 93 |
| 90 Preconditions.notNull(mClient); | 94 Preconditions.notNull(mClient); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 219 } |
| 216 } | 220 } |
| 217 }); | 221 }); |
| 218 } | 222 } |
| 219 | 223 |
| 220 ChromotingUtil.tintMenuIcons(this, menu); | 224 ChromotingUtil.tintMenuIcons(this, menu); |
| 221 | 225 |
| 222 // Wait to set the input mode until after the default tinting has been a pplied. | 226 // Wait to set the input mode until after the default tinting has been a pplied. |
| 223 setInputMode(mInputMode); | 227 setInputMode(mInputMode); |
| 224 | 228 |
| 229 // Keyboard state must be set after the options menu is created since it needs to alter the | |
| 230 // visibility of the keyboard button. | |
|
joedow
2016/10/05 22:50:59
Shorten this to one line if possible:
"Keyboard st
Yuwei
2016/10/06 00:26:50
Done.
| |
| 231 setKeyboardState(getResources().getConfiguration().keyboard); | |
| 232 | |
| 225 return super.onCreateOptionsMenu(menu); | 233 return super.onCreateOptionsMenu(menu); |
| 226 } | 234 } |
| 227 | 235 |
| 236 @Override | |
| 237 public void onConfigurationChanged(Configuration config) { | |
| 238 super.onConfigurationChanged(config); | |
| 239 setKeyboardState(config.keyboard); | |
| 240 } | |
| 241 | |
| 242 private void setKeyboardState(int keyboardState) { | |
| 243 mHasPhysicalKeyboard = (keyboardState & Configuration.KEYBOARD_NOKEYS) = = 0; | |
|
Yuwei
2016/10/06 00:26:50
Oops. Looks like keyboardState is just an integer
| |
| 244 mToolbar.getMenu().findItem(R.id.actionbar_keyboard).setVisible(!mHasPhy sicalKeyboard); | |
| 245 } | |
| 246 | |
| 228 public Event<SystemUiVisibilityChangedEventParameter> onSystemUiVisibilityCh anged() { | 247 public Event<SystemUiVisibilityChangedEventParameter> onSystemUiVisibilityCh anged() { |
| 229 return mOnSystemUiVisibilityChanged; | 248 return mOnSystemUiVisibilityChanged; |
| 230 } | 249 } |
| 231 | 250 |
| 232 public Event<InputModeChangedEventParameter> onInputModeChanged() { | 251 public Event<InputModeChangedEventParameter> onInputModeChanged() { |
| 233 return mOnInputModeChanged; | 252 return mOnInputModeChanged; |
| 234 } | 253 } |
| 235 | 254 |
| 236 private InputMode getInitialInputModeValue() { | 255 private InputMode getInitialInputModeValue() { |
| 237 // Load the previously-selected input mode from Preferences. | 256 // 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() { | 396 private static int getLayoutFlags() { |
| 378 int flags = 0; | 397 int flags = 0; |
| 379 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | 398 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| 380 flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; | 399 flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 381 flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; | 400 flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 382 flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; | 401 flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; |
| 383 } | 402 } |
| 384 return flags; | 403 return flags; |
| 385 } | 404 } |
| 386 | 405 |
| 406 /** | |
| 407 * Shows the soft keyboard on the remote desktop view. Do nothing if a physi cal keyboard is | |
| 408 * present. | |
|
joedow
2016/10/05 22:50:59
nit: Shorten to one line if possible...
Yuwei
2016/10/06 00:26:50
Done.
| |
| 409 */ | |
| 410 public void showKeyboard() { | |
| 411 if (!mHasPhysicalKeyboard) { | |
| 412 UiUtils.showKeyboard(mRemoteHostDesktop); | |
| 413 } | |
| 414 } | |
| 415 | |
| 387 public void showSystemUi() { | 416 public void showSystemUi() { |
| 388 // Request exit from any fullscreen mode. The action-bar controls will b e shown in response | 417 // 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 | 418 // 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. | 419 // 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(); | 420 int flags = View.SYSTEM_UI_FLAG_VISIBLE | getLayoutFlags(); |
| 392 getWindow().getDecorView().setSystemUiVisibility(flags); | 421 getWindow().getDecorView().setSystemUiVisibility(flags); |
| 393 | 422 |
| 394 // The OS will not call onSystemUiVisibilityChange() if the soft keyboar d is visible which | 423 // 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. | 424 // means our ActionBar will not be shown if this function is called in t hat scenario. |
| 396 if (mSoftInputVisible) { | 425 if (mSoftInputVisible) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 @Override | 569 @Override |
| 541 public boolean dispatchKeyEvent(KeyEvent event) { | 570 public boolean dispatchKeyEvent(KeyEvent event) { |
| 542 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { | 571 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 543 mClient.destroy(); | 572 mClient.destroy(); |
| 544 return super.dispatchKeyEvent(event); | 573 return super.dispatchKeyEvent(event); |
| 545 } | 574 } |
| 546 | 575 |
| 547 return mInjector.sendKeyEvent(event); | 576 return mInjector.sendKeyEvent(event); |
| 548 } | 577 } |
| 549 } | 578 } |
| OLD | NEW |