Skip to content

Commit

Permalink
Merge pull request #34 from jogrimst/master
Browse files Browse the repository at this point in the history
#33 Add Letter/Number/Word to UsageEvent
  • Loading branch information
literacyapp authored Dec 17, 2016
2 parents cd50f64 + a1af764 commit 510fd31
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 41 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ To notify this application about usage activity in another application, there ar
intent.setAction("literacyapp.intent.action.USAGE_EVENT");
intent.putExtra("packageName", "org.package.name");
intent.putExtra("literacySkill", "PHONEMIC_AWARENESS");
intent.putExtra("letter", "a");
sendBroadcast(intent);

### Shell command example:

am broadcast
-n org.literacyapp.analytics
am broadcast
-a literacyapp.intent.action.USAGE_EVENT
-e packageName org.package.name
-e literacySkill PHONEMIC_AWARENESS
-e letter a

## Parameter names and values

Expand All @@ -42,4 +43,10 @@ For the `literacySkill` parameter, the following values are used for representin

### "numeracySkill"

For the `numeracySkill` parameter, the following values are used for representing the Early Grade Mathematics Assessment (EGMA): https://github.com/literacyapp-org/literacyapp-model/blob/master/src/main/java/org/literacyapp/model/enums/content/NumeracySkill.java
For the `numeracySkill` parameter, the following values are used for representing the Early Grade Mathematics Assessment (EGMA): https://github.com/literacyapp-org/literacyapp-model/blob/master/src/main/java/org/literacyapp/model/enums/content/NumeracySkill.java

### "letter"

### "number"

### "word"
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "org.literacyapp.analytics"
minSdkVersion 21
targetSdkVersion 23
versionCode 1000004
versionName "1.0.4"
versionCode 1000005
versionName "1.0.5"
}

buildTypes {
Expand All @@ -31,7 +31,7 @@ android {
}

greendao {
schemaVersion 1000004
schemaVersion android.defaultConfig.versionCode
daoPackage 'org.literacyapp.analytics.dao'
targetGenDir '../app/src/main/java'
}
Expand All @@ -50,7 +50,7 @@ dependencies {

testCompile 'junit:junit:4.12'

compile 'org.literacyapp:literacyapp-model:1.1.18'
compile 'org.literacyapp:literacyapp-model:1.1.32'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'commons-io:commons-io:2.5'
compile 'org.greenrobot:greendao:3.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public void onCreate() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int oldVersionCode = sharedPreferences.getInt(PREF_APP_VERSION_CODE, 0);
int newVersionCode = VersionHelper.getAppVersionCode(getApplicationContext());
if ((oldVersionCode > 0) && (oldVersionCode < newVersionCode)) {
if (oldVersionCode == 0) {
sharedPreferences.edit().putInt(PREF_APP_VERSION_CODE, newVersionCode).commit();
oldVersionCode = newVersionCode;
}
if (oldVersionCode < newVersionCode) {
Log.i(getClass().getName(), "Upgrading application from version " + oldVersionCode + " to " + newVersionCode);
// if (newVersionCode == ???) {
// // Put relevant tasks required for upgrading here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ public DevOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory
public void onUpgrade(Database db, int oldVersion, int newVersion) {
Log.i(getClass().getName(), "Upgrading schema from version " + oldVersion + " to " + newVersion);

if (newVersion == 1000003) {
// Upgrade to schemaVersion 1000003
DbMigrationHelper.migrate(db, UsageEventDao.class);
if (oldVersion < 1000003) {
DbMigrationHelper.migrate(db,
UsageEventDao.class
);
}

if (oldVersion < 1000004) {
DbMigrationHelper.migrate(db,
UsageEventDao.class
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 1000004): knows all DAOs.
* Master of DAO (schema version 1000005): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 1000004;
public static final int SCHEMA_VERSION = 1000005;

/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
Expand Down
80 changes: 68 additions & 12 deletions app/src/main/java/org/literacyapp/analytics/dao/UsageEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ public static class Properties {
public final static Property DeviceId = new Property(1, String.class, "deviceId", false, "DEVICE_ID");
public final static Property Time = new Property(2, long.class, "time", false, "TIME");
public final static Property PackageName = new Property(3, String.class, "packageName", false, "PACKAGE_NAME");
public final static Property LiteracySkill = new Property(4, String.class, "literacySkill", false, "LITERACY_SKILL");
public final static Property NumeracySkill = new Property(5, String.class, "numeracySkill", false, "NUMERACY_SKILL");
public final static Property StudentId = new Property(4, String.class, "studentId", false, "STUDENT_ID");
public final static Property LiteracySkill = new Property(5, String.class, "literacySkill", false, "LITERACY_SKILL");
public final static Property NumeracySkill = new Property(6, String.class, "numeracySkill", false, "NUMERACY_SKILL");
public final static Property Letter = new Property(7, String.class, "letter", false, "LETTER");
public final static Property Number = new Property(8, Integer.class, "number", false, "NUMBER");
public final static Property Word = new Property(9, String.class, "word", false, "WORD");
}

private final CalendarConverter timeConverter = new CalendarConverter();
Expand All @@ -59,8 +63,12 @@ public static void createTable(Database db, boolean ifNotExists) {
"\"DEVICE_ID\" TEXT NOT NULL ," + // 1: deviceId
"\"TIME\" INTEGER NOT NULL ," + // 2: time
"\"PACKAGE_NAME\" TEXT NOT NULL ," + // 3: packageName
"\"LITERACY_SKILL\" TEXT," + // 4: literacySkill
"\"NUMERACY_SKILL\" TEXT);"); // 5: numeracySkill
"\"STUDENT_ID\" TEXT," + // 4: studentId
"\"LITERACY_SKILL\" TEXT," + // 5: literacySkill
"\"NUMERACY_SKILL\" TEXT," + // 6: numeracySkill
"\"LETTER\" TEXT," + // 7: letter
"\"NUMBER\" INTEGER," + // 8: number
"\"WORD\" TEXT);"); // 9: word
}

/** Drops the underlying database table. */
Expand All @@ -81,14 +89,34 @@ protected final void bindValues(DatabaseStatement stmt, UsageEvent entity) {
stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime()));
stmt.bindString(4, entity.getPackageName());

String studentId = entity.getStudentId();
if (studentId != null) {
stmt.bindString(5, studentId);
}

LiteracySkill literacySkill = entity.getLiteracySkill();
if (literacySkill != null) {
stmt.bindString(5, literacySkillConverter.convertToDatabaseValue(literacySkill));
stmt.bindString(6, literacySkillConverter.convertToDatabaseValue(literacySkill));
}

NumeracySkill numeracySkill = entity.getNumeracySkill();
if (numeracySkill != null) {
stmt.bindString(6, numeracySkillConverter.convertToDatabaseValue(numeracySkill));
stmt.bindString(7, numeracySkillConverter.convertToDatabaseValue(numeracySkill));
}

String letter = entity.getLetter();
if (letter != null) {
stmt.bindString(8, letter);
}

Integer number = entity.getNumber();
if (number != null) {
stmt.bindLong(9, number);
}

String word = entity.getWord();
if (word != null) {
stmt.bindString(10, word);
}
}

Expand All @@ -104,14 +132,34 @@ protected final void bindValues(SQLiteStatement stmt, UsageEvent entity) {
stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime()));
stmt.bindString(4, entity.getPackageName());

String studentId = entity.getStudentId();
if (studentId != null) {
stmt.bindString(5, studentId);
}

LiteracySkill literacySkill = entity.getLiteracySkill();
if (literacySkill != null) {
stmt.bindString(5, literacySkillConverter.convertToDatabaseValue(literacySkill));
stmt.bindString(6, literacySkillConverter.convertToDatabaseValue(literacySkill));
}

NumeracySkill numeracySkill = entity.getNumeracySkill();
if (numeracySkill != null) {
stmt.bindString(6, numeracySkillConverter.convertToDatabaseValue(numeracySkill));
stmt.bindString(7, numeracySkillConverter.convertToDatabaseValue(numeracySkill));
}

String letter = entity.getLetter();
if (letter != null) {
stmt.bindString(8, letter);
}

Integer number = entity.getNumber();
if (number != null) {
stmt.bindLong(9, number);
}

String word = entity.getWord();
if (word != null) {
stmt.bindString(10, word);
}
}

Expand All @@ -127,8 +175,12 @@ public UsageEvent readEntity(Cursor cursor, int offset) {
cursor.getString(offset + 1), // deviceId
timeConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // time
cursor.getString(offset + 3), // packageName
cursor.isNull(offset + 4) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 4)), // literacySkill
cursor.isNull(offset + 5) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 5)) // numeracySkill
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // studentId
cursor.isNull(offset + 5) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 5)), // literacySkill
cursor.isNull(offset + 6) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 6)), // numeracySkill
cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // letter
cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8), // number
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // word
);
return entity;
}
Expand All @@ -139,8 +191,12 @@ public void readEntity(Cursor cursor, UsageEvent entity, int offset) {
entity.setDeviceId(cursor.getString(offset + 1));
entity.setTime(timeConverter.convertToEntityProperty(cursor.getLong(offset + 2)));
entity.setPackageName(cursor.getString(offset + 3));
entity.setLiteracySkill(cursor.isNull(offset + 4) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 4)));
entity.setNumeracySkill(cursor.isNull(offset + 5) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 5)));
entity.setStudentId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setLiteracySkill(cursor.isNull(offset + 5) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 5)));
entity.setNumeracySkill(cursor.isNull(offset + 6) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 6)));
entity.setLetter(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
entity.setNumber(cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8));
entity.setWord(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
}

@Override
Expand Down
59 changes: 53 additions & 6 deletions app/src/main/java/org/literacyapp/analytics/model/UsageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,51 @@ public class UsageEvent {
@Id(autoincrement = true)
private Long id;

// TODO: replace with Device
// TODO: replace with Device?
@NotNull
private String deviceId;

@NotNull
@Convert(converter = CalendarConverter.class, columnType = Long.class)
private Calendar time;

// TODO: replace with Application
// TODO: replace with Application?
@NotNull
private String packageName;

// TODO: Student
// TODO: replace with Student?
private String studentId;

@Convert(converter = LiteracySkillConverter.class, columnType = String.class)
private LiteracySkill literacySkill;

@Convert(converter = NumeracySkillConverter.class, columnType = String.class)
private NumeracySkill numeracySkill;

@Generated(hash = 1321395035)
// TODO: replace with Letter?
private String letter;

// TODO: replace with Number?
private Integer number;

// TODO: replace with Word?
private String word;

@Generated(hash = 1208691141)
public UsageEvent(Long id, @NotNull String deviceId, @NotNull Calendar time,
@NotNull String packageName, LiteracySkill literacySkill,
NumeracySkill numeracySkill) {
@NotNull String packageName, String studentId,
LiteracySkill literacySkill, NumeracySkill numeracySkill, String letter,
Integer number, String word) {
this.id = id;
this.deviceId = deviceId;
this.time = time;
this.packageName = packageName;
this.studentId = studentId;
this.literacySkill = literacySkill;
this.numeracySkill = numeracySkill;
this.letter = letter;
this.number = number;
this.word = word;
}

@Generated(hash = 2057329387)
Expand Down Expand Up @@ -102,4 +117,36 @@ public NumeracySkill getNumeracySkill() {
public void setNumeracySkill(NumeracySkill numeracySkill) {
this.numeracySkill = numeracySkill;
}

public String getStudentId() {
return this.studentId;
}

public void setStudentId(String studentId) {
this.studentId = studentId;
}

public String getLetter() {
return this.letter;
}

public void setLetter(String letter) {
this.letter = letter;
}

public Integer getNumber() {
return this.number;
}

public void setNumber(Integer number) {
this.number = number;
}

public String getWord() {
return this.word;
}

public void setWord(String word) {
this.word = word;
}
}
Loading

0 comments on commit 510fd31

Please sign in to comment.