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
3 // found in the LICENSE file.
5 package org.chromium.chromoting;
7 import android.app.Activity;
8 import android.content.res.Configuration;
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;
17 import org.chromium.chromoting.jni.JniInterface;
20 * A simple screen that does nothing except display a DesktopView and notify it of rotations.
22 public class Desktop extends Activity {
23 /** The surface that displays the remote host's desktop feed. */
24 private DesktopView remoteHostDesktop;
26 /** Called when the activity is first created. */
28 public void onCreate(Bundle savedInstanceState) {
29 super.onCreate(savedInstanceState);
30 remoteHostDesktop = new DesktopView(this);
31 setContentView(remoteHostDesktop);
34 /** Called when the activity is finally finished. */
36 public void onDestroy() {
38 JniInterface.disconnectFromHost();
41 /** Called when the display is rotated (as registered in the manifest). */
43 public void onConfigurationChanged(Configuration newConfig) {
44 super.onConfigurationChanged(newConfig);
45 remoteHostDesktop.onScreenConfigurationChanged();
48 /** Called to initialize the action bar. */
50 public boolean onCreateOptionsMenu(Menu menu) {
51 getMenuInflater().inflate(R.menu.desktop_actionbar, menu);
52 return super.onCreateOptionsMenu(menu);
55 /** Called whenever an action bar button is pressed. */
57 public boolean onOptionsItemSelected(MenuItem item) {
58 switch (item.getItemId()) {
59 case R.id.actionbar_keyboard:
60 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);
62 case R.id.actionbar_hide:
63 getActionBar().hide();
66 return super.onOptionsItemSelected(item);
71 * Called once when a keyboard key is pressed, then again when that same key is released. This
72 * is not guaranteed to be notified of all soft keyboard events: certian keyboards might not
73 * call it at all, while others might skip it in certain situations (e.g. swipe input).
76 public boolean dispatchKeyEvent(KeyEvent event) {
77 boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN;
79 switch (event.getKeyCode()) {
80 case KeyEvent.KEYCODE_AT:
81 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
82 JniInterface.keyboardAction(KeyEvent.KEYCODE_2, depressed);
84 case KeyEvent.KEYCODE_POUND:
85 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
86 JniInterface.keyboardAction(KeyEvent.KEYCODE_3, depressed);
88 case KeyEvent.KEYCODE_STAR:
89 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
90 JniInterface.keyboardAction(KeyEvent.KEYCODE_8, depressed);
92 case KeyEvent.KEYCODE_PLUS:
93 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
94 JniInterface.keyboardAction(KeyEvent.KEYCODE_EQUALS, depressed);
97 // We try to send all other key codes to the host directly.
98 JniInterface.keyboardAction(event.getKeyCode(), depressed);
101 return super.dispatchKeyEvent(event);