Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. package com.example.naufal.restoapps_user;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.os.Bundle;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10. import android.widget.Toast;
  11.  
  12. import org.json.JSONException;
  13. import org.json.JSONObject;
  14.  
  15. import java.io.BufferedReader;
  16. import java.io.BufferedWriter;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.InputStreamReader;
  20. import java.io.OutputStream;
  21. import java.io.OutputStreamWriter;
  22. import java.net.HttpURLConnection;
  23. import java.net.MalformedURLException;
  24. import java.net.URL;
  25. import java.net.URLConnection;
  26. import java.net.URLEncoder;
  27.  
  28. /**
  29. * Created by Naufal on 1/2/2017.
  30. */
  31.  
  32. public class login_client extends AsyncTask<String,String,String> {
  33. EditText usernamelogin, passwordcx;
  34. Context context;
  35. String username="cxcx",passwor="cxcx",identitcx;
  36. login login=new login();TextView text;
  37. int client=0;
  38. public login_client(Context applicationContext,TextView textView) {
  39. this.context = applicationContext;
  40. this.text=textView;
  41. }
  42.  
  43. @Override
  44. protected void onProgressUpdate(String... values) {
  45. super.onProgressUpdate(values);
  46. Toast.makeText(context, "hmm...", Toast.LENGTH_SHORT).show();
  47. }
  48.  
  49. @Override
  50. protected String doInBackground(String... params) {
  51. String link = "http://nwebtekno.comxa.com/profilephone.php";
  52. String valuecx = "";
  53.  
  54. try {
  55. String username = namaclient();
  56. String password = passwclient();
  57. URL url = new URL(link);
  58. HttpURLConnection urlconection = (HttpURLConnection) url.openConnection();
  59. urlconection.setDoInput(true);
  60. urlconection.setDoOutput(true);
  61. urlconection.setRequestMethod("POST");
  62. OutputStream writer = urlconection.getOutputStream();
  63. BufferedWriter write = new BufferedWriter(new OutputStreamWriter(writer));
  64. String passing;
  65. passing = URLEncoder.encode("username") + "=";
  66. passing += username+"&";
  67.  
  68. passing += URLEncoder.encode("password")+"=" +
  69. password;
  70. write.write(passing);
  71. write.flush();
  72. InputStream input = urlconection.getInputStream();
  73. BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  74. String value = "";
  75. while ((value = reader.readLine()) != null) {
  76. valuecx += value;
  77. }
  78. } catch (MalformedURLException e) {
  79. e.printStackTrace();
  80. } catch (IOException e) {
  81. e.printStackTrace();
  82. }
  83.  
  84.  
  85. return valuecx;
  86. }
  87.  
  88. @Override
  89. protected void onPreExecute() {
  90. super.onPreExecute();
  91. Toast.makeText(context, "please cx", Toast.LENGTH_SHORT).show();
  92. }
  93.  
  94. @Override
  95. protected void onPostExecute(String s) {
  96. super.onPostExecute(s);
  97. String wellcome = s;
  98.  
  99. try {
  100.  
  101. JSONObject jsonObject=new JSONObject(s);
  102. int checkprofile=jsonObject.getInt("checkprofilecheck");
  103. if (checkprofile == 1) {
  104. String identitas=jsonObject.getString("identitas");
  105. text.setText(identitas);
  106. String cx= login.check(identitas);
  107. this.identitcx=identitas;
  108. Toast.makeText(context,"somnething cx"+checkprofile+"identitas"+identitas+""+cx,Toast.LENGTH_SHORT).show();
  109.  
  110. }else if(checkprofile==4){
  111. Toast.makeText(context,"somnething check something ",Toast.LENGTH_SHORT).show();
  112.  
  113. } else if(checkprofile==0){
  114. Toast.makeText(context, "server checkcx", Toast.LENGTH_SHORT).show();
  115.  
  116. }
  117. }catch(Exception e){
  118. Toast.makeText(context,"something "+e,Toast.LENGTH_SHORT).show();
  119. }
  120. }
  121. public void nama(String username){
  122. this.username=username;
  123. }
  124. public void passwor(String passwor){
  125. this.passwor=passwor;
  126. }
  127. public String namaclient(){
  128. return this.username;
  129. }
  130. public String passwclient() {
  131. return this.passwor;
  132. }
  133. public String identitas(){
  134. return this.identitcx;
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement