How to make pdf book app using recyclerview in android studio

Recyclerview is look like list view but its much better than list view because it is use in a lots of application like Facebook, Instagram, twitter etc. we have many method to convert PDF in to app.

PDF file is beneficial for user to read easily. If we can use PDF URL in our app. Our app size is 3 to 5 MB but if we can use pdf files than our app size is increase because pdf library size is 20 MB.

In this app we can developed splash screen, navigation drawer and pdf files show in recycler view, apply ads in app and at the end we can change the icon of app. so this tutorial is for those developer who cannot know how to make complete app for play store.

 Steps

  1. Add dependencies in build.gradule. its very import so don’t miss this step.
  2. Make icon for app which is also very import for app.
  3. Create admob account than apply for adsense because without admob you cannot earn money from app.
  4. Make image for splash screen.
  5. Upload pdf files on google drive than copy the link of that urls these urls are used in app.

 

Code

Add Dependencies in Build.Gradule

    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-ads:12.0.0'
    implementation 'com.android.support:design:28.0.0'

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.niazi.pdfbookapp">

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/icon_image"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/icon_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".About"  android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"></activity>
        <activity
            android:name=".FullView"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" />
        <activity
            android:name=".MainActivity"
            android:label="Book App" />
        <activity
            android:name=".SplashScreen"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

SplashScreen.java

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashScreen extends AppCompatActivity {

    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_splash_screen );
     handler=new Handler (  );


     handler.postDelayed ( new Runnable () {
         @Override
         public void run() {
             Intent intent=new Intent ( SplashScreen.this,MainActivity.class );
             startActivity ( intent );
             finish ();
         }
     },3000 );


    }
}

activity_splash_screen.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:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".SplashScreen">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="RRB GROUP D NTPC"
        android:textColor="@android:color/black"
        android:textSize="28dp"
        android:textStyle="bold" />


</LinearLayout>

menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@id/home" android:title="Home"> </item>
<item android:id="@+id/more" android:title="More App"> </item>
    <item android:id="@+id/about" android:title="About"></item>

</menu>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#D81B60</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="back" >#324918</color>
</resources>

navbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:background="@color/back"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
   android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="280dp">


    <ImageView
          android:background="@drawable/splash"
        android:layout_gravity="center"
        android:layout_width="180dp"
        android:layout_height="160dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="RRB GROUP D NTPC"
        android:textColor="@android:color/white"
        android:textSize="28dp"
        android:textStyle="bold"

        />



</LinearLayout>


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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="vertical"
    android:id="@+id/drawer"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">




    <android.support.v7.widget.RecyclerView

        android:id="@+id/RecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>


        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:headerLayout="@layout/navbar"
        android:layout_gravity="start"
        app:menu="@menu/menu_item">

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

MainActivity.java

import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;

import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle actionBarDrawerToggle;

    RecyclerView recyclerView;
    CustomAdapter customAdapter;

    String []urls;
    String []titles;


    private AdView mAdView;


    @Override
    public void onBackPressed() {

        super.onBackPressed();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        recyclerView=(RecyclerView )findViewById ( R.id.RecyclerView );
        MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);











        urls=new String[]{

             "link 1",
             "link 2",
             "link 3",
        };

        titles=new String[]{


                "Title 1 ",
                "Title 2",
                "Title 3 "

        };


      customAdapter=new CustomAdapter ( this,titles,urls );
      recyclerView.setLayoutManager ( new LinearLayoutManager ( this ) );
      recyclerView.setAdapter ( customAdapter );


        drawerLayout=(DrawerLayout)findViewById(R.id.drawer);
        NavigationView  navigationView=( NavigationView )findViewById(R.id.nav_view);
        actionBarDrawerToggle=new ActionBarDrawerToggle(this,drawerLayout,R.string.Open,R.string.Close);
        actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
        actionBarDrawerToggle.syncState();

        drawerLayout.addDrawerListener(actionBarDrawerToggle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener()

        {

            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {

                int id=menuItem.getItemId();
                if(id==R.id.home)
                {
                    Toast.makeText(MainActivity.this,"Home",Toast.LENGTH_LONG).show();



                }

                else if (id==R.id.more)
                {
                    final String appPackageName="com.niazi.pdfbookapp"; // getPackageName() from Context or Activity object
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                    }
                }
                else if (id==R.id.about)
                {
                    Intent intent=new Intent ( MainActivity.this, About.class );
                    startActivity ( intent);
                }
                return true;
            }
        });



    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {



        return actionBarDrawerToggle.onOptionsItemSelected(item)||  super.onOptionsItemSelected(item) ;
    }

}

Part 1 Video Complete now. this is video help you to learn this code kindly watch this video.

 

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

    android:layout_marginTop="20dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/linear"
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_margin="20dp"
        android:background="@drawable/splash"
        android:layout_width="100dp"
        android:layout_height="100dp"
        />
    <TextView

    android:id="@+id/titles"
        android:textColor="@android:color/black"
        android:textSize="20dp"
        android:text="Hey Here is title"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
</LinearLayout>

CustomAdapter.java

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomHolder>
{

    Context context;
    String []title;
    String [] urlLink;

    public CustomAdapter(Context context, String[] title, String[] urlLink) {
        this.context = context;
        this.title = title;
        this.urlLink = urlLink;
    }

    @NonNull
    @Override
    public CustomHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view= LayoutInflater.from ( context ).inflate ( R.layout.list_item,viewGroup,false );

        return new CustomHolder ( view );
    }

    @Override
    public void onBindViewHolder(@NonNull CustomHolder customHolder, int i)
    {

        String title1= title[i];
        final String urls=urlLink[i];

        customHolder.textView.setText ( title1 );

        customHolder.linearLayout.setOnClickListener ( new View.OnClickListener () {
            @Override
            public void onClick(View v) {

                Intent intent =new Intent ( context,FullView.class );

                intent.putExtra ( "url",urls );

                context.startActivity ( intent );
            }
        } );


    }

    @Override
    public int getItemCount() {
        return title.length;
    }

    class CustomHolder extends RecyclerView.ViewHolder {

       ImageView imageView;
       TextView textView;
       LinearLayout linearLayout;
        public CustomHolder(@NonNull View itemView) {
            super ( itemView );

            linearLayout=(LinearLayout ) itemView.findViewById ( R.id.linear );

            imageView=(ImageView) itemView.findViewById ( R.id.image );
            textView=(TextView) itemView.findViewById ( R.id.titles );
        }
    }

}

activity_full_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".FullView">


    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </WebView>
</android.support.constraint.ConstraintLayout>

FullView.java

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class FullView extends AppCompatActivity {

    WebView webView;
    private InterstitialAd mInterstitialAd;


    @Override
    public void onBackPressed() {
        super.onBackPressed ();
        IntertitialAd();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_full_view );
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        Intent intent= getIntent ();

        String url=intent.getStringExtra ( "url" );


        webView=(WebView) findViewById ( R.id.webview );
        WebSettings webSettings=webView.getSettings ();

        webSettings.setJavaScriptEnabled ( true );


        webView.loadUrl ( url );



    }

    void IntertitialAd()
    {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {

        }
    }
}


Part 2 & 3 is Complete now. this is video help you to learn this code kindly watch this video.

How to put ads in recyclerview. This tutorial help us so kindly watch this video.

activity_about.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="vertical"
    android:layout_gravity="center"
    android:gravity="center"
    tools:context=".About">


    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="@drawable/splash"
        />

    <TextView
        android:layout_marginTop="20dp"
        android:textStyle="bold"
        android:textSize="20dp"
        android:textColor="@android:color/black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" RRB GROUP D NTPC"
        />
    <TextView
        android:layout_marginTop="20dp"
        android:textStyle="bold"
        android:textSize="16dp"
        android:textColor="@android:color/black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" Verision 1.0"
        />


    <LinearLayout
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:layout_gravity="center"
        android:background="@android:color/black"

        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:gravity="center"

            android:textStyle="bold"
            android:textSize="16dp"
            android:textColor="@android:color/white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Visit My Website www.bsprogram.com"
            />


    </LinearLayout>

</LinearLayout>

About.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class About extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_about );
    }
}

6 thoughts on “How to make pdf book app using recyclerview in android studio”

  1. Assalamualaikum vai
    Can you please give me the the source code for this project. Because just copy pest from this post code are many error show in andoid Studio.. I follow your all video but too error show in project. Pls bro give me the source code of this project.

Leave a Reply

Your email address will not be published. Required fields are marked *