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
- Intuitive List of Chapters
- Reader-Friendly Interface
- Multiple Platform Support
- Support Different Formats
- 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.
- apply plugin: 'com.android.application'
-
- android {
- compileSdkVersion 29
- buildToolsVersion "29.0.2"
- defaultConfig {
- applicationId "com.example.book"
- minSdkVersion 24
- targetSdkVersion 29
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
- }
- }
- }
-
- dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.appcompat:appcompat:1.2.0'
- implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
-
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'androidx.test.ext:junit:1.1.2'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
- implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
-
- }
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
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <ImageView
- android:id="@+id/img"
- android:layout_width="329dp"
- android:layout_height="409dp"
- android:layout_marginLeft="40dp"
- android:layout_marginTop="20dp"
- android:src="@drawable/logo" />
-
- <TextView
- android:id="@+id/tv3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="70sp"
- android:layout_marginTop="568sp"
- android:fontFamily="cursive"
- android:text="Powered by Yatish Chhonkar"
- android:textColor="@color/colorwhite"
- android:textSize="25sp" />
-
- </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.
- public class Splash_screen extends AppCompatActivity {
-
- TextView slogan ,txt;
-
- Animation topanim,bottomanim;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- setContentView(R.layout.activity_splash_screen);
-
- slogan=(TextView)findViewById(R.id.tv2);
- txt=(TextView)findViewById(R.id.tv3);
-
-
-
- topanim = AnimationUtils.loadAnimation(this,R.anim.top_animation);
- bottomanim = AnimationUtils.loadAnimation(this,R.anim.bottom_animation);
-
-
-
- slogan.setAnimation(bottomanim);
- txt.setAnimation(bottomanim);
-
-
-
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
-
- Intent intent = new Intent(Splash_screen.this,MainActivity.class);
- startActivity(intent);
- finish();
-
- }
- },6000);
-
- }
- }
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
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout 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"
- tools:context=".pdfOpener">
-
- <com.github.barteksc.pdfviewer.PDFView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/pdfViewer">
-
- </com.github.barteksc.pdfviewer.PDFView>
-
- </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
- public class pdfOpener extends AppCompatActivity {
-
- PDFView myPDFViewer;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_pdf_opener);
-
- myPDFViewer = (PDFView) findViewById(R.id.pdfViewer);
-
- String getItam =getIntent().getStringExtra("PdfFieName");
-
- if(getItam.equals("संख्या पद्धति")){
- myPDFViewer.fromAsset("संख्या पद्धति.pdf").load();
- }
-
- if(getItam.equals("सरलीकरण")){
- myPDFViewer.fromAsset("सरलीकरण.pdf").load();
- }
-
- if(getItam.equals("LCM तथा HCF")){
- myPDFViewer.fromAsset("LCM तथा HCF.pdf").load();
- }
-
- if(getItam.equals("वर्गमूल तथा घनमूल")){
- myPDFViewer.fromAsset("वर्गमूल तथा घनमूल.pdf").load();
- }
-
- if(getItam.equals("घातांक एवं करणी")){
- myPDFViewer.fromAsset("घातांक एवं करणी.pdf").load();
- }
-
- if(getItam.equals("औसत")){
- myPDFViewer.fromAsset("औसत.pdf").load();
- }
-
- if(getItam.equals("प्रतिशत")){
- myPDFViewer.fromAsset("प्रतिशत.pdf").load();
- }
-
- if(getItam.equals("लाभ और हानि")){
- myPDFViewer.fromAsset("लाभ और हानि.pdf").load();
- }
-
- if(getItam.equals("आयु पर आधरित प्रश्न")){
- myPDFViewer.fromAsset("आयु पर आधरित प्रश्न.pdf").load();
- }
-
- if(getItam.equals("अनुपात एवं समानुपात")){
- myPDFViewer.fromAsset("अनुपात एवं समानुपात.pdf").load();
- }
-
- if(getItam.equals("साझा")){
- myPDFViewer.fromAsset("साझा.pdf").load();
- }
-
- if(getItam.equals("मिश्रण")){
- myPDFViewer.fromAsset("मिश्रण.pdf").load();
- }
-
- if(getItam.equals("मिश्र समानुपात")){
- myPDFViewer.fromAsset("मिश्र समानुपात.pdf").load();
- }
-
- if(getItam.equals("साधारण ब्याज")){
- myPDFViewer.fromAsset("साधारण ब्याज.pdf").load();
- }
-
- if(getItam.equals("चक्रवृध्दि ब्याज")){
- myPDFViewer.fromAsset("चक्रवृध्दि ब्याज.pdf").load();
- }
-
-
- if(getItam.equals("कार्य तथा समय")){
- myPDFViewer.fromAsset("कार्य तथा समय.pdf").load();
- }
-
- if(getItam.equals("नल एवमं हौज़")){
- myPDFViewer.fromAsset("नल एवमं हौज़.pdf").load();
- }
-
- if(getItam.equals("रेलगाडी")){
- myPDFViewer.fromAsset("रेलगाडी.pdf").load();
- }
-
- if(getItam.equals("नाव तथा धारा")) {
- myPDFViewer.fromAsset("नाव तथा धारा.pdf").load();
- }
-
- if(getItam.equals("क्षेत्रफल एवमं आयतन")) {
- myPDFViewer.fromAsset("क्षेत्रफल एवमं आयतन.pdf").load();
-
- }
- }
- }
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.
- <RelativeLayout
-
- 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"
- tools:context=".MainActivity">
-
- <ListView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/lstview"
- android:padding="15dp"/>
- </RelativeLayout>
Step 8
Here we set data into list view which we create in XML
Main Activity-.java
- public class MainActivity extends AppCompatActivity {
-
- ListView lsview;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- lsview = (ListView) findViewById(R.id.lstview);
-
- String[] chapter = {
- "संख्या पद्धति",
- "सरलीकरण",
- "LCM तथा HCF",
- "वर्गमूल तथा घनमूल",
- "घातांक एवं करणी",
- "औसत",
- "प्रतिशत",
- "लाभ और हानि",
- "आयु पर आधरित प्रश्न",
- "अनुपात एवं समानुपात",
- "साझा",
- "मिश्रण",
- "मिश्र समानुपात",
- "साधारण ब्याज",
- "चक्रवृध्दि ब्याज",
- "कार्य तथा समय",
- "नल एवमं हौज़",
- "रेलगाडी",
- "नाव तथा धारा",
- "क्षेत्रफल एवमं आयतन"
- };
-
- ArrayAdapter < String > adapter = new ArrayAdapter < String > (this, android.R.layout.simple_list_item_1, chapter) {
-
- @NonNull
- @Override
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
-
- View view = super.getView(position, convertView, parent);
-
- TextView mytxt = (TextView) view.findViewById(android.R.id.text1);
- return view;
- }
- };
-
- lsview.setAdapter(adapter);
-
-
- lsview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
-
- String iteam = lsview.getItemAtPosition(position).toString();
-
- Intent start = new Intent(getApplicationContext(), pdfOpener.class);
- start.putExtra("PdfFieName", iteam);
- startActivity(start);
-
- }
- });
- }
- }
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
- eBooks save space
- eBooks save money
- eBooks help the environment
- An eBook is portable and convenient
- 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.