Advertisement
Guest User

Pengaturan.java

a guest
Mar 11th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. package id.dismut.bmi;
  2.  
  3. import android.app.ActionBar;
  4. import android.app.Activity;
  5. import android.app.Dialog;
  6. import android.content.Intent;
  7. import android.database.Cursor;
  8. import android.database.SQLException;
  9. import android.database.sqlite.SQLiteDatabase;
  10. import android.graphics.Color;
  11. import android.graphics.drawable.ColorDrawable;
  12. import android.os.Bundle;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.Window;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.TextView;
  19. import android.widget.Toast;
  20.  
  21. public class Pengaturan extends Activity {
  22. Button btnNama,btnUsername,btnPassword,btnData,btnOk,btnCancel;
  23. EditText txtNama;
  24. String nama;
  25. protected Cursor cursor;
  26. DataHelper dbHelper;
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_pengaturan);
  31.  
  32. ActionBar actionBar = getActionBar();
  33. actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0091ea")));
  34. getActionBar().setDisplayHomeAsUpEnabled(true);
  35.  
  36. dbHelper = new DataHelper(this);
  37. final SQLiteDatabase db = dbHelper.getReadableDatabase();
  38. btnNama = (Button) findViewById(R.id.btnNama);
  39. btnUsername = (Button) findViewById(R.id.btnUsername);
  40. btnPassword = (Button) findViewById(R.id.btnPassword);
  41. btnData = (Button) findViewById(R.id.btnData);
  42.  
  43. btnNama.setOnClickListener(new View.OnClickListener() {
  44.  
  45. @Override
  46. public void onClick(View v) {
  47. final Dialog dialog = new Dialog(Pengaturan.this);
  48. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  49. dialog.setContentView(R.layout.dialog_nama);
  50.  
  51. txtNama = (EditText) dialog.findViewById(R.id.txtNama);
  52. btnOk = (Button) dialog.findViewById(R.id.button2);
  53. btnCancel = (Button) dialog.findViewById(R.id.button1);
  54. nama = txtNama.getText().toString();
  55.  
  56. btnOk.setOnClickListener(new View.OnClickListener() {
  57.  
  58. @Override
  59. public void onClick(View v) {
  60. String sql = "UPDATE user SET nama = '"+nama+"' WHERE username = (SELECT username FROM session)";
  61. try {
  62. db.execSQL(sql);
  63. Toast.makeText(getBaseContext(), "Berhasil mengubah "+nama+" ll", Toast.LENGTH_SHORT).show();
  64. dialog.dismiss();
  65. }
  66. catch (SQLException e) {
  67. Toast.makeText(getBaseContext(), "Gagal mengubah", Toast.LENGTH_SHORT).show();
  68. }
  69. }
  70. });
  71.  
  72. dialog.show();
  73.  
  74. }
  75. });
  76. btnUsername.setOnClickListener(new View.OnClickListener() {
  77.  
  78. @Override
  79. public void onClick(View v) {
  80. final Dialog dialog = new Dialog(Pengaturan.this);
  81. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  82. dialog.setContentView(R.layout.dialog_username);
  83.  
  84. EditText txtUsername = (EditText) dialog.findViewById(R.id.txtUsername);
  85. Button btnOk = (Button) dialog.findViewById(R.id.button2);
  86. Button btnCancel = (Button) dialog.findViewById(R.id.button1);
  87.  
  88. dialog.show();
  89.  
  90. }
  91. });
  92. btnPassword.setOnClickListener(new View.OnClickListener() {
  93.  
  94. @Override
  95. public void onClick(View v) {
  96. final Dialog dialog = new Dialog(Pengaturan.this);
  97. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  98. dialog.setContentView(R.layout.dialog_password);
  99.  
  100. EditText txtPasswordLama = (EditText) dialog.findViewById(R.id.txtUsername);
  101. EditText txtPasswordBaru = (EditText) dialog.findViewById(R.id.txtPasswordBaru);
  102. EditText txtPasswordBaruUlang = (EditText) dialog.findViewById(R.id.txtPasswordBaru);
  103. Button btnOk = (Button) dialog.findViewById(R.id.button2);
  104. Button btnCancel = (Button) dialog.findViewById(R.id.button1);
  105.  
  106. dialog.show();
  107.  
  108. }
  109. });
  110. btnData.setOnClickListener(new View.OnClickListener() {
  111.  
  112. @Override
  113. public void onClick(View v) {
  114. final Dialog dialog = new Dialog(Pengaturan.this);
  115. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  116. dialog.setContentView(R.layout.dialog_confirm);
  117.  
  118. TextView judul = (TextView) dialog.findViewById(R.id.txtJudul);
  119. TextView isi = (TextView) dialog.findViewById(R.id.txtIsi);
  120. Button btnOk = (Button) dialog.findViewById(R.id.button2);
  121. Button btnCancel = (Button) dialog.findViewById(R.id.button1);
  122.  
  123. judul.setText("Konfirmasi");
  124. isi.setText("Apakah anda yakin akan menghapus semua data?");
  125. dialog.show();
  126.  
  127. }
  128. });
  129. }
  130.  
  131. @Override
  132. public boolean onOptionsItemSelected(MenuItem item) {
  133. // Handle action bar item clicks here. The action bar will
  134. // automatically handle clicks on the Home/Up button, so long
  135. // as you specify a parent activity in AndroidManifest.xml.
  136. int id = item.getItemId();
  137. switch(id) {
  138. case android.R.id.home :
  139. this.finish();
  140. Intent i = new Intent(Pengaturan.this, MainActivity.class);
  141. startActivity(i);
  142. return true;
  143. }
  144. return super.onOptionsItemSelected(item);
  145. }
  146. @Override
  147. public void onBackPressed() {
  148. this.finish();
  149. Intent i = new Intent(Pengaturan.this, MainActivity.class);
  150. startActivity(i);
  151. super.onBackPressed();
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement