Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.villvatharisan.tmapp;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.Handler;
- import android.text.Editable;
- import android.text.TextUtils;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.example.villvatharisan.tmapp.Handler.HttpHandler;
- import com.example.villvatharisan.tmapp.Handler.link;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import java.util.HashMap;
- /**
- * Created by villvatharisan on 04/07/2018.
- */
- public class forgotPassword extends Activity {
- private Handler handler = new Handler();
- EditText email;
- Button proceed;
- ImageView back;
- TextView msgEmail,msgEmailTwo, general;
- String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]{2,3}+";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.forgot_password);
- general = findViewById(R.id.general_text);
- general.setVisibility(View.INVISIBLE);
- back = findViewById(R.id.back);
- back.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- Intent intent = new Intent(getApplicationContext(), loginActivity.class);
- startActivity(intent);
- return false;
- }
- });
- email = (EditText) findViewById(R.id.txt_email);
- msgEmail = findViewById(R.id.msgEmail);
- msgEmailTwo = findViewById(R.id.msgEmailTwo);
- proceed = findViewById(R.id.proceed);
- proceed.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String eml = email.getText().toString();
- Log.i("eml","eml " + eml);
- if (eml.isEmpty()){
- email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.inactive,0);
- msgEmail.setVisibility(View.VISIBLE);
- } else if (!eml.matches(emailPattern) && eml.length() > 0){
- msgEmail.setVisibility(View.GONE);
- msgEmailTwo.setVisibility(View.VISIBLE);
- } else {
- forgot_password(eml,forgotPassword.this);
- }
- }
- });
- email.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
- }
- @Override
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
- }
- @Override
- public void afterTextChanged(Editable editable) {
- String test = email.getText().toString();
- if (TextUtils.isEmpty(test)){
- email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.inactive,0);
- } else if (!test.matches(emailPattern) && editable.length() > 0){
- email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.cross_active,0);
- } else if (!TextUtils.isEmpty(test)){
- email.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.active,0);
- msgEmail.setVisibility(View.GONE);
- msgEmailTwo.setVisibility(View.GONE);
- }
- }
- });
- }
- public void forgot_password(final String emailAddress, final Activity activity) {
- class forgot_password extends AsyncTask<Void, Void, String> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(Void... params) {
- HttpHandler httpHandler = new HttpHandler();
- HashMap<String, String> data = new HashMap<>();
- data.put("email", emailAddress);
- String s = httpHandler.sendPostRequest(link.forgotPassword, data);
- return s;
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- try {
- Log.i("FP", "FP " + s);
- JSONObject jsonObject = new JSONObject(s);
- if (jsonObject.getInt("status") == 0) {
- String array = "";
- String Object = jsonObject.getString("msg");
- Log.i("Object", "Object " + Object);
- JSONArray jsonArray = new JSONArray(Object);
- for (int i = 0; i < jsonArray.length(); i++) {
- array = String.valueOf(jsonArray.get(0));
- Log.i("Object", "msg " + array);
- }
- TextView msg = new TextView(forgotPassword.this);
- msg.setPadding(100, 50, 100, 100);
- msg.setText("Email not found.");
- msg.setGravity(Gravity.CENTER);
- msg.setTextSize(16);
- DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_NEUTRAL) {
- finish();
- }
- }
- };
- AlertDialog.Builder builder = new AlertDialog.Builder(forgotPassword.this);
- builder.setView(msg);
- builder.setCancelable(true);
- AlertDialog dialog = builder.create();
- dialog.show();
- }else{
- TextView msg = new TextView(forgotPassword.this);
- msg.setPadding(100, 50, 100, 100);
- msg.setText("Reset password link has been send.");
- msg.setGravity(Gravity.CENTER);
- msg.setTextSize(16);
- AlertDialog.Builder builder = new AlertDialog.Builder(forgotPassword.this);
- builder.setView(msg);
- builder.setCancelable(true);
- AlertDialog dialog = builder.create();
- dialog.show();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(getApplicationContext(), loginActivity.class);
- startActivity(intent);
- }
- }, 2000);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- new forgot_password().execute();
- }
- public void info() {
- TextView title = new TextView(this);
- title.setGravity(Gravity.CENTER);
- title.setTextSize(15);
- TextView msg = new TextView(this);
- msg.setPadding(100, 50, 100, 100);
- msg.setText("Password reset link sent to email.");
- msg.setGravity(Gravity.CENTER);
- msg.setTextSize(25);
- DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_NEUTRAL) {
- finish();
- }
- }
- };
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setCustomTitle(title);
- builder.setView(msg);
- builder.setCancelable(true);
- AlertDialog dialog = builder.create();
- dialog.show();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(getApplicationContext(), loginActivity.class);
- startActivity(intent);
- }
- }, 5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement