package by.chemerisuk.cordova.coreextensions;

import org.json.JSONArray;
import org.json.JSONException;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;

import android.content.Context;
import android.content.Intent;


public class CoreAndroidExtensions extends CordovaPlugin {
    public static final String PLUGIN_NAME = "CoreAndroidExtensions";

    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback context from which we were invoked.
     * @return                  A PluginResult object with a status and message.
     */
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        PluginResult.Status status = PluginResult.Status.OK;
        String result = "";

        try {
            if (action.equals("minimizeApp")) {
                this.minimizeApp();
            } else if (action.equals("resumeApp")) {
                this.resumeApp();
            }

            callbackContext.sendPluginResult(new PluginResult(status, result));
            return true;
        } catch (JSONException e) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
            return false;
        }
    }

    private void minimizeApp() {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        this.cordova.getActivity().startActivity(intent);
    }

    private void resumeApp() {
        Context ctx = cordova.getActivity().getApplicationContext();
        Intent intent = new Intent(ctx, cordova.getActivity().getClass());

        intent.setAction(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_NO_ANIMATION);

        ctx.startActivity(intent);
    }
}
@@ -991,26 +991,8 @@
 %22;%0A%0A
-        try %7B%0A    
     
@@ -1039,28 +1039,24 @@
             
-   
- 
 this.minimiz
@@ -1055,36 +1055,32 @@
 .minimizeApp();%0A
-    
         %7D else i
@@ -1120,28 +1120,24 @@
             
- 
-   
 this.resumeA
@@ -1150,27 +1150,19 @@
         
-    %7D%0A%0A    
+%7D%0A%0A
         
@@ -1233,28 +1233,24 @@
 ));%0A        
-    
 return true;
@@ -1254,180 +1254,8 @@
 ue;%0A
-        %7D catch (JSONException e) %7B%0A            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));%0A            return false;%0A        %7D%0A
     

remove unnecessary code