
package com.imin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.apache.cordova.PluginResult.Status;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.util.Iterator;

import android.graphics.Typeface;

import android.os.Build;


import android.widget.Toast;

import java.util.concurrent.TimeUnit;
import java.lang.reflect.Method;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;




import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;

import android.content.Intent;
import android.content.IntentFilter;
// import com.example.NeptunePrinter;
// import com.example.ScannerTester;
// import com.example.MagTester;
// import com.example.PedTester;
// import com.pax.dal.entity.EScannerType;
//
// import com.pax.dal.entity.TrackData;
import android.os.SystemClock;


import android.Manifest;
import android.annotation.TargetApi;

import android.content.pm.PackageManager;
import android.content.res.Configuration;

import android.text.TextUtils;

// import android.view.LayoutInflater;
// import android.view.View;
// import android.view.ViewGroup;
// import android.widget.AdapterView;
// import android.widget.ArrayAdapter;
// import android.widget.CheckBox;
// import android.widget.EditText;
// import android.widget.ListView;
// import android.widget.Spinner;
// import android.widget.TextView;
// import android.widget.Toast;




import java.io.IOException;
import java.io.UnsupportedEncodingException;

import java.util.List;

// import androidx.annotation.RequiresApi;
// import androidx.appcompat.app.AppCompatActivity;
// import androidx.core.app.ActivityCompat;
// import androidx.core.content.ContextCompat;
// import androidx.recyclerview.widget.GridLayoutManager;
// import androidx.recyclerview.widget.RecyclerView;

import com.imin.Scan;
public class IminScanner extends CordovaPlugin {

    private static final String TAG = "Imin";

    CallbackContext callbackContext = null;
    Context context = null;


    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
    }

    public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
        this.callbackContext = callbackContext;
        Log.d(TAG,action);
        context = cordova.getActivity().getApplicationContext();

        if (action.equals("scan")) {
          cordova.getThreadPool().execute(new Runnable() {
                          @Override
                          public void run() {

                              context = cordova.getActivity().getApplicationContext();

                              startScan(context);
                      }
                      });


      }
      return true;
    }

  private void startScan(Context context) {
         Intent intent = new Intent(context, Scan.class);
         cordova.getActivity().startActivity(intent);
     }
    }
