Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1.     private class SendLoginData extends AsyncTask<String, Void, String> {
  2.  
  3.         private ProgressDialog pDialog;
  4.  
  5.         @Override
  6.         protected void onPreExecute() {
  7.             super.onPreExecute();
  8.             pDialog = new ProgressDialog(LoginActivity.this);
  9.             pDialog.setMessage("Please wait...");
  10.             pDialog.setCancelable(false);
  11.             pDialog.show();
  12.         }
  13.  
  14.         @SuppressWarnings("deprecation")
  15.         @Override
  16.         protected String doInBackground(String... arg) {
  17.             String username = arg[0];
  18.             String password = arg[1];
  19.  
  20.             List<NameValuePair> params = new ArrayList<NameValuePair>();
  21.             params.add(new BasicNameValuePair("username", username));
  22.             params.add(new BasicNameValuePair("password", password));
  23.             ServiceHandler serviceClient = new ServiceHandler();
  24.             String json = serviceClient.makeServiceCall(API_LOGIN, ServiceHandler.POST, params);
  25.             Log.d("Cek-json","json: " + json);
  26.  
  27.             String permission = null;
  28.             String status = null;
  29.             if (json != null) {
  30.                 try {
  31.                     JSONObject jsonObj = new JSONObject(json);
  32.                     permission = jsonObj.getString("GroupPermission");
  33.                     status = jsonObj.getString("status");
  34.                 } catch (JSONException e) {
  35.                     e.printStackTrace();
  36.                 }
  37.  
  38.             } else {
  39.                 Log.e("JSON Data", "Didn't receive any data from server!");
  40.             }
  41.  
  42.             Log.d("Cek-json","result: " + permission);
  43.             return status;
  44.         }
  45.  
  46.         @Override
  47.         protected void onPostExecute(String result) {
  48.             if (pDialog.isShowing())
  49.                 pDialog.dismiss();
  50.  
  51.             if (result.equals("sukses")) {
  52.                 Intent intent = new Intent(LoginActivity.this, MenuActivity.class);
  53.                 intent.putExtra("USERNAME", mUsername);
  54.                 startActivity(intent);
  55.             } else {
  56.                 Toast.makeText(getApplication(), "Username/Password tidak valid", Toast.LENGTH_LONG).show();
  57.             }
  58.  
  59.         }
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement