use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class StatusBar method execute.
/**
* 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 True if the action was valid, false otherwise.
*/
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
Log.v(TAG, "Executing action: " + action);
final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow();
if ("_ready".equals(action)) {
boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
}
if ("show".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
return true;
}
if ("hide".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
return true;
}
return false;
}
use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class AndroidPreferences method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
final JSONObject params = args.getJSONObject(0);
final String preferenceLib = params.getString("preferenceLib");
final String preferenceName = params.getString("preferenceName");
final String preferenceValue = params.getString("preferenceValue");
if (preferenceLib != null && preferenceName != null && preferenceValue != null && !preferenceLib.equals("") && !preferenceName.equals("")) {
final SharedPreferences settings = cordova.getActivity().getSharedPreferences(preferenceLib, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = settings.edit();
if (action.equals("set") && settings != null && editor != null) {
editor.putString(preferenceName, preferenceValue);
editor.commit();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else if (action.equals("get") && settings != null && editor != null) {
final String returnValue = settings.getString(preferenceName, "");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, returnValue));
} else {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
}
} else {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.ERROR);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
}
} catch (final JSONException e) {
e.printStackTrace();
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
});
return true;
}
use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class PackageVersion method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
if (action.equals("get")) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
final String version = getPackageVersion();
if (version != null) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, version));
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
}
}
});
return true;
} else {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.INVALID_ACTION);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
return false;
}
}
use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class Share method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
final JSONObject jo = args.getJSONObject(0);
doSendIntent(jo.getString("subject"), jo.getString("text"));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} catch (final JSONException e) {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
});
return true;
}
use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class Toasts method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
if (action.equals("cancel")) {
cancelToast();
} else {
try {
final String message = args.getString(0);
if (action.equals("show_long")) {
showToast(message, Toast.LENGTH_LONG);
} else {
showToast(message, Toast.LENGTH_SHORT);
}
} catch (final JSONException e) {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
}
});
return true;
}
Aggregations