TUGAS
UAS MOBILE PROGRAMMING
“QUIS
IT”
NAMA :
ABDULLAH
NIM :
161011400114
KELAS :
06TPLM001
"GAMBAR "TAMPILAN SPLASH SCREEN"
GAMBAR "TAMPIALN
HALAMAN LOGIN KETIKA SALAH USERNAME & PASSWORD"
GAMBAR "TAMPILAN HALAMAN
LOGIN"
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="project.uas_abdullah"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15"
/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".Splash_Screen"
android:label="@string/title_activity_splash__screen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=".Home"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name"
>
</activity>
<activity
android:name=".QuisActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".HighestScoreActivity"
android:label="@string/app_name">
</activity>
</application>
</manifest>
splash_screen.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:background="#ffffff"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"
android:text="@string/hello_world"
android:textColor="@color/welcome"
android:textSize="28sp"
android:textStyle="bold"
tools:context=".Splash_Screen"
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:src="@drawable/icon_quiz"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/imageView1"
android:layout_marginTop="16dp"
android:text="@string/quiz_it"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/hitam"
android:textStyle="bold"
/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="36dp"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progress"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp"
android:text="@string/Nama"
android:textStyle="italic"
/>
</RelativeLayout>
home.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0072bc"
android:stretchColumns="1"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:gravity="center"
android:text="@string/form_login"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:fontFamily="arial"
android:textStyle="bold"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:layout_marginLeft="15dp"
android:text="@string/user"
android:textColor="#fff"
android:textStyle="bold"
/>
<EditText
android:id="@+id/txtUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView2"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:ems="10"
android:textColor="#000"
>
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtUser"
android:layout_below="@+id/txtUser"
android:layout_marginTop="5dp"
android:textColor="#fff"
android:textStyle="bold"
android:text="@string/pass"
/>
<EditText
android:id="@+id/txtPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_alignRight="@+id/txtUser"
android:layout_below="@+id/textView3"
android:layout_marginTop="5dp"
android:ems="10"
android:inputType="textPassword"
android:textColor="#000"
/>
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtPass"
android:layout_below="@+id/txtPass"
android:layout_marginRight="2dp"
android:background="@drawable/background"
android:minHeight="30dip"
android:onClick="Login"
android:text="@string/btn_Login"
android:textStyle="bold"
android:width="100dp"
/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/btnLogin"
android:layout_marginBottom="17dp"
android:textColor="#fff"
android:textSize="12sp"
android:textStyle="italic"
android:text="@string/copyright"
/>
</RelativeLayout>
activity_quis.xml
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Question to
answer"
android:textSize="20sp"
tools:context=".QuisActivity"
/>
<Button
android:id="@+id/choice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@color/warna"
android:padding="8dp"
android:onClick="onClick"
android:text="A"
/>
<Button
android:id="@+id/choice2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:onClick="onClick"
android:background="@color/warna"
android:text="B"
/>
<Button
android:id="@+id/choice3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:onClick="onClick"
android:background="@color/warna"
android:text="C"
/>
<Button
android:id="@+id/choice4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:onClick="onClick"
android:background="@color/warna"
android:text="D"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:background="#d4390a"
android:padding="6dp"
>
<TextView
android:id="@+id/score_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Score"
android:textColor="#fff"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/score_text"
android:text="0/0"
android:textColor="#fff"
android:textSize="16dp"
/>
</RelativeLayout>
</LinearLayout>
activity_highest_score.xml
<?xml version="1.0"
encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:padding="16dp"
android:layout_height="match_parent"
tools:context="com.latihan.quisapp.HighestScoreActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/textScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/warna"
android:padding="16dp"
android:text="Skor Anda
:"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/textHighScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#d439da"
android:padding="16dp"
android:text="Skor Tertinggi
:"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"
/>
<Button
android:text="Coba
Lagi"
android:id="@+id/button"
android:onClick="onClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</RelativeLayout>
Splash_Screen.java
package
project.uas_abdullah;
import
android.os.Bundle;
import android.app.Activity;
import
android.content.Intent;
public class
Splash_Screen extends Activity {
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Thread splash = new Thread(){
public void run(){
try {
sleep(5000);
}
catch(InterruptedException a){
a.printStackTrace();
}
finally {
startActivity(new
Intent(Splash_Screen.this,Home.class));
finish();
}
}
};
splash.start();
}
}
Home.java
package project.uas_abdullah;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Home extends Activity {
EditText
user,pass;
Button
login;
@Override
protected
void onCreate(Bundle savedInstanceState) {
//
TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
user =
(EditText) findViewById(R.id.txtUser);
pass =
(EditText) findViewById(R.id.txtPass);
login
= (Button) findViewById(R.id.btnLogin);
login.setTextColor(Color.WHITE);
}
public
void Login(View view) {
if(user.getText().toString().length()==0){
user.setError("Username
Masih Kosong!");
user.requestFocus();
}else
if(pass.getText().toString().length()==0){
pass.setError("Password
Masih Kosong!");
pass.requestFocus();
}else
if(user.getText().toString().length()==0 &&
(pass.getText().toString().length()==0)){
user.setError("Username
Masih Kosong!");
pass.setError("Password
Masih Kosong!");
user.requestFocus();
}else
if(user.getText().toString().equals("admin")&&
pass.getText().toString().equals("admin")){
Toast.makeText(getApplicationContext(),
"Login Berhasil", Toast.LENGTH_SHORT).show();
Intent
intent = new Intent(this, QuisActivity.class);
startActivity(intent);
}else
{
Toast.makeText(getApplicationContext(),
"Username & Password Salah!", Toast.LENGTH_SHORT).show();
user.setText("");
pass.setText(null);
user.requestFocus();
}
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
//
TODO Auto-generated method stub
return
super.onCreateOptionsMenu(menu);
}
}
QuestionBank.java
package project.uas_abdullah;
public class QuestionBank {
private String textQuestions [] = {
"1. Siapakah penemu Bahasa Pemrograman C?",
"2. Manakah yang bukan Pendiri Youtube?",
"3. Tahun berapakah Google didirikan?",
"4. Manakah yang bukan bahasa Pemrograman?",
"5. Kode Pascal yang digunakan untuk menampilkan data ke
layar tanpa disertai mencetak baris baru adalah?"
};
//array of
multiple choices for each question
private String multipleChoice [][] = {
{"Dennis Ritchie", "Bill Gates", "Larry Page", "Steve Chen"},
{"Steve Chen", "Jawed Karim", "Larry Page", "Chad Hurley"},
{"1997", "1998", "2000", "2001"},
{"C", "HTML", "PHP", "Ruby"},
{"write", "writeln", "read", "readln"}
};
private String mCorrectAnswers[] = {"Dennis Ritchie", "Larry Page", "1998", "HTML", "write"};
public int getLength() { return textQuestions.length;}
public String getQuestion(int a) {
String question = textQuestions[a];
return question;
}
public String getChoice(int index, int num) {
String choice0 = multipleChoice[index][num-1];
return choice0;
}
public String getCorrectAnswer(int a) {
String answer = mCorrectAnswers[a];
return answer;
}
}
QuisActivity.java
package project.uas_abdullah;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuisActivity extends Activity {
private
QuestionBank mQuestionLibrary = new QuestionBank();
private
TextView mScoreView; // Untuk menampilkan Skor saat ini
private
TextView mQuestionView; //Untuk menampilkan jawaban
private
Button mButtonChoice1; //Jawaban 1
private
Button mButtonChoice2; //Jawaban 2
private
Button mButtonChoice3; //Jawaban 3
private
Button mButtonChoice4; //Jawaban 4
private
String mAnswer; //Untuk cek jawaban benar atau tidaknya
private
int mScore = 0; //Current total score
private
int mQuestionNumber = 0;
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quis);
mScoreView = (TextView) findViewById(R.id.score);
mQuestionView = (TextView) findViewById(R.id.question);
mButtonChoice1 = (Button) findViewById(R.id.choice1);
mButtonChoice2 = (Button) findViewById(R.id.choice2);
mButtonChoice3 = (Button) findViewById(R.id.choice3);
mButtonChoice4 = (Button)
findViewById(R.id.choice4);
updateQuestion();
updateScore(mScore);
}
private
void updateQuestion() {
if(mQuestionNumber<mQuestionLibrary.getLength())
{
mQuestionView.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
mButtonChoice1.setText(mQuestionLibrary.getChoice(mQuestionNumber,
1));
mButtonChoice2.setText(mQuestionLibrary.getChoice(mQuestionNumber,
2));
mButtonChoice3.setText(mQuestionLibrary.getChoice(mQuestionNumber,
3));
mButtonChoice4.setText(mQuestionLibrary.getChoice(mQuestionNumber,
4));
mAnswer =
mQuestionLibrary.getCorrectAnswer(mQuestionNumber);
mQuestionNumber++;
}else {
Toast.makeText(QuisActivity.this,
"Its was the last question!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent
(QuisActivity.this, HighestScoreActivity.class);
intent.putExtra("score",
mScore);
startActivity(intent);
}
}
private
void updateScore(int point) {
mScoreView.setText("" +
mScore+"/"+mQuestionLibrary.getLength());
}
public
void onClick(View view) {
Button answer = (Button) view;
//if the answer is correct, increase the
score
if(answer.getText() == mAnswer){
mScore = mScore + 1;
Toast.makeText(QuisActivity.this,
"Benar!", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(QuisActivity.this,
"Salah!", Toast.LENGTH_SHORT).show();
}
updateScore(mScore);
updateQuestion();
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.splash_screen, menu);
return
true;
}
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
switch
(item.getItemId()) {
case
R.id.menu_settings:
Intent
intent = new Intent(QuisActivity.this, Home.class);
startActivity(intent);
}
return
super.onOptionsItemSelected(item);
}
}
HighestScoreActivity.java
package project.uas_abdullah;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class HighestScoreActivity extends Activity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
//
TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_highest_score);
TextView
txtScore = (TextView) findViewById(R.id.textScore);
TextView
txtHighScore = (TextView) findViewById(R.id.textHighScore);
Intent
intent = getIntent();
int
score = intent.getIntExtra("score", 0);
txtScore.setText("Your
Score : " + score);
SharedPreferences
mypref = getPreferences(MODE_PRIVATE);
int
highscore = mypref.getInt("highscore", 0);
if(highscore>=score){
txtHighScore.setText("High
Score : "+highscore);
}else
{
txtHighScore.setText("New
highscore: "+score);
SharedPreferences.Editor
editor = mypref.edit();
editor.putInt("highscore",
score);
editor.commit();
}
}
public
void onClick(View view) {
Intent
intent = new Intent(HighestScoreActivity.this, QuisActivity.class);
startActivity(intent);
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.splash_screen, menu);
return
true;
}
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
switch
(item.getItemId()) {
case
R.id.menu_settings:
Intent
intent = new Intent(HighestScoreActivity.this, Home.class);
startActivity(intent);
}
return
super.onOptionsItemSelected(item);
}
}
t





Komentar
Posting Komentar