Advertisement
Guest User

login salah

a guest
Apr 4th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 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. Button login;
  60. private boolean doubleBackToExitPressedOnce;
  61. private Handler mHandler = new Handler();
  62.  
  63. JSONParser jsonParser = new JSONParser();
  64.  
  65. private static final String SUCCESS_TAG = "success";
  66. private static final String FAILED_TAG = "failed";
  67.  
  68. //ANNISA
  69. private EditText et_Username;
  70. // Password
  71. private EditText et_Password;
  72.  
  73. String username;
  74. String password;
  75. String id;
  76. String hak_akses;
  77. String uname;
  78. String kode;
  79. String pwd;
  80.  
  81. private static String url_cari = "http://cavendish.esy.es/pdam/db_login.php";
  82.  
  83. // JSONParser jsonParser = new JSONParser();
  84. private ProgressDialog pDialog;
  85.  
  86. //sharedpreference
  87. private SharedPreference sharedPreference;
  88. Activity context = this;
  89. Activity context2 = this;
  90. Activity context3 = this;
  91. Activity context4 = this;
  92. private String text;
  93. private String text2;
  94. private String text3;
  95. private Boolean status_login;
  96. int success;
  97.  
  98. private static final String TAG_Loket = "Loket";
  99.  
  100. class login extends AsyncTask<String, String, String> {
  101. /**
  102. * Menampilkan Progress Dialog
  103. */
  104.  
  105. String username;
  106. String password;
  107.  
  108. @Override
  109. protected void onPreExecute() {
  110. super.onPreExecute();
  111. pDialog = new ProgressDialog(Login.this);
  112. pDialog.setMessage("Autentikasi . . . ");
  113. pDialog.setIndeterminate(false);
  114. pDialog.setCancelable(true);
  115. pDialog.show();
  116. }
  117.  
  118. public login(String username, String password){
  119.  
  120. this.username = username;
  121. this.password = password;
  122. }
  123.  
  124. /**
  125. * Menyimpan Data
  126. */
  127. protected String doInBackground(String... args) {
  128. //int success;
  129. try{
  130. //build parameter
  131. List<NameValuePair> parameter = new ArrayList<NameValuePair>();
  132. parameter.add(new BasicNameValuePair("Username", username));
  133. parameter.add(new BasicNameValuePair("Password", password));
  134.  
  135. //log watching
  136. Log.d("request", "starting");
  137.  
  138. //create connection http
  139. JSONObject jsonObject = jsonParser.makeHttpRequest(url_cari, "GET", parameter);
  140.  
  141. //log json respond
  142. Log.d("request", jsonObject.toString());
  143. //json usccess tag
  144. success = jsonObject.getInt(SUCCESS_TAG);
  145.  
  146. if(success == 1){
  147. Log.d("request", "Login Success"+jsonObject.toString());
  148. if (jsonObject.getInt("success") == 1) {
  149. JSONObject localJSONObject2 = jsonObject.getJSONArray("Hasil").getJSONObject(0);
  150. Login.this.id = localJSONObject2.getString("ID");
  151. Login.this.uname = localJSONObject2.getString("Username");
  152. Login.this.pwd = localJSONObject2.getString("Password");
  153. Login.this.hak_akses = localJSONObject2.getString("HakAkses");
  154. Login.this.kode = localJSONObject2.getString("Kode");
  155.  
  156. text = Login.this.kode;
  157. text2 = Login.this.hak_akses;
  158. text3 = Login.this.uname;
  159. sharedPreference.save(context, text);
  160. sharedPreference.save(context2, text2);
  161. sharedPreference.save(context3, text3);
  162. } else {
  163.  
  164. }
  165. runOnUiThread(new Runnable() {
  166.  
  167. public void run() {
  168.  
  169. Toast.makeText(Login.this.getApplicationContext(), "Login Berhasil", 0).show();
  170.  
  171. }
  172. });
  173. }else{
  174. runOnUiThread(new Runnable() {
  175.  
  176. public void run() {
  177.  
  178. Toast.makeText(Login.this.getApplicationContext(), "GAGAL", 0).show();
  179.  
  180. }
  181. });
  182. Log.d("request", jsonObject.getString(FAILED_TAG));
  183. }
  184.  
  185. } catch (JSONException e) {
  186. e.printStackTrace();
  187. }
  188. return null;
  189. }
  190.  
  191. /**
  192. * Setalah selesai dialog menghilang
  193. **/
  194. protected void onPostExecute(String file_url) {
  195. super.onPostExecute(file_url);
  196. pDialog.dismiss();
  197. }
  198. }
  199.  
  200. public void onClick(View arg0) {
  201.  
  202. }
  203.  
  204. protected void onCreate(Bundle paramBundle) {
  205. super.onCreate(paramBundle);
  206. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  207.  
  208. //Remove notification bar
  209. this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  210. setContentView(R.layout.login);
  211.  
  212. //sharedpreferences
  213. sharedPreference = new SharedPreference();
  214.  
  215. // Initialization
  216. et_Username = (EditText) findViewById(R.id.ed_dialog_cari);
  217. et_Password = (EditText) findViewById(R.id.editText2);
  218.  
  219. this.login = ((Button) findViewById(R.id.btn_dialog_cari));
  220. this.login.setOnClickListener(new View.OnClickListener() {
  221.  
  222. @Override
  223. public void onClick(View v) {
  224. // TODO Auto-generated method stub
  225. new login(et_Username.getText().toString(), et_Password.getText().toString()).execute();
  226. //yg ini langsung, kalau gagal harusnya tetap di halaman login tapi masih belum
  227. Intent localIntent = new Intent(v.getContext(),MainMenu.class);
  228. // localIntent(this, MainMenu.class);
  229. localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  230. startActivity(localIntent);
  231. runOnUiThread(new Runnable() {
  232.  
  233. public void run() {
  234.  
  235. Toast.makeText(Login.this.getApplicationContext(), "Username: "+text3, 0).show();
  236.  
  237. }
  238. });
  239. // if(success==1){
  240. // Intent localIntent = new Intent(v.getContext(),MainMenu.class);
  241. // // localIntent(this, MainMenu.class);
  242. // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  243. // startActivity(localIntent);
  244. // runOnUiThread(new Runnable() {
  245. //
  246. // public void run() {
  247. //
  248. // Toast.makeText(Login.this.getApplicationContext(), "Username: "+text3, 0).show();
  249. //
  250. // }
  251. // });
  252. // }else if(success==0){
  253. // Intent localIntent = new Intent(v.getContext(),Login.class);
  254. // // localIntent(this, MainMenu.class);
  255. // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  256. // startActivity(localIntent);
  257. // runOnUiThread(new Runnable() {
  258. //
  259. // public void run() {
  260. //
  261. // Toast.makeText(Login.this.getApplicationContext(), "Username dan Pass salah ", 0).show();
  262. //
  263. // }
  264. // });
  265. // }
  266. // else{
  267. // runOnUiThread(new Runnable() {
  268. //
  269. // public void run() {
  270. //
  271. // Toast.makeText(Login.this.getApplicationContext(), "beneran gagal nih ", 0).show();
  272. //
  273. // }
  274. // });
  275. // }
  276.  
  277. }
  278.  
  279. private void localIntent(OnClickListener onClickListener, Class<MainMenu> class1) {
  280. // TODO Auto-generated method stub
  281.  
  282. }
  283. });
  284.  
  285. }
  286.  
  287. private final Runnable mRunnable = new Runnable() {
  288. @Override
  289. public void run() {
  290. doubleBackToExitPressedOnce = false;
  291. }
  292. };
  293.  
  294. @Override
  295. protected void onDestroy()
  296. {
  297. super.onDestroy();
  298. finish ();
  299. if (mHandler != null) { mHandler.removeCallbacks(mRunnable); }
  300.  
  301. }
  302.  
  303. @Override
  304. public void onBackPressed() {
  305. if (doubleBackToExitPressedOnce) {
  306. super.onBackPressed();
  307. return;
  308. }
  309.  
  310. this.doubleBackToExitPressedOnce = true;
  311. Toast.makeText(this, "Tekan tombol back lagi untuk keluar", Toast.LENGTH_SHORT).show();
  312.  
  313. mHandler.postDelayed(mRunnable, 2000);
  314. }
  315.  
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement