Visvesvaraya Technological University: "Book Library"
Visvesvaraya Technological University: "Book Library"
Visvesvaraya Technological University: "Book Library"
ON
“Book Library”
Submitted in partial fulfillment of the requirements for the
Mobile Application Development Lab (18CSMP68)
BACHELOR OF ENGINEERING
IN
NAGARAJ. A
Associate Professor
Department of Computer Science and Engineering
CERTIFICATE
This is to certify that the Mini Project titled 'Book Library' carried out by Mr/Ms
VISHAL.S.NAIK, USN: 1JT19CS104, a bonafide student of Jyothy Institute of
Technology, in partial fulfillment for the award of Bachelor of Engineering, in
Computer Science and Engineering under Visvesvaraya Technological University, Belagavi,
during the year 2021- 2022.
The project report has been approved, as it satisfies the academic requirements in respect of
Mini Project prescribed for the course Mobile Application Development Lab (18CSMP68).
........................................... .…..............................
Prof. Nagaraj. A Dr. Prabhanjan. S.
Associate Professor Prof & Head of Dept - CSE
Dept of CSE JIT, Bengaluru
JIT, Bengaluru
External Viva
1)
2)
DECLARATION
Date : 13-07-2022
Place : Bangalore
USN : 1JT19CS104
Name : Vishal.S.Naik
ACKNOWLEDGEMENT
I would like to thank Dr. Prabhanjan. S, Head of Dept - CSE, for providing us an
opportunity to carry out Mini Project and for his valuable guidance and support.
I would like to thank, Prof. Nagaraj. A, Faculty In Charge, for guiding us during
the period of Mini Project.
I would like to thank all the faculty members of CSE department for the support
extended during the course of Mini Project.
I would like to thank the non-teaching members of the Dept of CSE, for helping
us during the Mini Project.
Last but not the least, I would like to thank our parents and friends without
whose constant help, the completion of Mini Project would have not been
possible.
VISHAL.S.NAIK [ 1JT19CS104 ]
Table of Contents
Sr No Description Page No
01 Problem statement with input and
output diagram
02 XML files code
04 Screen shots
CHAPTER 1
Problem statement
with
input and output diagram
BOOK LIBRARY
Problem Statement:
Develop an android application - Library management application that helps the user to manage by
adding a Book, delete a book, search a book, update and display all the current available Books in form
of a list.
activity_add.xml:
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pages_input" />
<Button
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="160dp"
android:text="View all data"
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pages_input" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_update.xml:
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Number of pages"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/author_input2" />
<Button
android:id="@+id/update_button"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="40dp"
android:text="Update"
android:textSize="20sp"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pages_input2" />
<Button
android:id="@+id/delete_button"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="16dp"
android:text="Delete"
android:textAllCaps="false"
android:textColor="@color/red"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/update_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_main.xml:
app:srcCompat="@drawable/ic_add" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:paddingTop="?attr/actionBarSize"
android:layout_width="409dp"
android:layout_height="729dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/empty_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:alpha="0.1"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_empty" />
<TextView
android:id="@+id/no_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="No Data."
android:textSize="20sp"
android:alpha="0.4"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/empty_imageview" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_home.xml:
android:layout_marginRight="59dp"
android:text="BOOKHOUSE"
android:textColor="@color/cardview_dark_background"
android:textSize="50dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnmain"
android:layout_width="377dp"
android:layout_height="62dp"
android:layout_marginTop="400dp"
android:text="Add Books"
android:textAllCaps="false"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
my_row.xml:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="Title 1"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000"
app:layout_constraintStart_toEndOf="@+id/book_id_txt"
app:layout_constraintTop_toTopOf="@+id/book_id_txt" />
<TextView
android:id="@+id/book_author_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Author1"
app:layout_constraintStart_toStartOf="@+id/book_title_txt"
app:layout_constraintTop_toBottomOf="@+id/book_title_txt"/>
<TextView
android:id="@+id/book_pages_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="120"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
HomeActivity.java:
package com.example.Library.MadProject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
MainActivity.java:
package com.example.Library.MadProject;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.material.floatingactionbutton. FloatingActionButton;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
FloatingActionButton add_button;
ImageView empty_imageview;
TextView no_data;
MyDatabaseHelper myDB;
ArrayList<String> book_id, book_title, book_author, book_pages;
CustomAdapter customAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerView);
add_button = findViewById(R.id.add_button);
empty_imageview = findViewById(R.id.empty_imageview);
no_data = findViewById(R.id.no_data);
add_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,
AddActivity.class);
startActivity(intent);
}
});
myDB = new MyDatabaseHelper(MainActivity.this);
book_id = new ArrayList<>();
book_title = new ArrayList<>();
book_author = new ArrayList<>();
book_pages = new ArrayList<>();
storeDataInArrays();
customAdapter = new CustomAdapter(MainActivity.this,this, book_id,
book_title, book_author, book_pages);
recyclerView.setAdapter(customAdapter);
recyclerView.setLayoutManager(new
LinearLayoutManager(MainActivity.this));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1){
recreate();
}
}
void storeDataInArrays(){
Cursor cursor = myDB.readAllData();
if(cursor.getCount() == 0){
empty_imageview.setVisibility(View.VISIBLE);
no_data.setVisibility(View.VISIBLE);
}else{
while (cursor.moveToNext()){
book_id.add(cursor.getString(0));
book_title.add(cursor.getString(1));
book_author.add(cursor.getString(2));
book_pages.add(cursor.getString(3));
}
empty_imageview.setVisibility(View.GONE);
no_data.setVisibility(View.GONE);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.delete_all){
confirmDialog();
}
return super.onOptionsItemSelected(item);
}
void confirmDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Delete All?");
builder.setMessage("Are you sure you want to delete all Data?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MyDatabaseHelper myDB = new MyDatabaseHelper (MainActivity.this);
myDB.deleteAllData();
//Refresh Activity
Intent intent = new Intent(MainActivity.this,
MainActivity.class);
startActivity(intent);
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.create().show();
}
}
AddActivity.java:
package com.example.Library.MadProject;
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;
public class AddActivity extends AppCompatActivity implements
View.OnClickListener{
EditText title_input, author_input, pages_input;
Button add_button,View_button;
@Override
title_input = findViewById(R.id.title_input);
author_input = findViewById(R.id.author_input);
pages_input = findViewById(R.id.pages_input);
View_button=findViewById(R.id.btnView);
View_button.setOnClickListener(this);
add_button = findViewById(R.id.add_button);
add_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyDatabaseHelper myDB = new MyDatabaseHelper
(AddActivity.this);
myDB.addBook(title_input.getText().toString().trim(),
author_input.getText().toString().trim(),
Integer.valueOf(pages_input.getText().toString().trim()));
}
});
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
}
UpdateActivity.java:
package com.example.Library.MadProject;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
});
builder.setNegativeButton("No", new DialogInterface.
OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.create().show();
}
}
CustomAdapter.java:
package com.example.Library.MadProject;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;
import com.example.Library.MadProject.R;
import java.util.ArrayList;
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder>
{
private Context context;
private Activity activity;
private ArrayList book_id, book_title, book_author, book_pages;
holder.book_id_txt.setText(String.valueOf(book_id.get(position)));
holder.book_title_txt.setText(String.valueOf(book_title.get(position)));
holder.book_author_txt.setText(String.valueOf(book_author.get(position)));
holder.book_pages_txt.setText(String.valueOf(book_pages.get(position)));
//Recyclerview onClickListener
holder.mainLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, UpdateActivity.class);
intent.putExtra("id", String.valueOf(book_id.get(position)));
intent.putExtra("title", String.valueOf(book_title.get(position)));
intent.putExtra("author",
String.valueOf(book_author.get(position)) );
intent.putExtra("pages", String.valueOf(book_pages.get(position)));
activity.startActivityForResult(intent, 1);
}
});
}
@Override
public int getItemCount() {
return book_id.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView book_id_txt, book_title_txt, book_author_txt, book_pages_txt;
LinearLayout mainLayout;
MyViewHolder(@NonNull View itemView) {
super(itemView);
book_id_txt = itemView.findViewById(R.id.book_id_txt);
book_title_txt = itemView.findViewById(R.id.book_title_txt);
book_author_txt = itemView.findViewById(R.id.book_author_txt);
book_pages_txt = itemView.findViewById(R.id.book_pages_txt);
mainLayout = itemView.findViewById(R.id.mainLayout);
//Animate Recyclerview
Animation translate_anim = AnimationUtils.loadAnimation(context,R.anim.
translate_anim);
mainLayout.setAnimation(translate_anim);
}
}
}
MyDatabaseHelper.java:
package com.example.Library.MadProject;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
import androidx.annotation.Nullable;
public class MyDatabaseHelper extends SQLiteOpenHelper {
private Context context;
private static final String DATABASE_NAME = "BookLibrary.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "my_library";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_TITLE = "book_title";
private static final String COLUMN_AUTHOR = "book_author";
private static final String COLUMN_PAGES = "book_pages";
MyDatabaseHelper(@Nullable Context context) {
cv.put(COLUMN_TITLE, title);
cv.put(COLUMN_AUTHOR, author);
cv.put(COLUMN_PAGES, pages);
long result = db.insert(TABLE_NAME,null, cv);
if(result == -1){
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Added Successfully!",
Toast.LENGTH_SHORT).show();
}
}
Cursor readAllData(){
String query = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
}else{
Toast.makeText(context, "Successfully Deleted.",
Toast.LENGTH_SHORT).show();
}
}
void deleteAllData(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_NAME);
}
}
Screen Shots
BOOK LIBRARY
Screenshots:
Figure 4.5: Update and Delete Page Figure 4.6: Successful Updation