Tuesday, March 7, 2017
Multimedia Dictionary app for Android – with Source codes
Multimedia Dictionary app for Android – with Source codes
I decided to publish the following source code of a Multimedia Dictionary app for Android. The apps is a dictionary of the following languages, Malay, Arabic and English. All the word entries are available in the locally (sqlite), however we do not have the complete word list.
This code is specifically designed to support only Android 2.1, 2.2 and 2.3. This is due to lack of Arabic character support in the listed Android version. And there s a special treatment to the Arabic characters which we found quite complicated. It wont run beautifully on the Android 3.0 and above.
Sorry for the lack of documentation, however if youre familiar with Java in Android, it actually simple. Ill do further documentation later.
You may somehow revamp the apps, or do what ever you want. I would like to However make only one request, please do not remove the advertisement in the main screen.
To test the Arabic input, you need to have the Arabic keyboard use this http://bit.ly/ask1-1. Not sure with other Arabic keyboard. If you need to install the keyboard APK in the emulator, use this tutorial - http://blog.kerul.net/2012/08/how-to-install-apk-files-on-android.html
->Source codes download here http://bit.ly/kamus-code
->APK file download here http://bit.ly/kamus-apk
File structure;
Java Source codes main.java the main that calls all thre tabs ArabicReshaper.java, ArabicUtilities.java a2m.java e2ma.java m2a.java MyDBHelper.java Layout main.xml a2m.xml e2ma.xml m2a.xml |
The English to Malay-Arabic layout;
<?xml version="1.0" encoding="utf-8"?>
<TableLayout >="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow
android:id="@+id/tableAdMob"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView
android_id="@+id/adView1"
android_layout_width="fill_parent"
android_layout_height="wrap_content"
ads_adSize="BANNER"
ads_adUnitId="738a44d913034b9f"
android_layout_column="0"
android_layout_span="3"
/>
</TableRow>
<TableRow>
<TextView android:text="English word"
android:textColor="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<EditText android:text=""
android:layout_column="0"
android:id="@+id/txtenglish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2" />
<Button android:text="Search"
android:layout_column="2"
android:id="@+id/btncari"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="Malay word here"
android:id="@+id/tvmelayu"
android:layout_column="0"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text=""
android:layout_column="2"
android:drawableLeft="@drawable/sound"
android:id="@+id/btnsebutan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow>
<TextView android:text="Arabic word here"
android:id="@+id/tvarab"
android:layout_column="0"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text=""
android:layout_column="2"
android:drawableLeft="@drawable/sound"
android:id="@+id/btnsebutan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<LinearLayout android:gravity="center_horizontal">
<Button android:text="Download image"
android:id="@+id/btndownimej"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TableRow android:gravity="center_horizontal">
<ImageView
android:id="@+id/image1"
android:layout_height="100sp"
android:layout_width="100sp"
/>
</TableRow>
<TableRow>
<TextView android:text=" "
android:textColor="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
The English to Malay-Arabic Java code;
package net.kerul.mdictionary;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class e2ma extends Activity implements OnClickListener {
// widget - txtmelayu, btncari, tvarab, image, btnsebutan
protected EditText txtenglish;
protected Button btncari, btndownimej, btnsebutan,btnsebutan1;
protected TextView tvmelayu,tvarab;
protected ImageView image1;
protected MyDBHelper myDBHelper;
// protected Cursor cursor;
protected SQLiteDatabase db;
protected String imejurl, voiceurl;
protected Drawable drawable;
protected String va,ia,vm;//to hold sound name publicly
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//kat server KUIS
imejurl="http://www.kuis.edu.my/iame/ommar/image/";
voiceurl="http://www.kuis.edu.my/iame/ommar/voice/";
setContentView(R.layout.e2ma);
txtenglish= (EditText) findViewById(R.id.txtenglish);
txtenglish.requestFocus();
btncari = (Button) findViewById(R.id.btncari);
btncari.setOnClickListener(this);
//tvarab = (TextView) findViewById(R.id.tvarab);
//tvarab.setTypeface(tfarabic);
tvmelayu = (TextView) findViewById(R.id.tvmelayu);
tvarab = (TextView) findViewById(R.id.tvarab);
// the image download button
btndownimej = (Button) findViewById(R.id.btndownimej);
btndownimej.setEnabled(false);// disable button
btndownimej.setOnClickListener(this);
//define image drawer
image1 = (ImageView) findViewById(R.id.image1);
image1.setImageResource(R.drawable.icon);
//image1.setAdjustViewBounds(true); // set the ImageView bounds to match
// the Drawables dimensions
btnsebutan = (Button) findViewById(R.id.btnsebutan);
btnsebutan.setEnabled(false);// disable button
btnsebutan.setOnClickListener(this);
// Log.i("*****", "create UI Melayu-Arab");
btnsebutan1 = (Button) findViewById(R.id.btnsebutan1);
btnsebutan1.setEnabled(false);// disable button
btnsebutan1.setOnClickListener(this);
// database initial
myDBHelper = new MyDBHelper(this);
db = myDBHelper.getReadableDatabase();
//admob widget - private AdView adView;
adView = (AdView)findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
}
public void onClick(View v) {
String melayu="", imeja="", voicem="", voicea;
String bi,uarab="";
//jmCursor cmelayu;
Cursor cjoiner;
Cursor cbi, carab,cmelayu;
switch (v.getId()) {
case R.id.btncari:
bi=txtenglish.getText().toString().trim().toLowerCase();
// tvarab.setText(ArabicUtilities.reshape(uarab));
//search for the arabic word
String qbi="SELECT * FROM english where kataeng="+bi+";";
Log.i("-----search table english---- ",qbi);
//tvmelayu.setText(qarab);
cbi = db.rawQuery(qbi, null);
if(cbi.getCount()!=0){
cbi.moveToFirst();
//tvmelayu.setText("Perkataan "+bi+" ada: "+cbi.getString(0).toString());
//get malay word in joiner table
String qjoiner ="SELECT * FROM melayuarab where kataeng="+bi+";";
Log.i("-----search table joiner----- ",qjoiner);
cjoiner=db.rawQuery(qjoiner, null);
if(cjoiner.getCount()!=0){
cjoiner.moveToFirst();//go to first row
melayu=cjoiner.getString(0).toString();
uarab=cjoiner.getString(2).toString();
tvmelayu.setText("Perkataan Melayu Adalah: "+melayu);
tvarab.setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
tvarab.setText(ArabicUtilities.reshape("Perkataan Arab adalah: "+uarab));
}else{
tvmelayu.setText("Perkataan "+melayu+" tiada dalam joiner");
tvarab.setText("Perkataan "+uarab+" tiada dalam joiner");
}
//get malay details in melayu table
//String qmelayu ="SELECT * FROM melayu where katamelayu="+melayu+";";
//Log.i("-----search table melayu---- ",qmelayu);
//cmelayu=db.rawQuery(qmelayu, null);
//cmelayu.moveToFirst();//go to first row
//imeje=ie=cbi.getString(3).toString();
//Log.i("-----display---- ",imejm);
//voicee=ve=cbi.getString(4).toString();
//if word found and voice also available, activate "Sebutan" button
String qmelayu ="SELECT * FROM melayu where katamelayu="+melayu+";";
//Log.i("-----search table melayu---- ",qmelayu);
cmelayu=db.rawQuery(qmelayu, null);
cmelayu.moveToFirst();//go to first row
//Log.i("-----display---- ",imejm);
voicem=vm=cmelayu.getString(4).toString();
//if word found and voice also available, activate "Sebutan" button
if(voicem!=null){
btnsebutan.setEnabled(true);
vm=cmelayu.getString(4).toString();
}else{
btnsebutan.setEnabled(false);
}
String qarab ="SELECT * FROM arab where ukataarab="+uarab+";";
Log.i("-----search table arab---- ",qarab);
carab=db.rawQuery(qarab, null);
carab.moveToFirst();//go to first row
imeja=ia=carab.getString(6).toString();
//Log.i("-----display---- ",imeja);
voicea=va=carab.getString(7).toString();
//tvarab.setText(uarab+", "+imeja+", "+voicea);
//reset font textview arab
//if word found and voice also available, activate "Sebutan" button
if(voicea!=null){
btnsebutan1.setEnabled(true);
va=carab.getString(7).toString();
}else{
btnsebutan1.setEnabled(false);
}
if(imeja!=null){
btndownimej.setEnabled(true);
ia=carab.getString(6).toString();
}else{
btnsebutan1.setEnabled(false);
}
}
else{
//tvarab.setText("Maaf, "+melayu+" tiada dalam pangkalan data");
Toast.makeText(getApplicationContext(), "Maaf, "+bi+" tiada dalam pangkalan data",Toast.LENGTH_SHORT).show();
//tvarab.setText(ArabicUtilities.reshape("Maaf, "+uarab+" tiada dalam pangkalan data"));
btnsebutan.setEnabled(false);
}
break;
case R.id.btndownimej:
if (ia==null ||ia=="notavailable.jpg"){
Toast.makeText(getApplicationContext(), "Sorry, the image is not yet available.",Toast.LENGTH_SHORT).show();
break;
}
//image download and display
drawable = LoadImageFromWebOperations(imejurl+ia);
image1.setImageDrawable(drawable);
break;
case R.id.btnsebutan://malay
if (vm==null ||vm=="notavailable.mp3"){
Toast.makeText(getApplicationContext(), "Sorry, the sound is not yet available.",Toast.LENGTH_SHORT).show();
break;
}
// Toast.makeText(getApplicationContext(), "you choose -",Toast.LENGTH_SHORT).show();
//sound download and play
MediaPlayer mp = new MediaPlayer();
try {
//mp.create(t ,R.raw.makana);
//Toast.makeText(m2a.this, "Downloading sound...", Toast.LENGTH_SHORT).show();
mp.setDataSource(voiceurl+vm);
Toast.makeText(e2ma.this, "Download voice "+voiceurl+vm, Toast.LENGTH_SHORT).show();
//Toast.makeText(m2a.this, "Playing sound ", Toast.LENGTH_SHORT).show();
mp.prepare();
mp.start();
} catch (IOException e) {
// TODO Auto-generated catch block
//String err=" file download error" + e.toString();
Toast.makeText(e2ma.this, "Download error!!! ", Toast.LENGTH_SHORT).show();
Log.i("------------",e.toString());
}
// i.e. react on the end of the music-file:
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
// File has ended !!! <img src="http://www.anddev.org/images/smilies/wink.png" alt=";)" title="Wink" />
}
});
break;
case R.id.btnsebutan1://arabic
if (va==null ||va=="notavailable.mp3"){
Toast.makeText(getApplicationContext(), "Sorry, the sound is not yet available.",Toast.LENGTH_SHORT).show();
break;
}
// Toast.makeText(getApplicationContext(), "you choose -",Toast.LENGTH_SHORT).show();
//sound download and play
MediaPlayer mp1 = new MediaPlayer();
try {
//mp.create(t ,R.raw.makana);
//Toast.makeText(m2a.this, "Downloading sound...", Toast.LENGTH_SHORT).show();
mp1.setDataSource(voiceurl+va);
Toast.makeText(e2ma.this, "Download voice "+voiceurl+va, Toast.LENGTH_SHORT).show();
//Toast.makeText(m2a.this, "Playing sound ", Toast.LENGTH_SHORT).show();
mp1.prepare();
mp1.start();
} catch (IOException e) {
// TODO Auto-generated catch block
//String err=" file download error" + e.toString();
Toast.makeText(e2ma.this, "Download error!!! ", Toast.LENGTH_SHORT).show();
Log.i("------------",e.toString());
}
// i.e. react on the end of the music-file:
mp1.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
// File has ended !!! <img src="http://www.anddev.org/images/smilies/wink.png" alt=";)" title="Wink" />
}
});
break;
}
}
//this function is to handle image download from the web
private Drawable LoadImageFromWebOperations(String url){
try
{
Toast.makeText(this.getApplicationContext(), "Downloading image from " + url, Toast.LENGTH_SHORT).show();
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
Toast.makeText(this.getApplicationContext(), "Download finish", Toast.LENGTH_SHORT).show();
retuGo to link Download
Labels: –, android, app, codes, dictionary, for, multimedia, source, with