Advertisement
annisa27

login 2

Mar 1st, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. package com.dish.menu;
  2.  
  3. import android.os.AsyncTask;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.content.Intent;
  7. import java.util.ArrayList;
  8.  
  9. import org.apache.http.message.BasicNameValuePair;
  10. import org.json.JSONException;
  11. import org.json.JSONObject;
  12.  
  13. import com.dish.nama.Bayar;
  14. import com.dish.nama.Detail;
  15. import com.dish.nama.JSONParser;
  16. import com.dish.nama.Print;
  17. import com.dish.nama.R;
  18.  
  19. import android.app.Activity;
  20. import android.app.ProgressDialog;
  21. import android.content.Intent;
  22. import android.view.Menu;
  23. import android.view.View;
  24. import android.view.View.OnClickListener;
  25. import android.widget.Button;
  26. import android.widget.EditText;
  27. import android.widget.TextView;
  28. import android.widget.Toast;
  29.  
  30. public class LoginActivity extends Activity implements View.OnClickListener{
  31. // User name
  32. private EditText et_Username;
  33. // Password
  34. private EditText et_Password;
  35. // Sign In
  36. private Button bt_SignIn;
  37. // Message
  38. //private TextView tv_Message;
  39. String username;
  40. String password;
  41. String id;
  42. String hak_akses;
  43. String uname;
  44. String kode;
  45. String pwd;
  46. TextView login;
  47. private static String url_cari = "http://cavendish.esy.es/pdam/db_login.php";
  48.  
  49.  
  50. JSONParser jsonParser = new JSONParser();
  51. private ProgressDialog pDialog;
  52.  
  53.  
  54.  
  55. private static final String TAG_Loket = "Loket";
  56.  
  57. @Override
  58. protected void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.activity_login);
  61.  
  62. // Initialization
  63. et_Username = (EditText) findViewById(R.id.usernameET);
  64. et_Password = (EditText) findViewById(R.id.passwordET);
  65. bt_SignIn = (Button) findViewById(R.id.loginBtn);
  66.  
  67. bt_SignIn.setOnClickListener(this);
  68. }
  69.  
  70. @Override
  71. public void onClick(View v) {
  72. // TODO Auto-generated method stub
  73. // Stores User name
  74. username = String.valueOf(et_Username.getText());
  75. // Stores Password
  76. password = String.valueOf(et_Password.getText());
  77.  
  78. runOnUiThread(new Runnable() {
  79.  
  80. public void run() {
  81.  
  82. Toast.makeText(LoginActivity.this.getApplicationContext(), "a "+username+" " +password, 0).show();
  83.  
  84. }
  85. });
  86.  
  87. class Cari extends AsyncTask<String, String, String> {
  88.  
  89. protected String doInBackground(String[] paramArrayOfString) {
  90. try {
  91. ArrayList localArrayList = new ArrayList();
  92. // username = String.valueOf(et_Username.getText());
  93. // // Stores Password
  94. // password = String.valueOf(et_Password.getText());
  95. localArrayList.add(new BasicNameValuePair(username, password));
  96. //localArrayList.add(new BasicNameValuePair("Password", password));
  97. System.out.println(localArrayList);
  98. JSONObject localJSONObject1 = LoginActivity.this.jsonParser.makeHttpRequest(LoginActivity.url_cari, "GET",
  99. localArrayList);
  100. Log.d("Hasil", localJSONObject1.toString());
  101.  
  102. String aq = localJSONObject1.getString("message");
  103. if(aq.equals("Hasil Tidak Ditemukan1")){
  104. runOnUiThread(new Runnable() {
  105.  
  106. public void run() {
  107.  
  108. Toast.makeText(LoginActivity.this.getApplicationContext(), "a", 0).show();
  109.  
  110. }
  111. });
  112. }else{
  113. runOnUiThread(new Runnable() {
  114.  
  115. public void run() {
  116.  
  117. Toast.makeText(LoginActivity.this.getApplicationContext(), "b", 0).show();
  118.  
  119. }
  120. });
  121. }
  122.  
  123. if (localJSONObject1.getInt("success") == 1) {
  124. JSONObject localJSONObject2 = localJSONObject1.getJSONArray("Hasil").getJSONObject(0);
  125. LoginActivity.this.id = localJSONObject2.getString("ID");
  126. LoginActivity.this.uname = localJSONObject2.getString("Username");
  127. LoginActivity.this.pwd = localJSONObject2.getString("Password");
  128. LoginActivity.this.hak_akses = localJSONObject2.getString("HakAkses");
  129. LoginActivity.this.kode = localJSONObject2.getString("Kode");
  130. } else {
  131. //Toast.makeText(Bayar.this.getApplicationContext(), "Pelanggan Telah Membayar", 0).show();
  132. }
  133. } catch (JSONException localJSONException) {
  134. localJSONException.printStackTrace();
  135. }
  136. return null;
  137. }
  138. }
  139.  
  140. runOnUiThread(new Runnable() {
  141.  
  142. public void run() {
  143.  
  144. Toast.makeText(LoginActivity.this.getApplicationContext(), "a"+LoginActivity.this.uname, 0).show();
  145.  
  146. }
  147. });
  148. // Validates the User name and Password for admin, admin
  149. if (username.equals(LoginActivity.this.uname) && password.equals(LoginActivity.this.pwd)) {
  150. runOnUiThread(new Runnable() {
  151.  
  152. public void run() {
  153.  
  154. Toast.makeText(LoginActivity.this.getApplicationContext(), "Login Berhasil", 0).show();
  155.  
  156. }
  157. });
  158. Intent localIntent = new Intent(this, Maintenance.class);
  159. startActivity(localIntent);
  160. } else {
  161. runOnUiThread(new Runnable() {
  162.  
  163. public void run() {
  164.  
  165. Toast.makeText(LoginActivity.this.getApplicationContext(), "Login Gagal", 0).show();
  166.  
  167. }
  168. });
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement