Add comments to onKeyDown() method.

This commit is contained in:
Bryce Curtis 2010-11-11 14:08:55 -06:00
parent e8b85f6cf7
commit 49341356d7

View File

@ -661,7 +661,7 @@ public class DroidGap extends PhonegapActivity {
* The webview client receives notifications about appView * The webview client receives notifications about appView
*/ */
public class GapViewClient extends WebViewClient { public class GapViewClient extends WebViewClient {
// TODO: hide splash screen here // TODO: hide splash screen here
DroidGap ctx; DroidGap ctx;
@ -787,36 +787,48 @@ public class DroidGap extends PhonegapActivity {
} }
} }
public boolean onKeyDown(int keyCode, KeyEvent event)
{ /**
if (keyCode == KeyEvent.KEYCODE_BACK) { * Called when a key is pressed.
if (mKey.isBound()) *
{ * @param keyCode
//We fire an event here! * @param event
appView.loadUrl("javascript:document.keyEvent.backTrigger()"); */
} @Override
else public boolean onKeyDown(int keyCode, KeyEvent event) {
{
// only go back if the webview tells you that it is possible to go back // If back key
if(appView.canGoBack()) if (keyCode == KeyEvent.KEYCODE_BACK) {
{
appView.goBack(); // If back key is bound, then send event to JavaScript
} if (mKey.isBound()) {
else // if you can't go back, invoke behavior of super class this.appView.loadUrl("javascript:document.keyEvent.backTrigger()");
{ }
return super.onKeyDown(keyCode, event);
} // If not bound
} else {
}
// Go to previous page in webview if it is possible to go back
if (keyCode == KeyEvent.KEYCODE_MENU) if (this.appView.canGoBack()) {
{ this.appView.goBack();
// This is where we launch the menu }
appView.loadUrl("javascript:keyEvent.menuTrigger()");
} // If not, then invoke behavior of super class
return false; else {
return super.onKeyDown(keyCode, event);
}
}
}
if (keyCode == KeyEvent.KEYCODE_MENU) {
// This is where we launch the menu
appView.loadUrl("javascript:keyEvent.menuTrigger()");
}
return false;
} }
/** /**
* Removes the splash screen from root view and adds the WebView * Removes the splash screen from root view and adds the WebView
*/ */
@ -824,7 +836,7 @@ public class DroidGap extends PhonegapActivity {
root.removeView(splashScreen); root.removeView(splashScreen);
root.addView(this.appView); root.addView(this.appView);
} }
/** /**
* Any calls to Activity.startActivityForResult must use method below, so * Any calls to Activity.startActivityForResult must use method below, so
* the result can be routed to them correctly. * the result can be routed to them correctly.