How to Build a Simple Android App for Breathing Exercise?
Android mobiles are very handy, and they provide the information instantaneously. Just assume that you are continuously flying or attending patients or participating in meetings etc., very often. During those times, there are possibilities of getting stressed and hence meditation is very much essential in this fast running lives. Here providing the source code for the breathing exercise app and surely that will be helpful to get more energetic and enthusiastic. 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.
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: Before going to the coding section first you have to do some pre-task
Go to the app > res > values > colors.xml file and set the colors for your app.
Go to the Gradle Scripts > build.gradle (Module: app) file and import the following dependencies and click the “Sync Now” on the above pop up.
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
exclude group: ‘com.android.support’, module: ‘support-annotations’
Below is the complete code for the build.gradle (Module: app) file:
Step 3: Designing the UI Part
Working with the activity_main.xml file:
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Here, content_main.xml got included. Below is the code for it:
You can see in above code as “bg_circle_inner” and “bg_circle_outer“. That we need to create (Go to the drawable > right-click > New > Drawable Resource File) in the drawable folder.
Below is the code for the bg_circle_inner.xml file:
Below is the code for the bg_circle_outer.xml file:
Basically, bg_circle_outer.xml and bg_circle_inner.xml are the XML files that create oval shape and they are used in content_main.xml. They meant to show the “inhale” and “exhale” purpose.
Step 4: Working with the Java file
Working with the MainActivity.java file:
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file.
Create a new java class and name the file as SettingsUtils. Below is the code for the SettingsUtils.java class file.
Create a new java class and name the file as BreathePreferences. Below is the code for the BreathePreferences.java class file.
Create a new java class and name the file as Constants. Below is the code for the Constants.java class file.
Create a new java Enum and name the file as Preset. Below is the code for the Preset.java class file.
Create a new java class and name the file as SettingsDialog. Below is the code for the SettingsDialog.java class file.
On execution of code, we can able to get the output as shown in the attached video.
Github Link: https://github.com/raj123raj/meditation