// Path: RecordingLib/src/com/vpedak/testsrecorder/core/events/PressBackAction.java
// public class PressBackAction extends Action {
//     public void accept(StringBuilder sb, TestGenerator generator, Subject subject){
//         generator.generateActon(sb, this, subject);
//     }
// }
// 
// Path: RecordingLib/src/com/vpedak/testsrecorder/core/events/RecordingEvent.java
// public class RecordingEvent {
//     private String group = null;
//     private Subject subject;
//     private Action action;
//     private String description;
//     private long time;
// 
//     public RecordingEvent(String group, Subject subject, Action action) {
//         this.group = group;
//         this.subject = subject;
//         this.action = action;
//     }
// 
//     public RecordingEvent(Subject subject, Action action, String description) {
//         this.subject = subject;
//         this.action = action;
//         this.description = description;
//     }
// 
//     public Subject getSubject() {
//         return subject;
//     }
// 
//     public Action getAction() {
//         return action;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public String getGroup() {
//         return group;
//     }
// 
//     public void setGroup(String group) {
//         this.group = group;
//     }
// 
//     public long getTime() {
//         return time;
//     }
// 
//     public void setTime(long time) {
//         this.time = time;
//     }
// 
//     public void accept(StringBuilder sb, TestGenerator generator){
//         generator.generateEvent(sb, this);
//     }
// 
//     @Override
//     public String toString() {
//         return "event=["+time+","+(getGroup()==null?"":getGroup())+","+subject.toString()+","+action.toString()+"," +
//                 (description==null?"":description)+"]";
//     }
// 
//     public static RecordingEvent fromString(String str) {
//         String tmp = str.substring(7, str.length()-1);
//         String arr[] = tmp.split("[,]");
// 
//         String timeStr = arr[0];
//         String group = arr[1];
//         String subjectStr = arr[2];
//         String actionStr = arr[3];
//         String description = arr.length == 5 ? arr[4] : null;
//         RecordingEvent event = new RecordingEvent(Subject.fromString(subjectStr), Action.fromString(actionStr), description);
// 
//         event.setTime(Long.parseLong(timeStr));
// 
//         if (group.length() > 0) {
//             event.setGroup(group);
//         }
// 
//         return event;
//     }
// }


import android.app.Activity;
import android.app.Instrumentation;
import android.content.IntentFilter;
import android.os.Looper;
import android.util.Log;
import android.util.Printer;
import com.vpedak.testsrecorder.core.events.PressBackAction;
import com.vpedak.testsrecorder.core.events.RecordingEvent;
import java.lang.reflect.Field;
import java.util.EmptyStackException;
import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
        activityProcessor = new ActivityProcessor(uniqueId, instr, eventWriter);

        activityProcessor.processActivity(activity);

        try {
            fResumed = Activity.class.getDeclaredField("mResumed");
            fResumed.setAccessible(true);

            fStopped = Activity.class.getDeclaredField("mStopped");
            fStopped.setAccessible(true);
        } catch (NoSuchFieldException e) {
            Log.e(ActivityProcessor.ANDRIOD_TEST_RECORDER, "NoSuchFieldException", e);
        }
    }

    public void start() {
        new Timer().schedule(new ActivityTask(this), 300L, 300L);
    }

    public synchronized void check() {
        Activity test = monitor.getLastActivity();
        if (test != null && test != activity && !isStopped(test)) {
            boolean push = true;
            if (isResumed(test)) {
                try {
                    if (stack.peek().equals(test) ) {
                        stack.pop();
                        push = false;

                        if (!wasEvent) {
// Path: RecordingLib/src/com/vpedak/testsrecorder/core/events/PressBackAction.java
// public class PressBackAction extends Action {
//     public void accept(StringBuilder sb, TestGenerator generator, Subject subject){
//         generator.generateActon(sb, this, subject);
//     }
// }
// 
// Path: RecordingLib/src/com/vpedak/testsrecorder/core/events/RecordingEvent.java
// public class RecordingEvent {
//     private String group = null;
//     private Subject subject;
//     private Action action;
//     private String description;
//     private long time;
// 
//     public RecordingEvent(String group, Subject subject, Action action) {
//         this.group = group;
//         this.subject = subject;
//         this.action = action;
//     }
// 
//     public RecordingEvent(Subject subject, Action action, String description) {
//         this.subject = subject;
//         this.action = action;
//         this.description = description;
//     }
// 
//     public Subject getSubject() {
//         return subject;
//     }
// 
//     public Action getAction() {
//         return action;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public String getGroup() {
//         return group;
//     }
// 
//     public void setGroup(String group) {
//         this.group = group;
//     }
// 
//     public long getTime() {
//         return time;
//     }
// 
//     public void setTime(long time) {
//         this.time = time;
//     }
// 
//     public void accept(StringBuilder sb, TestGenerator generator){
//         generator.generateEvent(sb, this);
//     }
// 
//     @Override
//     public String toString() {
//         return "event=["+time+","+(getGroup()==null?"":getGroup())+","+subject.toString()+","+action.toString()+"," +
//                 (description==null?"":description)+"]";
//     }
// 
//     public static RecordingEvent fromString(String str) {
//         String tmp = str.substring(7, str.length()-1);
//         String arr[] = tmp.split("[,]");
// 
//         String timeStr = arr[0];
//         String group = arr[1];
//         String subjectStr = arr[2];
//         String actionStr = arr[3];
//         String description = arr.length == 5 ? arr[4] : null;
//         RecordingEvent event = new RecordingEvent(Subject.fromString(subjectStr), Action.fromString(actionStr), description);
// 
//         event.setTime(Long.parseLong(timeStr));
// 
//         if (group.length() > 0) {
//             event.setGroup(group);
//         }
// 
//         return event;
//     }
// }


// Path: RecordingLib/src/com/vpedak/testsrecorder/core/ActivityListener.java
import android.app.Activity;
import android.app.Instrumentation;
import android.content.IntentFilter;
import android.os.Looper;
import android.util.Log;
import android.util.Printer;
import com.vpedak.testsrecorder.core.events.PressBackAction;
import com.vpedak.testsrecorder.core.events.RecordingEvent;
import java.lang.reflect.Field;
import java.util.EmptyStackException;
import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;

        activityProcessor = new ActivityProcessor(uniqueId, instr, eventWriter);

        activityProcessor.processActivity(activity);

        try {
            fResumed = Activity.class.getDeclaredField("mResumed");
            fResumed.setAccessible(true);

            fStopped = Activity.class.getDeclaredField("mStopped");
            fStopped.setAccessible(true);
        } catch (NoSuchFieldException e) {
            Log.e(ActivityProcessor.ANDRIOD_TEST_RECORDER, "NoSuchFieldException", e);
        }
    }

    public void start() {
        new Timer().schedule(new ActivityTask(this), 300L, 300L);
    }

    public synchronized void check() {
        Activity test = monitor.getLastActivity();
        if (test != null && test != activity && !isStopped(test)) {
            boolean push = true;
            if (isResumed(test)) {
                try {
                    if (stack.peek().equals(test) ) {
                        stack.pop();
                        push = false;

                        if (!wasEvent) {
                            eventWriter.writeEvent(new RecordingEvent(new Espresso(), new PressBackAction(), "Press on the back button"));