Login Activity.
Java
package com.example.travel_guide;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>
{
private Context context;
private ArrayList name_id, mobile_id, adhaar_id, blood_id, gender_id;
public MyAdapter(Context context, ArrayList name_id, ArrayList
mobile_id, ArrayList adhaar_id, ArrayList blood_id, ArrayList gender_id) {
this.context = context;
this.name_id = name_id;
this.mobile_id = mobile_id;
this.adhaar_id = adhaar_id;
this.blood_id = blood_id;
this.gender_id = gender_id;
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
View v =
LayoutInflater.from(context).inflate(R.layout.userentry,parent,false);
return new MyViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int
position) {
holder.name_id.setText(String.valueOf(name_id.get(position)));
holder.mobile_id.setText(String.valueOf(mobile_id.get(position)));
holder.adhaar_id.setText(String.valueOf(adhaar_id.get(position)));
holder.blood_id.setText(String.valueOf(blood_id.get(position)));
holder.gender_id.setText(String.valueOf(gender_id.get(position)));
@Override
public int getItemCount() {
return name_id.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView name_id,mobile_id, adhaar_id, blood_id,gender_id ;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
name_id = itemView.findViewById(R.id.textname);
mobile_id = itemView.findViewById(R.id.textmobile);
adhaar_id = itemView.findViewById(R.id.textadhaar);
blood_id = itemView.findViewById(R.id.textblood);
gender_id = itemView.findViewById(R.id.textgender);
}
}
}
Register Activity.Java
package com.example.travel_guide;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class RegisterActivity extends AppCompatActivity {
EditText edUsername, edEmail, edPassword,edConfirm;
Button btn;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
edUsername = findViewById(R.id.editTextRegUsername);
edPassword = findViewById(R.id.editTextRegPassword);
edEmail = findViewById(R.id.editTextRegEmail);
edConfirm = findViewById(R.id.editTextRegConfirmPassword);
btn = findViewById(R.id.buttonRegister);
tv = findViewById(R.id.textViewExistingUser);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new
Intent(RegisterActivity.this,LoginActivity.class));
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String username = edUsername.getText().toString();
String email = edEmail.getText().toString();
String password = edPassword.getText().toString();
String confirm = edConfirm.getText().toString();
Database db= new
Database(getApplicationContext(),"TRAVEL_GUIDE", null,1);
if (username.length() == 0 || email.length()==0 ||
password.length() == 0 || confirm.length()==0) {
Toast.makeText(getApplicationContext(), "Please fill
All details", Toast.LENGTH_SHORT).show();
} else {
if (password.compareTo(confirm) == 0) {
if(isValid(password)){
db.register(username,email,password);
Toast.makeText(getApplicationContext(),"Record
Inserted", Toast.LENGTH_SHORT).show();
startActivity(new
Intent(RegisterActivity.this,LoginActivity.class));
}
else {
Toast.makeText(getApplicationContext(),"Password must contain at least 8
characters, having letter,digit and special
symbol",Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), "Password
and confirm didn't match", Toast.LENGTH_SHORT).show();
}
}
}
});
}
public static boolean isValid(String passwordhere){
int f1=0,f2=0,f3=0;
if (passwordhere.length() < 8) {
return false;
}else {
for (int p = 0; p < passwordhere.length(); p++) {
if (Character.isLetter(passwordhere.charAt(p))) {
f1=1;
}
}
for (int r = 0; r < passwordhere.length(); r++) {
if (Character.isLetter(passwordhere.charAt(r))) {
f2=1;
}
}
for (int s = 0; s < passwordhere.length(); s++) {
char c = passwordhere.charAt(s);
if(c>=33&&c<=46||c==64){
f3=1;
}
}
if(f1==1 && f2==1 && f3==1)
return true;
return false;
}
}
}
Database.java
package com.example.travel_guide;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class Database extends SQLiteOpenHelper {
public Database(@Nullable Context context, @Nullable String name,
@Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String qry1 = "create table users(username text,email text,password
text)";
sqLiteDatabase.execSQL(qry1);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
public void register(String username,String email,String password) {
ContentValues cv = new ContentValues();
cv.put("username",username);
cv.put("email",email);
cv.put("password",password);
SQLiteDatabase db = getWritableDatabase();
db.insert("users",null,cv);
db.close();
}
public int login(String username,String password){
int result=0;
String str[] = new String[2];
str[0] = username;
str[1] = password;
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery("select * from users where username=? and
password=?",str);
if(c.moveToFirst()){
result=1;
}
return result;
}
}
Explore Activity.Java
package com.example.travel_guide;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class ExploreActivity extends AppCompatActivity implements
View.OnClickListener {
private CardView D,D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13,D14;
private ImageButton btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explore);
btn = findViewById(R.id.homeid);
D = (CardView) findViewById(R.id.cardLabTest);
D1 = (CardView) findViewById(R.id.cardLabTest1);
D2 = (CardView) findViewById(R.id.cardLabTest2);
D3 = (CardView) findViewById(R.id.cardLabTest3);
D4 = (CardView) findViewById(R.id.cardLabTest4);
D5 = (CardView) findViewById(R.id.cardLabTest5);
D6 = (CardView) findViewById(R.id.cardLabTest6);
D7 = (CardView) findViewById(R.id.cardLabTest7);
D8 = (CardView) findViewById(R.id.cardLabTest8);
D9 = (CardView) findViewById(R.id.cardLabTest9);
D10 = (CardView) findViewById(R.id.cardLabTest10);
D11 = (CardView) findViewById(R.id.cardLabTest11);
D12 = (CardView) findViewById(R.id.cardLabTest12);
D13 = (CardView) findViewById(R.id.cardLabTest13);
D14 = (CardView) findViewById(R.id.cardLabTest14);
btn.setOnClickListener((View.OnClickListener)this);
D.setOnClickListener((View.OnClickListener) this);
D1.setOnClickListener((View.OnClickListener) this);
D2.setOnClickListener((View.OnClickListener) this);
D3.setOnClickListener((View.OnClickListener) this);
D4.setOnClickListener((View.OnClickListener) this);
D5.setOnClickListener((View.OnClickListener) this);
D6.setOnClickListener((View.OnClickListener) this);
D7.setOnClickListener((View.OnClickListener) this);
D8.setOnClickListener((View.OnClickListener) this);
D9.setOnClickListener((View.OnClickListener) this);
D10.setOnClickListener((View.OnClickListener) this);
D11.setOnClickListener((View.OnClickListener) this);
D12.setOnClickListener((View.OnClickListener) this);
D13.setOnClickListener((View.OnClickListener) this);
D14.setOnClickListener((View.OnClickListener) this);
}
@Override
public void onClick(View v) {
Intent i ;
switch (v.getId()){
case R.id.cardLabTest: i = new
Intent(this,cardActivity.class); startActivity(i); break;
case R.id.cardLabTest1: i = new
Intent(this,card1Activity.class); startActivity(i); break;
case R.id.cardLabTest2: i = new
Intent(this,card2Activity.class); startActivity(i); break;
case R.id.cardLabTest3: i = new
Intent(this,card3Activity.class); startActivity(i); break;
case R.id.cardLabTest4: i = new
Intent(this,card4Activity.class); startActivity(i); break;
case R.id.cardLabTest5: i = new
Intent(this,card5Activity.class); startActivity(i); break;
case R.id.cardLabTest6: i = new
Intent(this,card6Activity.class); startActivity(i); break;
case R.id.cardLabTest7: i = new
Intent(this,card7Activity.class); startActivity(i); break;
case R.id.cardLabTest8: i = new
Intent(this,card8Activity.class); startActivity(i); break;
case R.id.cardLabTest9: i = new
Intent(this,card9Activity.class); startActivity(i); break;
case R.id.cardLabTest10: i = new
Intent(this,card10Activity.class); startActivity(i); break;
case R.id.cardLabTest11: i = new
Intent(this,card11Activity.class); startActivity(i); break;
case R.id.cardLabTest12: i = new
Intent(this,card12Activity.class); startActivity(i); break;
case R.id.cardLabTest13: i = new
Intent(this,card13Activity.class); startActivity(i); break;
case R.id.cardLabTest14: i = new
Intent(this,card14Activity.class); startActivity(i); break;
case R.id.homeid: i = new
Intent(this,HomeActivity.class);startActivity(i); break;
Home Activity.Java
package com.example.travel_guide;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
SharedPreferences sharedPreferences =
getSharedPreferences("shared_prefs", Context.MODE_PRIVATE);
String username = sharedPreferences.getString("username",
"").toString();
Toast.makeText(getApplicationContext(), "Welcome
"+username,Toast.LENGTH_SHORT).show();
CardView mybooking = findViewById(R.id.cardMyBooking);
CardView profile = findViewById(R.id.cardLabTest);
CardView exit = findViewById(R.id.cardExit);
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.apply();
startActivity(new
Intent(HomeActivity.this,LoginActivity.class));
}
});
CardView findDoctor = findViewById(R.id.cardFindDoctor);
findDoctor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new
Intent(HomeActivity.this,ExploreActivity.class));
}
});
mybooking.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new
Intent(HomeActivity.this,MyBookingActivity.class));
}
});
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(HomeActivity.this,profile.class));
}
});
}
}
Profile Activity.Java
package com.example.travel_guide;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class profile extends AppCompatActivity {
EditText name1,mobile1,adhaar1,blood1,gender1;
Button save1,view,delete;
DBHelper DB;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
name1=findViewById(R.id.ProfileName);
mobile1=findViewById(R.id.ProfileMobile);
adhaar1=findViewById(R.id.ProfileAdhaar);
blood1=findViewById(R.id.ProfileBlood);
gender1=findViewById(R.id.ProfileGender);
save1=findViewById(R.id.insert);
view=findViewById(R.id.views);
delete=findViewById(R.id.delete);
DB = new DBHelper(this);
save1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nameTXT = name1.getText().toString();
String mobileTXT = mobile1.getText().toString();
String adhaarTXT= adhaar1.getText().toString();
String bloodTXT= blood1.getText().toString();
String genderTXT= gender1.getText().toString();
Boolean checkinsertdata = DB.insertuserdata(nameTXT,
mobileTXT, adhaarTXT, bloodTXT, genderTXT);
if(checkinsertdata==true)
Toast.makeText(profile.this,"New Entry Inserted",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(profile.this,"New Entry Not
Inserted",Toast.LENGTH_SHORT).show();
}
});
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nameTXT = name1.getText().toString();
Boolean checkdeletedata = DB.deletedata(nameTXT);
if(checkdeletedata==true)
Toast.makeText(profile.this,"Entry Deleted",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(profile.this," Entry Not
Deleted",Toast.LENGTH_SHORT).show();
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(profile.this, ViewProfile.class));
}
});
}
}
View Profile.Java
package com.example.travel_guide;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Toast;
import java.util.ArrayList;
public class ViewProfile extends AppCompatActivity {
RecyclerView recyclerView;
ArrayList<String> name, mobile, adhaar, blood, gender, place, state,
address;
DBHelper DB;
MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_profile);
DB = new DBHelper(this);
name = new ArrayList<>();
mobile = new ArrayList<>();
adhaar = new ArrayList<>();
blood = new ArrayList<>();
gender = new ArrayList<>();
place = new ArrayList<>();
state = new ArrayList<>();
address = new ArrayList<>();
recyclerView = findViewById(R.id.recyclerview);
adapter = new MyAdapter(this, name, mobile, adhaar, blood, gender);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
displaydata();
private void displaydata() {
Cursor cursor = DB.getdata();
if (cursor.getCount() == 0) {
Toast.makeText(ViewProfile.this, "No Entry Exists",
Toast.LENGTH_SHORT).show();
return;
} else {
while (cursor.moveToNext()) {
name.add(cursor.getString(0));
mobile.add(cursor.getString(1));
adhaar.add(cursor.getString(2));
blood.add(cursor.getString(3));
gender.add(cursor.getString(4));
place.add(cursor.getString(5));
state.add(cursor.getString(6));
address.add(cursor.getString(7));
}
}
}
}
DBHelper.java
package com.example.travel_guide;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(@Nullable Context context) {
super(context, "Userdata.dp", null, 1);
}
@Override
public void onCreate(SQLiteDatabase DB) {
DB.execSQL("create Table Userdetails(name TEXT primary key, mobile
TEXT, adhaar TEXT, blood TEXT, gender TEXT)");
@Override
public void onUpgrade(SQLiteDatabase DB, int i, int i1) {
DB.execSQL("drop Table if exists Userdetails");
public Boolean insertuserdata(String name, String mobile, String
adhaar, String blood, String gender){
SQLiteDatabase DB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name",name);
contentValues.put("mobile",mobile);
contentValues.put("adhaar",adhaar);
contentValues.put("blood" ,blood);
contentValues.put("gender" ,gender);
long result=DB.insert("userdetails", null,contentValues);
if(result==-1){
return false;
}else {
return true;
}
public Boolean deletedata(String name){
SQLiteDatabase DB = this.getWritableDatabase();
Cursor cursor = DB.rawQuery("Select * from Userdetails where name =
?", new String[] {name});
if(cursor.getCount()>0) {
long result = DB.delete("userdetails", "name=?", new String[]
{name});
if (result == -1) {
return false;
} else {
return true;
}
}else {
return false;
}
public Cursor getdata(){
SQLiteDatabase DB = this.getWritableDatabase();
Cursor cursor = DB.rawQuery("Select * from Userdetails", null);
return cursor;
MyAdapter.java
package com.example.travel_guide;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>
{
private Context context;
private ArrayList name_id, mobile_id, adhaar_id, blood_id, gender_id;
public MyAdapter(Context context, ArrayList name_id, ArrayList
mobile_id, ArrayList adhaar_id, ArrayList blood_id, ArrayList gender_id) {
this.context = context;
this.name_id = name_id;
this.mobile_id = mobile_id;
this.adhaar_id = adhaar_id;
this.blood_id = blood_id;
this.gender_id = gender_id;
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
View v =
LayoutInflater.from(context).inflate(R.layout.userentry,parent,false);
return new MyViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int
position) {
holder.name_id.setText(String.valueOf(name_id.get(position)));
holder.mobile_id.setText(String.valueOf(mobile_id.get(position)));
holder.adhaar_id.setText(String.valueOf(adhaar_id.get(position)));
holder.blood_id.setText(String.valueOf(blood_id.get(position)));
holder.gender_id.setText(String.valueOf(gender_id.get(position)));
}
@Override
public int getItemCount() {
return name_id.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView name_id,mobile_id, adhaar_id, blood_id,gender_id ;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
name_id = itemView.findViewById(R.id.textname);
mobile_id = itemView.findViewById(R.id.textmobile);
adhaar_id = itemView.findViewById(R.id.textadhaar);
blood_id = itemView.findViewById(R.id.textblood);
gender_id = itemView.findViewById(R.id.textgender);
}
}
}