Guest User

code

a guest
Oct 26th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. package com.inzenjer.inzenjerstaffportal1;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14. import com.android.volley.DefaultRetryPolicy;
  15. import com.android.volley.Request;
  16. import com.android.volley.RequestQueue;
  17. import com.android.volley.Response;
  18. import com.android.volley.VolleyError;
  19. import com.android.volley.toolbox.StringRequest;
  20. import com.android.volley.toolbox.Volley;
  21. import com.inzenjer.inzenjerstaffportal1.configs.Config;
  22.  
  23. import org.json.JSONArray;
  24. import org.json.JSONException;
  25. import org.json.JSONObject;
  26.  
  27. import java.util.HashMap;
  28. import java.util.Map;
  29.  
  30. public class AppMain extends AppCompatActivity {
  31. private String username, password;
  32. Button login;
  33. TextView fgt;
  34. EditText tusername, tPassword;
  35. ProgressDialog pg;
  36. String status;
  37. TextView txt;
  38.  
  39. @Override
  40. protected void onCreate(Bundle savedInstanceState) {
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.activity_app_main);
  43. login = (Button) findViewById(R.id.loginid);
  44. tusername = (EditText) findViewById(R.id.email_username);
  45. tPassword = (EditText) findViewById(R.id.passwordid);
  46. fgt = (TextView) findViewById(R.id.forgetpossword);
  47. //txt = (TextView) findViewById(R.id.username_dis);
  48.  
  49. login.setOnClickListener(new View.OnClickListener() {
  50. @Override
  51. public void onClick(View view) {
  52. signin();
  53. ;
  54. }
  55. });
  56.  
  57. fgt.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View view) {
  60. fgtpassword();
  61. }
  62. });
  63. }
  64.  
  65. private void signin() {
  66. Config.Email = tusername.getText().toString().trim();
  67. pg = ProgressDialog.show(AppMain.this, "Please wait...", "Fetching...", false, false);
  68. RequestQueue queue = Volley.newRequestQueue(AppMain.this);
  69. String response = "";
  70. final String finalResponse = response;
  71. String S_URL = "https://inzenjerdemo.000webhostapp.com/login.php"; //here url is not passing
  72. StringRequest postRequest = new StringRequest(Request.Method.POST, S_URL,
  73. new Response.Listener<String>() {
  74. @Override
  75. public void onResponse(String response) {
  76.  
  77. pg.dismiss();
  78. //String sm = response.toString();
  79.  
  80. try {
  81. JSONObject jsonObject = new JSONObject(response);
  82. JSONArray result = jsonObject.getJSONArray("result");
  83. JSONObject employee = result.getJSONObject(1);
  84. status = employee.getString("status");
  85. Config.Name = employee.getString("Name");
  86.  
  87. try {
  88. Config.Mobile = employee.getString("Mobile");
  89. } catch (Exception e) {
  90.  
  91. }
  92. try {
  93. Config.Photo = employee.getString("photo");
  94. } catch (Exception e) {
  95.  
  96. }
  97.  
  98. //TODO try catch from exeptions
  99.  
  100. Toast.makeText(AppMain.this, Config.Name + " " + Config.Photo + " " + Config.Mobile, Toast.LENGTH_SHORT).show();
  101. //Toast.makeText(AppMain.this, response, Toast.LENGTH_SHORT).show();
  102. //Toast.makeText(AppMain.this, status, Toast.LENGTH_SHORT).show();
  103. // View inflatedView = getLayoutInflater().inflate(R.layout.content_home, null);
  104. // TextView text = (TextView) inflatedView.findViewById(R.id.username_dis);
  105. // text.setText(Config.Name);
  106. //Toast.makeText(AppMain.this, sm , Toast.LENGTH_SHORT).show();
  107. //Toast.makeText(AppMain.this, status, Toast.LENGTH_SHORT).show();
  108.  
  109.  
  110. } catch (JSONException e) {
  111. Toast.makeText(AppMain.this, e.toString(), Toast.LENGTH_SHORT).show();
  112. e.printStackTrace();
  113. }
  114. if (status.equals("sucess")) {
  115.  
  116. Intent i = new Intent(AppMain.this, Home.class);
  117. startActivity(i);
  118.  
  119.  
  120. }
  121. if (status.equals("Fail")) {
  122.  
  123. Toast.makeText(AppMain.this, "No User ", Toast.LENGTH_SHORT).show();
  124.  
  125. }
  126. }
  127. },
  128. new Response.ErrorListener() {
  129. @Override
  130. public void onErrorResponse(VolleyError error) {
  131. // error
  132. Log.e("ErrorResponse", finalResponse);
  133. Toast.makeText(AppMain.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
  134.  
  135.  
  136. }
  137. }
  138. ) {
  139. @Override
  140. protected Map<String, String> getParams() {
  141. Map<String, String> params = new HashMap<String, String>();
  142.  
  143.  
  144. params.put("FirstName", tusername.getText().toString());//here username passing
  145. params.put("Password", tPassword.getText().toString());//and password is
  146.  
  147. return params;
  148. }
  149. };
  150. postRequest.setRetryPolicy(new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  151. queue.add(postRequest);
  152. }
  153.  
  154. private void fgtpassword() {
  155. Intent i = new Intent(AppMain.this, forgetpassword.class);
  156. startActivity(i);
  157. }
  158. }
Add Comment
Please, Sign In to add comment