1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.lekonquer.raoul.IMessage;
import com.lekonquer.raoul.connectdb.SendSMS;
import com.mobsandgeeks.saripaar.ValidationError;
import com.mobsandgeeks.saripaar.Validator;
import com.mobsandgeeks.saripaar.annotation.ConfirmPassword;
import com.mobsandgeeks.saripaar.annotation.Email;
import com.mobsandgeeks.saripaar.annotation.NotEmpty;
import com.mobsandgeeks.saripaar.annotation.Password;
import com.mobsandgeeks.saripaar.annotation.Pattern;
import org.json.JSONArray;
import java.util.List;
import java.util.Random;
/**
* Created by user on .
*/
public class SigninActivity extends AppCompatActivity implements Validator.ValidationListener, IMessage {
@NotEmpty
private EditText editTextName;
private EditText editTextFirstName;
@NotEmpty
@Email
private EditText editTextEmail;
@NotEmpty
@Pattern(regex = "^[2]\\d{4}\\d{4}$")
private EditText editPhoneNumber;
@NotEmpty
@Password
private EditText editTextPassword;
@NotEmpty
@ConfirmPassword
private EditText editTextConfirmPass;
private Validator validator;
private static final String INSERT_NEW_CODE = "https://xxxxx/yyy.php";
private JSONArray fOffersResult = null;
private SendSM fSendSM = new SendSM();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
initViews();
validator = new Validator(this);
validator.setValidationListener(this);
}
private void initViews(){
editTextName = (EditText) findViewById(R.id.textView);
editTextFirstName = (EditText) findViewById(R.id.textView5);
editTextEmail = (EditText) findViewById(R.id.textView7);
editPhoneNumber = (EditText) findViewById(R.id.textView6);
editTextPassword = (EditText) findViewById(R.id.textPassword);
editTextConfirmPass = (EditText) findViewById(R.id.textConfPassword);
}
public void signIn(View view) {
Log.i("test", "in button signin");
//validator.validate();
if(!SigninActivity.this.isFinishing()){
startActivity(new Intent(SigninActivity.this, ConfirmPhoneNumber.class));
}
}
@Override
public void onValidationSucceeded() {
Toast.makeText(this, "We got it right!", Toast.LENGTH_SHORT).show();
Log.w("validateSucceeded ", "before send sms");
//Gets the code
Random r = new Random();
int codetouse = r.nextInt(100000);
Log.w("code", ""+codetouse);
Toast.makeText(this, "Code to use:"+codetouse, Toast.LENGTH_SHORT).show();
}
@Override
public void onValidationFailed(List<ValidationError> errors) {
for (ValidationError error : errors) {
View view = error.getView();
String message = error.getCollatedErrorMessage(this);
// Display error messages
if (view instanceof EditText) {
((EditText) view).setError(message);
} else {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
}
@Override
public void getOffersResultPostExecute(int pReturnStatus, String pCalledUrl, JSONArray pOffers) {
}
} |
Partager