I am trying to parse InputEvents of an Android device.
Background:
- For an android device we have a utility
geteventwhich gives all the touch events that are sent to a device.getevent -lgives all the input events to the device.- Every event has 3 fields -
EVENT_TYPE,EVENT_CODEandVALUE.EVENT_TYPEcan be of following types -EV_KEY,EV_ABSandEV_SYN.- In turn, each
EVENT_TYPEcan have differentEVENT_CODES.
For e.g.
EV_KEY-->BTN_TOUCH
EV_ABS-->ABS_MT_TOUCH_MAJOR, ABS_MT_TRACKING_ID, ABS_MT_POSITION_X, ABS_MT_POSITION_Yand
EV_SYN-->SYN_MT_REPORT, SYN_REPORT- And every
EVENT_CODEcan have aVALUE.- Every event is separated by a
SYN_REPORT.- Each event can itself be a multi touch event be separated by a
SYN_MT_REPORT.- Every touch starts with a
EV_KEY - BTN_TOUCH - DOWNand ends with aEV_KEY - BTN_TOUCH - UPcombination. (There are event separators afterEV_KEY - BTN_TOUCH - UPviz.SYN_MT_REPORTandSYN_REPORT, but they are not important.
More description: Event Types and Multi Touch events
EV_KEY BTN_TOUCH DOWN <-------------- EV_ABS ABS_MT_TOUCH_MAJOR 00000011 | EV_ABS ABS_MT_TRACKING_ID 00000000 | EV_ABS ABS_MT_POSITION_X 0000011c |---First event, EV_ABS ABS_MT_POSITION_Y 000001f4 | with DOWN and only EV_SYN SYN_MT_REPORT 00000000 | 1 finger touched. EV_SYN SYN_REPORT 00000000 <-------------- EV_ABS ABS_MT_TOUCH_MAJOR 00000011 <-------------- EV_ABS ABS_MT_TRACKING_ID 00000000 <------- | EV_ABS ABS_MT_POSITION_X 0000011c | | EV_ABS ABS_MT_POSITION_Y 000001f4 Finger 1 | EV_SYN SYN_MT_REPORT 00000000 <------- | EV_ABS ABS_MT_TOUCH_MAJOR 00000013 |---Second event EV_ABS ABS_MT_TRACKING_ID 00000001 <------- | with 2 mutitouch events EV_ABS ABS_MT_POSITION_X 00000076 | | EV_ABS ABS_MT_POSITION_Y 0000026e Finger 2 | EV_SYN SYN_MT_REPORT 00000000 <------- | EV_SYN SYN_REPORT 00000000 <-------------- EV_ABS ABS_MT_TOUCH_MAJOR 00000011 <-------------- EV_ABS ABS_MT_TRACKING_ID 00000000 <------- | EV_ABS ABS_MT_POSITION_X 00000190 | | EV_ABS ABS_MT_POSITION_Y 0000035d Finger 1 | EV_SYN SYN_MT_REPORT 00000000 <------- | EV_ABS ABS_MT_TOUCH_MAJOR 00000013 | EV_ABS ABS_MT_TRACKING_ID 00000001 <------- | EV_ABS ABS_MT_POSITION_X 000000f8 | | EV_ABS ABS_MT_POSITION_Y 000003cf Finger 2 |---Third event EV_SYN SYN_MT_REPORT 00000000 <------- | with 3 mulittouch events EV_ABS ABS_MT_TOUCH_MAJOR 00000015 | EV_ABS ABS_MT_TRACKING_ID 00000002 <------- | EV_ABS ABS_MT_POSITION_X 00000251 | | EV_ABS ABS_MT_POSITION_Y 00000310 Finger 3 | EV_SYN SYN_MT_REPORT 00000000 <------- | EV_SYN SYN_REPORT 00000000 <-------------- EV_KEY BTN_TOUCH UP <-------------- EV_SYN SYN_MT_REPORT 00000000 |---Final Event, EV_SYN SYN_REPORT 00000000 <-------------- only 1 finger
An example of actual input is:
EV_KEY BTN_TOUCH DOWN EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000011c EV_ABS ABS_MT_POSITION_Y 000001f4 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 00000076 EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 000001cd EV_ABS ABS_MT_POSITION_Y 000001a3 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000014b EV_ABS ABS_MT_POSITION_Y 0000026e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000b7 EV_ABS ABS_MT_POSITION_Y 000002ef EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000209 EV_ABS ABS_MT_POSITION_Y 00000225 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000015f EV_ABS ABS_MT_POSITION_Y 000002a1 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000c7 EV_ABS ABS_MT_POSITION_Y 00000319 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 0000021e EV_ABS ABS_MT_POSITION_Y 00000258 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 00000167 EV_ABS ABS_MT_POSITION_Y 000002cc EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000d4 EV_ABS ABS_MT_POSITION_Y 00000339 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000228 EV_ABS ABS_MT_POSITION_Y 0000027d EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000016f EV_ABS ABS_MT_POSITION_Y 000002ed EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000dd EV_ABS ABS_MT_POSITION_Y 0000035e EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000231 EV_ABS ABS_MT_POSITION_Y 000002a1 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 00000178 EV_ABS ABS_MT_POSITION_Y 0000030f EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000e4 EV_ABS ABS_MT_POSITION_Y 0000037d EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 0000023a EV_ABS ABS_MT_POSITION_Y 000002c2 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 00000182 EV_ABS ABS_MT_POSITION_Y 00000329 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000eb EV_ABS ABS_MT_POSITION_Y 0000039b EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000242 EV_ABS ABS_MT_POSITION_Y 000002de EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000018a EV_ABS ABS_MT_POSITION_Y 00000343 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000ef EV_ABS ABS_MT_POSITION_Y 000003b3 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000247 EV_ABS ABS_MT_POSITION_Y 000002f6 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000018e EV_ABS ABS_MT_POSITION_Y 00000354 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000f3 EV_ABS ABS_MT_POSITION_Y 000003c2 EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 0000024d EV_ABS ABS_MT_POSITION_Y 00000306 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 0000018f EV_ABS ABS_MT_POSITION_Y 0000035c EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000f5 EV_ABS ABS_MT_POSITION_Y 000003cb EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 0000024f EV_ABS ABS_MT_POSITION_Y 0000030e EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000011 EV_ABS ABS_MT_TRACKING_ID 00000000 EV_ABS ABS_MT_POSITION_X 00000190 EV_ABS ABS_MT_POSITION_Y 0000035d EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000013 EV_ABS ABS_MT_TRACKING_ID 00000001 EV_ABS ABS_MT_POSITION_X 000000f8 EV_ABS ABS_MT_POSITION_Y 000003cf EV_SYN SYN_MT_REPORT 00000000 EV_ABS ABS_MT_TOUCH_MAJOR 00000015 EV_ABS ABS_MT_TRACKING_ID 00000002 EV_ABS ABS_MT_POSITION_X 00000251 EV_ABS ABS_MT_POSITION_Y 00000310 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_KEY BTN_TOUCH UP EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000
This is how I am trying to parse it:
package com.xolo;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public Main() {
}
public void readFile() {
File file = new File("....../output2.txt");
List<Event> listOfEvents = null;
try {
BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
listOfEvents = createEvents(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (listOfEvents == null) {
return;
}
for (Event event : listOfEvents) {
System.out.println(event.toString());
}
}
private List<Event> createEvents(BufferedReader is) {
List<Event> listOfEvents = new ArrayList<>();
Event event = null;
String[] tokens;
try {
while (true) {
tokens = is.readLine().split("\\s+");
if (tokens[1].equalsIgnoreCase("BTN_TOUCH")) {
if (tokens[2].equalsIgnoreCase("DOWN")) {
event = new Event();
continue;
} else if (tokens[2].equalsIgnoreCase("UP")) {
tokens = is.readLine().split("\\s+");
if (tokens[1].equalsIgnoreCase("SYN_MT_REPORT")) {
tokens = is.readLine().split("\\s+");
if (tokens[1].equalsIgnoreCase("SYN_REPORT")) {
return listOfEvents;
} else {
throw new IllegalArgumentException();
}
} else {
throw new IllegalArgumentException();
}
}
} else if (tokens[1].equalsIgnoreCase("ABS_MT_TOUCH_MAJOR")) {
event.mtEvents.add(createMTEvent(is));
} else if (tokens[1].equalsIgnoreCase("SYN_REPORT")) {
if (event == null) {
throw new IllegalArgumentException();
}
listOfEvents.add(event);
event = new Event();
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private MTEvent createMTEvent(BufferedReader is) {
String[] tokens;
try {
tokens = is.readLine().split("\\s+");
if (!tokens[1].equalsIgnoreCase("ABS_MT_TRACKING_ID")) {
throw new IllegalArgumentException();
}
int id = Integer.valueOf(tokens[2]);
tokens = is.readLine().split("\\s+");
if (!tokens[1].equalsIgnoreCase("ABS_MT_POSITION_X")) {
throw new IllegalArgumentException();
}
int x = Integer.parseInt(tokens[2], 16);
tokens = is.readLine().split("\\s+");
if (!tokens[1].equalsIgnoreCase("ABS_MT_POSITION_Y")) {
throw new IllegalArgumentException();
}
int y = Integer.parseInt(tokens[2], 16);
tokens = is.readLine().split("\\s+");
if (!tokens[1].equalsIgnoreCase("SYN_MT_REPORT")) {
throw new IllegalArgumentException();
}
return new MTEvent(id, x, y);
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
}
return null;
}
public static void main(String[] args) {
Main mn = new Main();
mn.readFile();
}
private class MTEvent {
int trackingID;
int x;
int y;
public MTEvent(int id, int x, int y) {
this.trackingID = id;
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "ID: " + trackingID + ", x: " + x + ", y: " + y;
}
}
private class Event {
List<MTEvent> mtEvents;
Event() {
mtEvents = new ArrayList<>();
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Event: \n");
for (MTEvent mtEvent : mtEvents) {
stringBuilder.append(mtEvent.toString()).append("\n");
}
return stringBuilder.toString();
}
}
}
I tried to separate the individual event and MultiTouch event into separate methods but I don't think I have done it right.
There are a number of things that I want to correct:
- The parsing logic itself.
- The Exceptions thrown (any different way to do it?)
- The splitting of
inputonspacecharacters (any better way to do it?).