mirror of
https://github.com/Priyatham-sai-chand/alzapp.git
synced 2026-10-05 07:41:33 -07:00
age calc
This commit is contained in:
parent
13517af628
commit
d5971cf24a
3 changed files with 51 additions and 60 deletions
|
|
@ -1,33 +0,0 @@
|
||||||
package com.example.alzapp;
|
|
||||||
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
|
|
||||||
import android.app.DatePickerDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
/*******
|
|
||||||
Created on: 21/01/2020
|
|
||||||
|
|
||||||
By: B.Priyatham sai chand
|
|
||||||
|
|
||||||
|
|
||||||
********/
|
|
||||||
|
|
||||||
public class DatePickerFragment extends DialogFragment {
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
int year = c.get(Calendar.YEAR);
|
|
||||||
int month = c.get(Calendar.MONTH);
|
|
||||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
|
||||||
|
|
||||||
return new DatePickerDialog(getActivity(), (DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class Registerequest extends StringRequest {
|
||||||
private static final String REGISTER_REQUEST_URL = "https://eclectic-sweeps.000webhostapp.com/registration_enc.php";
|
private static final String REGISTER_REQUEST_URL = "https://eclectic-sweeps.000webhostapp.com/registration_enc.php";
|
||||||
private Map<String, String> params;
|
private Map<String, String> params;
|
||||||
|
|
||||||
public Registerequest(String firstname, String lastname,String username,String dob,String email,String password,String gender, Response.Listener<String> listener) {
|
Registerequest(String firstname, String lastname, String username, String dob, String email, String password, String gender, int age, Response.Listener<String> listener) {
|
||||||
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
|
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
|
||||||
params = new HashMap<>();
|
params = new HashMap<>();
|
||||||
params.put("username", username);
|
params.put("username", username);
|
||||||
|
|
@ -20,6 +20,7 @@ public class Registerequest extends StringRequest {
|
||||||
params.put("dob",dob);
|
params.put("dob",dob);
|
||||||
params.put("email",email);
|
params.put("email",email);
|
||||||
params.put("gender",gender);
|
params.put("gender",gender);
|
||||||
|
params.put("age",age+"");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.example.alzapp;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
@ -28,9 +30,9 @@ import java.time.Period;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
/*******
|
/*******
|
||||||
Created on: 21/01/2020
|
Created on: 21/01/2020
|
||||||
|
|
||||||
|
|
@ -39,7 +41,7 @@ import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
********/
|
********/
|
||||||
|
|
||||||
public class registration extends AppCompatActivity implements DatePickerDialog.OnDateSetListener {
|
public class registration extends AppCompatActivity {
|
||||||
private TextView signin;
|
private TextView signin;
|
||||||
private TextView dob;
|
private TextView dob;
|
||||||
private RadioGroup radioSexGroup;
|
private RadioGroup radioSexGroup;
|
||||||
|
|
@ -50,7 +52,10 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
private EditText lastname;
|
private EditText lastname;
|
||||||
private EditText email_id;
|
private EditText email_id;
|
||||||
private Button signup;
|
private Button signup;
|
||||||
String ages;
|
private DatePickerDialog.OnDateSetListener mDateSetListener;
|
||||||
|
int age;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -83,12 +88,39 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
dob.setOnClickListener(new View.OnClickListener() {
|
dob.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
DialogFragment datePicker = new DatePickerFragment();
|
Calendar cal = Calendar.getInstance();
|
||||||
datePicker.show(getSupportFragmentManager(), "date picker");
|
int year = cal.get(Calendar.YEAR);
|
||||||
|
int month = cal.get(Calendar.MONTH);
|
||||||
|
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
DatePickerDialog dialog = new DatePickerDialog(
|
||||||
|
registration.this,
|
||||||
|
android.R.style.Theme_Holo_Light_Dialog_MinWidth,
|
||||||
|
mDateSetListener,
|
||||||
|
year,month,day);
|
||||||
|
|
||||||
|
Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
|
@Override
|
||||||
|
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
|
||||||
|
month = month + 1;
|
||||||
|
|
||||||
|
String s = day + " " +month + " " + year;
|
||||||
|
LocalDate l1 = LocalDate.of(year, month, day);
|
||||||
|
age(s,l1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
Button back = findViewById(R.id.back);
|
Button back = findViewById(R.id.back);
|
||||||
|
|
||||||
back.setOnClickListener(new View.OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
@ -142,7 +174,7 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Registerequest reg_request = new Registerequest(firstname.getText().toString(),lastname.getText().toString(),username.getText().toString(),dob.getText().toString(),email_id.getText().toString(),password.getText().toString(),radioSexButton.getText().toString(),responseListener);
|
Registerequest reg_request = new Registerequest(firstname.getText().toString(),lastname.getText().toString(),username.getText().toString(),dob.getText().toString(),email_id.getText().toString(),password.getText().toString(),radioSexButton.getText().toString(),age,responseListener);
|
||||||
RequestQueue queue = Volley.newRequestQueue(registration.this);
|
RequestQueue queue = Volley.newRequestQueue(registration.this);
|
||||||
queue.add(reg_request);
|
queue.add(reg_request);
|
||||||
|
|
||||||
|
|
@ -158,25 +190,11 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
|
|
||||||
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.set(Calendar.YEAR, year);
|
|
||||||
c.set(Calendar.MONTH, month);
|
|
||||||
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
||||||
String currentDateString = DateFormat.getDateInstance(DateFormat.DEFAULT).format(c.getTime());
|
|
||||||
LocalDate l1 = LocalDate.of(year, month, dayOfMonth);
|
|
||||||
|
|
||||||
age(currentDateString,l1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void openActivity() {
|
public void openActivity() {
|
||||||
|
|
||||||
Intent intent = new Intent(this,login.class);
|
Intent intent = new Intent(this,login.class);
|
||||||
|
|
@ -187,6 +205,8 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void checkButton(View v) {
|
public void checkButton(View v) {
|
||||||
int radioId = radioSexGroup.getCheckedRadioButtonId();
|
int radioId = radioSexGroup.getCheckedRadioButtonId();
|
||||||
|
|
||||||
|
|
@ -199,17 +219,20 @@ public class registration extends AppCompatActivity implements DatePickerDialog.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
DateFormat originalFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
|
DateFormat originalFormat = new SimpleDateFormat("dd MM yyyy", Locale.US);
|
||||||
DateFormat targetFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
|
DateFormat targetFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
|
||||||
Date date = originalFormat.parse(s);
|
Date date = originalFormat.parse(s);
|
||||||
if (date != null) {
|
if(date != null) {
|
||||||
String formattedDate = targetFormat.format(date);
|
String formattedDate = targetFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDate now1 = LocalDate.now();
|
LocalDate now1 = LocalDate.now();
|
||||||
Period diff1 = Period.between(l1, now1);
|
Period diff1 = Period.between(l1, now1);
|
||||||
int age = diff1.getYears();
|
age = diff1.getYears();
|
||||||
ages = String.valueOf(age);
|
String ages = String.valueOf(age);
|
||||||
|
TextView textView = findViewById(R.id.dob1);
|
||||||
|
textView.setText(s);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue