mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Hacking together a work-around for the default back behaviour
This commit is contained in:
parent
b65a0b1bd6
commit
bb501de22c
@ -28,6 +28,32 @@ function Device() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* You must explicitly override the back button.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Device.prototype.overrideBackButton = function()
|
||||||
|
{
|
||||||
|
BackButton.override();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This resets the back button to the default behaviour
|
||||||
|
*/
|
||||||
|
|
||||||
|
Device.prototype.resetBackButton = function()
|
||||||
|
{
|
||||||
|
BackButton.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This terminates the activity!
|
||||||
|
*/
|
||||||
|
Device.prototype.exitApp = function()
|
||||||
|
{
|
||||||
|
BackButton.exitApp();
|
||||||
|
}
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
navigator.device = window.device = new Device();
|
navigator.device = window.device = new Device();
|
||||||
});
|
});
|
||||||
|
@ -2,17 +2,10 @@ function KeyEvent()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.prototype.menuTrigger = function()
|
KeyEvent.prototype.backTrigger = function()
|
||||||
{
|
{
|
||||||
var e = document.createEvent('Events');
|
var e = document.createEvent('Events');
|
||||||
e.initEvent('menuKeyDown');
|
e.initEvent('backKeyDown');
|
||||||
document.dispatchEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyEvent.prototype.searchTrigger= function()
|
|
||||||
{
|
|
||||||
var e = document.createEvent('Events');
|
|
||||||
e.initEvent('searchKeyDown');
|
|
||||||
document.dispatchEvent(e);
|
document.dispatchEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ public class DroidGap extends Activity {
|
|||||||
private CompassListener mCompass;
|
private CompassListener mCompass;
|
||||||
private Storage cupcakeStorage;
|
private Storage cupcakeStorage;
|
||||||
private CryptoHandler crypto;
|
private CryptoHandler crypto;
|
||||||
|
private BrowserKey mKey;
|
||||||
|
|
||||||
private Uri imageUri;
|
private Uri imageUri;
|
||||||
|
|
||||||
@ -150,6 +151,7 @@ public class DroidGap extends Activity {
|
|||||||
netMan = new NetworkManager(appView, this);
|
netMan = new NetworkManager(appView, this);
|
||||||
mCompass = new CompassListener(appView, this);
|
mCompass = new CompassListener(appView, this);
|
||||||
crypto = new CryptoHandler(appView);
|
crypto = new CryptoHandler(appView);
|
||||||
|
mKey = new BrowserKey(appView, this);
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
appView.addJavascriptInterface(gap, "DroidGap");
|
appView.addJavascriptInterface(gap, "DroidGap");
|
||||||
@ -161,6 +163,7 @@ public class DroidGap extends Activity {
|
|||||||
appView.addJavascriptInterface(netMan, "NetworkManager");
|
appView.addJavascriptInterface(netMan, "NetworkManager");
|
||||||
appView.addJavascriptInterface(mCompass, "CompassHook");
|
appView.addJavascriptInterface(mCompass, "CompassHook");
|
||||||
appView.addJavascriptInterface(crypto, "GapCrypto");
|
appView.addJavascriptInterface(crypto, "GapCrypto");
|
||||||
|
appView.addJavascriptInterface(mKey, "BackButton");
|
||||||
|
|
||||||
|
|
||||||
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
||||||
@ -219,6 +222,8 @@ public class DroidGap extends Activity {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//We clear the back button state
|
||||||
|
mKey.reset();
|
||||||
view.loadUrl(url);
|
view.loadUrl(url);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -309,43 +314,43 @@ public class DroidGap extends Activity {
|
|||||||
quotaUpdater.updateQuota(currentQuota);
|
quotaUpdater.updateQuota(currentQuota);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a test of console.log, because we don't have this in Android 2.01
|
|
||||||
public void addMessageToConsole(String message, int lineNumber, String sourceID)
|
|
||||||
{
|
|
||||||
Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
|
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
|
||||||
public void onConsoleMessage(String message, int lineNumber, String sourceID)
|
public void onConsoleMessage(String message, int lineNumber, String sourceID)
|
||||||
{
|
{
|
||||||
Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message);
|
// This is a kludgy hack!!!!
|
||||||
}
|
Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
||||||
String testUrl = appView.getUrl();
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
appView.goBack();
|
if (mKey.isBound())
|
||||||
if(appView.getUrl() == testUrl)
|
{
|
||||||
{
|
//We fire an event here!
|
||||||
return super.onKeyDown(keyCode, event);
|
appView.loadUrl("javascript:document.keyEvent.backTrigger()");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String testUrl = appView.getUrl();
|
||||||
|
appView.goBack();
|
||||||
|
if(appView.getUrl() == testUrl)
|
||||||
|
{
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_MENU)
|
if (keyCode == KeyEvent.KEYCODE_MENU)
|
||||||
{
|
{
|
||||||
|
// This is where we launch the menu
|
||||||
appView.loadUrl("javascript:keyEvent.menuTrigger()");
|
appView.loadUrl("javascript:keyEvent.menuTrigger()");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_SEARCH)
|
|
||||||
{
|
|
||||||
appView.loadUrl("javascript:keyEvent.searchTrigger()");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user