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.app.Activity; | 7 import android.app.Activity; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.util.Log; |
| 11 import android.view.KeyEvent; |
| 12 import android.view.Menu; |
| 13 import android.view.MenuItem; |
| 14 import android.view.WindowManager; |
| 15 import android.view.inputmethod.InputMethodManager; |
10 | 16 |
11 import org.chromium.chromoting.jni.JniInterface; | 17 import org.chromium.chromoting.jni.JniInterface; |
12 | 18 |
13 /** | 19 /** |
14 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. | 20 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. |
15 */ | 21 */ |
16 public class Desktop extends Activity { | 22 public class Desktop extends Activity { |
17 /** Whether the device has just been rotated. */ | 23 /** The surface that displays the remote host's desktop feed. */ |
18 private DesktopView remoteHostDesktop; | 24 private DesktopView remoteHostDesktop; |
19 | 25 |
20 /** Called when the activity is first created. */ | 26 /** Called when the activity is first created. */ |
21 @Override | 27 @Override |
22 public void onCreate(Bundle savedInstanceState) { | 28 public void onCreate(Bundle savedInstanceState) { |
23 super.onCreate(savedInstanceState); | 29 super.onCreate(savedInstanceState); |
24 remoteHostDesktop = new DesktopView(this); | 30 remoteHostDesktop = new DesktopView(this); |
25 setContentView(remoteHostDesktop); | 31 setContentView(remoteHostDesktop); |
26 } | 32 } |
27 | 33 |
28 /** Called when the activity is finally finished. */ | 34 /** Called when the activity is finally finished. */ |
29 @Override | 35 @Override |
30 public void onDestroy() { | 36 public void onDestroy() { |
31 super.onDestroy(); | 37 super.onDestroy(); |
32 JniInterface.disconnectFromHost(); | 38 JniInterface.disconnectFromHost(); |
33 } | 39 } |
34 | 40 |
35 /** Called when the display is rotated (as registered in the manifest). */ | 41 /** Called when the display is rotated (as registered in the manifest). */ |
36 @Override | 42 @Override |
37 public void onConfigurationChanged(Configuration newConfig) { | 43 public void onConfigurationChanged(Configuration newConfig) { |
38 super.onConfigurationChanged(newConfig); | 44 super.onConfigurationChanged(newConfig); |
39 remoteHostDesktop.requestCanvasRedraw(); | 45 remoteHostDesktop.requestRecheckConstrainingDimension(); |
| 46 } |
| 47 |
| 48 /** Called to initialize the action bar. */ |
| 49 @Override |
| 50 public boolean onCreateOptionsMenu(Menu menu) { |
| 51 getMenuInflater().inflate(R.menu.actionbar, menu); |
| 52 return super.onCreateOptionsMenu(menu); |
| 53 } |
| 54 |
| 55 /** Called whenever an action bar button is pressed. */ |
| 56 @Override |
| 57 public boolean onOptionsItemSelected(MenuItem item) { |
| 58 switch (item.getItemId()) { |
| 59 case R.id.actionbar_keyboard: |
| 60 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).tog
gleSoftInput(0, 0); |
| 61 return true; |
| 62 case R.id.actionbar_hide: |
| 63 getActionBar().hide(); |
| 64 return true; |
| 65 default: |
| 66 return super.onOptionsItemSelected(item); |
| 67 } |
| 68 } |
| 69 |
| 70 /** Called when a hardware key is pressed, and usually when a software key i
s pressed. */ |
| 71 @Override |
| 72 public boolean dispatchKeyEvent(KeyEvent event) { |
| 73 JniInterface.keyboardAction(event.getKeyCode(), event.getAction() == Key
Event.ACTION_DOWN); |
| 74 |
| 75 if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { |
| 76 // We stop this event from propagating further to prevent the keyboa
rd from closing. |
| 77 return true; |
| 78 } |
| 79 |
| 80 return super.dispatchKeyEvent(event); |
40 } | 81 } |
41 } | 82 } |
OLD | NEW |