<commit_before>package plugin.google.maps;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;

import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLngBounds;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaResourceApi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface  {

  /**
   * Create ground overlay
   * 
   * @param args
   * @param callbackContext
   * @throws JSONException
   */
  public void create(JSONArray args, CallbackContext callbackContext) throws JSONException {
    JSONObject opts = args.getJSONObject(1);
    _createGroundOverlay(opts, callbackContext);
  }
  
  public void _createGroundOverlay(final JSONObject opts, final CallbackContext callbackContext) throws JSONException {
    final GroundOverlayOptions options = new GroundOverlayOptions();
    final JSONObject properties = new JSONObject();

    if (opts.has("anchor")) {
      JSONArray anchor = opts.getJSONArray("anchor");
      options.anchor((float)anchor.getDouble(0), (float)anchor.getDouble(1));
    }
    if (opts.has("bearing")) {
      options.bearing((float)opts.getDouble("bearing"));
    }
    if (opts.has("opacity")) {
      options.transparency(1 - (float)opts.getDouble("opacity"));
    }
    if (opts.has("zIndex")) {
      options.zIndex((float)opts.getDouble("zIndex"));
    }
    if (opts.has("visible")) {
      options.visible(opts.getBoolean("visible"));
    }
    if (opts.has("bounds")) {
      JSONArray points = opts.getJSONArray("bounds");
      LatLngBounds bounds = PluginUtil.JSONArray2LatLngBounds(points);
      options.positionFromBounds(bounds);
    }
    if (opts.has("clickable")) {
      properties.put("isClickable", opts.getBoolean("clickable"));
    } else {
      properties.put("isClickable", true);
    }
    properties.put("isVisible", options.isVisible());

    // Since this plugin provide own click detection,
    // disable default clickable feature.
    options.clickable(false);

    // Load image
    final String imageUrl = opts.getString("url");
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {

        setImage_(options, imageUrl, new PluginAsyncInterface() {

          @Override
          public void onPostExecute(Object object) {
            if (object == null) {
              callbackContext.error("Cannot create a ground overlay");
              return;
            }
            GroundOverlay groundOverlay = (GroundOverlay)object;
            String id = groundOverlay.getId();

            self.objects.put("groundoverlay_" + id, groundOverlay);

            self.objects.put("groundoverlay_bounds_" + id, groundOverlay.getBounds());

            self.objects.put("groundoverlay_property_" + id, properties);

            self.objects.put("groundoverlay_initOpts_" + id, opts);

            JSONObject result = new JSONObject();
            try {
              result.put("hashCode", groundOverlay.hashCode());
              result.put("id", "groundoverlay_" + id);
            } catch (Exception e) {
              e.printStackTrace();
            }
            callbackContext.success(result);
          }

          @Override
          public void onError(String errorMsg) {
            callbackContext.error(errorMsg);
          }

        });
      }
    });

  }
  

  /**
   * Remove this tile layer
   * @param args
   * @param callbackContext
   * @throws JSONException 
   */
  public void remove(JSONArray args, CallbackContext callbackContext) throws JSONException {
    String id = args.getString(0);
    GroundOverlay groundOverlay = (GroundOverlay)self.objects.get(id);
    if (groundOverlay == null) {
      this.sendNoResult(callbackContext);
      return;
    }

    String propertyId = "groundoverlay_property_" + id;
    self.objects.remove(propertyId);
    groundOverlay.remove();
    this.sendNoResult(callbackContext);
  }


  /**
   * Set image of the ground-overlay
   * @param args
   * @param callbackContext
   * @throws JSONException 
   */
  public void setImage(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
    String id = args.getString(0);
    GroundOverlay groundOverlay = (GroundOverlay)self.objects.get(id);
    String url = args.getString(1);
    
    String propertyId = "groundoverlay_initOpts_" + groundOverlay.getId();
    JSONObject opts = (JSONObject) self.objects.get(propertyId);
    opts.put("url", url);
    self.objects.put(propertyId, opts);
    
    _createGroundOverlay(opts, callbackContext);
  }<commit_msg>(Android) Implement the GroundOverlay class<commit_after>package plugin.google.maps;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;

import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLngBounds;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaResourceApi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class PluginGroundOverlay extends MyPlugin implements MyPluginInterface  {

  /**
   * Create ground overlay
   * 
   * @param args
   * @param callbackContext
   * @throws JSONException
   */
  public void create(JSONArray args, CallbackContext callbackContext) throws JSONException {
    JSONObject opts = args.getJSONObject(1);
    _createGroundOverlay(opts, callbackContext);
  }
  
  public void _createGroundOverlay(final JSONObject opts, final CallbackContext callbackContext) throws JSONException {
    final GroundOverlayOptions options = new GroundOverlayOptions();
    final JSONObject properties = new JSONObject();

    if (opts.has("anchor")) {
      JSONArray anchor = opts.getJSONArray("anchor");
      options.anchor((float)anchor.getDouble(0), (float)anchor.getDouble(1));
    }
    if (opts.has("bearing")) {
      options.bearing((float)opts.getDouble("bearing"));
    }
    if (opts.has("opacity")) {
      options.transparency(1 - (float)opts.getDouble("opacity"));
    }
    if (opts.has("zIndex")) {
      options.zIndex((float)opts.getDouble("zIndex"));
    }
    if (opts.has("visible")) {
      options.visible(opts.getBoolean("visible"));
    }
    if (opts.has("bounds")) {
      JSONArray points = opts.getJSONArray("bounds");
      LatLngBounds bounds = PluginUtil.JSONArray2LatLngBounds(points);
      options.positionFromBounds(bounds);
    }
    if (opts.has("clickable")) {
      properties.put("isClickable", opts.getBoolean("clickable"));
    } else {
      properties.put("isClickable", true);
    }
    properties.put("isVisible", options.isVisible());

    // Since this plugin provide own click detection,
    // disable default clickable feature.
    options.clickable(false);

    // Load image
    final String imageUrl = opts.getString("url");
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {

        setImage_(options, imageUrl, new PluginAsyncInterface() {

          @Override
          public void onPostExecute(Object object) {
            if (object == null) {
              callbackContext.error("Cannot create a ground overlay");
              return;
            }
            GroundOverlay groundOverlay = (GroundOverlay)object;
            String id = groundOverlay.getId();

            self.objects.put("groundoverlay_" + id, groundOverlay);

            self.objects.put("groundoverlay_bounds_" + id, groundOverlay.getBounds());

            self.objects.put("groundoverlay_property_" + id, properties);

            self.objects.put("groundoverlay_initOpts_" + id, opts);

            JSONObject result = new JSONObject();
            try {
              result.put("hashCode", groundOverlay.hashCode());
              result.put("id", "groundoverlay_" + id);
            } catch (Exception e) {
              e.printStackTrace();
            }
            callbackContext.success(result);
          }

          @Override
          public void onError(String errorMsg) {
            callbackContext.error(errorMsg);
          }

        });
      }
    });

  }
  

  /**
   * Remove this tile layer
   * @param args
   * @param callbackContext
   * @throws JSONException 
   */
  public void remove(JSONArray args, final CallbackContext callbackContext) throws JSONException {
    final String id = args.getString(0);
    final GroundOverlay groundOverlay = (GroundOverlay)self.objects.get(id);
    if (groundOverlay == null) {
      this.sendNoResult(callbackContext);
      return;
    }

    self.objects.remove(id.replace("groundoverlay_", "groundoverlay_property_"));
    self.objects.remove(id.replace("groundoverlay_", "groundoverlay_initOpts_"));
    self.objects.remove(id.replace("groundoverlay_", "groundoverlay_bounds_"));
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        GroundOverlay groundOverlay = (GroundOverlay)self.objects.get(id);
        groundOverlay.remove();
        self.objects.remove(id);
        sendNoResult(callbackContext);
      }
    });
  }


  /**
   * Set image of the ground-overlay
   * @param args
   * @param callbackContext
   * @throws JSONException 
   */
  public void setImage(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
    String id = args.getString(0);
    GroundOverlay groundOverlay = (GroundOverlay)self.objects.get(id);
    String url = args.getString(1);
    
    String propertyId = "groundoverlay_initOpts_" + groundOverlay.getId();
    JSONObject opts = (JSONObject) self.objects.get(propertyId);
    opts.put("url", url);
    self.objects.put(propertyId, opts);
    
    _createGroundOverlay(opts, callbackContext);
  }
{'fraction_non_alphanumeric': 0.11600642904415241, 'fraction_numerical': 0.0015127162711543916, 'mean_word_length': 3.197619047619048, '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': '6957091', 'n_tokens_mistral': 2959, 'n_tokens_neox': 2951, 'n_words': 590}