Skip to content
Related Articles

Related Articles

Improve Article

Implementation of WhatsNew Library in Android

  • Last Updated : 15 May, 2021

In this article, we are going to show the important content of the app using the WhatsNew library. It can be simply thought of like showing some information like notification, instruction, faq, or terms and conditions like things. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.



Step 2: Add dependency and mavenCentral() Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation ‘io.github.tonnyl:whatsnew:0.1.7’

Add the mavenCentral() repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects {

 repositories {

   …

   mavenCentral()

     }

}

After adding this dependency sync your project and now we will move towards its implementation.  

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 



XML




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">
  
    <Button
        android:id="@+id/whatsnew"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Whats New" />
      
</LinearLayout>

Step 4: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. 

// This is what we are using to show our data
new WhatsNewItem(“Firebase Authentication”, “Firebase Authentication service provides easy to use UI libraries and SDKs to authenticate users to your app.”, R.drawable.circle),

Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.

Java




import android.os.Bundle;
import android.view.View;
import android.widget.Button;
  
import androidx.appcompat.app.AppCompatActivity;
  
import io.github.tonnyl.whatsnew.WhatsNew;
import io.github.tonnyl.whatsnew.item.WhatsNewItem;
import io.github.tonnyl.whatsnew.util.PresentationOption;
  
public class MainActivity extends AppCompatActivity {
  
    Button button;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
          
        // initialising layout
        button = findViewById(R.id.whatsnew);
          
        // click on button
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // creating a new Instance for 
                // showing Content using WhatsNew
                WhatsNew whatsNew = WhatsNew.newInstance(
                        // add as much item you want with 
                        // item title, description and image
                        new WhatsNewItem("Firebase Authentication", "Firebase Authentication service provides easy to use UI libraries and SDKs to authenticate users to your app.", R.drawable.circle),
                        new WhatsNewItem("Firebase Realtime Database", "The Firebase Realtime Database is a cloud based NoSQL database ", R.drawable.circle),
                        new WhatsNewItem("Cloud Firestore", " The cloud Firestore is a NoSQL document database that provides services like store, sync, and query through the application on a global scale", R.drawable.circle),
                        new WhatsNewItem("Firebase", " irebase is a product of Google which helps developers to build, manage, and grow their apps easily. It helps developers to build their apps faster and in a more secure way.", WhatsNewItem.NO_IMAGE_RES_ID)
                );
                whatsNew.setPresentationOption(PresentationOption.DEBUG);
                // on click present this layout
                whatsNew.presentAutomatically(MainActivity.this);
            }
        });
    }
}

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :