Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Question1/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'com.android.application'
}

android {
namespace 'com.example.registrationapp'
compileSdk 36

defaultConfig {
applicationId "com.example.registrationapp"
minSdk 24
targetSdk 36
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
26 changes: 26 additions & 0 deletions Question1/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".DisplayActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.registrationapp;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class DisplayActivity extends AppCompatActivity {

private TextView textViewName, textViewEmail, textViewGender, textViewDOB;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);

// Initialize views
textViewName = findViewById(R.id.textViewName);
textViewEmail = findViewById(R.id.textViewEmail);
textViewGender = findViewById(R.id.textViewGender);
textViewDOB = findViewById(R.id.textViewDOB);

// Get data from intent
String name = getIntent().getStringExtra("name");
String email = getIntent().getStringExtra("email");
String gender = getIntent().getStringExtra("gender");
String dob = getIntent().getStringExtra("dob");

// Display the information (password is NOT shown)
textViewName.setText(name);
textViewEmail.setText(email);
textViewGender.setText(gender);
textViewDOB.setText(dob);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.example.registrationapp;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {

private EditText editTextName, editTextEmail, editTextDOB, editTextPassword;
private RadioGroup radioGroupGender;
private Button buttonRegister;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize views
editTextName = findViewById(R.id.editTextName);
editTextEmail = findViewById(R.id.editTextEmail);
editTextDOB = findViewById(R.id.editTextDOB);
editTextPassword = findViewById(R.id.editTextPassword);
radioGroupGender = findViewById(R.id.radioGroupGender);
buttonRegister = findViewById(R.id.buttonRegister);

// DatePickerDialog for Date of Birth
editTextDOB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDatePickerDialog();
}
});

// Register button click listener
buttonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
validateAndRegister();
}
});
}

private void showDatePickerDialog() {
final Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(
MainActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
// Month is 0-indexed, so add 1
String date = selectedDay + "/" + (selectedMonth + 1) + "/" + selectedYear;
editTextDOB.setText(date);
}
},
year, month, day
);
datePickerDialog.show();
}

private void validateAndRegister() {
String name = editTextName.getText().toString().trim();
String email = editTextEmail.getText().toString().trim();
String dob = editTextDOB.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
int selectedGenderId = radioGroupGender.getCheckedRadioButtonId();

// Check fields from top to bottom, show only one toast at a time
if (name.isEmpty()) {
Toast.makeText(this, "Please enter your name", Toast.LENGTH_SHORT).show();
return;
}

if (email.isEmpty()) {
Toast.makeText(this, "Please enter your email address", Toast.LENGTH_SHORT).show();
return;
}

// Validate email format
if (!isValidEmail(email)) {
Toast.makeText(this, "Please enter a valid email address", Toast.LENGTH_SHORT).show();
return;
}

if (selectedGenderId == -1) {
Toast.makeText(this, "Please select your gender", Toast.LENGTH_SHORT).show();
return;
}

if (dob.isEmpty()) {
Toast.makeText(this, "Please select your date of birth", Toast.LENGTH_SHORT).show();
return;
}

if (password.isEmpty()) {
Toast.makeText(this, "Password should be at least 8 characters long", Toast.LENGTH_SHORT).show();
return;
}

// Validate password
if (password.length() < 8) {
Toast.makeText(this, "Password should be at least 8 characters long", Toast.LENGTH_SHORT).show();
return;
}

if (!isValidPassword(password)) {
Toast.makeText(this, "Password should contain 1 numeric digit, 1 uppercase letter, and 1 special character", Toast.LENGTH_SHORT).show();
return;
}

// Get selected gender text
RadioButton selectedGenderButton = findViewById(selectedGenderId);
String gender = selectedGenderButton.getText().toString();

// All validations passed — open second activity
Intent intent = new Intent(MainActivity.this, DisplayActivity.class);
intent.putExtra("name", name);
intent.putExtra("email", email);
intent.putExtra("gender", gender);
intent.putExtra("dob", dob);
startActivity(intent);
}

private boolean isValidEmail(String email) {
// A valid email: username@domain.com
// Username: letters, numbers, underscores, periods, dashes
// Domain: multiple parts separated by dots
String emailPattern = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
return Pattern.matches(emailPattern, email);
}

private boolean isValidPassword(String password) {
// Must contain at least one numeric digit
boolean hasDigit = false;
// Must contain at least one uppercase letter
boolean hasUppercase = false;
// Must contain at least one special character from @#$%^&+=!
boolean hasSpecialChar = false;

String specialCharacters = "@#$%^&+=!";

for (char c : password.toCharArray()) {
if (Character.isDigit(c)) {
hasDigit = true;
} else if (Character.isUpperCase(c)) {
hasUppercase = true;
} else if (specialCharacters.indexOf(c) != -1) {
hasSpecialChar = true;
}
}

return hasDigit && hasUppercase && hasSpecialChar;
}
}
18 changes: 18 additions & 0 deletions Question1/app/src/main/res/drawable/app_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="150dp"
android:height="150dp"
android:viewportWidth="150"
android:viewportHeight="150">
<!-- Background circle -->
<path
android:fillColor="#6200EE"
android:pathData="M75,75m-70,0a70,70 0,1 1,140 0a70,70 0,1 1,-140 0" />
<!-- Person icon -->
<path
android:fillColor="#FFFFFF"
android:pathData="M75,50c8.28,0 15,-6.72 15,-15s-6.72,-15 -15,-15 -15,6.72 -15,15 6.72,15 15,15z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M75,60c-20,0 -40,10 -40,20v10h80v-10c0,-10 -20,-20 -40,-20z" />
</vector>
11 changes: 11 additions & 0 deletions Question1/app/src/main/res/drawable/ic_calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#757575">
<path
android:fillColor="#000000"
android:pathData="M19,3h-1V1h-2v2H8V1H6v2H5C3.89,3 3.01,3.9 3.01,5L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2zM19,19H5V8h14v11zM9,10H7v2h2v-2zM13,10h-2v2h2v-2zM17,10h-2v2h2v-2z" />
</vector>
11 changes: 11 additions & 0 deletions Question1/app/src/main/res/drawable/ic_email.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#757575">
<path
android:fillColor="#000000"
android:pathData="M20,4H4C2.9,4 2.01,4.9 2.01,6L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5V6l8,5 8,-5v2z" />
</vector>
11 changes: 11 additions & 0 deletions Question1/app/src/main/res/drawable/ic_lock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#757575">
<path
android:fillColor="#000000"
android:pathData="M18,8h-1V6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2H6c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8H8.9V6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z" />
</vector>
11 changes: 11 additions & 0 deletions Question1/app/src/main/res/drawable/ic_person.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#757575">
<path
android:fillColor="#000000"
android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />
</vector>
Loading