Today the usage of smartphones is increasing day by day. the smartphone makes the task very easy. today many of smartphone is very useful for people like the smartphone is used in management. the smartphone makes it possible to connect with each other. the concept of the internet is well defined in smartphones. the cell tower is well managed for smartphones for making calls and provides an internet connection to smartphones. the smartphone makes very complex calculations easy. as the craze and usage of smartphones is increasing day by day, many android developers taking advantage of it. they are making new useful android apps and uploads that app on the google play store. their apps are getting millions of downloads. I have made many android apps that are very useful to simple people. I have made Age calculator which is able to tell you're correct age throw your birthdate. you just have to enter your birthdate in this app and your correct age is automatically generated and displays to you. the smartphone makes human life very simple and easy.
Many smartphone apps are very useful in health, automation, artificial intelligence, traveling.
If you make an android app, that will be very beneficial to you. you will earn money throw your app because the craze of the smartphone app is increasing day by day. in this article I will show you that how you can make an age calculator in the android studio first I am showing you the code of the age calculator then I will explain to you how I made this app.
Age calculator Android app explanation:-
following things required to make age calculator app:-
- knowledge of java language
- data structure
- basic knowledge of programming
- android studio
- xml
- android
Manifest file:-
This includes a definition of all the components of android. this manifest file includes only one activity that is the main activity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ak.akshay.calc">
<application
android:allowBackup="true"
android:icon="@mipmap/age"
android:label="Age Calculator 2021"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Calc">
<activity android:name=".devendra">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>
MainActivity:-
MainActivity includes the main logic of building an age calculator.
Logic:- first subtract birthyear from current - from doing this you will get how old are you.
- now according to birthmonth and birthday , now make neccesary changes in month and year according to the value of birthmonth and current month.
package ak.akshay.calc;
import android.util.Log;
import android.view.View;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Devendra extends Activity {
EditText date;
TextView age;
protected void onCreate(Bundle dd)
{
super.onCreate(dd);
setContentView(R.layout.activity_main);
}
public void clkbtn(View vv) throws ParseException {
date=(EditText) findViewById(R.id.agee);
age=(TextView) findViewById(R.id.age);
String bdate=date.getText() + "";
Date dt=Calendar.getInstance().getTime();
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
String tdate=sdf.format(dt);
String bdatee[]=bdate.split("/");
String tdatee[]=tdate.split("/");
int cd=Integer.parseInt(tdatee[0]),cm=Integer.parseInt(tdatee[1]),cy=Integer.parseInt(tdatee[2]),bd=Integer.parseInt(bdatee[0]),bm=Integer.parseInt(bdatee[1]),by=Integer.parseInt(bdatee[2]);
Log.e("ak",bdate + tdate );
int fyear=cy-by;
int fmonth=0;
int fday=0;
int lastd=0;
int temp=0;
int lastDayOfMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=0;i<lastDayOfMonth.length;i++)
{
if(i+1==bm)
{
lastd=lastDayOfMonth[i];
}
}
if(cm!=bm) {
if(bd>cd) {
fday = (lastd - bd) + cd;
}
else if(bd<cd)
{
temp=cd-bd;
fday=lastd-temp;
}
if (fday >= lastd) {
fmonth = fday / lastd;
fday = fday % lastd;
if(fmonth==12)
{
fmonth=0;
fyear++;
}
}
if (bm > cm) {
fyear--;
fmonth = fmonth + (12 - bm);
} else {
fmonth = fmonth + (bm - cm);
}
}
else{
if(bd>cd)
{
fday=bd-cd;
}
else if(bd<cd)
{
fyear--;
fmonth=11;
temp=cd-bd;
fday=lastd - temp;
if (fday >= lastd) {
fmonth = fmonth + (fday / lastd);
fday = fday % lastd;
if(fmonth==12)
{
fmonth=0;
fyear++;
}
}
}
else if(bd==cd){
fmonth=0;
fday=0;
}
}
age.setText(fyear + " Years " + fmonth + "Months " + fday + "Days" );
}
}
Layout file:-
The layout file includes all the UI components that is required in making an age calculator.
- layout file includes edittext,textbox,image, button etc.
<?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"
android:background="#1B1A1A">
<TextView
android:id="@+id/textView"
android:layout_width="357dp"
android:layout_height="58dp"
android:background="#656ECA"
android:fontFamily="sans-serif-smallcaps"
android:onClick="clickbtn"
android:paddingLeft="90sp"
android:paddingTop="10dp"
android:shadowColor="#1A1A1B"
android:shadowDx="11"
android:shadowDy="1"
android:shadowRadius="10"
android:text="AGE COUNTER"
android:textColor="#FBECEC"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.84"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/ip"
android:layout_width="346dp"
android:layout_height="40dp"
android:layout_marginTop="36dp"
android:text="Enter your BIRTHDATE :"
android:textColor="#EADFDF"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/btn"
android:layout_width="172dp"
android:layout_height="47dp"
android:layout_marginTop="20dp"
android:background="#00FFD4"
android:fontFamily="@font/aclonica"
android:onClick="clkbtn"
android:padding="0dp"
android:shadowColor="#E4D7D7"
android:shadowDx="1"
android:shadowDy="2"
android:shadowRadius="40"
android:text="Count"
app:cornerRadius="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/agee" />
<TextView
android:id="@+id/textView3"
android:layout_width="215dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:shadowDx="4"
android:shadowDy="2"
android:shadowRadius="3"
android:text="AGE "
android:textColor="@color/mycolor"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.889"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn" />
<TextView
android:id="@+id/age"
android:layout_width="361dp"
android:layout_height="105dp"
android:layout_marginTop="16dp"
android:hint="your age will display here..."
android:shadowColor="#FFFFFF"
android:textColor="#F8F8F8"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.842"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/imageView"
android:layout_width="232dp"
android:layout_height="188dp"
android:layout_marginTop="12dp"
android:scaleType="fitEnd"
android:src="@drawable/bst"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/age"
app:layout_constraintVertical_bias="1.0" />
<EditText
android:id="@+id/agee"
android:layout_width="306dp"
android:layout_height="52dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="date"
android:singleLine="false"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ip" />
<TextView
android:id="@+id/textView2"
android:layout_width="113dp"
android:layout_height="30dp"
android:layout_marginTop="88dp"
android:text="@aboti_akshay"
android:textColor="#FBFBFB"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/age"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/textView4"
android:layout_width="85dp"
android:layout_height="64dp"
android:layout_marginBottom="20dp"
android:fontFamily="sans-serif-medium"
android:soundEffectsEnabled="true"
android:text="AVPTI"
android:textColor="#FFFFFF"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintHorizontal_bias="0.627"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/age"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
0 Comments