Commit f412b4ed authored by Mattia Ducci's avatar Mattia Ducci

minor fixes e refactoring

parent 83f59424
...@@ -29,8 +29,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -29,8 +29,8 @@ public class MainActivity extends AppCompatActivity {
private Icarus instance; private Icarus instance;
private EditText eventNameEditText; private EditText eventNameEditText;
private EditText eventCategoryEditText; Switch eventCategorySwitch;
private EditText eventLabelEditText; Switch eventLabelSwitch;
private EditText mostProbableActivityEditText; private EditText mostProbableActivityEditText;
@Override @Override
...@@ -61,8 +61,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -61,8 +61,8 @@ public class MainActivity extends AppCompatActivity {
else intPrefSwitch.setChecked(true); else intPrefSwitch.setChecked(true);
eventNameEditText=findViewById(R.id.editText_eventName); eventNameEditText=findViewById(R.id.editText_eventName);
eventCategoryEditText=findViewById(R.id.editText_eventCategory); eventCategorySwitch=findViewById(R.id.event_category_switch);
eventLabelEditText=findViewById(R.id.editText_eventLabel); eventLabelSwitch=findViewById(R.id.event_label_switch);
mostProbableActivityEditText=findViewById(R.id.editText_mostProbableActivity); mostProbableActivityEditText=findViewById(R.id.editText_mostProbableActivity);
} }
...@@ -106,16 +106,18 @@ public class MainActivity extends AppCompatActivity { ...@@ -106,16 +106,18 @@ public class MainActivity extends AppCompatActivity {
Log.d(CLASS_NAME,"on btn track event"); Log.d(CLASS_NAME,"on btn track event");
String eventName,eventCategory,eventLabel,mostProbableActivity; String eventName,mostProbableActivity;
EventTrackResource.EventCategory eventCategory;
EventTrackResource.EventLabel eventLabel;
if(eventNameEditText.getText().length() == 0) eventName="eventoProva"; if(eventNameEditText.getText().length() == 0) eventName="eventoProva";
else eventName=eventNameEditText.getText().toString(); else eventName=eventNameEditText.getText().toString();
if(eventCategoryEditText.getText().length()==0) eventCategory=EventTrackResource.EventCategories.APPLICATION.name().toLowerCase(); if(!eventCategorySwitch.isChecked()) eventCategory=EventTrackResource.EventCategory.APPLICATION;
else eventCategory=eventCategoryEditText.getText().toString(); else eventCategory=EventTrackResource.EventCategory.ACTION;
if(eventLabelEditText.getText().length()==0) eventLabel = EventTrackResource.EventLabel.FOREGROUND.name().toLowerCase(); if(!eventLabelSwitch.isChecked()) eventLabel = EventTrackResource.EventLabel.FOREGROUND;
else eventLabel=eventLabelEditText.getText().toString(); else eventLabel=EventTrackResource.EventLabel.BACKGROUND;
if(mostProbableActivityEditText.getText().length()==0) mostProbableActivity="running"; if(mostProbableActivityEditText.getText().length()==0) mostProbableActivity="running";
else mostProbableActivity=mostProbableActivityEditText.getText().toString(); else mostProbableActivity=mostProbableActivityEditText.getText().toString();
......
...@@ -75,6 +75,14 @@ ...@@ -75,6 +75,14 @@
android:text="Invia pref changes" /> android:text="Invia pref changes" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Track event"
android:textColor="@android:color/holo_red_light"
android:textSize="24sp" />
<EditText <EditText
android:id="@+id/editText_eventName" android:id="@+id/editText_eventName"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -83,28 +91,35 @@ ...@@ -83,28 +91,35 @@
android:hint="event name" android:hint="event name"
android:inputType="textPersonName" /> android:inputType="textPersonName" />
<EditText <Switch
android:id="@+id/editText_eventCategory" android:id="@+id/event_category_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:showText="true"
android:hint="event category" android:splitTrack="false"
android:inputType="textPersonName" /> android:text="Event category"
android:textOff="application"
android:textOn="action"
android:textSize="18sp" />
<EditText <Switch
android:id="@+id/editText_eventLabel" android:id="@+id/event_label_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:showText="true"
android:hint="event label" android:splitTrack="false"
android:inputType="textPersonName" /> android:text="Event label"
android:textOff="foreground"
android:textOn="background"
android:textSize="18sp" />
<EditText <EditText
android:id="@+id/editText_mostProbableActivity" android:id="@+id/editText_mostProbableActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:ems="18"
android:hint="most probable activity" android:hint="activity: walking or cycling. empty for running"
android:inputType="textPersonName" /> android:inputType="textPersonName" />
<Button <Button
......
...@@ -5,7 +5,22 @@ import org.json.JSONObject; ...@@ -5,7 +5,22 @@ import org.json.JSONObject;
public class EventTrackResource extends IcarusResource { public class EventTrackResource extends IcarusResource {
public enum EventCategories{ //categorie di evento //------------ JSON KEYS --------------------
private final static String CONFIDENCE_KEY="confidence";
private final static String START_TIMESTAMP_KEY="startTimestamp";
private final static String HEADING_KEY="heading";
private final static String COURSE_KEY="course";
private final static String SPEED_KEY="speed";
private final static String ACTIVITY_KEY="activity";
private final static String DIRECTION_KEY="direction";
private final static String EVENT_NAME_KEY="EventName";
private final static String EVENT_CATEGORY_KEY="EventCategory";
private final static String EVENT_LABEL_KEY="EventLabel";
private final static String EVENT_CONTEXT_KEY="EventContext";
//-----------------------------------------------------
public enum EventCategory{ //categorie di evento
APPLICATION,ACTION,NOTIFICATION; APPLICATION,ACTION,NOTIFICATION;
} }
...@@ -16,8 +31,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -16,8 +31,8 @@ public class EventTrackResource extends IcarusResource {
} }
private String eventName; private String eventName;
private String eventCategory; private EventCategory eventCategory;
private String eventLabel; private EventLabel eventLabel;
private int heading; private int heading;
private int course; private int course;
...@@ -25,7 +40,7 @@ public class EventTrackResource extends IcarusResource { ...@@ -25,7 +40,7 @@ public class EventTrackResource extends IcarusResource {
//i due successivi attributi sono quelli ritornati dall'ActivityRecognition di Google che dev'essere implementata nell'app chiamante //i due successivi attributi sono quelli ritornati dall'ActivityRecognition di Google che dev'essere implementata nell'app chiamante
//convertiti da quelli di Google a quelli del server.. vedi iMoveAndroid per il metodo di mapping tra i valori ritornati da Google e quelli //convertiti da quelli di Google a quelli del server.. vedi iMoveAndroid per il metodo di mapping tra i valori ritornati da Google e quelli
//per il server di ewtech. Fare copia incolla del metodo in progetti futuri. Non lo metto qua perchè non ho accesso ai codici delle attività //per il server di ewtech. Fare copia incolla del metodo in progetti futuri. Non lo metto qua perchè da qua non ho accesso ai codici delle attività
//non avendo la dipendenza all'ActivityRecognition all'interno di questa libreria //non avendo la dipendenza all'ActivityRecognition all'interno di questa libreria
private String mostProbableUserActivityName; private String mostProbableUserActivityName;
private int confidence; private int confidence;
...@@ -34,7 +49,7 @@ public class EventTrackResource extends IcarusResource { ...@@ -34,7 +49,7 @@ public class EventTrackResource extends IcarusResource {
private String[] userActivityToTrack; private String[] userActivityToTrack;
public EventTrackResource(String _eventName, String _eventCategory, String _eventLabel, int _heading, int _course, int _speed, public EventTrackResource(String _eventName, EventCategory _eventCategory, EventLabel _eventLabel, int _heading, int _course, int _speed,
String _mostProbableUserActivityName, int _confidence, boolean _accessibilityEnabled){ String _mostProbableUserActivityName, int _confidence, boolean _accessibilityEnabled){
super(); super();
...@@ -66,8 +81,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -66,8 +81,8 @@ public class EventTrackResource extends IcarusResource {
userActivityJSONObject.put(activityType,false); userActivityJSONObject.put(activityType,false);
} }
userActivityJSONObject.put("confidence",confidence); userActivityJSONObject.put(CONFIDENCE_KEY,confidence);
userActivityJSONObject.put("startTimestamp",System.currentTimeMillis()); userActivityJSONObject.put(START_TIMESTAMP_KEY,System.currentTimeMillis());
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -78,8 +93,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -78,8 +93,8 @@ public class EventTrackResource extends IcarusResource {
try { try {
directionJSONObject.put("heading",heading); //0..360 directionJSONObject.put(HEADING_KEY,heading); //0..360
directionJSONObject.put("course",course); //0..360 directionJSONObject.put(COURSE_KEY,course); //0..360
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -90,9 +105,9 @@ public class EventTrackResource extends IcarusResource { ...@@ -90,9 +105,9 @@ public class EventTrackResource extends IcarusResource {
try { try {
eventContextJSONObject.put("speed",speed); eventContextJSONObject.put(SPEED_KEY,speed);
eventContextJSONObject.put("activity",userActivityJSONObject); eventContextJSONObject.put(ACTIVITY_KEY,userActivityJSONObject);
eventContextJSONObject.put("direction",directionJSONObject); eventContextJSONObject.put(DIRECTION_KEY,directionJSONObject);
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -103,10 +118,10 @@ public class EventTrackResource extends IcarusResource { ...@@ -103,10 +118,10 @@ public class EventTrackResource extends IcarusResource {
try { try {
toSend.put("EventName",eventName); toSend.put(EVENT_NAME_KEY,eventName);
toSend.put("EventCategory",eventCategory); toSend.put(EVENT_CATEGORY_KEY,eventCategory.name().toLowerCase());
toSend.put("EventLabel",eventLabel+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF")); toSend.put(EVENT_LABEL_KEY,eventLabel.name().toLowerCase()+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF"));
toSend.put("EventContext",eventContextJSONObject); toSend.put(EVENT_CONTEXT_KEY,eventContextJSONObject);
} catch (JSONException jsonException){ } catch (JSONException jsonException){
......
...@@ -40,6 +40,25 @@ public class Icarus { ...@@ -40,6 +40,25 @@ public class Icarus {
private final static String ICARUS_URL="https://webdev.ewlab.di.unimi.it/icarus/str"; private final static String ICARUS_URL="https://webdev.ewlab.di.unimi.it/icarus/str";
//---------------- JSON KEYS ---------------------
private final static String UTC_KEY="utc";
private final static String USER_KEY="user";
private final static String LANG_KEY="lang";
private final static String ICARUS_VERSION_KEY="icarusversion";
private final static String APP_NAME_KEY="appname";
private final static String APP_VERSION_KEY="appversion";
private final static String OS_VERSION_KEY="osversion";
private final static String PLATFORM_KEY="platform";
private final static String DEVICE_KEY="device";
private final static String UUID_KEY="uuid";
private final static String TALKBACK_KEY="talkback";
private final static String DEBUG_KEY="debug";
private final static String TIMESTAMP_KEY="timestamp";
private final static String APP_DATA_KEY="appdata";
private final static String USER_DATA_KEY="userdata";
//------------------------------------------
private static final Icarus ourInstance = new Icarus(); private static final Icarus ourInstance = new Icarus();
private Queue<JSONObject> pendingResources; //FIFO private Queue<JSONObject> pendingResources; //FIFO
private Lock pendingResourceLock; private Lock pendingResourceLock;
...@@ -190,8 +209,8 @@ public class Icarus { ...@@ -190,8 +209,8 @@ public class Icarus {
long userTime=utcTime+timeOffsetBetweenMeAndGMT; long userTime=utcTime+timeOffsetBetweenMeAndGMT;
JSONObject timeJSON=new JSONObject(); JSONObject timeJSON=new JSONObject();
timeJSON.put("utc",utcTime); timeJSON.put(UTC_KEY,utcTime);
timeJSON.put("user",userTime); timeJSON.put(USER_KEY,userTime);
//---------------------- APP JSON --------------------- //---------------------- APP JSON ---------------------
...@@ -238,22 +257,22 @@ public class Icarus { ...@@ -238,22 +257,22 @@ public class Icarus {
} }
JSONObject appInfoJSON=new JSONObject(); JSONObject appInfoJSON=new JSONObject();
appInfoJSON.put("lang", Locale.getDefault().getLanguage()); appInfoJSON.put(LANG_KEY, Locale.getDefault().getLanguage());
appInfoJSON.put("icarusversion","Icarus:"+curContext.getResources().getInteger(R.integer.lib_version)); appInfoJSON.put(ICARUS_VERSION_KEY,"Icarus:"+curContext.getResources().getInteger(R.integer.lib_version));
appInfoJSON.put("appname",appName.toString()); appInfoJSON.put(APP_NAME_KEY,appName.toString());
appInfoJSON.put("appversion",clientAppVersion); appInfoJSON.put(APP_VERSION_KEY,clientAppVersion);
appInfoJSON.put("osversion", Build.VERSION.SDK_INT); appInfoJSON.put(OS_VERSION_KEY, Build.VERSION.SDK_INT);
appInfoJSON.put("platform","android"); appInfoJSON.put(PLATFORM_KEY,"android");
appInfoJSON.put("device",getDeviceName()); appInfoJSON.put(DEVICE_KEY,getDeviceName());
appInfoJSON.put("uuid",uuid); appInfoJSON.put(UUID_KEY,uuid);
appInfoJSON.put("talkback",accessibilityEnabled); appInfoJSON.put(TALKBACK_KEY,accessibilityEnabled);
//---------------- GENERAL JSON -------------------- //---------------- GENERAL JSON --------------------
toSend.put("debug",debug); toSend.put(DEBUG_KEY,debug);
toSend.put("timestamp",timeJSON); toSend.put(TIMESTAMP_KEY,timeJSON);
toSend.put("appdata",appInfoJSON); toSend.put(APP_DATA_KEY,appInfoJSON);
toSend.put("userdata",userData); toSend.put(USER_DATA_KEY,userData);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment