// Path: traction/src/main/java/traction/mvc/controllers/FragmentController.java
// public class FragmentController
// extends Fragment
// {
// 	/**
// 	 * Helper to implement Controller logic.
// 	 */
// 	protected final ControllerHelper View = new ControllerHelper(this);
// 
// 	@Override
// 	public void onCreate(Bundle savedInstanceState)
// 	{	
// 		super.onCreate(savedInstanceState);
// 		setRetainInstance(true);
// 	}
// 	
// 	@Override
// 	public View onCreateView(LayoutInflater notUsed, ViewGroup container, Bundle savedInstanceState) 
// 	{
// 		View v = View.inflateView(View.getContentView(), container, container != null);
//         IViewBinding vb = ViewFactory.getViewBinding(v);
//         if (vb != null) {
//             View.ensureMenuInflator(vb.getBindingInventory());
//         }
//         return v;
// 	}
// 	
// 	@Override
// 	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
// 	{
//         View.onCreateOptionsMenu(menu);
// 	}
// 
// 	@Override
// 	public void onDestroyView() 
// 	{		
// 		super.onDestroyView();	
// 		ViewFactory.DetachContext(getView());
// 	}
// 
//     @Override
//     public void onAttach(Activity activity)
//     {
//         super.onAttach(activity);
//         View.registerFragmentToActivity(this, activity);
//     }
// 
//     @Override
//     public void onDetach()
//     {
//         super.onDetach();
//         View.unregisterFragmentFromActivity(this, getActivity());
//     }
// 
//     @Override
//     public void onStart()
//     {
//         super.onStart();
//         View.connectFragmentViewToParentView(this);
//     }
// }
// 
// Path: traction/src/main/java/traction/mvc/implementations/CommandArgument.java
// public class CommandArgument
// {
//     private String commandName;
//     private boolean eventCancelled;
//     private JSONObject tagProperties;
// 
//     public boolean isEventCancelled()
//     {
//         return eventCancelled;
//     }
// 
//     public void setEventCancelled(boolean isCancelled)
//     {
//         eventCancelled = isCancelled;
//     }
// 
//     public CommandArgument(String commandName)
//     {
//         this(commandName, null);
//     }
// 
//     public CommandArgument(String commandName, JSONObject tagProperties)
//     {
//         this.commandName = commandName;
//         this.eventCancelled = false;
//         this.tagProperties = tagProperties;
//     }
// 
//     public JSONObject getEventData()
//     {
//         return tagProperties;
//     }
// 
//     public String getCommandName()
//     {
//         return commandName;
//     }
// }
// 
// Path: traction/src/main/java/traction/mvc/interfaces/IOnExecuteListener.java
// public interface IOnExecuteListener
// {
//     void onExecuted(CommandArgument arg);
// }
// 
// Path: Demo/src/main/java/ni3po42/android/tractiondemo/models/ICalculatorModel.java
// public interface ICalculatorModel
// {
//     String getDisplay();
//     void setDisplay(String str);
// 
//     Command getNumberUpdate();
//     Command getOperation();
//     Command getClearDisplay();
//     Command getSwitchToDecimal();
// }


import android.os.Bundle;
import org.json.JSONException;
import org.json.JSONObject;
import traction.mvc.controllers.FragmentController;
import traction.mvc.implementations.CommandArgument;
import traction.mvc.interfaces.IOnExecuteListener;
import ni3po42.android.tractiondemo.R;
import ni3po42.android.tractiondemo.models.ICalculatorModel;
    public void doOperation(JSONObject argument)
    {
        String action = null;
        ICalculatorModel model = View.getScope();
        try
        {
            action = argument.getString("CommandValue");
        }
        catch (JSONException ex)
        {

        }

        if ("+/-".equals(action))
        {
            currentValue*=-1;
            model.setDisplay(String.valueOf(currentValue));
            return;
        }
        else if ("=".equals(action))
        {
            popStack();
            if ("+".equals(currentAction))
                    currentValue += stack;
            else if ("-".equals(currentAction))
                    currentValue = stack - currentValue;
            else if ("X".equals(currentAction))
                    currentValue *= stack;
            else if ("/".equals(currentAction)) {
                if (currentValue == 0) {
// Path: traction/src/main/java/traction/mvc/controllers/FragmentController.java
// public class FragmentController
// extends Fragment
// {
// 	/**
// 	 * Helper to implement Controller logic.
// 	 */
// 	protected final ControllerHelper View = new ControllerHelper(this);
// 
// 	@Override
// 	public void onCreate(Bundle savedInstanceState)
// 	{	
// 		super.onCreate(savedInstanceState);
// 		setRetainInstance(true);
// 	}
// 	
// 	@Override
// 	public View onCreateView(LayoutInflater notUsed, ViewGroup container, Bundle savedInstanceState) 
// 	{
// 		View v = View.inflateView(View.getContentView(), container, container != null);
//         IViewBinding vb = ViewFactory.getViewBinding(v);
//         if (vb != null) {
//             View.ensureMenuInflator(vb.getBindingInventory());
//         }
//         return v;
// 	}
// 	
// 	@Override
// 	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
// 	{
//         View.onCreateOptionsMenu(menu);
// 	}
// 
// 	@Override
// 	public void onDestroyView() 
// 	{		
// 		super.onDestroyView();	
// 		ViewFactory.DetachContext(getView());
// 	}
// 
//     @Override
//     public void onAttach(Activity activity)
//     {
//         super.onAttach(activity);
//         View.registerFragmentToActivity(this, activity);
//     }
// 
//     @Override
//     public void onDetach()
//     {
//         super.onDetach();
//         View.unregisterFragmentFromActivity(this, getActivity());
//     }
// 
//     @Override
//     public void onStart()
//     {
//         super.onStart();
//         View.connectFragmentViewToParentView(this);
//     }
// }
// 
// Path: traction/src/main/java/traction/mvc/implementations/CommandArgument.java
// public class CommandArgument
// {
//     private String commandName;
//     private boolean eventCancelled;
//     private JSONObject tagProperties;
// 
//     public boolean isEventCancelled()
//     {
//         return eventCancelled;
//     }
// 
//     public void setEventCancelled(boolean isCancelled)
//     {
//         eventCancelled = isCancelled;
//     }
// 
//     public CommandArgument(String commandName)
//     {
//         this(commandName, null);
//     }
// 
//     public CommandArgument(String commandName, JSONObject tagProperties)
//     {
//         this.commandName = commandName;
//         this.eventCancelled = false;
//         this.tagProperties = tagProperties;
//     }
// 
//     public JSONObject getEventData()
//     {
//         return tagProperties;
//     }
// 
//     public String getCommandName()
//     {
//         return commandName;
//     }
// }
// 
// Path: traction/src/main/java/traction/mvc/interfaces/IOnExecuteListener.java
// public interface IOnExecuteListener
// {
//     void onExecuted(CommandArgument arg);
// }
// 
// Path: Demo/src/main/java/ni3po42/android/tractiondemo/models/ICalculatorModel.java
// public interface ICalculatorModel
// {
//     String getDisplay();
//     void setDisplay(String str);
// 
//     Command getNumberUpdate();
//     Command getOperation();
//     Command getClearDisplay();
//     Command getSwitchToDecimal();
// }


// Path: Demo/src/main/java/ni3po42/android/tractiondemo/controllers/CalculatorController.java
import android.os.Bundle;
import org.json.JSONException;
import org.json.JSONObject;
import traction.mvc.controllers.FragmentController;
import traction.mvc.implementations.CommandArgument;
import traction.mvc.interfaces.IOnExecuteListener;
import ni3po42.android.tractiondemo.R;
import ni3po42.android.tractiondemo.models.ICalculatorModel;

    public void doOperation(JSONObject argument)
    {
        String action = null;
        ICalculatorModel model = View.getScope();
        try
        {
            action = argument.getString("CommandValue");
        }
        catch (JSONException ex)
        {

        }

        if ("+/-".equals(action))
        {
            currentValue*=-1;
            model.setDisplay(String.valueOf(currentValue));
            return;
        }
        else if ("=".equals(action))
        {
            popStack();
            if ("+".equals(currentAction))
                    currentValue += stack;
            else if ("-".equals(currentAction))
                    currentValue = stack - currentValue;
            else if ("X".equals(currentAction))
                    currentValue *= stack;
            else if ("/".equals(currentAction)) {
                if (currentValue == 0) {
                    currentValue = Double.NaN;