Advertisement
annisa27

123

Mar 15th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1. package com.dish.menu;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.graphics.Color;
  6. import android.graphics.drawable.ColorDrawable;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.view.View;
  10. import android.view.Window;
  11. import android.view.WindowManager;
  12. import android.widget.Button;
  13. import android.widget.Toast;
  14.  
  15. import com.dish.menu.Login.login;
  16. import com.dish.nama.Awal;
  17. import com.dish.nama.JSONParser;
  18. import com.dish.nama.MainMenu;
  19. import com.dish.nama.R;
  20.  
  21. import android.os.AsyncTask;
  22. import android.os.Bundle;
  23. import android.util.Log;
  24. import android.content.Intent;
  25. import android.content.SharedPreferences;
  26. import android.content.SharedPreferences.Editor;
  27.  
  28. import java.util.ArrayList;
  29. import java.util.List;
  30.  
  31. import org.apache.http.NameValuePair;
  32. import org.apache.http.message.BasicNameValuePair;
  33. import org.json.JSONException;
  34. import org.json.JSONObject;
  35.  
  36. import com.dish.sharedpreferences.SharedPreference;
  37. import com.dish.nama.Bayar;
  38. import com.dish.nama.Detail;
  39. import com.dish.nama.Edit;
  40. import com.dish.nama.JSONParser;
  41. import com.dish.nama.MainActivity;
  42. import com.dish.nama.Next;
  43. import com.dish.nama.Print;
  44. import com.dish.nama.R;
  45.  
  46. import android.app.Activity;
  47. import android.app.ProgressDialog;
  48. import android.content.Intent;
  49. import android.view.Menu;
  50.  
  51. import android.view.View.OnClickListener;
  52.  
  53. import android.widget.EditText;
  54. import android.widget.TextView;
  55.  
  56.  
  57. public class Login extends Activity implements View.OnClickListener {
  58.  
  59.  
  60. Button login;
  61. private boolean doubleBackToExitPressedOnce;
  62. private Handler mHandler = new Handler();
  63.  
  64.  
  65. //EditText nama, no_samb, no_pin, status1, status2, status3;
  66. JSONParser jsonParser = new JSONParser();
  67.  
  68. //ANNISA
  69. private EditText et_Username;
  70. // Password
  71. private EditText et_Password;
  72. // Sign In
  73. // private Button bt_SignIn;
  74. // Message
  75. //private TextView tv_Message;
  76. String username;
  77. String password;
  78. String id;
  79. String hak_akses;
  80. String uname;
  81. String kode;
  82. String pwd;
  83. // TextView login;
  84. // String [] data;
  85. private static String url_cari = "http://cavendish.esy.es/pdam/db_login.php";
  86.  
  87.  
  88. // JSONParser jsonParser = new JSONParser();
  89. private ProgressDialog pDialog;
  90.  
  91. //sharedpreference
  92. private SharedPreference sharedPreference;
  93. Activity context = this;
  94. Activity context2 = this;
  95. Activity context3 = this;
  96. Activity context4 = this;
  97. private String text;
  98. private String text2;
  99. private String text3;
  100. private Boolean status_login;
  101.  
  102. private static final String TAG_Loket = "Loket";
  103.  
  104. class login extends AsyncTask<String, String, String> {
  105. /**
  106. * Menampilkan Progress Dialog
  107. */
  108.  
  109. String username;
  110. String password;
  111.  
  112. @Override
  113. protected void onPreExecute() {
  114. super.onPreExecute();
  115. pDialog = new ProgressDialog(Login.this);
  116. pDialog.setMessage("Autentikasi . . . ");
  117. pDialog.setIndeterminate(false);
  118. pDialog.setCancelable(true);
  119. pDialog.show();
  120. }
  121.  
  122. public login(String username, String password){
  123.  
  124. this.username = username;
  125. this.password = password;
  126. runOnUiThread(new Runnable() {
  127.  
  128. public void run() {
  129.  
  130. Toast.makeText(Login.this.getApplicationContext(), "Masuk Asynctask", 0).show();
  131.  
  132. }
  133. });
  134. runOnUiThread(new Runnable() {
  135.  
  136. public void run() {
  137.  
  138. Toast.makeText(Login.this.getApplicationContext(), "Ini di class login Async: "+Login.this.username, 0).show();
  139.  
  140. }
  141. });
  142. }
  143.  
  144. /**
  145. * Menyimpan Data
  146. */
  147. protected String doInBackground(String... args) {
  148. // String username = et_Username.getText().toString();
  149. // String password = et_Password.getText().toString();
  150.  
  151. runOnUiThread(new Runnable() {
  152.  
  153. public void run() {
  154.  
  155. Toast.makeText(Login.this.getApplicationContext(), "Masuk DoInBackground", 0).show();
  156.  
  157. }
  158. });
  159.  
  160. try {
  161. ArrayList localArrayList = new ArrayList();
  162. localArrayList.add(new BasicNameValuePair("Username", Login.this.username));
  163. localArrayList.add(new BasicNameValuePair("Password", Login.this.password));
  164. System.out.println(localArrayList);
  165. JSONObject localJSONObject1 = Login.this.jsonParser.makeHttpRequest(Login.url_cari, "GET",
  166. localArrayList);
  167. Log.d("Hasil", localJSONObject1.toString());
  168. if (localJSONObject1.getInt("success") == 1) {
  169. JSONObject localJSONObject2 = localJSONObject1.getJSONArray("Hasil").getJSONObject(0);
  170. Login.this.id = localJSONObject2.getString("ID");
  171. Login.this.uname = localJSONObject2.getString("Username");
  172. Login.this.pwd = localJSONObject2.getString("Password");
  173. Login.this.hak_akses = localJSONObject2.getString("HakAkses");
  174. Login.this.kode = localJSONObject2.getString("Kode");
  175.  
  176. } else {
  177. //Toast.makeText(Bayar.this.getApplicationContext(), "Pelanggan Telah Membayar", 0).show();
  178. }
  179. runOnUiThread(new Runnable() {
  180.  
  181. public void run() {
  182.  
  183. Toast.makeText(Login.this.getApplicationContext(), "doinbackground "+uname, 0).show();
  184.  
  185. }
  186. });
  187. } catch (JSONException localJSONException) {
  188. localJSONException.printStackTrace();
  189. }
  190. return null;
  191. }
  192.  
  193. /**
  194. * Setalah selesai dialog menghilang
  195. **/
  196. protected void onPostExecute(String file_url) {
  197. // menutup progres dialog jika sudah selesai
  198. // super.onPostExecute(file_url);
  199. pDialog.dismiss();
  200. }
  201. }
  202.  
  203. public void onClick(View arg0) {
  204. // Stores User name
  205. username = String.valueOf(et_Username.getText());
  206. // Stores Password
  207. password = String.valueOf(et_Password.getText());
  208.  
  209. // switch (arg0.getId()) {
  210. // case R.id.btn_dialog_cari:
  211. if(text==null){
  212. new login(et_Username.getText().toString(), et_Password.getText().toString()).execute();
  213. // login a = new login();
  214.  
  215. // Validates the User name and Password for admin, admin
  216. if (username.equals(this.uname) && password.equals(this.pwd)) {
  217.  
  218. // Save the text in SharedPreference
  219. text = this.kode;
  220. text2 = this.hak_akses;
  221. text3 = this.username;
  222. sharedPreference.save(context, text);
  223. sharedPreference.save(context2, text2);
  224. sharedPreference.save(context3, text3);
  225.  
  226. runOnUiThread(new Runnable() {
  227.  
  228. public void run() {
  229.  
  230. Toast.makeText(Login.this.getApplicationContext(), "Login Berhasil: "+text3, 0).show();
  231.  
  232. }
  233. });
  234.  
  235. Intent localIntent = new Intent(this, MainMenu.class);
  236. localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  237. startActivity(localIntent);
  238. runOnUiThread(new Runnable() {
  239.  
  240. public void run() {
  241.  
  242. Toast.makeText(Login.this.getApplicationContext(), "sharedpreference "+text3, 0).show();
  243.  
  244. }
  245. });
  246. // finish();
  247. } else {
  248. runOnUiThread(new Runnable() {
  249.  
  250. public void run() {
  251.  
  252. Toast.makeText(Login.this.getApplicationContext(), "Layar "+username+" database "+uname, 0).show();
  253.  
  254. }
  255. });
  256. runOnUiThread(new Runnable() {
  257.  
  258. public void run() {
  259.  
  260. Toast.makeText(Login.this.getApplicationContext(), "Login Gagal "+text3, 0).show();
  261.  
  262. }
  263. });
  264. }
  265. }else{
  266. Intent localIntent = new Intent(this, MainMenu.class);
  267. localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  268. startActivity(localIntent);
  269. }
  270. //---------------------------
  271. // Intent localIntent = new Intent(this, MainMenu.class);
  272. // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  273. // startActivity(localIntent);
  274. // finish();
  275. // break;}
  276. }
  277.  
  278. protected void onCreate(Bundle paramBundle) {
  279. super.onCreate(paramBundle);
  280. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  281.  
  282. //Remove notification bar
  283. this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  284. setContentView(R.layout.login);
  285.  
  286. //sharedpreferences
  287. sharedPreference = new SharedPreference();
  288.  
  289. // Initialization
  290. et_Username = (EditText) findViewById(R.id.ed_dialog_cari);
  291. et_Password = (EditText) findViewById(R.id.editText2);
  292. // bt_SignIn = (Button) findViewById(R.id.btn_dialog_cari);
  293.  
  294. this.login = ((Button) findViewById(R.id.btn_dialog_cari));
  295. this.login.setOnClickListener(this);
  296.  
  297. }
  298.  
  299. private final Runnable mRunnable = new Runnable() {
  300. @Override
  301. public void run() {
  302. doubleBackToExitPressedOnce = false;
  303. }
  304. };
  305.  
  306. @Override
  307. protected void onDestroy()
  308. {
  309. super.onDestroy();
  310. finish ();
  311. if (mHandler != null) { mHandler.removeCallbacks(mRunnable); }
  312.  
  313. }
  314.  
  315. @Override
  316. public void onBackPressed() {
  317. if (doubleBackToExitPressedOnce) {
  318. super.onBackPressed();
  319. return;
  320. }
  321.  
  322. this.doubleBackToExitPressedOnce = true;
  323. Toast.makeText(this, "Tekan tombol back lagi untuk keluar", Toast.LENGTH_SHORT).show();
  324.  
  325. mHandler.postDelayed(mRunnable, 2000);
  326.  
  327.  
  328. }
  329.  
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement