Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. package com.example.villvatharisan.tmapp;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.os.AsyncTask;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.text.Editable;
  11. import android.text.TextUtils;
  12. import android.text.TextWatcher;
  13. import android.util.Log;
  14. import android.view.Gravity;
  15. import android.view.MotionEvent;
  16. import android.view.View;
  17. import android.widget.Button;
  18. import android.widget.EditText;
  19. import android.widget.ImageView;
  20. import android.widget.TextView;
  21.  
  22. import com.example.villvatharisan.tmapp.Handler.HttpHandler;
  23. import com.example.villvatharisan.tmapp.Handler.link;
  24.  
  25. import org.json.JSONArray;
  26. import org.json.JSONObject;
  27.  
  28. import java.util.HashMap;
  29.  
  30. /**
  31. * Created by villvatharisan on 04/07/2018.
  32. */
  33.  
  34. public class forgotPassword extends Activity {
  35.  
  36. private Handler handler = new Handler();
  37.  
  38. EditText email;
  39. Button proceed;
  40. ImageView back;
  41. TextView msgEmail,msgEmailTwo, general;
  42.  
  43. String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]{2,3}+";
  44.  
  45. @Override
  46. protected void onCreate(Bundle savedInstanceState) {
  47. super.onCreate(savedInstanceState);
  48. setContentView(R.layout.forgot_password);
  49.  
  50. general = findViewById(R.id.general_text);
  51. general.setVisibility(View.INVISIBLE);
  52.  
  53. back = findViewById(R.id.back);
  54. back.setOnTouchListener(new View.OnTouchListener() {
  55. @Override
  56. public boolean onTouch(View view, MotionEvent motionEvent) {
  57.  
  58. Intent intent = new Intent(getApplicationContext(), loginActivity.class);
  59. startActivity(intent);
  60. return false;
  61. }
  62. });
  63.  
  64. email = (EditText) findViewById(R.id.txt_email);
  65. msgEmail = findViewById(R.id.msgEmail);
  66. msgEmailTwo = findViewById(R.id.msgEmailTwo);
  67.  
  68. proceed = findViewById(R.id.proceed);
  69. proceed.setOnClickListener(new View.OnClickListener() {
  70. @Override
  71. public void onClick(View view) {
  72.  
  73. String eml = email.getText().toString();
  74. Log.i("eml","eml " + eml);
  75.  
  76. if (eml.isEmpty()){
  77.  
  78. email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.inactive,0);
  79. msgEmail.setVisibility(View.VISIBLE);
  80.  
  81. } else if (!eml.matches(emailPattern) && eml.length() > 0){
  82.  
  83. msgEmail.setVisibility(View.GONE);
  84. msgEmailTwo.setVisibility(View.VISIBLE);
  85.  
  86. } else {
  87.  
  88. forgot_password(eml,forgotPassword.this);
  89.  
  90. }
  91.  
  92. }
  93. });
  94.  
  95. email.addTextChangedListener(new TextWatcher() {
  96. @Override
  97. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  98. }
  99.  
  100. @Override
  101. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  102. }
  103.  
  104. @Override
  105. public void afterTextChanged(Editable editable) {
  106. String test = email.getText().toString();
  107. if (TextUtils.isEmpty(test)){
  108.  
  109. email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.inactive,0);
  110.  
  111. } else if (!test.matches(emailPattern) && editable.length() > 0){
  112.  
  113. email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.cross_active,0);
  114.  
  115. } else if (!TextUtils.isEmpty(test)){
  116.  
  117. email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.active,0);
  118. msgEmail.setVisibility(View.GONE);
  119. msgEmailTwo.setVisibility(View.GONE);
  120.  
  121. }
  122. }
  123. });
  124. }
  125.  
  126. public void forgot_password(final String emailAddress, final Activity activity) {
  127.  
  128. class forgot_password extends AsyncTask<Void, Void, String> {
  129.  
  130. @Override
  131. protected void onPreExecute() {
  132. super.onPreExecute();
  133. }
  134.  
  135. @Override
  136. protected String doInBackground(Void... params) {
  137.  
  138. HttpHandler httpHandler = new HttpHandler();
  139.  
  140. HashMap<String, String> data = new HashMap<>();
  141. data.put("email", emailAddress);
  142.  
  143. String s = httpHandler.sendPostRequest(link.forgotPassword, data);
  144. return s;
  145. }
  146.  
  147. @Override
  148. protected void onPostExecute(String s) {
  149. super.onPostExecute(s);
  150.  
  151. try {
  152. Log.i("FP", "FP " + s);
  153. JSONObject jsonObject = new JSONObject(s);
  154. if (jsonObject.getInt("status") == 0) {
  155.  
  156. String array = "";
  157. String Object = jsonObject.getString("msg");
  158. Log.i("Object", "Object " + Object);
  159. JSONArray jsonArray = new JSONArray(Object);
  160. for (int i = 0; i < jsonArray.length(); i++) {
  161.  
  162. array = String.valueOf(jsonArray.get(0));
  163. Log.i("Object", "msg " + array);
  164.  
  165. }
  166.  
  167. TextView msg = new TextView(forgotPassword.this);
  168. msg.setPadding(100, 50, 100, 100);
  169. msg.setText("Email not found.");
  170. msg.setGravity(Gravity.CENTER);
  171. msg.setTextSize(16);
  172.  
  173. DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {
  174.  
  175. public void onClick(DialogInterface dialog, int which) {
  176. if (which == DialogInterface.BUTTON_NEUTRAL) {
  177. finish();
  178. }
  179. }
  180.  
  181. };
  182.  
  183. AlertDialog.Builder builder = new AlertDialog.Builder(forgotPassword.this);
  184. builder.setView(msg);
  185. builder.setCancelable(true);
  186.  
  187. AlertDialog dialog = builder.create();
  188. dialog.show();
  189.  
  190. }else{
  191. TextView msg = new TextView(forgotPassword.this);
  192. msg.setPadding(100, 50, 100, 100);
  193. msg.setText("Reset password link has been send.");
  194. msg.setGravity(Gravity.CENTER);
  195. msg.setTextSize(16);
  196.  
  197. AlertDialog.Builder builder = new AlertDialog.Builder(forgotPassword.this);
  198. builder.setView(msg);
  199. builder.setCancelable(true);
  200.  
  201. AlertDialog dialog = builder.create();
  202. dialog.show();
  203.  
  204. handler.postDelayed(new Runnable() {
  205. @Override
  206. public void run() {
  207.  
  208. Intent intent = new Intent(getApplicationContext(), loginActivity.class);
  209. startActivity(intent);
  210. }
  211. }, 2000);
  212.  
  213.  
  214. }
  215. } catch (Exception e) {
  216. e.printStackTrace();
  217. }
  218. }
  219. }
  220. new forgot_password().execute();
  221. }
  222.  
  223. public void info() {
  224.  
  225. TextView title = new TextView(this);
  226. title.setGravity(Gravity.CENTER);
  227. title.setTextSize(15);
  228.  
  229. TextView msg = new TextView(this);
  230. msg.setPadding(100, 50, 100, 100);
  231. msg.setText("Password reset link sent to email.");
  232. msg.setGravity(Gravity.CENTER);
  233. msg.setTextSize(25);
  234.  
  235. DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {
  236.  
  237. public void onClick(DialogInterface dialog, int which) {
  238. if (which == DialogInterface.BUTTON_NEUTRAL) {
  239. finish();
  240. }
  241. }
  242.  
  243. };
  244.  
  245. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  246. builder.setCustomTitle(title);
  247. builder.setView(msg);
  248. builder.setCancelable(true);
  249.  
  250. AlertDialog dialog = builder.create();
  251. dialog.show();
  252.  
  253. handler.postDelayed(new Runnable() {
  254. @Override
  255. public void run() {
  256.  
  257. Intent intent = new Intent(getApplicationContext(), loginActivity.class);
  258. startActivity(intent);
  259. }
  260. }, 5000);
  261.  
  262. }
  263.  
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement