Search in sources :

Example 11 with PluginResult

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;
}
Also used : Window(android.view.Window) PluginResult(org.apache.cordova.PluginResult) Activity(android.app.Activity)

Example 12 with PluginResult

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;
}
Also used : JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException)

Example 13 with PluginResult

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;
    }
}
Also used : PluginResult(org.apache.cordova.PluginResult)

Example 14 with PluginResult

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;
}
Also used : JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) JSONException(org.json.JSONException)

Example 15 with PluginResult

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;
}
Also used : PluginResult(org.apache.cordova.PluginResult) JSONException(org.json.JSONException)

Aggregations

PluginResult (org.apache.cordova.PluginResult)45 JSONException (org.json.JSONException)19 JSONObject (org.json.JSONObject)15 IOException (java.io.IOException)6 JSONArray (org.json.JSONArray)6 Uri (android.net.Uri)4 FileNotFoundException (java.io.FileNotFoundException)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 CallbackContext (org.apache.cordova.CallbackContext)3 CordovaInterface (org.apache.cordova.CordovaInterface)3 CordovaResourceApi (org.apache.cordova.CordovaResourceApi)3 NativeToJsMessageQueue (org.apache.cordova.NativeToJsMessageQueue)3 Test (org.junit.Test)3 SharedPreferences (android.content.SharedPreferences)2