Anggota Kelompok :
Irfan Andessa (161011400035)
Nurilah (161011400049)
Steffi Antoni (161011400067)
Buatlah file java dan xml seperti di bawah ini :
Lalu buat kodingannya satu persatu seperti ini :
MainActivity.java
package
com.example.dictionarytts;
import
android.app.Activity;
import
android.app.Dialog;
import
android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import
android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import
android.widget.Button;
import
android.widget.ImageButton;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity {
Button ok;
ImageButton start,list,about,exit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = (ImageButton)
findViewById(R.id.imageButton1);
list = (ImageButton) findViewById(R.id.imageButton2);
about = (ImageButton)
findViewById(R.id.imageButton3);
exit = (ImageButton) findViewById(R.id.imageButton4);
start.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
Intent intent = new Intent(v.getContext(),Dictionary.class);
startActivity(intent);
}
});
list.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
final Dialog dialog = new
Dialog(MainActivity.this);
dialog.setContentView(R.layout.list);
dialog.setTitle("List
Word");
Button ok = (Button) dialog.findViewById(R.id.button1);
ok.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
dialog.dismiss();
}
});
dialog.show();
}
});
about.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
final Dialog dialog = new
Dialog(MainActivity.this);
dialog.setContentView(R.layout.about);
dialog.setTitle("About");
Button ok = (Button) dialog.findViewById(R.id.buttonOK);
ok.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
dialog.dismiss();
}
});
dialog.show();
}
});
exit.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
System.exit(0);
}
});
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds
items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dictionary, menu);
return true;
}
@Override
public boolean
onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks
here. The action bar will
// automatically handle clicks on
the Home/Up button, so long
// as you specify a parent
activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
|
Dictionary.java
package
com.example.dictionarytts;
import java.util.Locale;
import
android.app.Activity;
import
android.database.Cursor;
import
android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import
android.widget.EditText;
import
android.widget.ImageButton;
import
android.widget.TextView;
import
android.widget.Toast;
import
android.speech.tts.TextToSpeech;
public class Dictionary extends Activity {
private TextToSpeech tts ,tts2;
private SQLiteDatabase db = null;
private Cursor kamusCursor = null;
private TextView romaji;
private EditText txtJepang;
private EditText txtInggris;
private EditText txtKeterangan;
private DataKamus datakamus = null;
private ImageButton inggris ,jepang ,inggris2;
public static final String JEPANG = "jepang";
public static final String INGGRIS = "inggris";
public static final String ROMAJI= "romaji";
public static final String KETERANGAN = "keterangan";
/** Called when the activity is first
created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
datakamus = new DataKamus(this);
db = datakamus.getWritableDatabase();
datakamus.createTable(db);
datakamus.generateData(db);
setContentView(R.layout.activity_dictionary);
txtJepang = (EditText)
findViewById(R.id.txtJepang);
txtInggris = (EditText)
findViewById(R.id.txtInggris);
txtKeterangan = (EditText)
findViewById(R.id.txtKeterangan);
inggris = (ImageButton)
findViewById(R.id.imageButton1);
jepang = (ImageButton)
findViewById(R.id.imageButton2);
romaji = (TextView)
findViewById(R.id.txtRomaji);
inggris2 = (ImageButton)
findViewById(R.id.imageButton3);
tts = new
TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated
method stub
if(status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.ENGLISH);
}
}
});
tts2 = new
TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated
method stub
if(status != TextToSpeech.ERROR) {
tts2.setLanguage(Locale.JAPANESE);
}
}
});
inggris.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
String toSpeak1 = txtInggris.getText().toString();
Toast.makeText(getApplicationContext(),
toSpeak1, Toast.LENGTH_SHORT).show();
tts.speak(toSpeak1, TextToSpeech.QUEUE_FLUSH, null);
}
});
jepang.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
String
toSpeak2 = txtJepang.getText().toString();
Toast.makeText(getApplicationContext(),
toSpeak2, Toast.LENGTH_SHORT).show();
tts2.speak(toSpeak2, TextToSpeech.QUEUE_FLUSH, null);
}
});
inggris2.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated
method stub
String
toSpeak3 = txtKeterangan.getText().toString();
Toast.makeText(getApplicationContext(),
toSpeak3, Toast.LENGTH_SHORT).show();
tts.speak(toSpeak3, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void getTerjemahan(View
view) {
String result = "";
String result2 = "";
String result3= "";
String japaneseword = txtInggris.getText().toString();
kamusCursor = db.rawQuery("SELECT ID,
INGGRIS, JEPANG, ROMAJI, KETERANGAN "
+ "FROM kamus
where INGGRIS ='" + japaneseword
+ "' ORDER BY INGGRIS", null);
if (kamusCursor.moveToFirst()) {
result = kamusCursor.getString(2);
for (; !kamusCursor.isAfterLast(); kamusCursor.moveToNext()) {
result = kamusCursor.getString(2);
}
}
if (kamusCursor.moveToFirst()) {
result2 = kamusCursor.getString(3);
for (; !kamusCursor.isAfterLast(); kamusCursor.moveToNext()) {
result2 = kamusCursor.getString(3);
}
}
if (kamusCursor.moveToFirst()) {
result3 = kamusCursor.getString(4);
for (; !kamusCursor.isAfterLast(); kamusCursor.moveToNext()) {
result3 = kamusCursor.getString(4);
}
}
if (result.equals("")) {
result = "KATA TIDAK
DITEMUKAN";
}
if (result2.equals("")) {
result = "KATA TIDAK
DITEMUKAN";
}
txtJepang.setText(result);
romaji.setText(result2);
txtKeterangan.setText(result3);
}
@Override
public void onDestroy() {
super.onDestroy();
kamusCursor.close();
db.close();
}
}
|
DataKamus.java
package
com.example.dictionarytts;
import
android.content.ContentValues;
import
android.content.Context;
import
android.database.sqlite.SQLiteDatabase;
import
android.database.sqlite.SQLiteOpenHelper;
public class DataKamus extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "dbkamus";
public static final String JEPANG = "jepang";
public static final String INGGRIS= "inggris";
public static final String ROMAJI= "romaji";
public static final String KETERANGAN = "keterangan";
//Constructor
DataKamus untuk initiate database
public DataKamus(Context context) {
super(context, DATABASE_NAME, null, 1);
}
//method
createTable untuk membuat table kamus
public void
createTable(SQLiteDatabase db){
db.execSQL("DROP TABLE
IF EXISTS kamus");
db.execSQL("CREATE
TABLE if not exists kamus (id INTEGER PRIMARY KEY AUTOINCREMENT, inggris
TEXT, jepang TEXT, romaji TEXT ,keterangan TEXT);");
}
//method
generateData untuk mengisikan data ke kamus.
public void
generateData(SQLiteDatabase db){
ContentValues cv=new ContentValues();
cv.put(INGGRIS, "air");
cv.put(JEPANG, "空気");
cv.put(ROMAJI, "Kuki");
cv.put(KETERANGAN, "Air is
mixture of gases that we breathe");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "beast");
cv.put(JEPANG, "獣");
cv.put(ROMAJI, "Kemono");
cv.put(KETERANGAN, "Beast is a
large or a dangerous animal");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "chocolate");
cv.put(JEPANG, "チョコレート");
cv.put(ROMAJI, "Chocoreto");
cv.put(KETERANGAN, "Chocolate
is hard brown sweet food made from cocoa beans");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "destroy");
cv.put(JEPANG, "破壊する");
cv.put(ROMAJI, "Hakai
suru");
cv.put(KETERANGAN, "Destroy
means break or damage something so badly 'till it no longer exists ,works,
etc");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "easy");
cv.put(JEPANG, "簡単");
cv.put(ROMAJI, "Kantan");
cv.put(KETERANGAN, "Easy means
free from anxiety ,pain or trouble");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "fast");
cv.put(JEPANG, "速い");
cv.put(ROMAJI, "Hayai");
cv.put(KETERANGAN, "Fast means
showing a time later than the true time");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "ghost");
cv.put(JEPANG, "幽霊");
cv.put(ROMAJI, "Yurei");
cv.put(KETERANGAN, "Ghost is an
apparition of a dead person which is believed to appear or become manifest to
the living");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "heat");
cv.put(JEPANG, "熱");
cv.put(ROMAJI, "Netsu");
cv.put(KETERANGAN, "Heat means
the quality of being hot or high temperature");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "innocent");
cv.put(JEPANG, "無実の");
cv.put(ROMAJI, "Mujitsu
no");
cv.put(KETERANGAN, "Innocent
means knowing nothing of evil");
db.insert("kamus", JEPANG, cv);
cv.put(INGGRIS, "joy");
cv.put(JEPANG, "喜び");
cv.put(ROMAJI, "Yorokobi");
cv.put(KETERANGAN, "Joy means
person or thing that causes you to feel very happy");
db.insert("kamus", JEPANG, cv);
}
@Override
public void
onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated
method stub
}
@Override
public void
onCreate(SQLiteDatabase db) {
// TODO Auto-generated
method stub
}
}
|
activity_main.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dictionarytts.MainActivity"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/txtAir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dictionary"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="@+id/txtInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English
-> Japanese"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtChoco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView
android:id="@+id/txtDestroy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/txtEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/list"
/>
<TextView
android:id="@+id/txtFast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List
Word"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about"
/>
<TextView
android:id="@+id/txtGhost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/exit"
/>
<TextView
android:id="@+id/txtHeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
|
activity_dictionary.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dictionarytts.Dictionary"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/txtDictionary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dictionary"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/txtInggris"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="7.33"
android:editable="true"
android:ems="10"
>
<requestFocus />
</EditText>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_speak"
/>
</LinearLayout>
<Button
android:id="@+id/btnTerjemah"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:onClick="getTerjemahan"
android:text="Find" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Japanese" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/txtJepang"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:ems="10"
/>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_speak"
/>
</LinearLayout>
<TextView
android:id="@+id/txtRomaji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<TextView
android:id="@+id/txtInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Information
:" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/txtKeterangan"
android:layout_width="266dp"
android:layout_height="150dp"
android:layout_weight="1"
android:editable="false"
android:ems="10"
/>
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_speak"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
|
list.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dictionarytts.list"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/txtAir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Air"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtBeast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beast"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtChoco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chocolate"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtDestroy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Destroy"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Easy"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtFast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fast"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtGhost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ghost"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtHeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heat"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtInno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Innocent"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtJoy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Joy"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</RelativeLayout>
|
about.xml
<?xml version="1.0"
encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/txtAir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This
application is some kind dictionary translator that used english and japanese
languange. This application can also speak of the part that we want to
hear."
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtInno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView
android:id="@+id/txtFast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView
android:id="@+id/txtGhost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView
android:id="@+id/txtHeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView
android:id="@+id/txtInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This
application made by : "
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtChoco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Irfan
Andessa (161011400035)"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtDestroy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nurilah
(161011400049)"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/txtEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Steffi
Antoni (161011400067)"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Button
android:id="@+id/buttonOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</RelativeLayout>
|
Hasil Run :
Sekian dari kami ,jika ada kekurangan atau kesalahan bisa tinggalkan pesan di kolom komentar. Terimakasih
Tidak ada komentar:
Posting Komentar