package com.simple.plugin;

import android.app.Activity;
import android.app.Application;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.supconit.develop.JSBridge;
import com.supconit.develop.Response;
import com.supconit.hcmobile.HcmobileApp;

import org.json.JSONArray;
import org.json.JSONException;

public class SimpleAndroidPluginNativiePart implements JSBridge {

    @Override
    public void onApplicationCreate(Application application) {

    }

    Activity activity;
    // todo 为了释放callBack内存 必须回调其中success或者error方法
    @Override
    public void execute(String action, JSONArray args, Response callbackContext) {

        switch (action) {
            case "ckme":
                try {
                    callbackContext.success("调用"+action+"---args---"+args.getJSONObject(0).getString("name"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case "dialog":
                callbackContext.success("调用成功"+action);
                break;
        }
        try {
            final String l1 = args.getString(0);
            HcmobileApp.getHandle().post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(activity, l1, Toast.LENGTH_SHORT).show();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onActivityCreate(final Activity act) {
        this.activity = act;

    }

    @Override
    public void onActivityPase(Activity activity) {

    }

    @Override
    public void onActivityDestory(Activity activity) {

    }
}