Created
March 20, 2018 08:19
-
-
Save Jabriko/b0784aaa77356f4f9650eaa1667269bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package id.indrasudirman.bahanujicoba; | |
| import android.content.DialogInterface; | |
| import android.content.Intent; | |
| import android.os.Bundle; | |
| 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.util.ArrayList; | |
| import io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip; | |
| public class MainActivity extends AppCompatActivity { | |
| private Rot13 rot13; | |
| 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.activity_main, 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(MainActivity.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(), MainActivity.class)); | |
| finish(); | |
| } | |
| }); | |
| AlertDialog alertDialog = alertDialogBuilder.create(); | |
| alertDialog.show(); | |
| } else { | |
| AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.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(), MainActivity.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