Skip to content

Commit

Permalink
Merge pull request #385 from jogrimst/master
Browse files Browse the repository at this point in the history
#384 Make MultimediaHelper part of the ContentProvider library
  • Loading branch information
literacyapp authored Mar 24, 2017
2 parents b48c959 + de80f1c commit 88807fc
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 125 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.literacyapp"
minSdkVersion 21
targetSdkVersion 23
versionCode 1005006
versionName "1.5.6"
versionCode 1005007
versionName "1.5.7"

// jackOptions {
// enabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.literacyapp.authentication.animaloverlay.AnimalOverlay;
import org.literacyapp.authentication.animaloverlay.AnimalOverlayHelper;
import org.literacyapp.authentication.helper.AuthenticationHelper;
import org.literacyapp.authentication.helper.AuthenticationInstructionHelper;
import org.literacyapp.authentication.helper.DetectionHelper;
import org.literacyapp.authentication.thread.RecognitionThread;
import org.literacyapp.authentication.thread.TrainingThread;
Expand All @@ -22,7 +23,6 @@
import org.literacyapp.contentprovider.dao.StudentImageCollectionEventDao;
import org.literacyapp.contentprovider.model.Student;
import org.literacyapp.util.EnvironmentSettings;
import org.literacyapp.util.MultimediaHelper;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.android.OpenCVLoader;
Expand Down Expand Up @@ -82,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
displayTemperatureNight = DetectionHelper.getDisplayTemperatureNight();

authenticationAnimation = (GifImageView) findViewById(R.id.authentication_animation);
MultimediaHelper.setAuthenticationInstructionAnimation(getApplicationContext(), authenticationAnimation);
AuthenticationInstructionHelper.setAuthenticationInstructionAnimation(getApplicationContext(), authenticationAnimation);

// Initialize DB Session
LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
Expand Down Expand Up @@ -201,7 +201,7 @@ public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

if (faceDetected && !isFaceInsideFrame){
DetectionHelper.drawArrowFromFaceToFrame(animalOverlay, imgRgba, face);
MultimediaHelper.playTabletPlacementOverlay(mediaPlayerTabletPlacement, mediaPlayerTabletPlacementOverlay, mediaPlayerAnimalSound);
AuthenticationInstructionHelper.playTabletPlacementOverlay(mediaPlayerTabletPlacement, mediaPlayerTabletPlacementOverlay, mediaPlayerAnimalSound);
}

if (DetectionHelper.shouldFallbackActivityBeStarted(startTimeFallback, currentTime)){
Expand All @@ -225,12 +225,12 @@ public void onResume()
numberOfTries = 0;
animalOverlay = animalOverlayHelper.getAnimalOverlay("");
if (animalOverlay != null) {
mediaPlayerAnimalSound = MediaPlayer.create(this, getResources().getIdentifier(animalOverlay.getSoundFile(), MultimediaHelper.RESOURCES_RAW_FOLDER, getPackageName()));
mediaPlayerAnimalSound = MediaPlayer.create(this, getResources().getIdentifier(animalOverlay.getSoundFile(), AuthenticationInstructionHelper.RESOURCES_RAW_FOLDER, getPackageName()));
}
preview.enableView();
mediaPlayerTabletPlacement = MultimediaHelper.getMediaPlayerTabletPlacement(getApplicationContext());
mediaPlayerTabletPlacement = AuthenticationInstructionHelper.getMediaPlayerTabletPlacement(getApplicationContext());
mediaPlayerTabletPlacement.start();
mediaPlayerTabletPlacementOverlay = MultimediaHelper.getMediaPlayerTabletPlacementOverlay(getApplicationContext());
mediaPlayerTabletPlacementOverlay = AuthenticationInstructionHelper.getMediaPlayerTabletPlacementOverlay(getApplicationContext());
tensorFlowLoadingThread.start();
startTimeFallback = new Date().getTime();
startTimeAuthenticationAnimation = new Date().getTime();
Expand All @@ -244,7 +244,7 @@ public void run() {
authenticationAnimation.setVisibility(View.INVISIBLE);

ImageView animalOverlayImageView = (ImageView)findViewById(R.id.animalOverlay);
animalOverlayImageView.setImageResource(getResources().getIdentifier(animalOverlay.getName(), MultimediaHelper.RESOURCES_DRAWABLE_FOLDER, getPackageName()));
animalOverlayImageView.setImageResource(getResources().getIdentifier(animalOverlay.getName(), AuthenticationInstructionHelper.RESOURCES_DRAWABLE_FOLDER, getPackageName()));
animalOverlayImageView.setVisibility(View.VISIBLE);

preview.disableView();
Expand Down
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.AuthenticationInstructionHelper;
import org.literacyapp.authentication.helper.DetectionHelper;
import org.literacyapp.contentprovider.dao.DaoSession;
import org.literacyapp.contentprovider.dao.StudentImageCollectionEventDao;
Expand All @@ -22,7 +23,6 @@
import org.literacyapp.receiver.BootReceiver;
import org.literacyapp.util.DeviceInfoHelper;
import org.literacyapp.util.EnvironmentSettings;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.util.StudentHelper;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
Expand Down Expand Up @@ -94,7 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
displayTemperatureNight = DetectionHelper.getDisplayTemperatureNight();

authenticationAnimation = (GifImageView) findViewById(R.id.authentication_animation);
MultimediaHelper.setAuthenticationInstructionAnimation(getApplicationContext(), authenticationAnimation);
AuthenticationInstructionHelper.setAuthenticationInstructionAnimation(getApplicationContext(), authenticationAnimation);

animalOverlayName = getIntent().getStringExtra(AuthenticationActivity.ANIMAL_OVERLAY_IDENTIFIER);

Expand Down Expand Up @@ -208,7 +208,7 @@ public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

if (faceDetected && !isFaceInsideFrame){
DetectionHelper.drawArrowFromFaceToFrame(animalOverlay, imgRgba, face);
MultimediaHelper.playTabletPlacementOverlay(mediaPlayerTabletPlacement, mediaPlayerTabletPlacementOverlay, mediaPlayerAnimalSound);
AuthenticationInstructionHelper.playTabletPlacementOverlay(mediaPlayerTabletPlacement, mediaPlayerTabletPlacementOverlay, mediaPlayerAnimalSound);
}

EnvironmentSettings.freeMemory();
Expand All @@ -224,14 +224,14 @@ public void onResume()
ppF = new PreProcessorFactory(getApplicationContext());
animalOverlay = animalOverlayHelper.getAnimalOverlay(animalOverlayName);
if (animalOverlay != null){
mediaPlayerAnimalSound = MediaPlayer.create(this, getResources().getIdentifier(animalOverlay.getSoundFile(), MultimediaHelper.RESOURCES_RAW_FOLDER, getPackageName()));
mediaPlayerAnimalSound = MediaPlayer.create(this, getResources().getIdentifier(animalOverlay.getSoundFile(), AuthenticationInstructionHelper.RESOURCES_RAW_FOLDER, getPackageName()));
}
preview.enableView();
if (!authenticationAnimationAlreadyPlayed){
mediaPlayerTabletPlacement = MultimediaHelper.getMediaPlayerTabletPlacement(getApplicationContext());
mediaPlayerTabletPlacement = AuthenticationInstructionHelper.getMediaPlayerTabletPlacement(getApplicationContext());
mediaPlayerTabletPlacement.start();
}
mediaPlayerTabletPlacementOverlay = MultimediaHelper.getMediaPlayerTabletPlacementOverlay(getApplicationContext());
mediaPlayerTabletPlacementOverlay = AuthenticationInstructionHelper.getMediaPlayerTabletPlacementOverlay(getApplicationContext());
startTimeFallback = new Date().getTime();
startTimeAuthenticationAnimation = new Date().getTime();
if (authenticationAnimationAlreadyPlayed){
Expand All @@ -247,7 +247,7 @@ public void run() {
authenticationAnimation.setVisibility(View.INVISIBLE);

ImageView animalOverlayImageView = (ImageView)findViewById(R.id.animalOverlay);
animalOverlayImageView.setImageResource(getResources().getIdentifier(animalOverlay.getName(), MultimediaHelper.RESOURCES_DRAWABLE_FOLDER, getPackageName()));
animalOverlayImageView.setImageResource(getResources().getIdentifier(animalOverlay.getName(), AuthenticationInstructionHelper.RESOURCES_DRAWABLE_FOLDER, getPackageName()));
animalOverlayImageView.setVisibility(View.VISIBLE);

preview.disableView();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.literacyapp.util;
package org.literacyapp.authentication.helper;

import android.content.Context;
import android.media.MediaPlayer;
Expand All @@ -16,99 +16,15 @@
import java.io.OutputStream;

/**
* Helper class for determining folder paths of multimedia content.
* Helper class for fetching image overlay displayed during authentication.
*/
public class MultimediaHelper {
public class AuthenticationInstructionHelper {

private static final String AUTHENTICATION_INSTRUCTION_BOY = "authentication_instruction_640";
private static final String AUTHENTICATION_INSTRUCTION_GIRL = "authentication_instruction_girl_640";
public static final String RESOURCES_DRAWABLE_FOLDER = "drawable";
public static final String RESOURCES_RAW_FOLDER = "raw";

public static File getMultimediaDirectory() {
File multimediaDirectory = new File(Environment.getExternalStorageDirectory() + "/.literacyapp/multimedia");
if (!multimediaDirectory.exists()) {
multimediaDirectory.mkdirs();
}
return multimediaDirectory;
}

public static File getAudioDirectory() {
File audioDirectory = new File(getMultimediaDirectory(), "audio");
if (!audioDirectory.exists()) {
audioDirectory.mkdir();
}
return audioDirectory;
}

public static File getImageDirectory() {
File imageDirectory = new File(getMultimediaDirectory(), "image");
if (!imageDirectory.exists()) {
imageDirectory.mkdir();
}
return imageDirectory;
}

public static File getVideoDirectory() {
File videoDirectory = new File(getMultimediaDirectory(), "video");
if (!videoDirectory.exists()) {
videoDirectory.mkdir();
}
return videoDirectory;
}

public static File getFile(Audio audio) {
File file = null;

if (audio == null) {
return null;
}

File audioDirectory = getAudioDirectory();
file = new File(audioDirectory, audio.getId() + "_r" + audio.getRevisionNumber() + "." + audio.getAudioFormat().toString().toLowerCase());

return file;
}

public static File getFile(Image image) {
File file = null;

if (image == null) {
return null;
}

File imageDirectory = getImageDirectory();
file = new File(imageDirectory, image.getId() + "_r" + image.getRevisionNumber() + "." + image.getImageFormat().toString().toLowerCase());

return file;
}

public static File getFile(Video video) {
File file = null;

if (video == null) {
return null;
}

File videoDirectory = getVideoDirectory();
file = new File(videoDirectory, video.getId() + "_r" + video.getRevisionNumber() + "." + video.getVideoFormat().toString().toLowerCase());

return file;
}

public static File getVideoThumbnail(Video video) {
File file = null;

if (video == null) {
return null;
}

File videoDirectory = getVideoDirectory();
file = new File(videoDirectory, video.getId() + "_r" + video.getRevisionNumber() + ".png");

return file;
}

public static void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.gson.reflect.TypeToken;

import org.literacyapp.LiteracyApplication;
import org.literacyapp.authentication.helper.AuthenticationInstructionHelper;
import org.literacyapp.contentprovider.dao.DaoSession;
import org.literacyapp.contentprovider.dao.StudentDao;
import org.literacyapp.contentprovider.dao.StudentImageCollectionEventDao;
Expand All @@ -19,7 +20,6 @@
import org.literacyapp.contentprovider.model.analytics.StudentImageCollectionEvent;
import org.literacyapp.service.FaceRecognitionTrainingJobService;
import org.literacyapp.util.AiHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.util.StudentHelper;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
Expand Down Expand Up @@ -319,7 +319,7 @@ private File createAvatarFileFromStudentImage(StudentImage studentImage, Student
Log.i(getClass().getName(), "createAvatarFileFromStudentImage: OutputStream with the file: " + avatarFile.getAbsolutePath());
OutputStream outputStream = new FileOutputStream(avatarFile);
Log.i(getClass().getName(), "createAvatarFileFromStudentImage: Start copying of the file...");
MultimediaHelper.copyFile(inputStream, outputStream);
AuthenticationInstructionHelper.copyFile(inputStream, outputStream);
Log.i(getClass().getName(), "createAvatarFileFromStudentImage: Finished file copying.");
} catch (FileNotFoundException e) {
Log.e(getClass().getName(), null, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.logic.CurriculumHelper;
import org.literacyapp.model.enums.content.LiteracySkill;
import org.literacyapp.model.enums.content.NumeracySkill;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.logic.CurriculumHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;

import java.io.File;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.literacyapp.logic.CurriculumHelper;
import org.literacyapp.model.enums.content.NumeracySkill;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.logic.CurriculumHelper;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.logic.CurriculumHelper;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.literacyapp.contentprovider.model.content.multimedia.JoinVideosWithLetters;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.literacyapp.contentprovider.model.content.multimedia.JoinVideosWithNumbers;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.literacyapp.R;
import org.literacyapp.contentprovider.dao.VideoDao;
import org.literacyapp.contentprovider.model.content.multimedia.Video;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.multimedia.Audio;
import org.literacyapp.util.MediaPlayerHelper;
import org.literacyapp.util.MultimediaHelper;
import org.literacyapp.contentprovider.util.MultimediaHelper;
import org.literacyapp.util.TtsHelper;

import java.io.File;
Expand Down
Loading

0 comments on commit 88807fc

Please sign in to comment.