package kr.co.purpleworks.cordova.modal;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.content.Intent;

public class Modal extends CordovaPlugin {
	private static final int ACTIVITY_MODAL = 1001;							// modal activity request code
	public static final String PARAM_LOAD_URL = "loadUrl";					// passing data

	private CallbackContext callbackContext;

	@Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		this.callbackContext = callbackContext;

        if (action.equals("open")) {
            String url = args.getString(0);
            Intent intent = new Intent(this.cordova.getActivity(), ModalActivity.class);
            intent.putExtra(PARAM_LOAD_URL, url);

            this.cordova.setActivityResultCallback(this);
            this.cordova.getActivity().startActivityForResult(intent, ACTIVITY_MODAL);

            return true;
        } else if(action.equals("close")) {
        	if (cordova.getActivity() instanceof ModalActivity) {
        		Intent intent = new Intent();
        		intent.putExtra("arg", args.toString());

        		this.cordova.getActivity().setResult(Activity.RESULT_OK, intent);
        		this.cordova.getActivity().finish();
			} else {
				callbackContext.error("Illegal Activity Exception");
			}

        	return true;
        }
        return false;
    }

	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if(requestCode == ACTIVITY_MODAL) {
			if(resultCode == Activity.RESULT_OK) {
				String arg = intent.getStringExtra("arg");
				this.callbackContext.success(arg);
			}
		}
	}
}

@@ -46,42 +46,38 @@
 ort 
-org.apache.cordova.CallbackContext
+kr.co.purpleworks.plugin_dev.R
 ;%0Aim
@@ -111,94 +111,8 @@
 dova
-Plugin;%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0A%0Aimport android.app.
 Acti
@@ -136,22 +136,17 @@
 oid.
-content.Intent
+os.Bundle
 ;%0A%0Ap
@@ -162,16 +162,24 @@
 ss Modal
+Activity
  extends
@@ -190,667 +190,132 @@
 dova
-Plugin %7B%0A%09private static final int ACTIVITY_MODAL = 1001;%09%09%09%09%09%09%09// modal activity request code%0A%09public static final String PARAM_LOAD_URL = %22loadUrl%22;%09%09%09%09%09// passing data%0A%0A%09private CallbackContext callbackContext;%0A%0A%09@Override%0A    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException %7B%0A%09%09this.callbackContext = callbackContext;%0A%0A        if (action.equals(%22open%22)) %7B%0A            String url = args.getString(0);%0A            Intent intent = new Intent(this.cordova.getActivity(), ModalActivity.class);%0A            intent.putExtra(PARAM_LOAD_URL, url);%0A%0A            this.cordova.setActivityResultCallback(this
+Activity%0A%7B%0A    @Override%0A    public void onCreate(Bundle savedInstanceState)%0A    %7B%0A        super.onCreate(savedInstanceState
 );%0A 
@@ -325,268 +325,102 @@
     
-  
-  
 this.
-cordova.getActivity().startActivityForResult(intent, ACTIVITY_MODAL);%0A%0A            return true;%0A        %7D else if(action.equals(%22close%22)) %7B%0A        %09if (cordova.getActivity() instanceof ModalActivity) %7B%0A        %09%09Intent intent = new Inten
+overridePendingTransition(R.anim.bottom_in, R.anim.hold);%0A        super.ini
 t();%0A
+%0A
         
 %09%09in
@@ -419,312 +419,124 @@
     
-%09%09intent.putExtra(%22arg%22, args.toString());%0A%0A        %09%09this.cordova.getActivity().setResult(Activity.RESULT_OK, intent);%0A        %09%09this.cordova.getActivity().finish();%0A%09%09%09%7D else %7B%0A%09%09%09%09callbackContext.error(%22Illegal Activity Exception%22);%0A%09%09%09%7D%0A%0A        %09return true
+String url = getIntent().getStringExtra(Modal.PARAM_LOAD_URL);%0A        super.loadUrl(url)
 ;%0A    
- 
-   %7D%0A        return false;
+%7D%0A%0A    @Override
 %0A    
-%7D%0A%0A%09
 publ
@@ -547,251 +547,113 @@
 oid 
-onActivityResult(int requestCode, int resultCode, Intent intent) %7B%0A%09%09if(requestCode == ACTIVITY_MODAL) %7B%0A%09%09%09if(resultCode == Activity.RESULT_OK) %7B%0A%09%09%09%09String arg = intent.getStringExtra(%22arg%22);%0A%09%09%09%09this.callbackContext.success(arg);%0A%09%09%09%7D%0A%09%09%7D%0A%09
+finish() %7B%0A    %09super.finish();%0A    %09this.overridePendingTransition(R.anim.hold, R.anim.bottom_out);%0A    
 %7D%0A%7D%0A

update ModalActivity.java