private PluginResult registerTagListener() throws NFCException, JSONException {
ReaderWriterManager nfc = ReaderWriterManager.getInstance();
tagListener = new DetectionListener() {
public void onTargetDetected(Target target) {
Hashtable props = Util.getTagProperties(target);
NDEFMessage message = null;
try {
NDEFTagConnection tagConnection = (NDEFTagConnection) Connector.open(target.getUri(Target.NDEF_TAG));
message = tagConnection.read(); // might want to handle NFCException different
} catch (IOException e) {
Logger.error("Failed reading tag " + e.toString());
}
fireNdefEvent(TAG_DEFAULT, message, props);
}
};
nfc.addDetectionListener(tagListener);
return new PluginResult(Status.OK);
}
java类org.apache.cordova.api.PluginResult的实例源码
NfcPlugin.java 文件源码
项目:mensacard-hack
阅读 30
收藏 0
点赞 0
评论 0
ForegroundGalleryLauncher.java 文件源码
项目:foreground-gallery-plugin
阅读 30
收藏 0
点赞 0
评论 0
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext;
this.targetHeight = 0;
this.targetWidth = 0;
this.mQuality = 80;
JSONObject options = args.optJSONObject(0);
if (options != null)
{
this.targetHeight = options.getInt("targetHeight");
this.targetWidth = options.getInt("targetWidth");
this.mQuality = options.getInt("quality");
}
this.getImage();
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
return true;
}
ForegroundGalleryLauncher.java 文件源码
项目:foreground-gallery-plugin
阅读 27
收藏 0
点赞 0
评论 0
public void processPicture(Bitmap bitmap)
{
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
try
{
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data))
{
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encodeBase64(code);
String js_out = new String(output);
this.success(new PluginResult(PluginResult.Status.OK,
"data:image/jpeg;base64," + js_out), this.callbackId);
js_out = null;
output = null;
code = null;
}
}
catch (Exception e)
{
this.failPicture("Error compressing image.");
}
jpeg_data = null;
}
AccelListener.java 文件源码
项目:12306-android-Decompile
阅读 23
收藏 0
点赞 0
评论 0
private void fail(int paramInt, String paramString)
{
JSONObject localJSONObject = new JSONObject();
try
{
localJSONObject.put("code", paramInt);
localJSONObject.put("message", paramString);
PluginResult localPluginResult = new PluginResult(PluginResult.Status.ERROR, localJSONObject);
localPluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(localPluginResult);
return;
}
catch (JSONException localJSONException)
{
while (true)
localJSONException.printStackTrace();
}
}
AccelListener.java 文件源码
项目:12306-android-Decompile
阅读 33
收藏 0
点赞 0
评论 0
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext)
{
if (paramString.equals("start"))
{
this.callbackContext = paramCallbackContext;
if (this.status != RUNNING)
start();
}
while (true)
{
PluginResult localPluginResult = new PluginResult(PluginResult.Status.NO_RESULT, "");
localPluginResult.setKeepCallback(true);
paramCallbackContext.sendPluginResult(localPluginResult);
return true;
if (!paramString.equals("stop"))
break;
if (this.status != RUNNING)
continue;
stop();
}
return false;
}
NativeToJsMessageQueue.java 文件源码
项目:12306-android-Decompile
阅读 25
收藏 0
点赞 0
评论 0
public void addPluginResult(PluginResult paramPluginResult, String paramString)
{
if (paramString == null)
{
Log.e("JsMessageQueue", "Got plugin result with no callbackId", new Throwable());
return;
}
if (paramPluginResult.getStatus() == PluginResult.Status.NO_RESULT.ordinal());
for (int i = 1; ; i = 0)
{
boolean bool = paramPluginResult.getKeepCallback();
if ((i != 0) && (bool))
break;
enqueueMessage(new JsMessage(paramPluginResult, paramString));
return;
}
}
InAppBrowser.java 文件源码
项目:12306-android-Decompile
阅读 31
收藏 0
点赞 0
评论 0
public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2)
{
super.onReceivedError(paramWebView, paramInt, paramString1, paramString2);
try
{
JSONObject localJSONObject = new JSONObject();
localJSONObject.put("type", "loaderror");
localJSONObject.put("url", paramString2);
localJSONObject.put("code", paramInt);
localJSONObject.put("message", paramString1);
InAppBrowser.this.sendUpdate(localJSONObject, true, PluginResult.Status.ERROR);
return;
}
catch (JSONException localJSONException)
{
Log.d("InAppBrowser", "Should never happen");
}
}
CloseDatabaseActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 26
收藏 0
点赞 0
评论 0
public PluginResult dispatch(BaseActionDispatcher.Context paramContext)
throws Throwable
{
DatabaseManager localDatabaseManager = DatabaseManager.getInstance();
try
{
localDatabaseManager.clearDbPath();
localDatabaseManager.clearDatabaseKey();
if (localDatabaseManager.isDatabaseOpen())
localDatabaseManager.closeDatabase();
PluginResult localPluginResult = new PluginResult(PluginResult.Status.OK, 0);
return localPluginResult;
}
catch (Throwable localThrowable)
{
}
return new PluginResult(PluginResult.Status.ERROR, 23);
}
FindByIdActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 25
收藏 0
点赞 0
评论 0
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext)
throws Throwable
{
JSONArray localJSONArray1 = getIds(paramContext);
try
{
JSONArray localJSONArray2 = (JSONArray)paramContext.performReadableDatabaseAction(new FindByIdAction(localJSONArray1, null));
if (localJSONArray2 == null)
return new PluginResult(PluginResult.Status.ERROR, 22);
JacksonSerializedPluginResult localJacksonSerializedPluginResult = new JacksonSerializedPluginResult(PluginResult.Status.OK, localJSONArray2);
return localJacksonSerializedPluginResult;
}
catch (Throwable localThrowable)
{
if (this.logger.isLoggable(6))
this.logger.logError("error while executing find by ID query on database \"" + paramContext.getDatabaseName() + "\"", localThrowable);
}
return new PluginResult(PluginResult.Status.ERROR, 22);
}
ChangePasswordActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 25
收藏 0
点赞 0
评论 0
public PluginResult dispatch(BaseActionDispatcher.Context paramContext)
throws Throwable
{
if (!DatabaseManager.getInstance().isDatabaseOpen())
return new PluginResult(PluginResult.Status.ERROR, -50);
String str1 = getNewPW(paramContext);
String str2 = getOldPW(paramContext);
String str3 = getUserName(paramContext);
SecurityManager localSecurityManager = SecurityManager.getInstance(paramContext.getCordovaContext().getActivity());
try
{
String str4 = localSecurityManager.getDPK(str2, str3);
String str5 = localSecurityManager.getSalt(str3);
localSecurityManager.storeDPK(str1, str3, str4, str5, true, false);
return new PluginResult(PluginResult.Status.OK, 0);
}
catch (Throwable localThrowable)
{
}
return new PluginResult(PluginResult.Status.ERROR, 24);
}
MarkCleanActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 21
收藏 0
点赞 0
评论 0
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext)
throws Throwable
{
JSONArray localJSONArray = getDocs(paramContext);
for (int i = 0; i < localJSONArray.length(); i++)
{
JSONObject localJSONObject = localJSONArray.getJSONObject(i);
MarkCleanAction localMarkCleanAction = new MarkCleanAction(localJSONObject.getInt("_id"), localJSONObject.getString("_operation"), null);
try
{
if (((Integer)paramContext.performWritableDatabaseAction(localMarkCleanAction)).intValue() > 0)
continue;
PluginResult localPluginResult = new PluginResult(PluginResult.Status.ERROR, 15);
return localPluginResult;
}
catch (Throwable localThrowable)
{
Exception localException = new Exception("Failed trying to mark document clean");
this.logger.logError("Failed trying to mark document clean", localException);
return new PluginResult(PluginResult.Status.ERROR, 15);
}
}
return new PluginResult(PluginResult.Status.OK, 0);
}
SimpleQueryActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 28
收藏 0
点赞 0
评论 0
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext)
throws Throwable
{
int i = -1;
try
{
int k = ((Integer)paramContext.performReadableDatabaseAction(new SimpleQueryAction(paramContext, null))).intValue();
i = k;
int j = getModifiedResultValue(i);
logResult(paramContext, j);
return new PluginResult(PluginResult.Status.OK, j);
}
catch (Throwable localThrowable)
{
while (true)
{
if (!this.logger.isLoggable(6))
continue;
this.logger.logError("error occurred while performing query:");
this.logger.logError(" " + getFormattedQuery(paramContext), localThrowable);
}
}
}
BaseActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 29
收藏 0
点赞 0
评论 0
public PluginResult dispatch(CordovaInterface paramCordovaInterface, JSONArray paramJSONArray)
throws Throwable
{
Context localContext = new Context(paramCordovaInterface);
collectParameters(localContext, paramJSONArray);
if (this.logger.isLoggable(3))
{
this.logger.logDebug("invoking action dispatcher \"" + this.name + "\" with parameters:");
Iterator localIterator = this.parameters.iterator();
while (localIterator.hasNext())
{
Parameter localParameter = (Parameter)localIterator.next();
String str = localParameter.getName();
if (localParameter.isLoggable())
{
this.logger.logDebug(" " + str + "=" + localContext.getUntypedParameter(str));
continue;
}
this.logger.logDebug(" " + str + "=[value not logged]");
}
}
return dispatch(localContext);
}
Echo.java 文件源码
项目:phonegap-FileViewer
阅读 27
收藏 0
点赞 0
评论 0
private PluginResult openFile(String fileUrl){
Log.d("FileViewerPlugin", "View file"+fileUrl);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(fileUrl);
String extension = fileUrl.substring(fileUrl.lastIndexOf(".")+1);
String type = "";
if (extension.toLowerCase().equals("pdf")) {
type = "application/pdf";
} else if (extension.toLowerCase().equals("flv")) {
type = "video/flv";
} else if (extension.toLowerCase().equals("mp4")) {
type = "video/mp4";
} else if (extension.toLowerCase().equals("jpg")) {
type = "image/jpg";
}
intent.setDataAndType(Uri.fromFile(file), type);
cordova.getActivity().startActivity(intent);
Log.d("FileViewerPlugin", "View complete in" + fileUrl);
return new PluginResult(PluginResult.Status.OK, fileUrl);
}
NativeToJsMessageQueue.java 文件源码
项目:cordova-android-chromeview
阅读 24
收藏 0
点赞 0
评论 0
/**
* Add a JavaScript statement to the list.
*/
public void addPluginResult(PluginResult result, String callbackId) {
if (callbackId == null) {
Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
return;
}
// Don't send anything if there is no result and there is no need to
// clear the callbacks.
boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
boolean keepCallback = result.getKeepCallback();
if (noResult && keepCallback) {
return;
}
JsMessage message = new JsMessage(result, callbackId);
if (FORCE_ENCODE_USING_EVAL) {
StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50);
message.encodeAsJsMessage(sb);
message = new JsMessage(sb.toString());
}
enqueueMessage(message);
}
NativeToJsMessageQueue.java 文件源码
项目:cordova-android-chromeview
阅读 27
收藏 0
点赞 0
评论 0
void encodeAsJsMessage(StringBuilder sb) {
if (pluginResult == null) {
sb.append(jsPayloadOrCallbackId);
} else {
int status = pluginResult.getStatus();
boolean success = (status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal());
sb.append("cordova.callbackFromNative('")
.append(jsPayloadOrCallbackId)
.append("',")
.append(success)
.append(",")
.append(status)
.append(",[")
.append(pluginResult.getMessage())
.append("],")
.append(pluginResult.getKeepCallback())
.append(");");
}
}
InAppBrowser.java 文件源码
项目:cordova-android-chromeview
阅读 33
收藏 0
点赞 0
评论 0
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_ERROR_EVENT);
obj.put("url", failingUrl);
obj.put("code", errorCode);
obj.put("message", description);
sendUpdate(obj, true, PluginResult.Status.ERROR);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
}
JREngagePhonegapPlugin.java 文件源码
项目:samplegit
阅读 19
收藏 0
点赞 0
评论 0
private void initializeJREngage(String appId, String tokenUrl) {
if (appId == null || appId.equals("")) {
postResultAndResetState(buildFailureResult(ConfigurationError.MISSING_APP_ID_ERROR,
"Missing appId in call to initialize"));
return;
}
try {
mJREngage = JREngage.initInstance(cordova.getActivity(), appId, tokenUrl, null);
} catch (IllegalArgumentException e) {
postResultAndResetState(buildFailureResult(ConfigurationError.GENERIC_CONFIGURATION_ERROR,
e.getLocalizedMessage()));
return;
}
postResultAndResetState(new PluginResult(Status.OK,
"{'stat':'ok','message':'Initializing JREngage...'}"));
}
InAppBrowser.java 文件源码
项目:cordova-android-chromium
阅读 29
收藏 0
点赞 0
评论 0
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_ERROR_EVENT);
obj.put("url", failingUrl);
obj.put("code", errorCode);
obj.put("message", description);
sendUpdate(obj, true, PluginResult.Status.ERROR);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
}
PlayServices.java 文件源码
项目:pico-phonegap-base
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void onSignInFailed(String reason){
JSONObject json = new JSONObject();
try{
json.put("type", GMS_SIGNIN);
json.put("signin", false);
json.put("message", reason);
}catch(JSONException ex){
Log.e(TAG, "signin failed exception: "+ex.getMessage());
return;
}
Log.d(TAG, "signin failed");
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
PlayServices.java 文件源码
项目:pico-phonegap-base
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void onStateConflict(int stateKey, String resolvedVersion, byte[] localData, byte[] serverData) {
// Need to resolve conflict between the two states.
// We do that by taking the union of the two sets of cleared levels,
// which means preserving the maximum star rating of each cleared
// level:
JSONObject json = new JSONObject();
try{
json.put("type", STATE_CONFLICTED);
json.put("stateKey", stateKey);
json.put("version", resolvedVersion);
json.put("localData", new JSONObject(new String(localData)));
json.put("serverData", new JSONObject(new String(serverData)));
}catch(JSONException ex){
Log.e(TAG, "STATE_CONFLICTED ["+stateKey+"] ["+resolvedVersion+"] exception: "+ex.getMessage());
return;
}
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
FileTransfer.java 文件源码
项目:cordova-android-chromium
阅读 34
收藏 0
点赞 0
评论 0
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals("upload") || action.equals("download")) {
String source = args.getString(0);
String target = args.getString(1);
if (action.equals("upload")) {
try {
source = URLDecoder.decode(source, "UTF-8");
upload(source, target, args, callbackContext);
} catch (UnsupportedEncodingException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error."));
}
} else {
download(source, target, args, callbackContext);
}
return true;
} else if (action.equals("abort")) {
String objectId = args.getString(0);
abort(objectId);
callbackContext.success();
return true;
}
return false;
}
AccelListener.java 文件源码
项目:12306-android-Decompile
阅读 27
收藏 0
点赞 0
评论 0
private void fail(int paramInt, String paramString)
{
JSONObject localJSONObject = new JSONObject();
try
{
localJSONObject.put("code", paramInt);
localJSONObject.put("message", paramString);
PluginResult localPluginResult = new PluginResult(PluginResult.Status.ERROR, localJSONObject);
localPluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(localPluginResult);
return;
}
catch (JSONException localJSONException)
{
while (true)
localJSONException.printStackTrace();
}
}
AccelListener.java 文件源码
项目:12306-android-Decompile
阅读 28
收藏 0
点赞 0
评论 0
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext)
{
if (paramString.equals("start"))
{
this.callbackContext = paramCallbackContext;
if (this.status != RUNNING)
start();
}
while (true)
{
PluginResult localPluginResult = new PluginResult(PluginResult.Status.NO_RESULT, "");
localPluginResult.setKeepCallback(true);
paramCallbackContext.sendPluginResult(localPluginResult);
return true;
if (!paramString.equals("stop"))
break;
if (this.status != RUNNING)
continue;
stop();
}
return false;
}
NativeToJsMessageQueue.java 文件源码
项目:12306-android-Decompile
阅读 24
收藏 0
点赞 0
评论 0
public void addPluginResult(PluginResult paramPluginResult, String paramString)
{
if (paramString == null)
{
Log.e("JsMessageQueue", "Got plugin result with no callbackId", new Throwable());
return;
}
if (paramPluginResult.getStatus() == PluginResult.Status.NO_RESULT.ordinal());
for (int i = 1; ; i = 0)
{
boolean bool = paramPluginResult.getKeepCallback();
if ((i != 0) && (bool))
break;
enqueueMessage(new JsMessage(paramPluginResult, paramString));
return;
}
}
InAppBrowser.java 文件源码
项目:12306-android-Decompile
阅读 27
收藏 0
点赞 0
评论 0
public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2)
{
super.onReceivedError(paramWebView, paramInt, paramString1, paramString2);
try
{
JSONObject localJSONObject = new JSONObject();
localJSONObject.put("type", "loaderror");
localJSONObject.put("url", paramString2);
localJSONObject.put("code", paramInt);
localJSONObject.put("message", paramString1);
InAppBrowser.this.sendUpdate(localJSONObject, true, PluginResult.Status.ERROR);
return;
}
catch (JSONException localJSONException)
{
Log.d("InAppBrowser", "Should never happen");
}
}
AccelListener.java 文件源码
项目:cordova-android-chromium
阅读 25
收藏 0
点赞 0
评论 0
/**
* Executes the request.
*
* @param action The action to execute.
* @param args The exec() arguments.
* @param callbackId The callback id used when calling back into JavaScript.
* @return Whether the action was valid.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
if (action.equals("start")) {
this.callbackContext = callbackContext;
if (this.status != AccelListener.RUNNING) {
// If not running, then this is an async call, so don't worry about waiting
// We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road
this.start();
}
}
else if (action.equals("stop")) {
if (this.status == AccelListener.RUNNING) {
this.stop();
}
} else {
// Unsupported action
return false;
}
PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
return true;
}
CloseDatabaseActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 26
收藏 0
点赞 0
评论 0
public PluginResult dispatch(BaseActionDispatcher.Context paramContext)
throws Throwable
{
DatabaseManager localDatabaseManager = DatabaseManager.getInstance();
try
{
localDatabaseManager.clearDbPath();
localDatabaseManager.clearDatabaseKey();
if (localDatabaseManager.isDatabaseOpen())
localDatabaseManager.closeDatabase();
PluginResult localPluginResult = new PluginResult(PluginResult.Status.OK, 0);
return localPluginResult;
}
catch (Throwable localThrowable)
{
}
return new PluginResult(PluginResult.Status.ERROR, 23);
}
FindByIdActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 25
收藏 0
点赞 0
评论 0
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext)
throws Throwable
{
JSONArray localJSONArray1 = getIds(paramContext);
try
{
JSONArray localJSONArray2 = (JSONArray)paramContext.performReadableDatabaseAction(new FindByIdAction(localJSONArray1, null));
if (localJSONArray2 == null)
return new PluginResult(PluginResult.Status.ERROR, 22);
JacksonSerializedPluginResult localJacksonSerializedPluginResult = new JacksonSerializedPluginResult(PluginResult.Status.OK, localJSONArray2);
return localJacksonSerializedPluginResult;
}
catch (Throwable localThrowable)
{
if (this.logger.isLoggable(6))
this.logger.logError("error while executing find by ID query on database \"" + paramContext.getDatabaseName() + "\"", localThrowable);
}
return new PluginResult(PluginResult.Status.ERROR, 22);
}
SimpleQueryActionDispatcher.java 文件源码
项目:12306-android-Decompile
阅读 26
收藏 0
点赞 0
评论 0
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext)
throws Throwable
{
int i = -1;
try
{
int k = ((Integer)paramContext.performReadableDatabaseAction(new SimpleQueryAction(paramContext, null))).intValue();
i = k;
int j = getModifiedResultValue(i);
logResult(paramContext, j);
return new PluginResult(PluginResult.Status.OK, j);
}
catch (Throwable localThrowable)
{
while (true)
{
if (!this.logger.isLoggable(6))
continue;
this.logger.logError("error occurred while performing query:");
this.logger.logError(" " + getFormattedQuery(paramContext), localThrowable);
}
}
}