package kr.co.purpleworks.cordova.modal;

import kr.co.purpleworks.plugin_dev.R;

import org.apache.cordova.CordovaActivity;

import android.os.Bundle;

public class ModalActivity extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.overridePendingTransition(R.anim.bottom_in, R.anim.hold);
        super.init();
        
        String url = getIntent().getStringExtra(Modal.PARAM_LOAD_URL);
        super.loadUrl(url);
    }
    
    @Override
    public void finish() {
    	super.finish();
    	this.overridePendingTransition(R.anim.hold, R.anim.bottom_out);
    }
}

@@ -46,74 +46,163 @@
 ort 
-kr.co.purpleworks.plugin_dev.R;%0A%0Aimport org.apache.cordova.Cordova
+org.apache.cordova.CallbackContext;%0Aimport org.apache.cordova.CordovaPlugin;%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0A%0Aimport android.app.
 Acti
@@ -207,17 +207,16 @@
 tivity;%0A
-%0A
 import a
@@ -226,17 +226,22 @@
 oid.
-os.Bundle
+content.Intent
 ;%0A%0Ap
@@ -257,24 +257,16 @@
 ss Modal
-Activity
  extends
@@ -277,100 +277,440 @@
 dova
-Activity %0A%7B%0A    @Override%0A    public void onCreate(Bundle savedInstanceState)
+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    
-%7B%0A
         
 supe
@@ -709,123 +709,334 @@
     
-super.onCreate(savedInstanceState);%0A        this.overridePendingTransition(R.anim.bottom_in, R.anim.hold
+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);%0A            this.cordova.getActivity().startActivityForResult(intent, ACTIVITY_MODAL
 );%0A
+%0A
         
 supe
@@ -1035,159 +1035,484 @@
     
-super.init();%0A        %0A        String url = getIntent().getStringExtra(Modal.PARAM_LOAD_URL);%0A        super.loadUrl(url);%0A    %7D%0A
+    return true;%0A        %7D else if(action.equals(%22close%22)) %7B%0A        %09if (cordova.getActivity() instanceof ModalActivity) %7B%0A        %09%09Intent intent = new Intent();%0A        %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;%0A  
     
+  %7D
 %0A    
-@Override
+    return false;
 %0A    
+%7D%0A%0A%09
 publ
@@ -1523,113 +1523,251 @@
 oid 
-finish() %7B%0A    %09super.finish();%0A    %09this.overridePendingTransition(R.anim.hold, R.anim.bottom_out);%0A    
+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
 %7D%0A%7D%0A

update ModalActivity