8.
0 Rationale:
Android application development is one of the rising and growing trend in the industry of
mobile. This course examines the principles of mobile application design and covers the
necessary concepts which are required to understand mobile based applications and develop
Android based Applications in particular. After completing this course students will design
and build a variety of real-time Apps using Android.
9.0 Aim Of The Project:
Develop Android Booklisting Application.
10.0 Course Outcomes Achieved:
a) Develop rich user interface by using layouts and control.
b) Use user interface component for android application
development.
c) Create android application using database.
11.0 Actual Methodology Followed:
• I Search topic from various sources such as youtube videos, web article And reference
Book, I Select topic as “Develop android book listing Application”, which address our
Course outcomes.
• Selected topic discussed with respective subject teacher and final the topic For micro-
Project.
• Project is built in android studio official IDE of Google (downloaded from
https://developer.android.com/studio).
• Project Scope and Planning:
Clearly define the scope of your book listing app. Understand the features and
Functionality you want to include.
• User Interface Design:
Based on the XML layouts (activity_main.xml, activity_settings.xml, book_item.xml,
Result_activity.xml), design the user interface. Ensure it is intuitive, user-friendly, and
Follows Android design guidelines.
• Implement the settings functionality from SettingsActivity.java. Ensure that user
Preferences, such as the number of books shown, are correctly applied.
• List View and Adapter:
Enhance the BookAdapter and associated XML layout (book_item.xml) for displaying
Book information in the ResultsActivity. Ensure smooth scrolling and display of book
Details.
• Backend Development:
Utilize Java language for backend logic.Develop backend services for data storage.Use
Flutter framework for cross-platform mobile app development targeting Android Devices.
12.0 Resources Used:
Sr. No. Name of the resource/Material used Specification
1. Laptop Ryzen 7, 1TB,16 GB
RAM
2. Software MS Word
3. Other resources Notes, Reference
Books
4. Search Engine Google Chrome
13.0 Program Code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.android.booklistingapp.MainActivity">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/placeholder_text"
android:id="@+id/search_bar"/>
<Button
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/search_button_text"android:id="@+id/search_button"/>
</LinearLayout>
ActivityMain.java
package com.example.android.booklistingapp;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;import
android.os.Bundle;
import android.text.InputFilter;
import android.util.Log; import
android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button; import
android.widget.EditText; import
android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private static final String BASE_URL =
"https://www.googleapis.com/books/v1/volumes?";
private String mFinalUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get a reference to search button
Button searchButton = (Button) findViewById(R.id.search_button);
/**
* This event will be called when user clicks on search button
*/
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Get a reference to search bar
EditText searchBar = (EditText) findViewById(R.id.search_bar);
// Store keyword typed by the user, i.e, Harry PotterString
keyword = searchBar.getText().toString();
mFinalUrl = addKeywordToUrl(keyword);
// Create intent to open ResultsActivity.java and show searching results
Intent openResultsActivity = new Intent(MainActivity.this,
ResultsActivity.class);
openResultsActivity.putExtra("finalUrl", mFinalUrl);
MainActivity.this.startActivity(openResultsActivity);
// new myAsyncTask().execute(finalUrl);
Log.v("ResultsActivity.java", "keyword value: " + keyword);
Log.v("ResultsActivity.java", "finalUrl value: " + mFinalUrl);
}
});
}
/**
* This method defines the final url which will be used to make the request
* @param keyword is the word that the user entered in the search box
* @return the formatted string
*/
private String addKeywordToUrl(String keyword) {
// Create a URI object
Uri baseUri = Uri.parse(BASE_URL); Uri.Builder
uriBuilder = baseUri.buildUpon();
// Append query parameter "q" to URI uriBuilder.appendQueryParameter("q", keyword);
// Return URI in String format
return uriBuilder.toString();
}
// Inflate the menu and respond when our users click on the menu item@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu); return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {int id =
item.getItemId();
if (id == R.id.action_settings) {
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_settings.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment android:name="com.example.android.booklistingapp.SettingsActivity$BookPre
ferenceFragment" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.booklistingapp.SettingsActivity"
tools:layout="@layout/activity_settings">
</fragment>
SettingsActivity.java
package com.example.android.booklistingapp;
import android.preference.EditTextPreference; import
android.preference.PreferenceFragment;import
android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;import
android.os.Bundle;
import android.text.InputFilter;
import android.widget.EditText;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
public static class BookPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_main);
// Only allow the user to input values from 1 to 40
// in the EditTextPreference for the number of books shownEditText
editText1 =
((EditTextPreference)findPreference(getString(R.string.settings_boo
ks_shown_key))).getEditText();
editText1.setFilters(new InputFilter[]{ new MinMaxFilter(1, 40) });
}
}
}
book_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:background="#FFF"
android:layout_height="200dp">
<ImageView
android:id="@+id/book_thumbnail"
android:layout_width="128dp"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/steve" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/book_main_info"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:layout_toRightOf="@id/book_thumbnail">
<TextView android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Steve Jobs"
android:maxLines="3"
android:ellipsize="end"
android:textColor="#424242"
android:layout_centerHorizontal="true"
android:id="@+id/book_title"
android:textSize="15sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_below="@id/book_title"
android:maxLines="3" android:gravity="center"
android:layout_centerHorizontal="true"
android:ellipsize="end"
android:id="@+id/book_description"
tools:text="La biografía definitiva de Steve Jobs, el fundador de Apple, escrita con su
colaboración. La muerte de Steve Jobs ha conmocionado al mundo. Tras entrevistarlo en más
de cuarenta ocasiones en los últimos dos años,además de a un centenar de personas de su
entorno, familiares, amigos, adversarios y colegas, Walter Isaacson nos presenta la única
biografía escrita con la colaboración de Jobs, el retrato definitivo de uno de los iconos
indiscutibles de nuestro tiempo, la crónica de la agitada vida y abrasiva personalidad del
genio cuya creatividad, energía y afán de perfeccionismo revolucionaron seis industrias: la
informática, el cine de animación, la música, la telefonía, las tabletas y la edición digital.
Consciente de que la mejor manera de crear valor en el siglo XXI es conectar la creatividad
con la tecnología, Jobs fundó una empresa en la que impresionantes saltos de la imaginación
van de la mano de asombrosos logros tecnológicos. Aunque Jobs colaboró en el libro, no
pidió ningún control sobre el contenido, ni siquiera ejerció el derecho a leerlo antes de su
publicación. No rehuyó ningún tema y animó a la gente que conocía a hablar con franqueza.
«He hecho muchas cosas de las que no me siento orgulloso, como dejar a mi novia
embarazada a los veintitrés años y cómo me comporté entonces, pero no hay ningún cadáver
en mi armario que no pueda salir a la luz». Jobs habla con una sinceridad a veces brutal
sobre la gente con laque ha trabajado y contra la que ha competido. De igual modo, sus
amigos, rivales y colegas ofrecen una visión sin edulcorar de las pasiones, los demonios, el
perfeccionismo, los deseos, el talento, los trucos y la obsesión por controlarlotodo que
modelaron su visión empresarial y los innovadores productos que logró crear. Su historia,
por tanto, está llena de enseñanzas sobre innovación, carácter, liderazgo y valores. La vida de
un genio capaz de enfurecer y seducir apartes iguales. Reseña: «El fallecimiento de Steve
Jobs ha precipitado un alud de libros sobre su figura. De todos ellos, la aproximación más
completa e interesante al personaje es la de Isaacson.» La Vanguardia"/>
</RelativeLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/book_thumbnail"
android:layout_below="@id/book_main_info"
android:id="@+id/linearLayout"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/book_authors"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="bottom"
android:textSize="12sp"
android:maxLines="2"
android:ellipsize="end" tools:text="Authors:
Walter Isaacson"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_gravity="bottom"
android:gravity="center"
android:id="@+id/book_page_count"
tools:text="Pages: 200"/>
<TextView android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="bottom"
android:textSize="12sp"
android:layout_height="wrap_content"
android:id="@+id/book_published_date"
tools:text="Published: 2011-10-28"/>
</LinearLayout>
</RelativeLayout>
result_activity.xml
<?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">
<ListView android:id="@+id/list"
android:dividerHeight="1dp"
android:divider="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<!-- Empty view is only visible when the list has no items. -->
<TextView android:id="@+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAppearance="?android:textAppearanceMedium"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar"
android:id="@+id/loading_indicator"
android:layout_centerInParent="true"/>
</RelativeLayout>
ResultsActivity.java
package com.example.android.booklistingapp;
import android.app.LoaderManager;
import android.content.Context; import
android.content.Intent;
import android.content.SharedPreferences;import
android.net.ConnectivityManager; import
android.net.NetworkInfo;
import android.net.Uri;
import android.preference.PreferenceManager; import
android.support.v7.app.AppCompatActivity;import
android.os.Bundle;
import android.util.Log; import
android.view.View; import
android.widget.Button;
import android.widget.EditText; import
android.widget.LinearLayout;import
android.widget.ListView; import
android.content.Loader; import
android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class ResultsActivity extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<List<Book>> {
private static final int BOOK_LOADER_ID = 1;private
boolean mFirstLoaderCreated = false; private
BookAdapter mAdapter;
private String mFinalUrl;
private TextView mEmptyStateTextView;
// private static final String BASE_URL =
"https://www.googleapis.com/books/v1/volumes?";
/* private static class myAsyncTask extends AsyncTask<String, Void,
List<Book>> {
@Override
protected List<Book> doInBackground(String...myString) {if
(myString[0] != null) {
List<Book> books = QueryUtils.fetchBookData(myString[0]);return
books;
}
return null;
}
@Override
protected void onPostExecute(List<Book> books) {if
(books != null) {
for (int i = 0; i < books.size(); i++) { Log.v("ResultsActivity.java", "First
book title: " +
books.get(i).mTitle);
}
} else {
Log.v("ResultsActivity.java", "This book doesn't exist in our stock");
}
}
}*/
// Get a reference to the LoaderManager in order to interact with Loaders
LoaderManager loaderManager = getLoaderManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.results_activity);
// Get intent from MainActivity.java Intent
getMainActivityIntent = getIntent();
// Get formatted URL to make request from MainActivity.javamFinalUrl =
getMainActivityIntent.getStringExtra("finalUrl");
ListView booksList = (ListView) findViewById(R.id.list);
mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
booksList.setEmptyView(mEmptyStateTextView);
mAdapter = new BookAdapter(this, new ArrayList<Book>());
booksList.setAdapter(mAdapter);
// Get a reference to the ConnectivityManager to check state of network
connectivity
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
// Get details on the currently active default data network NetworkInfo
networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
// Initialize the loader. Pass in the int ID constant defined above and pass in null for
// the bundle. Pass in this activity for the LoaderCallbacks parameter(which is
valid
// because this activity implements the LoaderCallbacks interface).
loaderManager.initLoader(BOOK_LOADER_ID, null,
ResultsActivity.this);
} else {
View loadingIndicator = findViewById(R.id.loading_indicator);
loadingIndicator.setVisibility(View.GONE);
mEmptyStateTextView.setText(R.string.no_internet_connection);
}
// loaderManager.restartLoader(BOOK_LOADER_ID, null,
ResultsActivity.this);
}
@Override
public Loader<List<Book>> onCreateLoader(int i, Bundle bundle) {
SharedPreferences sharedPrefs =
PreferenceManager.getDefaultSharedPreferences(this);
// Go and find in SharedPreferences file a string with the name
"books_shown"
// If it finds it, then it will return its value, otherwise it will return the value
in
// "settings_books_shown_default" which is 10String
numberOfBooksShown =
sharedPrefs.getString(getString(R.string.settings_books_shown_key),
getString(R.string.settings_books_shown_default));
Log.v("ResultActivity.java", "The value of numberOfBooksShown is: " +
numberOfBooksShown);
Uri baseUri = Uri.parse(mFinalUrl); Uri.Builder
uriBuilder = baseUri.buildUpon();
uriBuilder.appendQueryParameter("maxResults", numberOfBooksShown);
return new BookLoader(this, uriBuilder.toString());
}
@Override
public void onLoadFinished(Loader<List<Book>> loader, List<Book>books) {
// Remove the loading indicator once the books are loaded
View loadingIndicator = findViewById(R.id.loading_indicator);
loadingIndicator.setVisibility(View.GONE);
// If the book searched doesn't exist
// Show 'Book wasn't found"if
(books == null) {
mEmptyStateTextView.setText(R.string.book_wasnt_found);
}
if (mAdapter != null) {
mAdapter.clear();
if (books != null && !books.isEmpty()) {
mAdapter.addAll(books);
}
}
@Override
public void onLoaderReset(Loader<List<Book>> loader) {
Log.v("ResultsActivity.java", "This is onLoaderReset");
}
}
BookLoader.java
package com.example.android.booklistingapp;
import android.content.AsyncTaskLoader;import
android.content.Context;
import java.util.List;
/*
* Created by Rafael on 21/2/2018.*/
public class BookLoader extends AsyncTaskLoader<List<Book>> {private
String mUrl;
public BookLoader(Context context, String url) {
super(context);
mUrl = url;
}
@Override
protected void onStartLoading() {
forceLoad();
}
@Override
public List<Book> loadInBackground() {
List<Book> books = QueryUtils.fetchBookData(mUrl);return
books;
}
}
Book.java
package com.example.android.booklistingapp;import
android.graphics.Bitmap;
/**
* Created by Rafael on 17/2/2018.
*/
public class Book { private
String mTitle;
private String mPublishedDate;
private String mDescription; private
String mPageCount; private Bitmap
mBookImage; private String
mAuthors;
public Book(String title, String publishedDate, String description, StringpageCount,
Bitmap bookImage, String authors) {
mTitle = title;
mPublishedDate = publishedDate;
mDescription = description;
mPageCount = pageCount;
mBookImage = bookImage; mAuthors
= authors;
}
/**
* @return Book title
*/
public String getBookTitle() {
return mTitle;
}
/**
* @return Book PublishedDate
*/
public String getBookPublishedDate() {return
mPublishedDate;
}
/**
* @return Book Description
*/
public String getBookDescription() {return
mDescription;
}
/**
* @return Book PageCount
*/
public String getBookPageCount() {return
mPageCount;
}
/**
* @return Book thumbnail
*/
public Bitmap getBookThumbnail() {return
mBookImage;
}
/**
* @return Book authors
*/
public String getBookAuthors() {
return mAuthors;
}
Output:
15.0 Skill Developed:
• Android Development Skills:
Understanding of Android architecture.
Proficiency in Java programming languages.
Knowledge of Android SDK, APIs, and libraries.
Experience with Android Studio IDE.
• User Interface (UI) Design:
Designing intuitive user interfaces for displaying book listings.
Implementing navigation between different screens.
16.0 Applications:
• Educational Resource Platform:
Educational institutions or online learning platforms can use the app to provide access to digital
textbooks and course materials.
• Personal Book Catalog:
Individuals can use the app to maintain a catalog of their own books, including details such as title,
author, genre, and synopsis.
17.0 Reference:
• https://projectworlds.in/android-book-listing-app-project/