Skip to content

Instantly share code, notes, and snippets.

@Jabriko
Created March 16, 2018 06:15
Show Gist options
  • Save Jabriko/3b50d85256c72200d98bae90b0a6295f to your computer and use it in GitHub Desktop.
Save Jabriko/3b50d85256c72200d98bae90b0a6295f to your computer and use it in GitHub Desktop.
package id.indrasudirman.bahasainggris.activities.simplepast;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ScrollView;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import id.indrasudirman.bahasainggris.R;
import io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip;
public class SimplePastQuiz1 extends AppCompatActivity {
final String answerQuestion1 = "ngr";
final String answerQuestion2 = "ivfvgrq";
final String answerQuestion3 = "yvirq";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scrollable_contents_test);
assert getSupportActionBar() != null;
getSupportActionBar().setTitle("Simple Past Tense, Test 1");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ScrollView scrollable_contents = findViewById(R.id.scrollableContents);
getLayoutInflater().inflate(R.layout.activities_simple_past_quiz1, scrollable_contents);
}
public void toolTips(final View view) {
if (view.getId() == R.id.tooltip_simple_past_test1) {
new SimpleTooltip.Builder(this)
.anchorView(view)
.text("Bentuk Irregular verbs")
.gravity(Gravity.BOTTOM)
.animated(true)
.build()
.show();
} else if (view.getId() == R.id.tooltip_simple_past_test2) {
new SimpleTooltip.Builder(this)
.anchorView(view)
.text("Bentuk Regular verbs")
.gravity(Gravity.BOTTOM)
.animated(true)
.build()
.show();
} else if (view.getId() == R.id.tooltip_simple_past_test3) {
new SimpleTooltip.Builder(this)
.anchorView(view)
.text("Bentuk Regular verbs")
.gravity(Gravity.BOTTOM)
.animated(true)
.build()
.show();
}
}
public void checkAnswer(View view) {
ArrayList<String> incorrectAnswerList = new ArrayList<String>();
int numberOfQuestionCorrect = 0;
if (checkQuestion1()) {
numberOfQuestionCorrect++;
} else {
incorrectAnswerList.add("Soal No 1");
}
if (checkQuestion2()) {
numberOfQuestionCorrect++;
} else {
incorrectAnswerList.add("Soal No 2");
}
if (checkQuestion3()) {
numberOfQuestionCorrect++;
} else {
incorrectAnswerList.add("Soal No 3");
}
if (numberOfQuestionCorrect == 3) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SimplePastQuiz1.this);
alertDialogBuilder
.setTitle("Selamat!")
.setMessage("Anda berhasil, nilai Anda : " + numberOfQuestionCorrect + " Sempurna. Anda dapat melanjutkan ke pelajaran berikutnya.")
.setCancelable(false)
.setPositiveButton("Simple Past Tense 2",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(new Intent(getApplicationContext(), SimplePast2.class));
finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
} else {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SimplePastQuiz1.this);
alertDialogBuilder
.setTitle("Gagal!")
.setMessage("Anda gagal, Nilai Anda adalah : " + numberOfQuestionCorrect + " Anda belum dapat melanjutkan pelajaran berikutnya.")
.setCancelable(false)
.setPositiveButton("Mulai test lagi",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(new Intent(getApplicationContext(), SimplePastQuiz1.class));
finish();
}
})
.setNegativeButton("Keluar aplikasi",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
moveTaskToBack(true);
finish();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
private boolean checkQuestion1() {
EditText editTextQuestion1 = findViewById(R.id.answer_simple_past_test1);
return editTextQuestion1.getText().toString().equalsIgnoreCase(answerQuestion1);
}
private boolean checkQuestion2() {
EditText editTextQuestion2 = findViewById(R.id.answer_simple_past_test2);
return editTextQuestion2.getText().toString().equalsIgnoreCase(answerQuestion2);
}
private boolean checkQuestion3() {
EditText editTextQuestion3 = findViewById(R.id.answer_simple_past_test3);
return editTextQuestion3.getText().toString().equalsIgnoreCase(answerQuestion3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment