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
547061d4
Commit
547061d4
authored
May 01, 2018
by
Mattia Ducci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completamento dei JSON dei dati degli utenti con info sull'app e sul timestamp
parent
20b6a1b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
20 deletions
+112
-20
MainActivity.java
.../everywaretechnologies/it/icarusandroid/MainActivity.java
+2
-2
Icarus.java
...ava/framework/everywaretechnologies/it/icarus/Icarus.java
+109
-18
app_constants.xml
IcarusAndroid/icarus/src/main/res/values/app_constants.xml
+1
-0
No files found.
IcarusAndroid/app/src/main/java/framework/everywaretechnologies/it/icarusandroid/MainActivity.java
View file @
547061d4
...
@@ -63,7 +63,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -63,7 +63,7 @@ public class MainActivity extends AppCompatActivity {
else
else
eventType
=
enteredExitedScreenTrackSwitch
.
getTextOff
().
toString
();
eventType
=
enteredExitedScreenTrackSwitch
.
getTextOff
().
toString
();
instance
.
trackScreen
(
MainActivity
.
this
,
eventType
);
instance
.
trackScreen
(
MainActivity
.
this
,
eventType
,
true
);
}
}
public
void
onBtnUserPrefChanges
(
View
view
){
public
void
onBtnUserPrefChanges
(
View
view
){
...
@@ -85,6 +85,6 @@ public class MainActivity extends AppCompatActivity {
...
@@ -85,6 +85,6 @@ public class MainActivity extends AppCompatActivity {
userSettingsResource
.
addBoolean
(
"boolPref"
,
boolSwitchValue
);
userSettingsResource
.
addBoolean
(
"boolPref"
,
boolSwitchValue
);
userSettingsResource
.
addInt
(
"intPref"
,
intSwitchValue
);
userSettingsResource
.
addInt
(
"intPref"
,
intSwitchValue
);
instance
.
logUserSettings
(
userSettingsResource
);
instance
.
logUserSettings
(
userSettingsResource
,
true
);
}
}
}
}
IcarusAndroid/icarus/src/main/java/framework/everywaretechnologies/it/icarus/Icarus.java
View file @
547061d4
...
@@ -4,7 +4,11 @@ import android.app.AlertDialog;
...
@@ -4,7 +4,11 @@ import android.app.AlertDialog;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.os.Build
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.accessibility.AccessibilityManager
;
import
com.android.volley.Request
;
import
com.android.volley.Request
;
import
com.android.volley.RequestQueue
;
import
com.android.volley.RequestQueue
;
...
@@ -20,9 +24,12 @@ import org.json.JSONException;
...
@@ -20,9 +24,12 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Queue
;
import
java.util.Queue
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.TimeZone
;
import
java.util.UUID
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.function.Consumer
;
import
java.util.function.Consumer
;
...
@@ -68,20 +75,23 @@ public class Icarus {
...
@@ -68,20 +75,23 @@ public class Icarus {
//----------------- LOG PREFERENCE CHANGES -----------------------
//----------------- LOG PREFERENCE CHANGES -----------------------
public
void
logUserSettings
(
UserSettingsResource
userSettingsResource
){
public
void
logUserSettings
(
UserSettingsResource
userSettingsResource
,
boolean
debug
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log pref changes"
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log pref changes"
);
JSONObject
prefsChangesToLog
=
userSettingsResource
.
getUserSettingsChangesInJSONFormat
();
JSONObject
prefsChangesToLog
=
userSettingsResource
.
getUserSettingsChangesInJSONFormat
();
if
(
prefsChangesToLog
.
length
()>
0
)
//se non ho un JSON vuoto, cioè qualche pref è cambiata
if
(
prefsChangesToLog
.
length
()>
0
){
//se non ho un JSON vuoto, cioè qualche pref è cambiata
postIcarusHttpRequest
(
prefsChangesToLog
);
postIcarusHttpRequest
(
prefsChangesToLog
,
debug
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log pref changes -> Volley"
);
}
userSettingsResource
.
clear
();
userSettingsResource
.
clear
();
}
}
//---------------------- LOG SCREEN TRACKING ------------------------------
//---------------------- LOG SCREEN TRACKING ------------------------------
public
void
trackScreen
(
Context
c
,
String
screenEventType
){
public
void
trackScreen
(
Context
c
,
String
screenEventType
,
boolean
debug
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track"
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track"
);
...
@@ -96,7 +106,7 @@ public class Icarus {
...
@@ -96,7 +106,7 @@ public class Icarus {
try
{
try
{
JSONObject
icarusPayload
=
new
JSONObject
(
screenTrackJson
);
JSONObject
icarusPayload
=
new
JSONObject
(
screenTrackJson
);
postIcarusHttpRequest
(
icarusPayload
);
postIcarusHttpRequest
(
icarusPayload
,
debug
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track -> Volley"
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log screen track -> Volley"
);
...
@@ -109,7 +119,7 @@ public class Icarus {
...
@@ -109,7 +119,7 @@ public class Icarus {
//---------------------- LOG EVENT TRACKING --------------------------
//---------------------- LOG EVENT TRACKING --------------------------
public
void
logEvent
(
EventTrackResource
eventTrackResource
){
public
void
logEvent
(
EventTrackResource
eventTrackResource
,
boolean
debug
){
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log event"
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"log event"
);
...
@@ -119,9 +129,11 @@ public class Icarus {
...
@@ -119,9 +129,11 @@ public class Icarus {
//--------------------------- UTILITY ----------------------------------
//--------------------------- UTILITY ----------------------------------
private
void
postIcarusHttpRequest
(
final
JSONObject
icarusPayload
){
private
void
postIcarusHttpRequest
(
final
JSONObject
icarusPayload
,
final
boolean
debug
){
final
JsonObjectRequest
jsonObjectRequest
=
new
JsonObjectRequest
(
Request
.
Method
.
POST
,
ICARUS_URL
,
icarusPayload
,
new
Response
.
Listener
<
JSONObject
>()
{
JSONObject
toSendJson
=
createJSONToSend
(
icarusPayload
,
debug
);
//aggiunge informazioni al JSON ottenuto attraverso la raccolta dati dell'utente
final
JsonObjectRequest
jsonObjectRequest
=
new
JsonObjectRequest
(
Request
.
Method
.
POST
,
ICARUS_URL
,
toSendJson
,
new
Response
.
Listener
<
JSONObject
>()
{
@Override
@Override
public
void
onResponse
(
JSONObject
response
)
{
public
void
onResponse
(
JSONObject
response
)
{
...
@@ -134,7 +146,7 @@ public class Icarus {
...
@@ -134,7 +146,7 @@ public class Icarus {
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"messaggio pendente"
);
Log
.
d
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"messaggio pendente"
);
JSONObject
pendingResource
=
pendingResources
.
poll
();
JSONObject
pendingResource
=
pendingResources
.
poll
();
postIcarusHttpRequest
(
pendingResource
);
postIcarusHttpRequest
(
pendingResource
,
debug
);
}
}
pendingResourceLock
.
unlock
();
pendingResourceLock
.
unlock
();
...
@@ -155,18 +167,97 @@ public class Icarus {
...
@@ -155,18 +167,97 @@ public class Icarus {
mVolleyRequestQueue
.
add
(
jsonObjectRequest
);
//faccio effettivamente la richiesta
mVolleyRequestQueue
.
add
(
jsonObjectRequest
);
//faccio effettivamente la richiesta
}
}
//SharedPreferences utility methods
public
JSONObject
createJSONToSend
(
JSONObject
userData
,
boolean
debug
){
private
void
editIntPref
(
SharedPreferences
settings
,
String
nomePref
,
int
newValue
){
JSONObject
toSend
=
new
JSONObject
();
try
{
// ------------------- TIME JSON ----------------
long
utcTime
=
System
.
currentTimeMillis
();
//ritorna il tempo UTC tra ora e il 1 gennaio 1970 alle 00:00
TimeZone
myTimeZone
=
TimeZone
.
getDefault
();
int
timeOffsetBetweenMeAndGMT
=
myTimeZone
.
getOffset
(
utcTime
);
//ms
long
userTime
=
utcTime
+
timeOffsetBetweenMeAndGMT
;
JSONObject
timeJSON
=
new
JSONObject
();
timeJSON
.
put
(
"utc"
,
utcTime
);
timeJSON
.
put
(
"user"
,
userTime
);
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
//---------------------- APP JSON ---------------------
editor
.
putInt
(
nomePref
,
newValue
);
editor
.
commit
();
//trovo il nome dell'app che sta chiamando questo metodo
PackageManager
pm
=
curContext
.
getPackageManager
();
CharSequence
appName
=
pm
.
getApplicationLabel
(
curContext
.
getApplicationInfo
());
//trovo versione dell'app chiamante
int
clientAppVersion
;
try
{
PackageInfo
pinfo
=
pm
.
getPackageInfo
(
curContext
.
getPackageName
(),
0
);
clientAppVersion
=
pinfo
.
versionCode
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
e
.
printStackTrace
();
clientAppVersion
=
0
;
}
//controllo se l'accessibilità è attivata o no
AccessibilityManager
am
=(
AccessibilityManager
)
curContext
.
getSystemService
(
Context
.
ACCESSIBILITY_SERVICE
);
boolean
accessibilityEnabled
=
false
;
try
{
accessibilityEnabled
=
am
.
isTouchExplorationEnabled
();
}
catch
(
NullPointerException
npe
){
Log
.
e
(
curContext
.
getString
(
R
.
string
.
icarus_class
),
"errore ottenere accessibilityManager"
);
}
JSONObject
appInfoJSON
=
new
JSONObject
();
appInfoJSON
.
put
(
"lang"
,
Locale
.
getDefault
().
getLanguage
());
appInfoJSON
.
put
(
"log_lib"
,
"Icarus:"
+
curContext
.
getResources
().
getInteger
(
R
.
integer
.
lib_version
));
appInfoJSON
.
put
(
"appname"
,
appName
.
toString
());
appInfoJSON
.
put
(
"appversion"
,
clientAppVersion
);
appInfoJSON
.
put
(
"os"
,
Build
.
VERSION
.
SDK_INT
);
appInfoJSON
.
put
(
"device"
,
getDeviceName
());
appInfoJSON
.
put
(
"uuid"
,
UUID
.
randomUUID
().
toString
());
appInfoJSON
.
put
(
"talkback"
,
accessibilityEnabled
);
//---------------- GENERAL JSON --------------------
toSend
.
put
(
"debug"
,
debug
);
toSend
.
put
(
"timestamp"
,
timeJSON
);
toSend
.
put
(
"appData"
,
appInfoJSON
);
toSend
.
put
(
"userdata"
,
userData
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
toSend
;
}
}
private
void
editBoolPref
(
SharedPreferences
settings
,
String
nomePref
,
boolean
newValue
){
public
String
getDeviceName
()
{
String
manufacturer
=
Build
.
MANUFACTURER
;
String
model
=
Build
.
MODEL
;
if
(
model
.
toLowerCase
().
startsWith
(
manufacturer
.
toLowerCase
()))
{
return
capitalize
(
model
);
}
else
{
return
capitalize
(
manufacturer
)
+
" "
+
model
;
}
}
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
editor
.
putBoolean
(
nomePref
,
newValue
);
private
String
capitalize
(
String
s
)
{
editor
.
commit
();
if
(
s
==
null
||
s
.
length
()
==
0
)
{
return
""
;
}
char
first
=
s
.
charAt
(
0
);
if
(
Character
.
isUpperCase
(
first
))
{
return
s
;
}
else
{
return
Character
.
toUpperCase
(
first
)
+
s
.
substring
(
1
);
}
}
}
}
}
IcarusAndroid/icarus/src/main/res/values/app_constants.xml
View file @
547061d4
...
@@ -2,4 +2,5 @@
...
@@ -2,4 +2,5 @@
<resources>
<resources>
<string
name=
"icarus_class"
>
Icarus
</string>
<string
name=
"icarus_class"
>
Icarus
</string>
<integer
name=
"lib_version"
>
1
</integer>
</resources>
</resources>
\ No newline at end of file
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