Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
android-client
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
icarus
android-client
Commits
0a11b6f8
Commit
0a11b6f8
authored
Apr 29, 2018
by
Mattia Ducci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implementato screen tracking
parent
f082196a
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
218 additions
and
10 deletions
+218
-10
.gitignore
.gitignore
+1
-0
build_file_checksums.ser
IcarusAndroid/.idea/caches/build_file_checksums.ser
+0
-0
build.gradle
IcarusAndroid/app/build.gradle
+2
-0
MainActivity.java
.../everywaretechnologies/it/icarusandroid/MainActivity.java
+31
-0
activity_main.xml
IcarusAndroid/app/src/main/res/layout/activity_main.xml
+24
-4
build.gradle
IcarusAndroid/icarus/build.gradle
+1
-0
AndroidManifest.xml
IcarusAndroid/icarus/src/main/AndroidManifest.xml
+4
-1
EventTrackResource.java
...k/everywaretechnologies/it/icarus/EventTrackResource.java
+5
-0
Icarus.java
...ava/framework/everywaretechnologies/it/icarus/Icarus.java
+122
-4
IcarusResource.java
...ework/everywaretechnologies/it/icarus/IcarusResource.java
+4
-0
ScreenTrackResource.java
.../everywaretechnologies/it/icarus/ScreenTrackResource.java
+13
-0
UserSettingsResource.java
...everywaretechnologies/it/icarus/UserSettingsResource.java
+5
-0
app_constants.xml
IcarusAndroid/icarus/src/main/res/values/app_constants.xml
+5
-0
strings.xml
IcarusAndroid/icarus/src/main/res/values/strings.xml
+1
-1
No files found.
.gitignore
0 → 100644
View file @
0a11b6f8
AppuntiProgetto/
IcarusAndroid/.idea/caches/build_file_checksums.ser
View file @
0a11b6f8
No preview for this file type
IcarusAndroid/app/build.gradle
View file @
0a11b6f8
...
...
@@ -25,4 +25,6 @@ dependencies {
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation
project
(
':icarus'
)
}
IcarusAndroid/app/src/main/java/framework/everywaretechnologies/it/icarusandroid/MainActivity.java
View file @
0a11b6f8
...
...
@@ -2,14 +2,45 @@ package framework.everywaretechnologies.it.icarusandroid;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.Switch
;
import
framework.everywaretechnologies.it.icarus.Icarus
;
//classe di test Icarus framework
public
class
MainActivity
extends
AppCompatActivity
{
private
final
static
String
CLASS_NAME
=
"MainActivity"
;
private
Switch
enteredExitedScreenTrackSwitch
;
private
Icarus
instance
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
instance
=
Icarus
.
getInstance
(
MainActivity
.
this
);
instance
.
setApplicationContext
(
getApplicationContext
());
enteredExitedScreenTrackSwitch
=
findViewById
(
R
.
id
.
entered_exited_screen_track_switch
);
}
//------------------------- UI EVENT -----------------------
public
void
onBtnScreenEventTrack
(
View
view
){
Log
.
d
(
CLASS_NAME
,
"on btn screen event track"
);
String
eventType
=
null
;
if
(
enteredExitedScreenTrackSwitch
.
isChecked
())
eventType
=
enteredExitedScreenTrackSwitch
.
getTextOn
().
toString
();
else
eventType
=
enteredExitedScreenTrackSwitch
.
getTextOff
().
toString
();
instance
.
trackScreen
(
MainActivity
.
this
,
eventType
);
}
}
IcarusAndroid/app/src/main/res/layout/activity_main.xml
View file @
0a11b6f8
<?xml version="1.0" encoding="utf-8"?>
<android.
support.constraint.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.
widget.Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
tools:context=
".MainActivity"
>
<TextView
android:layout_width=
"wrap_content"
android:id=
"@+id/lbl_track_screen"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"Hello World!"
android:text=
"Track screen"
android:textColor=
"@android:color/holo_red_light"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<Switch
android:id=
"@+id/entered_exited_screen_track_switch"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:showText=
"true"
android:splitTrack=
"false"
android:text=
"Tipo di evento"
android:textOff=
"EXITED"
android:textOn=
"ENTERED"
/>
<Button
android:id=
"@+id/btn_send_screen_track_event"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:onClick=
"onBtnScreenEventTrack"
android:text=
"Invia screen track event"
/>
</android.widget.LinearLayout>
\ No newline at end of file
IcarusAndroid/icarus/build.gradle
View file @
0a11b6f8
...
...
@@ -33,4 +33,5 @@ dependencies {
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation
'com.android.volley:volley:1.1.0'
implementation
'com.google.code.gson:gson:2.8.3'
}
IcarusAndroid/icarus/src/main/AndroidManifest.xml
View file @
0a11b6f8
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"framework.everywaretechnologies.it.icarus"
/>
package=
"framework.everywaretechnologies.it.icarus"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<!-- richiesto da Volley -->
</manifest>
\ No newline at end of file
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/EventTrackResource.java
View file @
0a11b6f8
package
framework
.
everywaretechnologies
.
it
.
icarus
;
public
class
EventTrackResource
extends
IcarusResource
{
public
EventTrackResource
(){
super
();
}
}
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/Icarus.java
View file @
0a11b6f8
package
framework
.
everywaretechnologies
.
it
.
icarus
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.SharedPreferences
;
import
android.util.Log
;
import
com.android.volley.Request
;
import
com.android.volley.RequestQueue
;
import
com.android.volley.Response
;
import
com.android.volley.VolleyError
;
import
com.android.volley.toolbox.JsonObjectRequest
;
import
com.android.volley.toolbox.Volley
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.LinkedList
;
import
java.util.Queue
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
class
Icarus
{
public
class
Icarus
{
enum
Categories
{
APPLICATION
,
ACTION
,
NOTIFICATION
;
}
private
final
static
String
ICARUS_URL
=
"https://webdev.ewlab.di.unimi.it/icarus/str"
;
private
static
final
Icarus
ourInstance
=
new
Icarus
();
private
Queue
<
IcarusResource
>
pendingResources
;
private
Queue
<
JSONObject
>
pendingResources
;
//FIFO
private
Lock
pendingResourceLock
;
private
Context
appContext
;
// serve per istanziare un un'unica coda di richieste Volley (e non averne una per Activity)
private
static
Context
curContext
;
//context dell'Activity corrente
private
RequestQueue
mVolleyRequestQueue
;
public
static
Icarus
getInstance
(
Context
c
)
{
public
static
Icarus
getInstance
()
{
curContext
=
c
;
return
ourInstance
;
}
...
...
@@ -21,8 +53,94 @@ class Icarus {
pendingResourceLock
=
new
ReentrantLock
();
}
public
void
pushResource
(
IcarusResource
icarusResource
){
public
void
setApplicationContext
(
Context
applicationContext
){
appContext
=
applicationContext
;
//adesso che ho l'applicationContext dell'app chiamante creo la coda di richieste per Volley
mVolleyRequestQueue
=
Volley
.
newRequestQueue
(
appContext
);
}
//----------------- LOG PREFERENCE CHANGES -----------------------
public
void
logUserSettings
(
SharedPreferences
mySharedPrefs
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log pref changes"
);
}
//---------------------- LOG SCREEN TRACKING ------------------------------
public
void
trackScreen
(
Context
c
,
String
screenEventType
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track"
);
String
screenName
=
c
.
getClass
().
getSimpleName
();
if
(
screenEventType
.
equalsIgnoreCase
(
ScreenTrackResource
.
EVENT_ENTERED
)
||
screenEventType
.
equalsIgnoreCase
(
ScreenTrackResource
.
EVENT_EXITED
)
){
IcarusResource
resource
=
new
ScreenTrackResource
(
screenName
,
screenEventType
);
Gson
gson
=
new
Gson
();
String
screenTrackJson
=
gson
.
toJson
(
resource
);
try
{
JSONObject
icarusPayload
=
new
JSONObject
(
screenTrackJson
);
postIcarusHttpRequest
(
icarusPayload
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track -> Volley"
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
//---------------------- LOG EVENT TRACKING --------------------------
public
void
logEvent
(
String
eventName
,
String
category
,
String
label
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log event"
);
}
//--------------------------- UTILITY ----------------------------------
private
void
postIcarusHttpRequest
(
final
JSONObject
icarusPayload
){
final
JsonObjectRequest
jsonObjectRequest
=
new
JsonObjectRequest
(
Request
.
Method
.
POST
,
ICARUS_URL
,
icarusPayload
,
new
Response
.
Listener
<
JSONObject
>()
{
@Override
public
void
onResponse
(
JSONObject
response
)
{
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"onVolley response POSITIVE"
);
//controllo se ho qualche elemento che precedentemente non sono riuscito ad inviare e nel caso lo provo ad inviare
pendingResourceLock
.
lock
();
if
(
pendingResources
.
peek
()
!=
null
){
//se ho qualche elemento pendente da inviare
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"messaggi pendenti"
);
JSONObject
pendingResource
=
pendingResources
.
poll
();
postIcarusHttpRequest
(
pendingResource
);
}
pendingResourceLock
.
unlock
();
}
},
new
Response
.
ErrorListener
()
{
@Override
public
void
onErrorResponse
(
VolleyError
error
)
{
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"onVolley response NEGATIVE"
);
pendingResourceLock
.
lock
();
pendingResources
.
add
(
icarusPayload
);
pendingResourceLock
.
unlock
();
}
});
mVolleyRequestQueue
.
add
(
jsonObjectRequest
);
//faccio effettivamente la richiesta
}
}
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/IcarusResource.java
View file @
0a11b6f8
package
framework
.
everywaretechnologies
.
it
.
icarus
;
public
abstract
class
IcarusResource
{
public
IcarusResource
(){}
}
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/ScreenTrackResource.java
View file @
0a11b6f8
package
framework
.
everywaretechnologies
.
it
.
icarus
;
public
class
ScreenTrackResource
extends
IcarusResource
{
public
final
static
String
EVENT_ENTERED
=
"Entered"
;
public
final
static
String
EVENT_EXITED
=
"Exited"
;
private
String
ScreenName
;
//è un attributo anche se inizia con la lettera maiuscola perchè il server vuole così il nome del campo JSON
private
String
Event
;
public
ScreenTrackResource
(
String
_screenName
,
String
_event
){
super
();
ScreenName
=
_screenName
;
Event
=
_event
;
}
}
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/UserSettingsResource.java
View file @
0a11b6f8
package
framework
.
everywaretechnologies
.
it
.
icarus
;
public
class
UserSettingsResource
extends
IcarusResource
{
public
UserSettingsResource
(){
super
();
}
}
IcarusAndroid/icarus/src/main/res/values/app_constants.xml
0 → 100644
View file @
0a11b6f8
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"icarus_class"
>
Icarus
</string>
</resources>
\ No newline at end of file
IcarusAndroid/icarus/src/main/res/values/strings.xml
View file @
0a11b6f8
<resources>
<string
name=
"
app
_name"
>
Icarus
</string>
<string
name=
"
lib
_name"
>
Icarus
</string>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment