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 EditText editTextConfedential;
- private String salutation;
- private String fname;
- private String surname;
- private String username;
- private String password;
- private String dob;
- private String nationality;
- private String mobno;
- private String confedential;
- private String email;
- private String device_token="aswert1234";
- private String login_type="0";
- private static String TAG = RegisterActivity.class.getSimpleName();
- private Button buttonSubmit;
- /**
- * ATTENTION: This was auto-generated to implement the App Indexing API.
- * See https://g.co/AppIndexing/AndroidStudio for more information.
- */
- 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);
- editTextConfedential = (EditText) findViewById(R.id.edit_confdnt);
- buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
- requestQueue = Volley.newRequestQueue(this);
- buttonSubmit.setOnClickListener(this);
- // ATTENTION: This was auto-generated to implement the App Indexing API.
- // See https://g.co/AppIndexing/AndroidStudio for more information.
- client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
- }
- 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 for 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, true);
- //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);
- }
- });
- }
- //this method will register the user
- private void register() {
- isInternetOn();
- //Displaying a progress dialog
- final ProgressDialog loading = ProgressDialog.show(this, "Registering", "Please wait...", false, true);
- //Getting user data
- 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();
- confedential = editTextConfedential.getText().toString().trim();
- try {
- JSONObject obj = new JSONObject();
- obj.put(KEY_SALUTATION, salutation);
- obj.put(KEY_FIRSTNAME, fname);
- obj.put(KEY_SURNAME, surname);
- obj.put(KEY_USERNAME, username);
- obj.put(KEY_MOBILE_NO, mobno);
- obj.put(KEY_EMAIL, email);
- obj.put(KEY_CONFEDENTIAL, confedential);
- obj.put(KEY_DEVICETOKEN, device_token);
- obj.put(KEY_PASSWORD, password);
- obj.put(KEY_DOB, dob);
- obj.put(KEY_NATIONALITY, nationality);
- obj.put(KEY_LOGINTYPE, login_type);
- **JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
- "http://allwashes.com/allwashes.com/heroes/index.php/signUp",null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- Log.d("Response", response.toString());
- loading.dismiss();
- try {
- //Creating the json object from the response
- //JSONObject jsonResponse = new JSONObject(response.toString());
- //If it is success
- 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 {
- //If not successful user may already have registered
- 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, "Error: " + error.getMessage());
- }
- });
- requestQueue.add(jsonObjReq);
- }catch (JSONException e) {
- Log.e("MYAPP", "unexpected JSON exception", e);
- // Do something to recover ... or kill the app.
- }
- }
- @Override
- public void onClick(View v) {
- //Calling register method on register button click
- register();
- }
- public final boolean isInternetOn() {
- // get Connectivity Manager object to check connection
- ConnectivityManager connec =
- (ConnectivityManager) getSystemService(getBaseContext().CONNECTIVITY_SERVICE);
- // Check for network connections
- 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) {
- // if connected with internet
- //Toast.makeText(this, " Connected ", Toast.LENGTH_LONG).show();
- return true;
- } 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();
- // ATTENTION: This was auto-generated to implement the App Indexing API.
- // See https://g.co/AppIndexing/AndroidStudio for more information.
- client.connect();
- 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.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();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:fillViewport="false"
- android:background="@drawable/back_all">
- <ScrollView
- android:id="@+id/scroll"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:fillViewport="true" >
- <RelativeLayout
- android:id="@+id/container"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:text="Sign Up"
- android:textColor="#ffffff"
- android:textSize="28sp"
- android:textStyle="bold"
- android:gravity="center"
- android:id="@+id/textView5" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Salutation"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_marginTop="45dp"
- android:layout_below="@+id/textView5"
- android:layout_centerHorizontal="true"
- android:id="@+id/textView4" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/editText_fname"
- android:gravity="center"
- android:layout_below="@+id/textView4"
- android:backgroundTint="@android:color/darker_gray"
- android:layout_centerHorizontal="true"
- />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="First Name"
- android:gravity="center"
- android:textSize="18dp"
- android:id="@+id/textView6"
- android:textColor="#ffffff"
- android:layout_below="@+id/editText_fname"
- android:layout_centerHorizontal="true" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="30"
- android:gravity="center"
- android:id="@+id/textEmail"
- android:backgroundTint="@android:color/darker_gray"
- android:layout_below="@+id/textView6"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Sur Name"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/textEmail"
- android:layout_centerHorizontal="true"
- android:id="@+id/textView7" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/editText_password"
- android:layout_below="@+id/textView7"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="User Name"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/editText_password"
- android:layout_centerHorizontal="true"
- android:id="@+id/textView8" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edittxt_cnfrmpassword"
- android:layout_below="@+id/textView8"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Password"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edittxt_cnfrmpassword"
- android:layout_centerHorizontal="true"
- android:id="@+id/pswd" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="textPassword"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_pswd"
- android:layout_below="@+id/pswd"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Date Of Birth"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edit_pswd"
- android:layout_centerHorizontal="true"
- android:id="@+id/dob" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_dob"
- android:layout_below="@+id/dob"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Nationality"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edit_dob"
- android:layout_centerHorizontal="true"
- android:id="@+id/natnl" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_natnl"
- android:layout_below="@+id/natnl"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Mobile No"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edit_natnl"
- android:layout_centerHorizontal="true"
- android:id="@+id/mob_no" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="number"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_mob_no"
- android:layout_below="@+id/mob_no"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Email_address"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edit_mob_no"
- android:layout_centerHorizontal="true"
- android:id="@+id/email_adrs" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="textEmailAddress"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_email_adrs"
- android:layout_below="@+id/email_adrs"
- android:layout_centerHorizontal="true" />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Confedential"
- android:gravity="center"
- android:textSize="18dp"
- android:textColor="#ffffff"
- android:layout_below="@+id/edit_email_adrs"
- android:layout_centerHorizontal="true"
- android:id="@+id/confdnt" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:inputType="text"
- android:ems="20"
- android:gravity="center"
- android:backgroundTint="@android:color/darker_gray"
- android:id="@+id/edit_confdnt"
- android:layout_below="@+id/confdnt"
- android:layout_centerHorizontal="true" />
- <Button
- android:id="@+id/buttonSubmit"
- android:layout_width="fill_parent"
- android:layout_height="38dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="25dp"
- android:background="@drawable/roundbtn"
- android:text="submit"
- android:textColor="#FFFFFF"
- android:layout_below="@+id/edit_confdnt"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- <TextView android:id="@+id/link_to_login"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="you have already an account? Log in"
- android:gravity="center"
- android:textSize="20dip"
- android:textColor="#0b84aa"
- android:layout_marginTop="15dp"
- android:layout_below="@+id/buttonSubmit"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- </RelativeLayout>
- </ScrollView>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement