Skip to content

Commit

Permalink
Merge branch 'literacyapp-org/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo Grimstad committed Jan 5, 2017
2 parents 36b94f0 + 57c282d commit d5bca6f
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 258 deletions.
12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
android:name=".content.task.StarActivity"
android:screenOrientation="fullSensor" />
<activity android:name=".content.task.LessonCompleteActivity" />
<activity android:name=".authentication.StudentImageCollectionActivity"/>
<activity android:name=".authentication.StudentImageCollectionActivity"
android:screenOrientation="landscape"/>
<activity
android:name=".content.letter.LettersActivity"
android:icon="@mipmap/ic_launcher_literacy"
Expand Down Expand Up @@ -95,7 +96,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="org.literacyapp.CategoryActivity" />
</activity>
<activity android:name=".authentication.datacollection.StudentImageCollectionActivity"/>
<activity android:name=".authentication.datacollection.StudentImageCollectionActivity" />

<service
android:name=".service.ScreenOnService"
Expand Down Expand Up @@ -127,7 +128,12 @@
android:name=".authentication.fallback.StudentSelectionActivity"
android:label="@string/title_activity_student_selection"
android:theme="@style/AppTheme" />
<activity android:name=".authentication.AuthenticationActivity"/>
<activity android:name=".authentication.AuthenticationActivity"
android:screenOrientation="landscape"/>

<service
android:name=".service.synchronization.MergeSimilarStudentsJobService"
android:permission="android.permission.BIND_JOB_SERVICE" />
</application>

</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/org/literacyapp/LiteracyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class LiteracyApplication extends Application {
public static final int FACE_RECOGNITION_TRAINING_JOB_ID = 0;
public static final int CONTENT_SYNCRHONIZATION_JOB_ID = 1;
public static final int AUTHENTICATION_JOB_ID = 2;
public static final int MERGE_SIMILAR_STUDENTS_JOB_ID = 3;

public static final String PREF_APP_VERSION_CODE = "pref_app_version_code";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import org.literacyapp.R;
import org.literacyapp.authentication.animaloverlay.AnimalOverlay;
import org.literacyapp.authentication.animaloverlay.AnimalOverlayHelper;
import org.literacyapp.authentication.helper.AuthenticationHelper;
import org.literacyapp.authentication.helper.DetectionHelper;
import org.literacyapp.authentication.thread.RecognitionThread;
import org.literacyapp.authentication.thread.TrainingThread;
import org.literacyapp.dao.AuthenticationEventDao;
import org.literacyapp.dao.DaoSession;
import org.literacyapp.dao.StudentImageCollectionEventDao;
Expand All @@ -26,7 +30,6 @@
import org.opencv.core.Mat;
import org.opencv.core.Rect;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -90,12 +93,12 @@ protected void onCreate(Bundle savedInstanceState) {
preview.setVisibility(SurfaceView.VISIBLE);
preview.setCvCameraViewListener(this);

final TrainingHelper trainingHelper = new TrainingHelper(getApplicationContext());
final TrainingThread trainingThread = new TrainingThread(getApplicationContext());

tensorFlowLoadingThread = new Thread(new Runnable() {
@Override
public void run() {
tensorFlow = trainingHelper.getInitializedTensorFlow();
tensorFlow = trainingThread.getInitializedTensorFlow();
}
});

Expand Down Expand Up @@ -126,10 +129,14 @@ public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
prepareForAuthentication();

if (!recognitionThread.isAlive() && recognitionThreadStarted) {
Student student = recognitionThread.getStudent();
List<Student> students = recognitionThread.getRecognizedStudent();
Student student = new Student();
if (students.size() == 1){
student = students.get(0);
}
numberOfTries++;
Log.i(getClass().getName(), "Number of authentication/recognition tries: " + numberOfTries);
if (student != null) {
if ((student != null) && (students.size() == 1)) {
AuthenticationHelper.updateCurrentStudent(student, getApplicationContext(), false);
finish();
} else if (numberOfTries >= NUMBER_OF_MAXIMUM_TRIES) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.literacyapp.R;
import org.literacyapp.authentication.animaloverlay.AnimalOverlay;
import org.literacyapp.authentication.animaloverlay.AnimalOverlayHelper;
import org.literacyapp.authentication.helper.DetectionHelper;
import org.literacyapp.dao.DaoSession;
import org.literacyapp.dao.DeviceDao;
import org.literacyapp.dao.StudentImageCollectionEventDao;
Expand Down Expand Up @@ -69,7 +70,6 @@ public class StudentImageCollectionActivity extends AppCompatActivity implements
private boolean activityStopped;

// Image collection parameters
private static final boolean DIAGNOSE_MODE = true;
private static final long TIMER_DIFF = 200;
private static final int NUMBER_OF_IMAGES = 20;
private int imagesProcessed;
Expand Down Expand Up @@ -176,10 +176,6 @@ public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

studentImages.add(img);

if(DIAGNOSE_MODE) {
MatOperation.drawRectangleAndLabelOnPreview(imgRgba, face, "Face detected", true);
}

// Stop after NUMBER_OF_IMAGES (settings option)
if(imagesProcessed == NUMBER_OF_IMAGES){
storeStudentImages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import org.literacyapp.LiteracyApplication;
import org.literacyapp.R;
import org.literacyapp.authentication.AuthenticationHelper;
import org.literacyapp.authentication.helper.AuthenticationHelper;
import org.literacyapp.dao.StudentDao;
import org.literacyapp.model.Student;
import org.literacyapp.receiver.ScreenOnReceiver;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.StudentUpdateHelper;

import java.io.File;
import java.util.Calendar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.literacyapp.authentication;
package org.literacyapp.authentication.helper;

import android.content.Context;
import android.util.Log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.literacyapp.authentication;
package org.literacyapp.authentication.helper;

import android.content.Context;
import android.content.Intent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.literacyapp.authentication.thread;

import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.util.Log;
import android.view.Display;

import org.literacyapp.LiteracyApplication;
import org.literacyapp.authentication.AuthenticationActivity;
import org.literacyapp.dao.AuthenticationEventDao;
import org.literacyapp.dao.DaoSession;
import org.literacyapp.dao.StudentImageCollectionEventDao;
import org.literacyapp.model.analytics.AuthenticationEvent;
import org.literacyapp.model.analytics.StudentImageCollectionEvent;
import org.literacyapp.receiver.BootReceiver;
import org.literacyapp.service.synchronization.AuthenticationJobService;

import java.util.Date;
import java.util.List;

/**
* Created by sladomic on 01.01.17.
*/

public class AuthenticationThread extends Thread {
private Context context;
private AuthenticationJobService authenticationJobService;

public AuthenticationThread(AuthenticationJobService authenticationJobService){
this.authenticationJobService = authenticationJobService;
this.context = authenticationJobService.getApplicationContext();
}

@Override
public void run() {
if (!isScreenTurnedOff()){
if (didTheMinimumTimePassSinceLastExecution()){
Intent authenticationIntent = new Intent(context, AuthenticationActivity.class);
authenticationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(authenticationIntent);
Log.i(getClass().getName(), "The Authentication has been started.");
} else {
Log.i(getClass().getName(), "The Authentication was skipped because the minimum time since the last execution did not pass yet.");
}
} else {
Log.i(getClass().getName(), "The Authentication was skipped because the screen was turned off.");
}
authenticationJobService.jobFinished(authenticationJobService.getJobParameters(), false);
}

private boolean isScreenTurnedOff(){
boolean isScreenTurnedOff = false;
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : displayManager.getDisplays()) {
if (display.getState() != Display.STATE_ON) {
isScreenTurnedOff = true;
}
}
Log.i(getClass().getName(), "isScreenTurnedOff: " + isScreenTurnedOff);
return isScreenTurnedOff;
}

private boolean didTheMinimumTimePassSinceLastAuthentication(AuthenticationEventDao authenticationEventDao, long minimumTimeInMilliseconds){
boolean didTheMinimumTimePassSinceLastAuthentication = true;
// Get only the last AuthenticationEvent
List<AuthenticationEvent> authenticationEvents = authenticationEventDao.queryBuilder().orderDesc(AuthenticationEventDao.Properties.Time).limit(1).list();
if (authenticationEvents.size() > 0){
AuthenticationEvent authenticationEvent = authenticationEvents.get(0);
long lastAuthenticationTime = authenticationEvent.getTime().getTime().getTime();
long currentTime = new Date().getTime();
Log.i(getClass().getName(), "didTheMinimumTimePassSinceLastAuthentication: lastAuthenticationTime: " + new Date(lastAuthenticationTime) + " minimumTimeInMinutes: " + (minimumTimeInMilliseconds / 1000 / 60) + " currentTime: " + new Date(currentTime));
if ((lastAuthenticationTime + minimumTimeInMilliseconds) > currentTime){
didTheMinimumTimePassSinceLastAuthentication = false;
}
}
return didTheMinimumTimePassSinceLastAuthentication;
}

private boolean didTheMinimumTimePassSinceLastCollection(StudentImageCollectionEventDao studentImageCollectionEventDao, long minimumTimeInMilliseconds){
boolean didTheMinimumTimePassSinceLastCollection = true;
// Get only the last StudentImageCollectionEvent
List<StudentImageCollectionEvent> studentImageCollectionEvents = studentImageCollectionEventDao.queryBuilder().orderDesc(StudentImageCollectionEventDao.Properties.Time).limit(1).list();
if (studentImageCollectionEvents.size() > 0){
StudentImageCollectionEvent studentImageCollectionEvent = studentImageCollectionEvents.get(0);
long lastCollectionTime = studentImageCollectionEvent.getTime().getTime().getTime();
long currentTime = new Date().getTime();
Log.i(getClass().getName(), "didTheMinimumTimePassSinceLastCollection: lastCollectionTime: " + new Date(lastCollectionTime) + " minimumTimeInMinutes: " + (minimumTimeInMilliseconds / 1000 / 60) + " currentTime: " + new Date(currentTime));
if ((lastCollectionTime + minimumTimeInMilliseconds) > currentTime){
didTheMinimumTimePassSinceLastCollection = false;
}
}
return didTheMinimumTimePassSinceLastCollection;
}

private boolean didTheMinimumTimePassSinceLastExecution(){
LiteracyApplication literacyApplication = (LiteracyApplication) context;
DaoSession daoSession = literacyApplication.getDaoSession();
AuthenticationEventDao authenticationEventDao = daoSession.getAuthenticationEventDao();
StudentImageCollectionEventDao studentImageCollectionEventDao = daoSession.getStudentImageCollectionEventDao();
long minimumTimeInMilliseconds = BootReceiver.MINUTES_BETWEEN_AUTHENTICATIONS * 60 * 1000;
boolean didTheMinimumTimePassSinceLastAuthentication = didTheMinimumTimePassSinceLastAuthentication(authenticationEventDao, minimumTimeInMilliseconds);
boolean didTheMinimumTimePassSinceLastCollection = didTheMinimumTimePassSinceLastCollection(studentImageCollectionEventDao, minimumTimeInMilliseconds);
return (didTheMinimumTimePassSinceLastAuthentication && didTheMinimumTimePassSinceLastCollection);
}
}
Loading

0 comments on commit d5bca6f

Please sign in to comment.