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.app.Activity; | |
9 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
10 import android.os.Build; | 9 import android.os.Build; |
11 import android.os.Bundle; | 10 import android.os.Bundle; |
| 11 |
| 12 import android.support.v7.app.ActionBarActivity; |
| 13 |
12 import android.view.KeyCharacterMap; | 14 import android.view.KeyCharacterMap; |
13 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
14 import android.view.Menu; | 16 import android.view.Menu; |
15 import android.view.MenuItem; | 17 import android.view.MenuItem; |
16 import android.view.View; | 18 import android.view.View; |
17 import android.view.inputmethod.InputMethodManager; | 19 import android.view.inputmethod.InputMethodManager; |
18 import android.widget.ImageButton; | 20 import android.widget.ImageButton; |
19 | 21 |
20 import org.chromium.chromoting.jni.JniInterface; | 22 import org.chromium.chromoting.jni.JniInterface; |
21 | 23 |
22 import java.util.Set; | 24 import java.util.Set; |
23 import java.util.TreeSet; | 25 import java.util.TreeSet; |
24 | 26 |
25 /** | 27 /** |
26 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. | 28 * A simple screen that does nothing except display a DesktopView and notify it
of rotations. |
27 */ | 29 */ |
28 public class Desktop extends Activity implements View.OnSystemUiVisibilityChange
Listener { | 30 public class Desktop extends ActionBarActivity implements View.OnSystemUiVisibil
ityChangeListener { |
29 /** Web page to be displayed in the Help screen when launched from this acti
vity. */ | 31 /** Web page to be displayed in the Help screen when launched from this acti
vity. */ |
30 private static final String HELP_URL = | 32 private static final String HELP_URL = |
31 "http://support.google.com/chrome/?p=mobile_crd_connecthost"; | 33 "http://support.google.com/chrome/?p=mobile_crd_connecthost"; |
32 | 34 |
33 /** The surface that displays the remote host's desktop feed. */ | 35 /** The surface that displays the remote host's desktop feed. */ |
34 private DesktopView mRemoteHostDesktop; | 36 private DesktopView mRemoteHostDesktop; |
35 | 37 |
36 /** The button used to show the action bar. */ | 38 /** The button used to show the action bar. */ |
37 private ImageButton mOverlayButton; | 39 private ImageButton mOverlayButton; |
38 | 40 |
39 /** Set of pressed keys for which we've sent TextEvent. */ | 41 /** Set of pressed keys for which we've sent TextEvent. */ |
40 private Set<Integer> mPressedTextKeys = new TreeSet<Integer>(); | 42 private Set<Integer> mPressedTextKeys = new TreeSet<Integer>(); |
41 | 43 |
| 44 private ActivityLifecycleListener mActivityLifecycleListener; |
| 45 |
| 46 |
42 /** Called when the activity is first created. */ | 47 /** Called when the activity is first created. */ |
43 @Override | 48 @Override |
44 public void onCreate(Bundle savedInstanceState) { | 49 public void onCreate(Bundle savedInstanceState) { |
45 super.onCreate(savedInstanceState); | 50 super.onCreate(savedInstanceState); |
46 setContentView(R.layout.desktop); | 51 setContentView(R.layout.desktop); |
47 mRemoteHostDesktop = (DesktopView)findViewById(R.id.desktop_view); | 52 mRemoteHostDesktop = (DesktopView)findViewById(R.id.desktop_view); |
48 mOverlayButton = (ImageButton)findViewById(R.id.desktop_overlay_button); | 53 mOverlayButton = (ImageButton)findViewById(R.id.desktop_overlay_button); |
49 mRemoteHostDesktop.setDesktop(this); | 54 mRemoteHostDesktop.setDesktop(this); |
50 | 55 |
51 // Ensure the button is initially hidden. | 56 // Ensure the button is initially hidden. |
52 showActionBar(); | 57 showActionBar(); |
53 | 58 |
54 View decorView = getWindow().getDecorView(); | 59 View decorView = getWindow().getDecorView(); |
55 decorView.setOnSystemUiVisibilityChangeListener(this); | 60 decorView.setOnSystemUiVisibilityChangeListener(this); |
| 61 |
| 62 |
| 63 |
| 64 mActivityLifecycleListener = CapabilityManager.getInstance() |
| 65 .onActivityAcceptingListener(this, Capabilities.CAST_CAPABILITY); |
| 66 mActivityLifecycleListener.onActivityCreated(this, savedInstanceState); |
| 67 } |
| 68 |
| 69 |
| 70 @Override |
| 71 protected void onStart() { |
| 72 super.onStart(); |
| 73 mActivityLifecycleListener.onActivityStarted(this); |
| 74 } |
| 75 |
| 76 @Override |
| 77 protected void onPause() { |
| 78 if (isFinishing()) { |
| 79 mActivityLifecycleListener.onActivityPaused(this); |
| 80 } |
| 81 super.onPause(); |
| 82 } |
| 83 |
| 84 @Override |
| 85 public void onResume() { |
| 86 super.onResume(); |
| 87 mActivityLifecycleListener.onActivityResumed(this); |
| 88 } |
| 89 |
| 90 @Override |
| 91 protected void onStop() { |
| 92 mActivityLifecycleListener.onActivityStopped(this); |
| 93 super.onStop(); |
56 } | 94 } |
57 | 95 |
58 /** Called when the activity is finally finished. */ | 96 /** Called when the activity is finally finished. */ |
59 @Override | 97 @Override |
60 public void onDestroy() { | 98 public void onDestroy() { |
61 super.onDestroy(); | 99 super.onDestroy(); |
62 JniInterface.disconnectFromHost(); | 100 JniInterface.disconnectFromHost(); |
63 } | 101 } |
64 | 102 |
65 /** Called when the display is rotated (as registered in the manifest). */ | 103 /** Called when the display is rotated (as registered in the manifest). */ |
66 @Override | 104 @Override |
67 public void onConfigurationChanged(Configuration newConfig) { | 105 public void onConfigurationChanged(Configuration newConfig) { |
68 super.onConfigurationChanged(newConfig); | 106 super.onConfigurationChanged(newConfig); |
69 mRemoteHostDesktop.onScreenConfigurationChanged(); | 107 mRemoteHostDesktop.onScreenConfigurationChanged(); |
70 } | 108 } |
71 | 109 |
72 /** Called to initialize the action bar. */ | 110 /** Called to initialize the action bar. */ |
73 @Override | 111 @Override |
74 public boolean onCreateOptionsMenu(Menu menu) { | 112 public boolean onCreateOptionsMenu(Menu menu) { |
75 getMenuInflater().inflate(R.menu.desktop_actionbar, menu); | 113 getMenuInflater().inflate(R.menu.desktop_actionbar, menu); |
| 114 |
| 115 mActivityLifecycleListener.onActivityCreatedOptionsMenu(this, menu); |
| 116 |
76 return super.onCreateOptionsMenu(menu); | 117 return super.onCreateOptionsMenu(menu); |
77 } | 118 } |
78 | 119 |
79 /** Called whenever the visibility of the system status bar or navigation ba
r changes. */ | 120 /** Called whenever the visibility of the system status bar or navigation ba
r changes. */ |
80 @Override | 121 @Override |
81 public void onSystemUiVisibilityChange(int visibility) { | 122 public void onSystemUiVisibilityChange(int visibility) { |
82 // Ensure the action-bar's visibility matches that of the system control
s. This | 123 // Ensure the action-bar's visibility matches that of the system control
s. This |
83 // minimizes the number of states the UI can be in, to keep things simpl
e for the user. | 124 // minimizes the number of states the UI can be in, to keep things simpl
e for the user. |
84 | 125 |
85 // Determine if the system is in fullscreen/lights-out mode. LOW_PROFILE
is needed since | 126 // Determine if the system is in fullscreen/lights-out mode. LOW_PROFILE
is needed since |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 177 |
137 /** The overlay button's onClick handler. */ | 178 /** The overlay button's onClick handler. */ |
138 public void onOverlayButtonPressed(View view) { | 179 public void onOverlayButtonPressed(View view) { |
139 showActionBar(); | 180 showActionBar(); |
140 } | 181 } |
141 | 182 |
142 /** Called whenever an action bar button is pressed. */ | 183 /** Called whenever an action bar button is pressed. */ |
143 @Override | 184 @Override |
144 public boolean onOptionsItemSelected(MenuItem item) { | 185 public boolean onOptionsItemSelected(MenuItem item) { |
145 int id = item.getItemId(); | 186 int id = item.getItemId(); |
| 187 |
| 188 mActivityLifecycleListener.onActivityOptionsItemSelected(this, item); |
| 189 |
146 if (id == R.id.actionbar_keyboard) { | 190 if (id == R.id.actionbar_keyboard) { |
147 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleS
oftInput(0, 0); | 191 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleS
oftInput(0, 0); |
148 return true; | 192 return true; |
149 } | 193 } |
150 if (id == R.id.actionbar_hide) { | 194 if (id == R.id.actionbar_hide) { |
151 hideActionBar(); | 195 hideActionBar(); |
152 return true; | 196 return true; |
153 } | 197 } |
154 if (id == R.id.actionbar_disconnect) { | 198 if (id == R.id.actionbar_disconnect) { |
155 JniInterface.disconnectFromHost(); | 199 JniInterface.disconnectFromHost(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); | 288 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
245 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed); | 289 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed); |
246 return true; | 290 return true; |
247 | 291 |
248 default: | 292 default: |
249 // We try to send all other key codes to the host directly. | 293 // We try to send all other key codes to the host directly. |
250 return JniInterface.sendKeyEvent(keyCode, pressed); | 294 return JniInterface.sendKeyEvent(keyCode, pressed); |
251 } | 295 } |
252 } | 296 } |
253 } | 297 } |
OLD | NEW |