// Path: RecordingLib/src/com/vpedak/testsrecorder/core/EventWriter.java
// public class EventWriter {
//     private long uniqueId;
//     public static final String ANDRIOD_TEST_RECORDER = "AndriodTestRecorder";
//     public String tag;
//     private Map<String, RecordingEvent> delayedEvents = new HashMap<String, RecordingEvent>();
//     private EventWriterListener listener;
//     private long lastTime;
// 
//     public EventWriter(long uniqueId, EventWriterListener listener) {
//         this.uniqueId = uniqueId;
//         this.listener = listener;
//         tag = ANDRIOD_TEST_RECORDER+uniqueId;
//         lastTime = System.currentTimeMillis();
//     }
// 
//     public synchronized void writeEvent(RecordingEvent event) {
//         long diff = System.currentTimeMillis() - lastTime;
//         lastTime = System.currentTimeMillis();
// 
//         if (delayedEvents.size() > 0) {
//             for(RecordingEvent delayedEvent : delayedEvents.values()) {
//                 delayedEvent.setTime(diff);
//                 Log.d(tag, delayedEvent.toString());
//             }
//             delayedEvents.clear();
//         }
//         event.setTime(diff);
//         Log.d(tag, event.toString());
//         listener.onEventWritten();
//     }
// 
//     public synchronized void addDelayedEvent(String id, RecordingEvent delayedEvent) {
//         delayedEvents.put(id, delayedEvent);
//     }
// 
//     public interface EventWriterListener {
//         void onEventWritten();
//     }
// }
// 
// 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 com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.logcat.LogCatListener;
import com.android.ddmlib.logcat.LogCatMessage;
import com.android.ddmlib.logcat.LogCatReceiverTask;
import com.vpedak.testsrecorder.core.EventWriter;
import com.vpedak.testsrecorder.core.events.RecordingEvent;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
        int count = 0;
        while (bridge.hasInitialDeviceList() == false) {
            try {
                Thread.sleep(100);
                count++;
            } catch (InterruptedException e) {
            }
            if (count > 100) {
                throw new RuntimeException("Timeout connecting to the adb!");
            }
        }

        IDevice[] devices = bridge.getDevices();
        if (devices.length == 0) {
            throw new RuntimeException("Failed to find device");
        }

        IDevice device = devices[0];

        receiverTask = new LogCatReceiverTask(device);

        final String tag = EventWriter.ANDRIOD_TEST_RECORDER+uniqueId;

        receiverTask.addLogCatListener(new LogCatListener() {
            @Override
            public void log(List<LogCatMessage> list) {
                for (LogCatMessage message : list) {
                    if (tag.equals(message.getTag())) {
                        String str = message.getMessage();
                        try {
// Path: RecordingLib/src/com/vpedak/testsrecorder/core/EventWriter.java
// public class EventWriter {
//     private long uniqueId;
//     public static final String ANDRIOD_TEST_RECORDER = "AndriodTestRecorder";
//     public String tag;
//     private Map<String, RecordingEvent> delayedEvents = new HashMap<String, RecordingEvent>();
//     private EventWriterListener listener;
//     private long lastTime;
// 
//     public EventWriter(long uniqueId, EventWriterListener listener) {
//         this.uniqueId = uniqueId;
//         this.listener = listener;
//         tag = ANDRIOD_TEST_RECORDER+uniqueId;
//         lastTime = System.currentTimeMillis();
//     }
// 
//     public synchronized void writeEvent(RecordingEvent event) {
//         long diff = System.currentTimeMillis() - lastTime;
//         lastTime = System.currentTimeMillis();
// 
//         if (delayedEvents.size() > 0) {
//             for(RecordingEvent delayedEvent : delayedEvents.values()) {
//                 delayedEvent.setTime(diff);
//                 Log.d(tag, delayedEvent.toString());
//             }
//             delayedEvents.clear();
//         }
//         event.setTime(diff);
//         Log.d(tag, event.toString());
//         listener.onEventWritten();
//     }
// 
//     public synchronized void addDelayedEvent(String id, RecordingEvent delayedEvent) {
//         delayedEvents.put(id, delayedEvent);
//     }
// 
//     public interface EventWriterListener {
//         void onEventWritten();
//     }
// }
// 
// 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: src/com/vpedak/testsrecorder/plugin/core/EventReader.java
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.logcat.LogCatListener;
import com.android.ddmlib.logcat.LogCatMessage;
import com.android.ddmlib.logcat.LogCatReceiverTask;
import com.vpedak.testsrecorder.core.EventWriter;
import com.vpedak.testsrecorder.core.events.RecordingEvent;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

        int count = 0;
        while (bridge.hasInitialDeviceList() == false) {
            try {
                Thread.sleep(100);
                count++;
            } catch (InterruptedException e) {
            }
            if (count > 100) {
                throw new RuntimeException("Timeout connecting to the adb!");
            }
        }

        IDevice[] devices = bridge.getDevices();
        if (devices.length == 0) {
            throw new RuntimeException("Failed to find device");
        }

        IDevice device = devices[0];

        receiverTask = new LogCatReceiverTask(device);

        final String tag = EventWriter.ANDRIOD_TEST_RECORDER+uniqueId;

        receiverTask.addLogCatListener(new LogCatListener() {
            @Override
            public void log(List<LogCatMessage> list) {
                for (LogCatMessage message : list) {
                    if (tag.equals(message.getTag())) {
                        String str = message.getMessage();
                        try {
                            RecordingEvent event = RecordingEvent.fromString(str);