Flashcard Android Application

This is a simple flashcard Android application that contains images and pronunciations of the numbers. The apps contains numbers from 0 till 9. Navigation for previous and next number using image button. Voices are stored in MP3 audio format. Complete source code are also available for download using Eclipse Juno + ADT v 21.

Simple Number Flashcard Android AppsSimple Number Flashcard Android AppsSimple Number Flashcard Android Apps

Available in the Google Play –> https://play.google.com/store/apps/details?id=net.kerul.simplenumb3r5

Download the APK here –> https://docs.google.com/open?id=0B34ZxOOoeSDdanhBUlU3dWs3MFE

Download the complete source code here –> https://docs.google.com/open?id=0B34ZxOOoeSDdOGpIWk5Dd21mUDg

This apps does not implementing ViewFlipper yet (TODO).

The multimedia resources (available in the main source-code)

assets-simple-numbers-flashcardsdrawables-simple-numbers-flashcard

The main XML layout

<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="@drawable/bglight" >

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >

<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
ads:adSize="SMART_BANNER"
ads:adUnitId="738a44d913034b9f"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >

<ImageView
android:id="@+id/imagenumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/no0" />
</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >

<ImageButton
android:id="@+id/btnprevious"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/prev" />

<ImageButton
android:id="@+id/btninfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/info" />

<ImageButton
android:id="@+id/btnsound"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/sound" />

<ImageButton
android:id="@+id/btnnext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/next" />
</TableRow>

</TableLayout>

</RelativeLayout>


The Java Code






package net.kerul.simplenumb3r5;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;

public class SimpleNumb3r5 extends Activity implements OnClickListener{
//define all widgets
private ImageView imagenumber;
private ImageButton btnprevious, btninfo, btnsound, btnnext;
//define variables to track screen number, start from 0
private int screennumber=0;
protected AdView adView;
//define a sound controller
private MediaPlayer mp;
//define an array for the sound files
private String[] soundfile={"0.mp3","1.mp3","2.mp3","3.mp3","4.mp3",
"5.mp3","6.mp3","7.mp3","8.mp3","9.mp3"};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_numb3r5);
//admob widget
adView = (AdView)findViewById(R.id.ad);
adView.loadAd(new AdRequest());

imagenumber=(ImageView)findViewById(R.id.imagenumber);

//initialize the object for the button
btnprevious=(ImageButton)findViewById(R.id.btnprevious);
//this button will innitially be disabled
btnprevious.setEnabled(false);
//add listener to the button
btnprevious.setOnClickListener(this);
btninfo=(ImageButton)findViewById(R.id.btninfo);
btninfo.setOnClickListener(this);
btnsound=(ImageButton)findViewById(R.id.btnsound);
btnsound.setOnClickListener(this);
btnnext=(ImageButton)findViewById(R.id.btnnext);
btnnext.setOnClickListener(this);

}//end onCreate

//this method is to handle button click
public void onClick(View arg0) {

//when btnprevious is clicked
if(arg0.getId()==R.id.btnprevious){
screennumber--;//minus 1 to the screennumber
changeNumber(screennumber);
if(screennumber==0){
//disable btnprevious
btnprevious.setEnabled(false);
}else{
//enable btnprevious
btnprevious.setEnabled(true);
}
changeNumber(screennumber);
btnnext.setEnabled(true);
}

//when btnnext is clicked
else if(arg0.getId()==R.id.btnnext){
screennumber++;//add 1 to the screennumber
changeNumber(screennumber);
if(screennumber==9){
//disable btnprevious
btnnext.setEnabled(false);
}else{
//enable btnprevious
btnnext.setEnabled(true);
}
changeNumber(screennumber);
btnprevious.setEnabled(true);

}
//when btnplay is clicked
else if(arg0.getId()==R.id.btnsound){
//call the method playSound
playSound(soundfile[screennumber].toString());
}//end btnsound clicked
else if(arg0.getId()==R.id.btninfo){
//invoke the Info activity
Intent info = new Intent(this, Info.class);
startActivity(info);
}

}//end onClick

//this method is to change the number that appear on the screen
//after navigation button is clicked
private void changeNumber(int screen){
switch (screen){
case 0: imagenumber.setImageResource(R.drawable.no0);
break;
case 1: imagenumber.setImageResource(R.drawable.no1);
break;
case 2: imagenumber.setImageResource(R.drawable.no2);
break;
case 3: imagenumber.setImageResource(R.drawable.no3);
break;
case 4: imagenumber.setImageResource(R.drawable.no4);
break;
case 5: imagenumber.setImageResource(R.drawable.no5);
break;
case 6: imagenumber.setImageResource(R.drawable.no6);
break;
case 7: imagenumber.setImageResource(R.drawable.no7);
break;
case 8: imagenumber.setImageResource(R.drawable.no8);
break;
case 9: imagenumber.setImageResource(R.drawable.no9);
break;

}
}//end changeNumber

public void playSound(String soundName){
Boolean mpPlayingStatus;

try{//try to check MediaPlayer status
mpPlayingStatus=mp.isPlaying();
}
catch (Exception e){
mpPlayingStatus=false;
}
if(mpPlayingStatus==true){//if the MediaPlayer is playing a voice, stop it to play new voice
mp.stop();
mp.release();//remove sound from memory
}
else{
try
{
mp = new MediaPlayer();
AssetFileDescriptor afd = getAssets().openFd(soundName);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp.prepare();
mp.start();//play sound

}//try block
catch(Exception e) {
Log.i("Error playing sound: ", e.toString());
}
}
}//end playSound
}

4 comments:

  1. Great tutorial. I used your example & changed just the mp3 files but when you press next the previous audio continues to play! Please fix on your next update many thanks.

    ReplyDelete
    Replies
    1. Thank you very much for your comment, I'll keep in mind to fix this in the next update.

      Delete

Popular Posts