Skip to main content

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
}

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

Post a Comment

Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – https://play.google.com/store/apps/details?id=net.kerul.peribahasa English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur http://books.google.com.my/books/about/Peribahasa_dan_ungkapan_Inggeris_Melayu.html?id=bgwwQwAACAAJ CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

Most used STRING functions in my PHP coding

These are my favourite string manipulation functions in my daily coding life. Dedicated especially to Web Programming students. Read them and have fun. Expect a happiness after a storm , and you’ll find your “inner peace”… This post is still in draft. I’ll update and refine with more examples that I’ve personally develop. More after the break…

Kursus Laravel 2021

Tutorial LARAVEL bahasa Melayu (serasi versi 5.x & 6.x, 7.x) T0: Pengenalan Laravel (  http://fstm.kuis.edu.my/blog/laravel  ) T1: Kaedah install & guna Laragon (  http://fstm.kuis.edu.my/blog/laravel1  ) T2: Asas CRUD dalam Laravel (  http://fstm.kuis.edu.my/blog/laravel2  ) T3: Penukaran tema/template antaramuka sistem Laravel (  http://fstm.kuis.edu.my/blog/laravel3  ) T4: Carian rekod dalam Laravel  (  http://fstm.kuis.edu.my/blog/laravel4  ) T5: Kemaskini dan padam rekod dalam modul Laravel (  http://fstm.kuis.edu.my/blog/laravel5  ) T6: Paparan carian dengan pagination dalam Laravel (  http://fstm.kuis.edu.my/blog/laravel6   ) T7: Muat-naik fail imej ke server (  http://fstm.kuis.edu.my/blog/laravel-upload-imej  ) T8: Peranan pengguna ( user roles ) dalam Laravel ACL (  http://fstm.kuis.edu.my/blog/user-roles-laravel-acl  ) T9: Laravel REST API (  http://fstm.kuis.edu.my/blog/laravel-rest-api  ) Model-View-Controller dalam Laravel (  http://fs

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (  http://www.w3schools.com/bootstrap/   ) Available here -  http://getbootstrap.com/ Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here  http://bootstraphero.com/the-big-badass-list-of-twitter-bootstrap-resources/ Flat-UI is from DesignModo -   http://designmodo.com/flat/ Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

Simple Calculator with Spinner – Android Code

This code is a simple code for Android application. It has two textboxes to receive two numbers (decimal), list of mathematical operations with +, –, * and /. Choose the operation, and hit the “Display result” button. You will see the answer to the at the bottom of the button. Have fun with Android.   The Manifest file <? xml version="1.0" encoding="utf-8" ?> < LinearLayout xmlns : android = "http://schemas.android.com/apk/res/android" android : orientation = "vertical" android : layout_width = "fill_parent" android : layout_height = "fill_parent" > < EditText android : text = "@+id/EditText01" android : id = "@+id/EditText01" android : layout_width = "fill_parent" android : layout_height = "wrap_content" > </ EditText > < EditText android : text = "@+id/EditText02" android : id = "@+id/EditText02"