Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.avinash.myapplication;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.android.volley.AuthFailureError;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.VolleyLog;
- import com.android.volley.toolbox.JsonObjectRequest;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import com.google.android.gms.appindexing.Action;
- import com.google.android.gms.appindexing.AppIndex;
- import com.google.android.gms.common.api.GoogleApiClient;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- import java.util.Map;
- public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
- //Keys to send username, password, phone and otp
- public static final String KEY_SALUTATION = "salutation";
- public static final String KEY_FIRSTNAME = "fname";
- public static final String KEY_SURNAME = "surname";
- public static final String KEY_MOBILE_NO = "mobno";
- public static final String KEY_DOB = "dob";
- public static final String KEY_NATIONALITY = "nationality";
- public static final String KEY_USERNAME = "username";
- public static final String KEY_EMAIL = "email";
- public static final String KEY_PASSWORD = "password";
- public static final String KEY_CONFEDENTIAL = "confedential";
- public static final String KEY_DEVICETOKEN = "device_token";
- public static final String KEY_LOGINTYPE = "login_type";
- private EditText editTextConfirmOtp;
- private Button buttonConfirm;
- private RequestQueue requestQueue;
- private EditText editTextSalutation;
- private EditText editTextUserName;
- private EditText editTextFirstname;
- private EditText editTextSurname;
- private EditText editTextEmail;
- private EditText editTextMob_no;
- private EditText editTextDob;
- private EditText editTextNationality;
- private EditText editTextPassword;
- private String salutation,fname,surname,mobno,dob,nationality,username,email,password;
- private String confedential = "private";
- private String device_token="aswert1234";
- private String login_type="0";
- private static String TAG = RegisterActivity.class.getSimpleName();
- private Button buttonSubmit;
- private GoogleApiClient client;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- TextView registerScreen = (TextView) findViewById(R.id.link_to_login);
- // Listening to register new account link
- registerScreen.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Switching to Register screen
- Intent i = new Intent(getApplicationContext(), HelpingActivity.class);
- startActivity(i);
- }
- });
- // ================= Register Vadiation Code Here ============================
- editTextSalutation = (EditText) findViewById(R.id.editText_fname);
- editTextFirstname = (EditText) findViewById(R.id.textEmail);
- editTextSurname = (EditText) findViewById(R.id.editText_password);
- editTextUserName = (EditText) findViewById(R.id.edittxt_cnfrmpassword);
- editTextPassword = (EditText) findViewById(R.id.edit_pswd);
- editTextDob = (EditText) findViewById(R.id.edit_dob);
- editTextNationality = (EditText) findViewById(R.id.edit_natnl);
- editTextMob_no = (EditText) findViewById(R.id.edit_mob_no);
- editTextEmail = (EditText) findViewById(R.id.edit_email_adrs);
- buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
- requestQueue = Volley.newRequestQueue(this);
- buttonSubmit.setOnClickListener(this);
- client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
- }
- public void register() {
- Log.e(TAG, "register");
- if (!validate()) {
- Toast.makeText(this,"Valid register here ",Toast.LENGTH_LONG).show();
- return;
- }
- else{
- makeJsonObjectRequest1();
- }
- }
- public boolean validate() {
- boolean invalid = true;
- salutation = editTextSalutation.getText().toString().trim();
- fname = editTextFirstname.getText().toString().trim();
- surname = editTextSurname.getText().toString().trim();
- username = editTextUserName.getText().toString().trim();
- password = editTextPassword.getText().toString().trim();
- dob = editTextDob.getText().toString().trim();
- nationality = editTextNationality.getText().toString().trim();
- mobno = editTextMob_no.getText().toString().trim();
- email = editTextEmail.getText().toString().trim();
- if (salutation.isEmpty()) {
- editTextSalutation.setError("enter your salutation");
- invalid = false;
- } else {
- editTextSalutation.setError(null);
- }
- if (fname.isEmpty()) {
- editTextFirstname.setError("enter your first name");
- invalid = false;
- } else {
- editTextFirstname.setError(null);
- }
- if (surname.isEmpty()) {
- editTextSurname.setError("enter your surname");
- invalid = false;
- } else {
- editTextSurname.setError(null);
- }
- if (username.isEmpty()) {
- editTextUserName.setError("enter your username");
- invalid = false;
- } else {
- editTextUserName.setError(null);
- } if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
- editTextPassword.setError("between 4 and 10 alphanumeric characters");
- invalid = false;
- } else {
- editTextPassword.setError(null);
- } if (dob.isEmpty()) {
- editTextDob.setError("enter your Date of Birth");
- invalid = false;
- } else {
- editTextDob.setError(null);
- } if (nationality.isEmpty()) {
- editTextNationality.setError("enter your Nationality");
- invalid = false;
- } else {
- editTextNationality.setError(null);
- } if (mobno.isEmpty() || mobno.length() != 10) {
- editTextMob_no.setError("enter a valid 10 digit mobile no");
- invalid = false;
- } else {
- editTextMob_no.setError(null);
- } if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
- editTextEmail.setError("enter a valid email address");
- invalid = false;
- } else {
- editTextEmail.setError(null);
- }
- return invalid;
- }
- private void confirmOtp() throws JSONException {
- //Creating a LayoutInflater object for the dialog box
- LayoutInflater li = LayoutInflater.from(this);
- //Creating a view to get the dialog box
- View confirmDialog = li.inflate(R.layout.dialog_confirm, null);
- //Initizliaing confirm button fo dialog box and edittext of dialog box
- buttonConfirm = (Button) confirmDialog.findViewById(R.id.buttonConfirm);
- editTextConfirmOtp = (EditText) confirmDialog.findViewById(R.id.editTextOtp);
- //Creating an alertdialog builder
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
- //Adding our dialog box to the view of alert dialog
- alert.setView(confirmDialog);
- //Creating an alert dialog
- final AlertDialog alertDialog = alert.create();
- //Displaying the alert dialog
- alertDialog.show();
- //On the click of the confirm button from alert dialog
- buttonConfirm.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //Hiding the alert dialog
- alertDialog.dismiss();
- //Displaying a progressbar
- final ProgressDialog loading = ProgressDialog.show(RegisterActivity.this, "Authenticating", "Please wait while we check the entered code", false, false);
- //Getting the user entered otp from edittext
- final String otp = editTextConfirmOtp.getText().toString().trim();
- //Creating an string request
- StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.CONFIRM_URL,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //if the server response is success
- if (response.equalsIgnoreCase("success")) {
- //dismissing the progressbar
- loading.dismiss();
- //Starting a new activity
- startActivity(new Intent(RegisterActivity.this, SuccessActivity.class));
- } else {
- //Displaying a toast if the otp entered is wrong
- Toast.makeText(RegisterActivity.this, "Wrong OTP Please Try Again", Toast.LENGTH_LONG).show();
- try {
- //Asking user to enter otp again
- confirmOtp();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- alertDialog.dismiss();
- Toast.makeText(RegisterActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
- }
- }) {
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- Map<String, String> params = new HashMap<String, String>();
- //Adding the parameters otp and username
- params.put(Config.KEY_OTP, otp);
- // params.put(Config.KEY_USERNAME, username);
- return params;
- }
- };
- //Adding the request to the queue
- requestQueue.add(stringRequest);
- }
- });
- }
- private void makeJsonObjectRequest1(){
- isInternetOn();
- //Displaying a progress dialog
- final ProgressDialog loading = ProgressDialog.show(this, "Registering", "Please wait...", false, false);
- JSONObject obj11 = new JSONObject();
- try {
- obj11.put(KEY_SALUTATION, salutation);
- Log.e("salutation", salutation);
- obj11.put(KEY_FIRSTNAME, fname);
- Log.e("fname", fname);
- obj11.put(KEY_SURNAME, surname);
- Log.e("surname", surname);
- obj11.put(KEY_USERNAME, username);
- Log.e("username", username);
- obj11.put(KEY_MOBILE_NO, mobno);
- Log.e("mobno", mobno);
- obj11.put(KEY_EMAIL, email);
- Log.e("email", email);
- obj11.put(KEY_CONFEDENTIAL, confedential);
- Log.e("confedential", confedential);
- obj11.put(KEY_DEVICETOKEN, device_token);
- Log.e("device_token", device_token);
- obj11.put(KEY_PASSWORD, password);
- Log.e("password", password);
- obj11.put(KEY_DOB, dob);
- Log.e("dob", dob);
- obj11.put(KEY_NATIONALITY, nationality);
- Log.e("nationality", nationality);
- obj11.put(KEY_LOGINTYPE, login_type);
- Log.e("login_type", login_type);
- }catch(JSONException e){
- e.printStackTrace();
- }
- JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
- Config.REGISTER_URL,obj11,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- Log.d(TAG, response.toString());
- loading.dismiss();
- Toast.makeText(RegisterActivity.this, "Requesting for Otp..", Toast.LENGTH_LONG).show();
- try {
- if (response.getString(Config.TAG_RESPONSE).equalsIgnoreCase("true")) {
- Toast.makeText(RegisterActivity.this, "Requesting for Otp..", Toast.LENGTH_LONG).show();
- //Asking user to confirm otp
- confirmOtp();
- } else {
- Toast.makeText(RegisterActivity.this, "Username or Phone are already registered", Toast.LENGTH_LONG).show();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(RegisterActivity.this, "Volley Error..", Toast.LENGTH_LONG).show();
- VolleyLog.d(TAG, "errorRes: " + error.getMessage());
- }
- });
- requestQueue.add(jsonObjReq);
- }
- @Override
- public void onClick(View v) {
- register();
- }
- public final boolean isInternetOn() {
- // get Connectivity Manager object to check connection
- ConnectivityManager connec =
- (ConnectivityManager) getSystemService(getBaseContext().CONNECTIVITY_SERVICE);
- if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
- connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
- connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
- connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) {
- } else if (
- connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED ||
- connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) {
- Toast.makeText(this, " Connection Problem ", Toast.LENGTH_LONG).show();
- return false;
- }
- return false;
- }
- @Override
- public void onStart() {
- super.onStart();
- client.connect();
- Action viewAction = Action.newAction(
- Action.TYPE_VIEW,
- "Register Page",
- Uri.parse("http://host/path"),
- Uri.parse("android-app://com.example.avinash.myapplication/http/host/path")
- );
- AppIndex.AppIndexApi.start(client, viewAction);
- }
- @Override
- public void onStop() {
- super.onStop();
- // ATTENTION: This was auto-generated to implement the App Indexing API.
- // See https://g.co/AppIndexing/AndroidStudio for more information.
- Action viewAction = Action.newAction(
- Action.TYPE_VIEW, // TODO: choose an action type.
- "Register Page", // TODO: Define a title for the content shown.
- // TODO: If you have web page content that matches this app activity's content,
- // make sure this auto-generated web page URL is correct.
- // Otherwise, set the URL to null.
- Uri.parse("http://host/path"),
- // TODO: Make sure this auto-generated app URL is correct.
- Uri.parse("android-app://com.example.avinash.myapplication/http/host/path")
- );
- AppIndex.AppIndexApi.end(client, viewAction);
- client.disconnect();
- }
- 05-31 14:35:41.083 31467-31467/com.example.avinash.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.example.avinash.myapplication-1/lib/arm
- 05-31 14:35:48.811 31467-31467/com.example.avinash.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.example.avinash.myapplication-1/lib/arm
- 05-31 14:35:49.407 31467-31908/com.example.avinash.myapplication D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
- 05-31 14:35:49.450 31467-31908/com.example.avinash.myapplication I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ifd751822f5)
- OpenGL ES Shader Compiler Version: XE031.06.00.05
- Build Date: 01/26/16 Tue
- Local Branch: AU12_SBA
- Remote Branch:
- Local Patches:
- Reconstruct Branch:
- 05-31 14:35:49.451 31467-31908/com.example.avinash.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
- 05-31 14:36:12.926 31467-31903/com.example.avinash.myapplication D/Volley: [3407] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://allwashes.com/allwashes.com/heroes/index.php/updatePassword 0x597f401 NORMAL 1> [lifetime=3438], [size=1803], [rc=200], [retryCount=0]
- 05-31 14:36:12.937 31467-31467/com.example.avinash.myapplication D/Volley: [1] 7.onErrorResponse: MainActivity
- 05-31 14:36:12.947 31467-31467/com.example.avinash.myapplication D/Volley: [1] Request.finish: 3462 ms: [ ] http://allwashes.com/allwashes.com/heroes/index.php/updatePassword 0x597f401 NORMAL 1
- 05-31 14:36:13.037 31467-31908/com.example.avinash.myapplication V/RenderScript: 0xb815bf10 Launching thread(s), CPUs 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement