Skip to content

Commit

Permalink
Merge pull request #1 from sladomic/master
Browse files Browse the repository at this point in the history
SNAPSHOT 1.0.5
  • Loading branch information
Jo Grimstad authored Jun 8, 2017
2 parents 7280a98 + 43099e1 commit 453f62d
Show file tree
Hide file tree
Showing 64 changed files with 1,695 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
script:
# By default Travis CI executes './gradlew build connectedCheck' if no 'script:' section found.
- ./gradlew build

language: android

jdk:
- oraclejdk8

android:
components:
- tools
- build-tools-23.0.1
- android-23
- extra-android-m2repository

notifications:
email: false
46 changes: 46 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "org.literacyapp.handwriting_numbers"
minSdkVersion 21
targetSdkVersion 23
versionCode 1000005
versionName "1.0.5-SNAPSHOT"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
encoding = "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'org.literacyapp:literacyapp-model:1.1.47'
compile 'org.literacyapp:contentprovider:1.0.7'
compile 'org.tensorflow:tensorflow-android:1.2.0-rc0'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.literacyapp.handwriting_numbers;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("org.literacyapp.imagepicker", appContext.getPackageName());
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.literacyapp.handwriting_numbers">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name="HandwritingNumbersApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".WriteNumberActivity">
</activity>
<activity
android:name=".FinalActivity" />
</application>
</manifest>
Binary file added app/src/main/assets/expert-graph.pb
Binary file not shown.
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.literacyapp.handwriting_numbers;

import android.content.Intent;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import org.literacyapp.handwriting_numbers.util.MediaPlayerHelper;


public class FinalActivity extends AppCompatActivity {

private ImageView mFinalCheckmarkImageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);

mFinalCheckmarkImageView = (ImageView) findViewById(R.id.final_checkmark);
}

@Override
protected void onStart() {
super.onStart();

// Animate checkmark
mFinalCheckmarkImageView.postDelayed(new Runnable() {
@Override
public void run() {
mFinalCheckmarkImageView.setVisibility(View.VISIBLE);
Drawable drawable = mFinalCheckmarkImageView.getDrawable();
((Animatable) drawable).start();

MediaPlayer mediaPlayer = MediaPlayerHelper.playLessonCompleted(getApplicationContext());
if (mediaPlayer != null){
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
HandwritingNumbersApplication handwritingNumbersApplication = (HandwritingNumbersApplication) getApplicationContext();
handwritingNumbersApplication.setCompletionCounter(handwritingNumbersApplication.getCompletionCounter() + 1);
if (handwritingNumbersApplication.getCompletionCounter() < 5){
Intent intent = new Intent(getApplicationContext(), WriteNumberActivity.class);
startActivity(intent);
} else {
finishAffinity();
}
}
});
}
}
}, MediaPlayerHelper.DEFAULT_PLAYER_DELAY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.literacyapp.handwriting_numbers;

import android.app.Application;

/**
* Created by sladomic on 28.04.17.
*/

public class HandwritingNumbersApplication extends Application {
private int completionCounter;

@Override
public void onCreate() {
super.onCreate();

completionCounter = 0;
}

public int getCompletionCounter() {
return completionCounter;
}

public void setCompletionCounter(int completionCounter) {
this.completionCounter = completionCounter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.literacyapp.handwriting_numbers;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import org.literacyapp.contentprovider.ContentProvider;

public class MainActivity extends AppCompatActivity {

private static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
protected void onStart() {
Log.i(getClass().getName(), "onStart");
super.onStart();

// Ask for permissions
int permissionCheckWriteExternalStorage = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheckWriteExternalStorage != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
return;
}

ContentProvider.initializeDb(this);

Intent intent = new Intent(this, WriteNumberActivity.class);
startActivity(intent);

finish();
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if ((requestCode == PERMISSION_REQUEST_READ_EXTERNAL_STORAGE)) {
if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
// Permission granted. Restart application
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
// Permission denied. Close application
finish();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.literacyapp.handwriting_numbers;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import org.literacyapp.contentprovider.ContentProvider;
import org.literacyapp.contentprovider.dao.AudioDao;
import org.literacyapp.contentprovider.dao.DaoSession;
import org.literacyapp.contentprovider.model.content.Number;
import org.literacyapp.handwriting_numbers.util.MediaPlayerHelper;
import org.literacyapp.handwriting_numbers.view.DrawModel;
import org.literacyapp.handwriting_numbers.view.DrawView;
import org.literacyapp.handwriting_numbers.view.DrawViewOnTouchListener;
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;

import java.util.List;

public class WriteNumberActivity extends AppCompatActivity implements View.OnTouchListener {

private AudioDao audioDao;
private Number number;

private static final int PIXEL_WIDTH = 280;

private DrawModel mModel;
private DrawView mDrawView;

private static final String MODEL_FILE = "file:///android_asset/expert-graph.pb";

private TensorFlowInferenceInterface inferenceInterface;

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_write);

DaoSession daoSession = ContentProvider.getDaoSession();
audioDao = daoSession.getAudioDao();

List<Number> unlockedNumbers = ContentProvider.getUnlockedNumbers();
number = unlockedNumbers.get((int)(Math.random() * unlockedNumbers.size()));
Log.i(getClass().getName(), "number: " + number);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(number.getValue().toString());
// Set on listener to restart the drawing with a blank screen
textView.setOnTouchListener(this);

initTensorFlowAndLoadModel();

mModel = new DrawModel(PIXEL_WIDTH, PIXEL_WIDTH);

mDrawView = (DrawView) findViewById(R.id.view_draw);
mDrawView.setModel(mModel);
DrawViewOnTouchListener listener = new DrawViewOnTouchListener(mDrawView, mModel, inferenceInterface, number.getValue(), getApplicationContext());
mDrawView.setOnTouchListener(listener);
}

private void initTensorFlowAndLoadModel() {
Log.i(getClass().getName(), "initTensorFlowAndLoadModel");
try {
inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);
Log.d(getClass().getName(), "Load Success");
} catch (final Exception e) {
throw new RuntimeException("Error initializing TensorFlow!", e);
}
}

@Override
protected void onResume() {
Log.i(getClass().getName(), "onResume");
super.onResume();

mDrawView.onResume();

MediaPlayer mediaPlayer = MediaPlayerHelper.playInstructionSound(getApplicationContext());
if (mediaPlayer != null){
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
MediaPlayerHelper.playNumberSound(getApplicationContext(), audioDao, number);
}
});
}
}

@Override
protected void onPause() {
super.onPause();
mDrawView.onPause();
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mModel.clear();
mDrawView.reset();
mDrawView.invalidate();
return true;
}
}
Loading

0 comments on commit 453f62d

Please sign in to comment.