This source file includes following definitions.
- onCreate
- onDestroy
- onConfigurationChanged
- onCreateOptionsMenu
- showActionBar
- hideActionBar
- onOverlayButtonPressed
- onOptionsItemSelected
- dispatchKeyEvent
package org.chromium.chromoting;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton;
import org.chromium.chromoting.jni.JniInterface;
public class Desktop extends Activity {
private static final String HELP_URL =
"http://support.google.com/chrome/?p=mobile_crd_connecthost";
private DesktopView mRemoteHostDesktop;
private ImageButton mOverlayButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.desktop);
mRemoteHostDesktop = (DesktopView)findViewById(R.id.desktop_view);
mOverlayButton = (ImageButton)findViewById(R.id.desktop_overlay_button);
mRemoteHostDesktop.setDesktop(this);
showActionBar();
}
@Override
public void onDestroy() {
super.onDestroy();
JniInterface.disconnectFromHost();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mRemoteHostDesktop.onScreenConfigurationChanged();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.desktop_actionbar, menu);
return super.onCreateOptionsMenu(menu);
}
public void showActionBar() {
mOverlayButton.setVisibility(View.INVISIBLE);
getActionBar().show();
}
public void hideActionBar() {
mOverlayButton.setVisibility(View.VISIBLE);
getActionBar().hide();
}
public void onOverlayButtonPressed(View view) {
showActionBar();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionbar_keyboard:
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);
return true;
case R.id.actionbar_hide:
hideActionBar();
return true;
case R.id.actionbar_disconnect:
JniInterface.disconnectFromHost();
return true;
case R.id.actionbar_send_ctrl_alt_del:
{
int[] keys = {
KeyEvent.KEYCODE_CTRL_LEFT,
KeyEvent.KEYCODE_ALT_LEFT,
KeyEvent.KEYCODE_FORWARD_DEL,
};
for (int key : keys) {
JniInterface.sendKeyEvent(key, true);
}
for (int key : keys) {
JniInterface.sendKeyEvent(key, false);
}
}
return true;
case R.id.actionbar_help:
HelpActivity.launch(this, HELP_URL);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_MULTIPLE) {
JniInterface.sendTextEvent(event.getCharacters());
return super.dispatchKeyEvent(event);
}
boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN;
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_AT:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_2, depressed);
break;
case KeyEvent.KEYCODE_POUND:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_3, depressed);
break;
case KeyEvent.KEYCODE_STAR:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_8, depressed);
break;
case KeyEvent.KEYCODE_PLUS:
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, depressed);
break;
default:
JniInterface.sendKeyEvent(event.getKeyCode(), depressed);
}
return super.dispatchKeyEvent(event);
}
}