package mta.cordova.stplugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.LOG;
import org.apache.cordova.PermissionHelper;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.RawContacts;
import android.widget.Toast;

import java.lang.reflect.Method;

public class Stplugin extends CordovaPlugin {
    private static final String LOG_TAG = "Stplugin";
    private static boolean firstShow = true;
    private static boolean lastHideAfterDelay; // https://issues.apache.org/jira/browse/CB-9094
    private static int aaa = 0;


    /**
     * Remember last device orientation to detect orientation changes.
     */
    private int orientation;

    // Helper to be compile-time compatible with both Cordova 3.x and 4.x.
    /*private View getView() {
        try {
            return (View)webView.getClass().getMethod("getView").invoke(webView);
        } catch (Exception e) {
            return (View)webView;
        }
    }*/

    @Override
    protected void pluginInitialize() {
        aaa = 2;
    }

    @Override
    public void onPause(boolean multitasking) {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        Toast.makeText(cordova.getContext(), action, Toast.LENGTH_SHORT).show();
        if (action.equals("stCall")) {
            Toast.makeText(cordova.getContext(), action, Toast.LENGTH_SHORT).show();
            JSONObject r = new JSONObject();
            r.put("st1", aaa * 1 + 11);
            r.put("st2", aaa * 2 + 12);
            r.put("st3", aaa * 3 + 13);
            r.put("st4", aaa * 4 + 14);
            r.put("st5", aaa * 5 + 15);
            r.put("st6", aaa * 6 + 16);
            r.put("st7", aaa * 7 + 17);
            callbackContext.success(r);
        } else if (action.equals("stGive")) {
            JSONObject r = new JSONObject();
            r.put("st1", aaa * 1 + 21);
            r.put("st2", aaa * 2 + 22);
            r.put("st3", aaa * 3 + 23);
            r.put("st4", aaa * 4 + 24);
            r.put("st5", aaa * 5 + 25);
            r.put("st6", aaa * 6 + 26);
            r.put("st7", aaa * 7 + 27);
            callbackContext.success(r);
        } else {
            return false;
        }
        return true;
    }

    @Override
    public Object onMessage(String id, Object data) {

        return null;
    }
}
