How To Create An eBook Application In Android Studio

Introduction

 
An electronic book, also known as an eBook, is a book made available in digital form, consisting of text, images, or both, readable on the flat-panel display of computers or other electronic devices that features a controllable viewing screen, including desktop computers, laptops, tablets, and smartphones.
 

Features of eBooks

  1. Intuitive List of Chapters
  2. Reader-Friendly Interface
  3. Multiple Platform Support
  4. Support Different Formats
  5. Reading Tools

What makes them better than printed books?

 
eBooks Are More Portable Than Print
 
Printed books, especially hardbound editions, can be very heavy, while most modern eReader devices are lightweight. It's much easier to carry an eReader containing an entire library of titles than to bring even a few physical books.
 
eBooks Take Up Much Less Space
 
Avid readers tend to collect a lot of books, which can take up too much space and make your home feel cluttered. However, even the largest collection of eBooks won’t take up much physical space in your home.
 
There Are No Late Fees for Library eBooks
 
If you borrow a physical book from the library and forget to return it, you will be charged a late fee. Many libraries also now offer eBook loans in addition to their print book offerings. You don't have to return them by any due date instead, their licenses will simply expire on your device
 
Now we will learn how to program in Android studio using a java programming language step by step.
 
Step 1
 
First, we will create an Android Studio project named as per your choice. and go to Empty Activity, Android Studio will create MainActivity.java and activity_main.xml.
 
Step 2
 
Before starting we have to add the dependency that is used for open Pdf files in our build.gradle code file of the application. Here is our build.gradle file.
  1. apply plugin: 'com.android.application'      
  2.       
  3. android {      
  4.     compileSdkVersion 29      
  5.     buildToolsVersion "29.0.2"      
  6.     defaultConfig {      
  7.         applicationId "com.example.book"      
  8.         minSdkVersion 24      
  9.         targetSdkVersion 29      
  10.         versionCode 1      
  11.         versionName "1.0"      
  12.         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"      
  13.     }      
  14.     buildTypes {      
  15.         release {      
  16.             minifyEnabled false      
  17.             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'      
  18.         }      
  19.     }      
  20. }      
  21.       
  22. dependencies {      
  23.     implementation fileTree(dir: 'libs', include: ['*.jar'])      
  24.     implementation 'androidx.appcompat:appcompat:1.2.0'      
  25.     implementation 'androidx.constraintlayout:constraintlayout:2.0.4'      
  26.         
  27.     testImplementation 'junit:junit:4.12'      
  28.     androidTestImplementation 'androidx.test.ext:junit:1.1.2'      
  29.     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'      
  30.     implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'      
  31.       
  32. }     
Here we Implement two methods: com.github.barteksc:android-pdf-viewer:2.8.2' We add the material dependency in build.gradle file. the Android application which is used for material design, After adding the dependency in our project sync the project.
 
Step 3
 
After the successful sync of the project. go to splash screen activity   
 
Activity-Splash-Screen.xml
 
The first screen visible to the user when the application's launched.  We use Splash screens to display some animations and application logos, while some data for the next screens are fetched
  1. <RelativeLayout      
  2.          android:layout_width="match_parent"      
  3.          android:layout_height="match_parent">      
  4.        
  5.          <ImageView      
  6.              android:id="@+id/img"      
  7.              android:layout_width="329dp"      
  8.              android:layout_height="409dp"      
  9.              android:layout_marginLeft="40dp"      
  10.              android:layout_marginTop="20dp"      
  11.              android:src="@drawable/logo" />      
  12.        
  13.         <TextView      
  14.              android:id="@+id/tv3"      
  15.              android:layout_width="wrap_content"      
  16.              android:layout_height="wrap_content"      
  17.              android:layout_marginLeft="70sp"      
  18.              android:layout_marginTop="568sp"      
  19.              android:fontFamily="cursive"      
  20.              android:text="Powered by Yatish Chhonkar"      
  21.              android:textColor="@color/colorwhite"      
  22.              android:textSize="25sp" />      
  23.        
  24.      </RelativeLayout>      
After completing the XML part be jumped into  implementation in java.
 
Step 4 - Main Activity java
 
Here we implement java code with XML which is a simple constant screen for a fixed amount of time that is used to display the book content, logo, name.
  1. public class Splash_screen extends AppCompatActivity {    
  2.     
  3.     TextView slogan ,txt;    
  4.         
  5.     Animation topanim,bottomanim;    
  6.     
  7.     @Override    
  8.     protected void onCreate(Bundle savedInstanceState) {    
  9.         super.onCreate(savedInstanceState);    
  10.     
  11.        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);    
  12.     
  13.         setContentView(R.layout.activity_splash_screen);    
  14.     
  15.         slogan=(TextView)findViewById(R.id.tv2);    
  16.         txt=(TextView)findViewById(R.id.tv3);    
  17.     
  18.                        // Animation    
  19.     
  20.         topanim = AnimationUtils.loadAnimation(this,R.anim.top_animation);    
  21.         bottomanim = AnimationUtils.loadAnimation(this,R.anim.bottom_animation);    
  22.     
  23.         //Hooks    
  24.     
  25.         slogan.setAnimation(bottomanim);    
  26.         txt.setAnimation(bottomanim);    
  27.     
  28.         //Intent    
  29.     
  30.     new Handler().postDelayed(new Runnable() {    
  31.         @Override    
  32.         public void run() {    
  33.     
  34.             Intent intent = new Intent(Splash_screen.this,MainActivity.class);    
  35.             startActivity(intent);    
  36.             finish();    
  37.     
  38.         }    
  39.     },6000);    
  40.     
  41.     }    
  42. }   
Step 5 
 
While complying with the part of the splash screen we move to the next remaining part to open pdf content file.   
 
PdfOpner.xml
 
Create another empty activity to open Pdf file
 
 
  1. <?xml version="1.0" encoding="utf-8"?>    
  2.  <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  3.      xmlns:app="http://schemas.android.com/apk/res-auto"    
  4.      xmlns:tools="http://schemas.android.com/tools"    
  5.      android:layout_width="match_parent"    
  6.      android:layout_height="match_parent"    
  7.      tools:context=".pdfOpener">    
  8.      
  9.      <com.github.barteksc.pdfviewer.PDFView    
  10.          android:layout_width="match_parent"    
  11.          android:layout_height="match_parent"    
  12.          android:id="@+id/pdfViewer">    
  13.      
  14.      </com.github.barteksc.pdfviewer.PDFView>    
  15.      
  16.  </androidx.constraintlayout.widget.ConstraintLayout>   
Here we use a library for it too.. github.com/barteksc/AndroidPdfViewer in our project too
 
Step 6
 
While completing the part of the pdf opener file .xml we move to the next remaining part to pdf opener file .java class, 
 
PdfOpenerFile.java
 
 
  1. public class pdfOpener extends AppCompatActivity {    
  2.     
  3.     PDFView myPDFViewer;    
  4.     
  5.     @Override    
  6.  protected void onCreate(Bundle savedInstanceState) {    
  7.         super.onCreate(savedInstanceState);    
  8.         setContentView(R.layout.activity_pdf_opener);    
  9.     
  10.         myPDFViewer = (PDFView) findViewById(R.id.pdfViewer);    
  11.     
  12.         String getItam =getIntent().getStringExtra("PdfFieName");    
  13.     
  14.         if(getItam.equals("संख्या पद्धति")){    
  15.             myPDFViewer.fromAsset("संख्या पद्धति.pdf").load();    
  16.         }    
  17.     
  18.         if(getItam.equals("सरलीकरण")){    
  19.             myPDFViewer.fromAsset("सरलीकरण.pdf").load();    
  20.         }    
  21.     
  22.         if(getItam.equals("LCM तथा HCF")){    
  23.             myPDFViewer.fromAsset("LCM तथा HCF.pdf").load();    
  24.         }    
  25.     
  26.         if(getItam.equals("वर्गमूल तथा घनमूल")){    
  27.             myPDFViewer.fromAsset("वर्गमूल तथा घनमूल.pdf").load();    
  28.         }    
  29.     
  30.         if(getItam.equals("घातांक एवं करणी")){    
  31.             myPDFViewer.fromAsset("घातांक एवं करणी.pdf").load();    
  32.         }    
  33.     
  34.         if(getItam.equals("औसत")){    
  35.             myPDFViewer.fromAsset("औसत.pdf").load();    
  36.         }    
  37.     
  38.         if(getItam.equals("प्रतिशत")){    
  39.             myPDFViewer.fromAsset("प्रतिशत.pdf").load();    
  40.         }    
  41.     
  42.         if(getItam.equals("लाभ और हानि")){    
  43.             myPDFViewer.fromAsset("लाभ और हानि.pdf").load();    
  44.         }    
  45.     
  46.         if(getItam.equals("आयु पर आधरित प्रश्न")){    
  47.             myPDFViewer.fromAsset("आयु पर आधरित प्रश्न.pdf").load();    
  48.         }    
  49.     
  50.         if(getItam.equals("अनुपात एवं समानुपात")){    
  51.             myPDFViewer.fromAsset("अनुपात एवं समानुपात.pdf").load();    
  52.         }    
  53.     
  54.         if(getItam.equals("साझा")){    
  55.             myPDFViewer.fromAsset("साझा.pdf").load();    
  56.         }    
  57.     
  58.         if(getItam.equals("मिश्रण")){    
  59.             myPDFViewer.fromAsset("मिश्रण.pdf").load();    
  60.         }    
  61.     
  62.         if(getItam.equals("मिश्र समानुपात")){    
  63.             myPDFViewer.fromAsset("मिश्र समानुपात.pdf").load();    
  64.         }    
  65.     
  66.         if(getItam.equals("साधारण ब्याज")){    
  67.             myPDFViewer.fromAsset("साधारण ब्याज.pdf").load();    
  68.         }    
  69.     
  70.         if(getItam.equals("चक्रवृध्दि ब्याज")){    
  71.             myPDFViewer.fromAsset("चक्रवृध्दि ब्याज.pdf").load();    
  72.         }    
  73.     
  74.     
  75.         if(getItam.equals("कार्य तथा समय")){    
  76.             myPDFViewer.fromAsset("कार्य तथा समय.pdf").load();    
  77.         }    
  78.     
  79.         if(getItam.equals("नल एवमं हौज़")){    
  80.             myPDFViewer.fromAsset("नल एवमं हौज़.pdf").load();    
  81.         }    
  82.     
  83.         if(getItam.equals("रेलगाडी")){    
  84.             myPDFViewer.fromAsset("रेलगाडी.pdf").load();    
  85.         }    
  86.     
  87.         if(getItam.equals("नाव तथा धारा")) {    
  88.             myPDFViewer.fromAsset("नाव तथा धारा.pdf").load();    
  89.         }    
  90.     
  91.             if(getItam.equals("क्षेत्रफल एवमं आयतन")) {    
  92.                 myPDFViewer.fromAsset("क्षेत्रफल एवमं आयतन.pdf").load();    
  93.     
  94.             }    
  95.     }    
  96. }   
We can use a custom PDF Viewer.
 
In your Gradle file compile this: 'com.github.barteksc:android-pdf-viewer:2.0.3'
 
Step 7 - Activity-Main-.XML
 
While complying with the part of the pdf opener class .java we move to the next remaining part to Main Activity .xml, 
 
  
Here we add a list view in XML with match parent height and width and assign id as a listview. 
  1. <RelativeLayout      
  2.       
  3.  xmlns:android="http://schemas.android.com/apk/res/android"      
  4.  xmlns:app="http://schemas.android.com/apk/res-auto"      
  5.  xmlns:tools="http://schemas.android.com/tools"      
  6.  android:layout_width="match_parent"      
  7.  android:layout_height="match_parent"      
  8.  tools:context=".MainActivity">      
  9.       
  10. <ListView      
  11.     android:layout_width="match_parent"      
  12.     android:layout_height="match_parent"      
  13.     android:id="@+id/lstview"      
  14.     android:padding="15dp"/>      
  15. </RelativeLayout>     
Step 8
 
Here we set data into list view  which we create in XML  
 
Main Activity-.java 
 
  1. public class MainActivity extends AppCompatActivity {  
  2.   
  3.     ListView lsview;  
  4.   
  5.     @Override  
  6.     protected void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.activity_main);  
  9.   
  10.         lsview = (ListView) findViewById(R.id.lstview);  
  11.   
  12.         String[] chapter = {  
  13.             "संख्या पद्धति",  
  14.             "सरलीकरण",  
  15.             "LCM तथा HCF",  
  16.             "वर्गमूल तथा घनमूल",  
  17.             "घातांक एवं करणी",  
  18.             "औसत",  
  19.             "प्रतिशत",  
  20.             "लाभ और हानि",  
  21.             "आयु पर आधरित प्रश्न",  
  22.             "अनुपात एवं समानुपात",  
  23.             "साझा",  
  24.             "मिश्रण",  
  25.             "मिश्र समानुपात",  
  26.             "साधारण ब्याज",  
  27.             "चक्रवृध्दि ब्याज",  
  28.             "कार्य तथा समय",  
  29.             "नल एवमं हौज़",  
  30.             "रेलगाडी",  
  31.             "नाव तथा धारा",  
  32.             "क्षेत्रफल एवमं आयतन"  
  33.         };  
  34.   
  35.         ArrayAdapter < String > adapter = new ArrayAdapter < String > (this, android.R.layout.simple_list_item_1, chapter) {  
  36.   
  37.             @NonNull  
  38.             @Override  
  39.             public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {  
  40.   
  41.                 View view = super.getView(position, convertView, parent);  
  42.   
  43.                 TextView mytxt = (TextView) view.findViewById(android.R.id.text1);  
  44.                 return view;  
  45.             }  
  46.         };  
  47.   
  48.         lsview.setAdapter(adapter);  
  49.   
  50.   
  51.         lsview.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
  52.             @Override  
  53.             public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {  
  54.   
  55.                 String iteam = lsview.getItemAtPosition(position).toString();  
  56.   
  57.                 Intent start = new Intent(getApplicationContext(), pdfOpener.class);  
  58.                 start.putExtra("PdfFieName", iteam);  
  59.                 startActivity(start);  
  60.   
  61.             }  
  62.         });  
  63.     }  

Here we use listview, array adapter, and set adapter into list view once we click the listview, the intent will take us to Pdfopner class activity. 
 
 
After complying with the code it will look like as shown in the picture. It's ready to use.
 
Explanation
 
In the MainActivity.java file, we used List view and pdf open file by the line "findViewById(R.id.ls view)" we connect together and set the click listener name as per pdf file which saves in Array Adapter. Once we click the list view it fires in the intent and jumps into a pdf file.   
 
Benefits of eBooks  
  1. eBooks save space
  2. eBooks save money
  3. eBooks help the environment
  4. An eBook is portable and convenient 
  5. Instantly download 
You can have a look at the output below
 
 

Conclusion 

 
You can easily turn your eBook into a revenue-generating machine on any platform screen. The key being – effective use of the eBook features to stand out in the digital world. An eBook is a way of reaching your readers in a digital world.