package com.cowbell.cordova.geofence;

import java.util.ArrayList;
import java.util.List;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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

public class GeofencePlugin extends CordovaPlugin {
    public static final String TAG = "GeofencePlugin";
    private GeoNotificationManager geoNotificationManager;
    private Context context;
    protected static Boolean isInBackground = true;
    private static CordovaWebView webView = null;

    /**
     * @param cordova
     *            The context of the main Activity.
     * @param webView
     *            The associated CordovaWebView.
     */
    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
        GeofencePlugin.webView = webView;
        context = this.cordova.getActivity().getApplicationContext();
        Logger.setLogger(new Logger(TAG, context, false));
        geoNotificationManager = new GeoNotificationManager(context);
    }

    @Override
    public boolean execute(String action, JSONArray args,
            CallbackContext callbackContext) throws JSONException {
        Log.d(TAG, "GeofencePlugin execute action: " + action + " args: "
                + args.toString());

        if (action.equals("addOrUpdate")) {
            List<GeoNotification> geoNotifications = new ArrayList<GeoNotification>();
            for (int i = 0; i < args.length(); i++) {
                GeoNotification not = parseFromJSONObject(args.getJSONObject(i));
                if (not != null) {
                    geoNotifications.add(not);
                }
            }
            geoNotificationManager.addGeoNotifications(geoNotifications,
                    callbackContext);
        } else if (action.equals("remove")) {
            List<String> ids = new ArrayList<String>();
            for (int i = 0; i < args.length(); i++) {
                ids.add(args.getString(i));
            }
            geoNotificationManager.removeGeoNotifications(ids, callbackContext);
        } else if (action.equals("removeAll")) {
            geoNotificationManager.removeAllGeoNotifications(callbackContext);
        } else if (action.equals("getWatched")) {
            List<GeoNotification> geoNotifications = geoNotificationManager
                    .getWatched();
            callbackContext.success(Gson.get().toJson(geoNotifications));
        } else if (action.equals("initialize")) {

        } else {
            return false;
        }
        return true;

    }

    private GeoNotification parseFromJSONObject(JSONObject object) {
        GeoNotification geo = null;
        geo = GeoNotification.fromJson(object.toString());
        return geo;
    }

    public static void fireReceiveTransition(List<GeoNotification> notifications) {
        String js = "setTimeout('geofence.receiveTransition("
                + Gson.get().toJson(notifications) + ")',0)";
        if (webView == null) {
            Log.d(TAG, "Webview is null");
        } else {
            webView.sendJavascript(js);
        }
    }

}

@@ -369,24 +369,81 @@
 nt.Context;%0A
+import android.content.Intent;%0Aimport android.os.Bundle;%0A
 import andro
@@ -2830,24 +2830,594 @@
 ue;%0A%0A    %7D%0A%0A
+    /**%0A     * Called when the activity receives a new intent.%0A     */%0A    @Override%0A    public void onNewIntent(Intent intent) %7B%0A        super.onNewIntent(intent);%0A%0A        Bundle bundle = intent.getExtras();%0A        if(bundle != null) %7B%0A            String data = bundle.getString(%22geofence.notification.data%22);%0A            String js = %22setTimeout('geofence.receiveData(%22 + data + %22)',0)%22;%0A%0A            if (webView == null) %7B%0A                Log.d(TAG, %22Webview is null%22);%0A            %7D else %7B%0A                webView.sendJavascript(js);%0A            %7D%0A        %7D%0A    %7D%0A%0A
     private 

Add passing the intent data (onNewIntent) to the webview