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 {
private Icarus instance;
private EditText eventNameEditText;
private EditText eventCategoryEditText;
private EditText eventLabelEditText;
Switch eventCategorySwitch;
Switch eventLabelSwitch;
private EditText mostProbableActivityEditText;
@Override
......@@ -61,8 +61,8 @@ public class MainActivity extends AppCompatActivity {
else intPrefSwitch.setChecked(true);
eventNameEditText=findViewById(R.id.editText_eventName);
eventCategoryEditText=findViewById(R.id.editText_eventCategory);
eventLabelEditText=findViewById(R.id.editText_eventLabel);
eventCategorySwitch=findViewById(R.id.event_category_switch);
eventLabelSwitch=findViewById(R.id.event_label_switch);
mostProbableActivityEditText=findViewById(R.id.editText_mostProbableActivity);
}
......@@ -106,16 +106,18 @@ public class MainActivity extends AppCompatActivity {
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";
else eventName=eventNameEditText.getText().toString();
if(eventCategoryEditText.getText().length()==0) eventCategory=EventTrackResource.EventCategories.APPLICATION.name().toLowerCase();
else eventCategory=eventCategoryEditText.getText().toString();
if(!eventCategorySwitch.isChecked()) eventCategory=EventTrackResource.EventCategory.APPLICATION;
else eventCategory=EventTrackResource.EventCategory.ACTION;
if(eventLabelEditText.getText().length()==0) eventLabel = EventTrackResource.EventLabel.FOREGROUND.name().toLowerCase();
else eventLabel=eventLabelEditText.getText().toString();
if(!eventLabelSwitch.isChecked()) eventLabel = EventTrackResource.EventLabel.FOREGROUND;
else eventLabel=EventTrackResource.EventLabel.BACKGROUND;
if(mostProbableActivityEditText.getText().length()==0) mostProbableActivity="running";
else mostProbableActivity=mostProbableActivityEditText.getText().toString();
......
......@@ -75,6 +75,14 @@
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
android:id="@+id/editText_eventName"
android:layout_width="match_parent"
......@@ -83,28 +91,35 @@
android:hint="event name"
android:inputType="textPersonName" />
<EditText
android:id="@+id/editText_eventCategory"
<Switch
android:id="@+id/event_category_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="18"
android:hint="event category"
android:inputType="textPersonName" />
android:showText="true"
android:splitTrack="false"
android:text="Event category"
android:textOff="application"
android:textOn="action"
android:textSize="18sp" />
<EditText
android:id="@+id/editText_eventLabel"
<Switch
android:id="@+id/event_label_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="18"
android:hint="event label"
android:inputType="textPersonName" />
android:showText="true"
android:splitTrack="false"
android:text="Event label"
android:textOff="foreground"
android:textOn="background"
android:textSize="18sp" />
<EditText
android:id="@+id/editText_mostProbableActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="18"
android:hint="most probable activity"
android:hint="activity: walking or cycling. empty for running"
android:inputType="textPersonName" />
<Button
......
......@@ -5,7 +5,22 @@ import org.json.JSONObject;
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;
}
......@@ -16,8 +31,8 @@ public class EventTrackResource extends IcarusResource {
}
private String eventName;
private String eventCategory;
private String eventLabel;
private EventCategory eventCategory;
private EventLabel eventLabel;
private int heading;
private int course;
......@@ -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
//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
private String mostProbableUserActivityName;
private int confidence;
......@@ -34,7 +49,7 @@ public class EventTrackResource extends IcarusResource {
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){
super();
......@@ -66,8 +81,8 @@ public class EventTrackResource extends IcarusResource {
userActivityJSONObject.put(activityType,false);
}
userActivityJSONObject.put("confidence",confidence);
userActivityJSONObject.put("startTimestamp",System.currentTimeMillis());
userActivityJSONObject.put(CONFIDENCE_KEY,confidence);
userActivityJSONObject.put(START_TIMESTAMP_KEY,System.currentTimeMillis());
} catch (JSONException jsonException){
......@@ -78,8 +93,8 @@ public class EventTrackResource extends IcarusResource {
try {
directionJSONObject.put("heading",heading); //0..360
directionJSONObject.put("course",course); //0..360
directionJSONObject.put(HEADING_KEY,heading); //0..360
directionJSONObject.put(COURSE_KEY,course); //0..360
} catch (JSONException jsonException){
......@@ -90,9 +105,9 @@ public class EventTrackResource extends IcarusResource {
try {
eventContextJSONObject.put("speed",speed);
eventContextJSONObject.put("activity",userActivityJSONObject);
eventContextJSONObject.put("direction",directionJSONObject);
eventContextJSONObject.put(SPEED_KEY,speed);
eventContextJSONObject.put(ACTIVITY_KEY,userActivityJSONObject);
eventContextJSONObject.put(DIRECTION_KEY,directionJSONObject);
} catch (JSONException jsonException){
......@@ -103,10 +118,10 @@ public class EventTrackResource extends IcarusResource {
try {
toSend.put("EventName",eventName);
toSend.put("EventCategory",eventCategory);
toSend.put("EventLabel",eventLabel+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF"));
toSend.put("EventContext",eventContextJSONObject);
toSend.put(EVENT_NAME_KEY,eventName);
toSend.put(EVENT_CATEGORY_KEY,eventCategory.name().toLowerCase());
toSend.put(EVENT_LABEL_KEY,eventLabel.name().toLowerCase()+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF"));
toSend.put(EVENT_CONTEXT_KEY,eventContextJSONObject);
} catch (JSONException jsonException){
......
......@@ -40,6 +40,25 @@ public class Icarus {
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 Queue<JSONObject> pendingResources; //FIFO
private Lock pendingResourceLock;
......@@ -190,8 +209,8 @@ public class Icarus {
long userTime=utcTime+timeOffsetBetweenMeAndGMT;
JSONObject timeJSON=new JSONObject();
timeJSON.put("utc",utcTime);
timeJSON.put("user",userTime);
timeJSON.put(UTC_KEY,utcTime);
timeJSON.put(USER_KEY,userTime);
//---------------------- APP JSON ---------------------
......@@ -238,22 +257,22 @@ public class Icarus {
}
JSONObject appInfoJSON=new JSONObject();
appInfoJSON.put("lang", Locale.getDefault().getLanguage());
appInfoJSON.put("icarusversion","Icarus:"+curContext.getResources().getInteger(R.integer.lib_version));
appInfoJSON.put("appname",appName.toString());
appInfoJSON.put("appversion",clientAppVersion);
appInfoJSON.put("osversion", Build.VERSION.SDK_INT);
appInfoJSON.put("platform","android");
appInfoJSON.put("device",getDeviceName());
appInfoJSON.put("uuid",uuid);
appInfoJSON.put("talkback",accessibilityEnabled);
appInfoJSON.put(LANG_KEY, Locale.getDefault().getLanguage());
appInfoJSON.put(ICARUS_VERSION_KEY,"Icarus:"+curContext.getResources().getInteger(R.integer.lib_version));
appInfoJSON.put(APP_NAME_KEY,appName.toString());
appInfoJSON.put(APP_VERSION_KEY,clientAppVersion);
appInfoJSON.put(OS_VERSION_KEY, Build.VERSION.SDK_INT);
appInfoJSON.put(PLATFORM_KEY,"android");
appInfoJSON.put(DEVICE_KEY,getDeviceName());
appInfoJSON.put(UUID_KEY,uuid);
appInfoJSON.put(TALKBACK_KEY,accessibilityEnabled);
//---------------- GENERAL JSON --------------------
toSend.put("debug",debug);
toSend.put("timestamp",timeJSON);
toSend.put("appdata",appInfoJSON);
toSend.put("userdata",userData);
toSend.put(DEBUG_KEY,debug);
toSend.put(TIMESTAMP_KEY,timeJSON);
toSend.put(APP_DATA_KEY,appInfoJSON);
toSend.put(USER_DATA_KEY,userData);
} catch (JSONException e) {
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