<commit_before>package com.navtureapps.cordovaplugin;

import org.apache.cordova.*;
import org.json.JSONException;

import android.support.annotation.RequiresApi;
import android.widget.Toast;
import android.app.Activity;
import android.util.Log;
import android.content.Intent;
import java.lang.Runnable;
import java.util.ArrayList;
import org.json.JSONObject;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
import javax.security.auth.callback.Callback;
import io.proximi.proximiiolibrary.Proximiio;
import io.proximi.proximiiolibrary.ProximiioBeacon;
import io.proximi.proximiiolibrary.ProximiioFactory;
import io.proximi.proximiiolibrary.ProximiioGeofence;
import io.proximi.proximiiolibrary.ProximiioListener;
import io.proximi.proximiiolibrary.ProximiioFloor;
import android.Manifest;
import android.os.Build;
import android.content.pm.PackageManager;

public class ProximiioCordova extends CordovaPlugin implements OnRequestPermissionsResultCallback {
  private Proximiio proximiio;
  private ProximiioListener listener;
  private String id;
  private String token;
  private boolean handlePush = true;
  private boolean enableDebug = false;

  private Activity activity;
  private static final String TAG = "ProximiioCordova";

  private CallbackContext context;

  private static final String ACTION_SET_TOKEN = "setToken";
  private static final String ACTION_ENABLE_DEBUG = "enableDebug";
  private static final String ACTION_HANDLE_PUSH = "handlePush";
  private static final String ACTION_REQUEST_PERMISSIONS = "requestPermissions";

  private String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION };

  @Override
  public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
    activity = cordova.getActivity();
    context = callbackContext;
    cordova.setActivityResultCallback(this);
    if (action.equals(ACTION_SET_TOKEN)) {
        if (proximiio == null) {
          token = args.getString(0);
          PluginResult r = new PluginResult(PluginResult.Status.OK);          
          context.sendPluginResult(r);
          initProximiio();
          return true;
          // if(hasPermisssion()) {
          //     PluginResult r = new PluginResult(PluginResult.Status.OK);
          //     context.sendPluginResult(r);
          //     initProximiio();
          //     return true;
          // }
          // else {
          //     Log.d(TAG, "Permissions not found, requesting");
          //     PermissionHelper.requestPermissions(this, 0, permissions);
          // }
          // return true;
        }
    } else if (action.equals(ACTION_ENABLE_DEBUG)) {
      String value = args.getString(0);
      enableDebug = value.equals("true");
      log("execute", "Debug mode enabled");
    } else if (action.equals(ACTION_HANDLE_PUSH)) {
      String value = args.getString(0);
      handlePush = value.equals("true");
    } else if (actions.equals(ACTION_REQUEST_PERMISSIONS)) {
      if (proximiio != null) {
        proximiio.checkPermissions();
      }
    }
    return true;
  }

  private void initProximiio() {
    proximiio = ProximiioFactory.getProximiio(activity);
    listener = new ProximiioListener() {
      @Override
      public void geofenceEnter(final ProximiioGeofence geofence) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
              String geofenceJson = geofence.getJSON().toString();
              String action = "javascript:proximiio.triggeredGeofence(1, " + geofenceJson + ")";
              log("geofenceEnter", action);
              webView.loadUrl(action);
            }
        });
      }

      @Override
      public void geofenceExit(final ProximiioGeofence geofence, @Nullable Long dwellTime) {
        activity.runOnUiThread(new Runnable() {
          @Override
          public void run() {
            String geofenceJson = geofence.getJSON().toString();
            String action = "javascript:proximiio.triggeredGeofence(0, " + geofenceJson + ")";
            log("geofenceExit", action);<commit_msg>Update ProximiioCordova.java<commit_after>package com.navtureapps.cordovaplugin;

import org.apache.cordova.*;
import org.json.JSONException;

import android.support.annotation.RequiresApi;
import android.widget.Toast;
import android.app.Activity;
import android.util.Log;
import android.content.Intent;
import java.lang.Runnable;
import java.util.ArrayList;
import org.json.JSONObject;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
import javax.security.auth.callback.Callback;
import io.proximi.proximiiolibrary.Proximiio;
import io.proximi.proximiiolibrary.ProximiioBeacon;
import io.proximi.proximiiolibrary.ProximiioFactory;
import io.proximi.proximiiolibrary.ProximiioGeofence;
import io.proximi.proximiiolibrary.ProximiioListener;
import io.proximi.proximiiolibrary.ProximiioFloor;
import android.Manifest;
import android.os.Build;
import android.content.pm.PackageManager;

public class ProximiioCordova extends CordovaPlugin implements OnRequestPermissionsResultCallback {
  private Proximiio proximiio;
  private ProximiioListener listener;
  private String id;
  private String token;
  private boolean handlePush = true;
  private boolean enableDebug = false;

  private Activity activity;
  private static final String TAG = "ProximiioCordova";

  private CallbackContext context;

  private static final String ACTION_SET_TOKEN = "setToken";
  private static final String ACTION_ENABLE_DEBUG = "enableDebug";
  private static final String ACTION_HANDLE_PUSH = "handlePush";
  private static final String ACTION_REQUEST_PERMISSIONS = "requestPermissions";

  private String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION };

  @Override
  public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
    activity = cordova.getActivity();
    context = callbackContext;
    cordova.setActivityResultCallback(this);
    if (action.equals(ACTION_SET_TOKEN)) {
        if (proximiio == null) {
          token = args.getString(0);
          PluginResult r = new PluginResult(PluginResult.Status.OK);          
          context.sendPluginResult(r);
          initProximiio();
          return true;
          // if(hasPermisssion()) {
          //     PluginResult r = new PluginResult(PluginResult.Status.OK);
          //     context.sendPluginResult(r);
          //     initProximiio();
          //     return true;
          // }
          // else {
          //     Log.d(TAG, "Permissions not found, requesting");
          //     PermissionHelper.requestPermissions(this, 0, permissions);
          // }
          // return true;
        }
    } else if (action.equals(ACTION_ENABLE_DEBUG)) {
      String value = args.getString(0);
      enableDebug = value.equals("true");
      log("execute", "Debug mode enabled");
    } else if (action.equals(ACTION_HANDLE_PUSH)) {
      String value = args.getString(0);
      handlePush = value.equals("true");
    } else if (action.equals(ACTION_REQUEST_PERMISSIONS)) {
      if (proximiio != null) {
        proximiio.checkPermissions();
      }
    }
    return true;
  }

  private void initProximiio() {
    proximiio = ProximiioFactory.getProximiio(activity);
    listener = new ProximiioListener() {
      @Override
      public void geofenceEnter(final ProximiioGeofence geofence) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
              String geofenceJson = geofence.getJSON().toString();
              String action = "javascript:proximiio.triggeredGeofence(1, " + geofenceJson + ")";
              log("geofenceEnter", action);
              webView.loadUrl(action);
            }
        });
      }

      @Override
      public void geofenceExit(final ProximiioGeofence geofence, @Nullable Long dwellTime) {
        activity.runOnUiThread(new Runnable() {
          @Override
          public void run() {
            String geofenceJson = geofence.getJSON().toString();
            String action = "javascript:proximiio.triggeredGeofence(0, " + geofenceJson + ")";
            log("geofenceExit", action);
{'fraction_non_alphanumeric': 0.09603658536585366, 'fraction_numerical': 0.0016416510318949344, 'mean_word_length': 3.270906359539309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6867478', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2427, 'n_words': 500}