Skip to content

Commit

Permalink
Merge pull request #9 from sladomic/master
Browse files Browse the repository at this point in the history
Randomly present an unlocked letter and let the student draw the lett…
  • Loading branch information
Jo Grimstad authored Apr 28, 2017
2 parents 1365566 + 7a120b7 commit aee9579
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.literacyapp.handwriting"
minSdkVersion 21
targetSdkVersion 23
versionCode 1000002
versionName "1.0.2-SNAPSHOT"
versionCode 1000003
versionName "1.0.3-SNAPSHOT"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name="HandwritingApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand All @@ -20,5 +21,7 @@

<activity
android:name=".WriteLetterActivity" />
<activity
android:name=".FinalActivity" />
</application>
</manifest>
59 changes: 59 additions & 0 deletions app/src/main/java/org/literacyapp/handwriting/FinalActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.literacyapp.handwriting;

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

import org.literacyapp.handwriting.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) {
HandwritingApplication handwritingApplication = (HandwritingApplication) getApplicationContext();
handwritingApplication.setCompletionCounter(handwritingApplication.getCompletionCounter() + 1);
if (handwritingApplication.getCompletionCounter() < 5){
Intent intent = new Intent(getApplicationContext(), WriteLetterActivity.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;

import android.app.Application;

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

public class HandwritingApplication 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
Expand Up @@ -11,6 +11,10 @@
import android.util.Log;

import org.literacyapp.contentprovider.ContentProvider;
import org.literacyapp.contentprovider.model.content.Letter;
import org.literacyapp.contentprovider.model.content.Number;

import java.util.List;

public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import org.literacyapp.contentprovider.ContentProvider;
import org.literacyapp.contentprovider.dao.AudioDao;
Expand All @@ -23,6 +24,7 @@

import java.io.File;
import java.lang.reflect.Constructor;
import java.util.List;

public class WriteLetterActivity extends AppCompatActivity {

Expand All @@ -33,7 +35,6 @@ public class WriteLetterActivity extends AppCompatActivity {
private LetterBuffer lBuffer;

private AudioDao audioDao;
private LetterDao letterDao;
private Letter letter;

@Override
Expand All @@ -46,11 +47,12 @@ protected void onCreate(Bundle savedInstanceState) {
ocr = (Ocr) findViewById(R.id.writePad);

DaoSession daoSession = ContentProvider.getDaoSession();
letterDao = daoSession.getLetterDao();
audioDao = daoSession.getAudioDao();
letter = letterDao.queryBuilder()
.where(LetterDao.Properties.Text.eq("a"))
.unique();

List<Letter> unlockedLetters = ContentProvider.getUnlockedLetters();
letter = unlockedLetters.get((int)(Math.random() * unlockedLetters.size()));
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(letter.getText());
Log.i(getClass().getName(), "letter: " + letter);
}

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/literacyapp/handwriting/ocr/Ocr.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.literacyapp.handwriting.ocr;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.inputmethodservice.InputMethodService;
import android.media.MediaPlayer;
Expand All @@ -16,6 +17,8 @@

import org.encog.ml.data.MLData;
import org.encog.ml.data.basic.BasicMLData;
import org.literacyapp.handwriting.FinalActivity;
import org.literacyapp.handwriting.WriteLetterActivity;
import org.literacyapp.handwriting.entity.CharData;
import org.literacyapp.handwriting.entity.Engine;
import org.literacyapp.handwriting.entity.LanguageProcessor;
Expand Down Expand Up @@ -173,7 +176,8 @@ protected void onTouchUp() {

showCandidates();

MediaPlayerHelper.playLessonCompleted(getContext());
Intent intent = new Intent(getContext(), FinalActivity.class);
getContext().startActivity(intent);
}

private void clearAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* See https://developer.android.com/reference/android/media/MediaPlayer.html#create%28android.content.Context,%20int%29
*/
public class MediaPlayerHelper {
public static final long DEFAULT_PLAYER_DELAY = 1000;

private static final String INSTRUCTION_LETTER_1 = "can_you_draw_the_letter";
private static final String INSTRUCTION_LETTER_2 = "draw_the_letter";
private static final String INSTRUCTION_LETTER_3 = "now_try_to_draw_the_letter";
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/anim/checkmark_animation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:ordering="sequentially"
android:shareInterpolator="false">

<!-- Step 1 -->
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="M6,11 l0,0 l0,0"
android:valueTo="M6,11 l3.5,4 l0,0"
android:valueType="pathType" />

<!-- Step 2 -->
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="pathData"
android:valueFrom="M6,11 l3.5,4 l0,0"
android:valueTo="M6,11 l3.5,4 l8,-7"
android:valueType="pathType" />
</set>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/animated_checkmark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/checkmark">
<target
android:name="tick"
android:animation="@anim/checkmark_animation"/>
</animated-vector>
21 changes: 21 additions & 0 deletions app/src/main/res/drawable/checkmark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">

<group android:name="background">
<path
android:name="circle"
android:fillColor="@color/colorAccent"
android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0" />
</group>
<group android:name="check">
<path
android:name="tick"
android:pathData="M6,11 l0,0 l0,0"
android:strokeColor="#FFF"
android:strokeWidth="1" />
</group>
</vector>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_final.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context="org.literacyapp.handwriting.FinalActivity">

<ImageView
android:id="@+id/final_checkmark"
android:visibility="gone"
android:layout_width="256dp"
android:layout_height="256dp"
android:layout_centerInParent="true"
android:src="@drawable/animated_checkmark"
tools:visibility="visible"/>
</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_write_letter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
android:gravity="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="280sp"
android:text="a" />
android:text="a"
android:id="@+id/textView"/>

<android.support.v7.widget.CardView
android:layout_width="0dp"
Expand Down

0 comments on commit aee9579

Please sign in to comment.