Pulse View In Android Using Android Studio

Introduction

 
In this article, we are going to create a Pulse View in Android using Android Studio. Pulse View is a type of library that makes an image as an icon. This View is used in most popular apps including ShareIt and Tinder.
 
Step 1
 
Create a new project in Android Studio.
 
 
Give a name to the project and click "Next".
 
 
Select the "Phone and Tablet" option and click "Next".
 
 
Select an empty activity and click "Next".
 
 
At last, give the activity name and click on "Finish".
 
 
Step 2
 
Next, copy the source image in .png format.
 
 
Locate app>>res>>drawable folder and paste the copied image into the drawable folder.
 
 
Check whether it is pasted correctly.
 
 
Step 3
 
Locate the Gradle Scripts>>Build. Gradle.
 
 
And, type the following dependency in your app's build.gradle.
 
 
Then, click the "Sync Now" button from the top right corner and repeat this for step 4.
 
 
Code copy is here,
  1. compile 'com.github.devlight.pulseview:library:1.0.2'  
Step 4
 
Next, go to app >> res >> layout >> activity_main.xml. Select activity page.
 
 
Just type the code as given below.
 
 
The code copy is here.
  1. <LinearLayout  
  2.        android:orientation="horizontal"  
  3.        android:layout_alignParentBottom="true"  
  4.        android:weightSum="2"  
  5.        android:layout_width="match_parent"  
  6.        android:layout_height="wrap_content">  
  7.   
  8.        <Button  
  9.            android:id="@+id/btnStart"  
  10.            android:text="Start"  
  11.            android:layout_weight="1"  
  12.            android:layout_width="0dp"  
  13.            android:layout_height="wrap_content" />  
  14.   
  15.        <Button  
  16.            android:id="@+id/btnStop"  
  17.            android:text="Stop"  
  18.            android:layout_weight="1"  
  19.            android:layout_width="0dp"  
  20.            android:layout_height="wrap_content" />  
  21.    </LinearLayout>  
  22.   
  23.    <com.gigamole.library.PulseView  
  24.        android:id="@+id/pv"  
  25.        android:layout_width="match_parent"  
  26.        android:layout_height="match_parent"  
  27.        app:pv_alpha="70"  
  28.        app:pv_color="#FFF"  
  29.        app:pv_icon="@drawable/ic"  
  30.        app:pv_icon_height="100dp"  
  31.        app:pv_icon_width="100dp"  
  32.        app:pv_measure="height"  
  33.        app:pv_spawn_period="500"  
  34.        app:pv_interpolator="@android:anim/linear_interpolator"  
  35.        />  
Step 5
 
Next, go to app>>res>>values>>Styles.xml
 
 
Just type the following code.
 
 
Code copy is here.
  1. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">  
  2.        <!-- Customize your theme here. -->  
  3.        <item name="colorPrimary">@color/colorPrimary</item>  
  4.        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  
  5.        <item name="colorAccent">@color/colorAccent</item>  
  6.    </style>  
Step 6
 
Next, go to app >> java>>Mainactivity.java. Select Mainactivity page.
 
 
Just type the following code.
 
 
Code copy is here.
  1. public class MainActivity extends AppCompatActivity {  
  2.   
  3.     PulseView pulseView;  
  4.     Button btnStart, btnStop;  
  5.   
  6.     @Override  
  7.     protected void onCreate(Bundle savedInstanceState) {  
  8.         super.onCreate(savedInstanceState);  
  9.         setContentView(R.layout.activity_main);  
  10.   
  11.         pulseView = (PulseView) findViewById(R.id.pv);  
  12.         btnStart = (Button) findViewById(R.id.btnStart);  
  13.         btnStop = (Button) findViewById(R.id.btnStop);  
  14.   
  15.         btnStart.setOnClickListener(new View.OnClickListener() {  
  16.             @Override  
  17.             public void onClick(View view) {  
  18.                 pulseView.startPulse();  
  19.             }  
  20.         });  
  21.   
  22.         btnStop.setOnClickListener(new View.OnClickListener() {  
  23.             @Override  
  24.             public void onClick(View view) {  
  25.                 pulseView.finishPulse();  
  26.             }  
  27.         });  
Step 7
 
Verify the preview.
After the code is applied, the preview will appear like this.
 
 
Step 8
 
Next, go to Android Studio and deploy the application. Select an Emulator or your mobile with USB debugging enabled. Give it a few seconds to make installations and set permissions.
 
 
Run the application in your desired emulator (Shift + F10).
 
 
Explanation of source code
 
The source code used in the activitymain.xml file will insert the image into the app and render the Pulse View of the image given.
 

Summary

 
We have just created the app to see how the Pulse View works and learned where to use it.
 
*Support and Share! Thank you*


Similar Articles