mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +08:00
Remove channel.js. Remove double call to nativeReady in DroidGap. Niceify CommandResult.java
This commit is contained in:
parent
fb2b8345d1
commit
4fd8a4dad8
@ -1,81 +0,0 @@
|
|||||||
PhoneGap.Channel = function(type)
|
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
this.handlers = {};
|
|
||||||
this.guid = 0;
|
|
||||||
this.fired = false;
|
|
||||||
this.enabled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
PhoneGap.Channel.prototype.sub = function(f, c, g)
|
|
||||||
{
|
|
||||||
// need a function to call
|
|
||||||
if (f == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var func = f;
|
|
||||||
if (typeof c == "object" && f instanceof Function)
|
|
||||||
func = PhoneGap.close(c, f);
|
|
||||||
|
|
||||||
g = g || func.observer_guid || f.observer_guid || this.guid++;
|
|
||||||
func.observer_guid = g;
|
|
||||||
f.observer_guid = g;
|
|
||||||
this.handlers[g] = func;
|
|
||||||
return g;
|
|
||||||
};
|
|
||||||
|
|
||||||
PhoneGap.Channel.prototype.sob = function(f, c)
|
|
||||||
{
|
|
||||||
var g = null;
|
|
||||||
var _this = this;
|
|
||||||
var m = function() {
|
|
||||||
f.apply(c || null, arguments);
|
|
||||||
_this.dub(g);
|
|
||||||
}
|
|
||||||
if (this.fired) {
|
|
||||||
if (typeof c == "object" && f instanceof Function)
|
|
||||||
f = PhoneGap.close(c, f);
|
|
||||||
f.apply(this, this.fireArgs);
|
|
||||||
} else {
|
|
||||||
g = this.sub(m);
|
|
||||||
}
|
|
||||||
return g;
|
|
||||||
};
|
|
||||||
|
|
||||||
PhoneGap.Channel.prototype.dub = function(g)
|
|
||||||
{
|
|
||||||
if (g instanceof Function)
|
|
||||||
g = g.observer_guid;
|
|
||||||
this.handlers[g] = null;
|
|
||||||
delete this.handlers[g];
|
|
||||||
};
|
|
||||||
|
|
||||||
PhoneGap.Channel.prototype.fire = function(e)
|
|
||||||
{
|
|
||||||
if (this.enabled)
|
|
||||||
{
|
|
||||||
var fail = false;
|
|
||||||
for (var item in this.handlers) {
|
|
||||||
var handler = this.handlers[item];
|
|
||||||
if (handler instanceof Function) {
|
|
||||||
var rv = (handler.apply(this, arguments)==false);
|
|
||||||
fail = fail || rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.fired = true;
|
|
||||||
this.fireArgs = arguments;
|
|
||||||
return !fail;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
PhoneGap.Channel.merge = function(h, e) {
|
|
||||||
var i = e.length;
|
|
||||||
var f = function() {
|
|
||||||
if (!(--i)) h();
|
|
||||||
}
|
|
||||||
for (var j=0; j<i; j++) {
|
|
||||||
(!e[j].fired?e[j].sob(f):i--);
|
|
||||||
}
|
|
||||||
if (!i) h();
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
/* License (MIT)
|
/* License (MIT)
|
||||||
* Copyright (c) 2008 Nitobi
|
* Copyright (c) 2008 Nitobi
|
||||||
* website: http://phonegap.com
|
* website: http://phonegap.com
|
||||||
@ -160,11 +160,6 @@ public class DroidGap extends Activity {
|
|||||||
bindBrowser(appView);
|
bindBrowser(appView);
|
||||||
if(cupcakeStorage != null)
|
if(cupcakeStorage != null)
|
||||||
cupcakeStorage.setStorage(appPackage);
|
cupcakeStorage.setStorage(appPackage);
|
||||||
|
|
||||||
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
|
||||||
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
|
||||||
// from the JS side when the JS gets to that code.
|
|
||||||
appView.loadUrl("javascript:try{PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -442,7 +437,9 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
public class GapViewClient extends WebViewClient {
|
public class GapViewClient extends WebViewClient {
|
||||||
|
|
||||||
DroidGap mCtx;
|
// TODO: hide splash screen here
|
||||||
|
|
||||||
|
DroidGap mCtx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.phonegap.api;
|
package com.phonegap.api;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class CommandResult {
|
public class CommandResult {
|
||||||
private final int status;
|
private final int status;
|
||||||
@ -13,7 +13,12 @@ public class CommandResult {
|
|||||||
|
|
||||||
public CommandResult(Status status, String message) {
|
public CommandResult(Status status, String message) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = message;
|
this.message = "'" + message + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandResult(Status status, JSONObject message) {
|
||||||
|
this.status = status.ordinal();
|
||||||
|
this.message = message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
@ -25,7 +30,7 @@ public class CommandResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getJSONString() {
|
public String getJSONString() {
|
||||||
return "{ status: " + this.getStatus() + ", message: '" + URLEncoder.encode(this.getMessage()) + "' }";
|
return "{ status: " + this.getStatus() + ", message: " + this.getMessage() + " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toSuccessCallbackString(String callbackId) {
|
public String toSuccessCallbackString(String callbackId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user