Best Way to Create Timer App in Android

Best Way to Create Timer App in Android

Best Way to Create Timer App in Android

 

Hello Guys! in this article, I will tell you about an android app concept of timer app. Many people ask me that how can we create a timer app in android. So if you also have this question and if you are finding the best way to create timer app in android then you are at right place. Here you can get information for the best way to create timer app in android. In this article, you can get the source code for creating a timer app in android.




Best Way to Create Timer App in Android

Source code for Timer App in Android




activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@drawable/background"
tools:context="sumit.net.timerapp.MainActivity">

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/timer"
android:textSize="40dp"
android:textColor="#000000"
android:text="00:00:00"
android:paddingLeft="100dp"
android:paddingTop="50dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_below="@+id/timer"
android:layout_marginTop="20dp"
android:text="Start"
android:background="@drawable/button"
android:paddingLeft="20dp"
android:id="@+id/start"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/start"
android:layout_marginTop="20dp"
android:text="Pause"
android:background="@drawable/button"
android:paddingLeft="10dp"
android:id="@+id/pause"
/>

</RelativeLayout>




MainActivity.java

package sumit.net.timerapp;

import android.animation.TimeAnimator;
import android.media.TimedText;
import android.os.Handler;
import android.os.SystemClock;
import android.os.health.TimerStat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.Time;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

import org.w3c.dom.Text;

import java.util.Timer;

public class MainActivity extends AppCompatActivity {
TextView t1;
Button b1,b2;
long startTime=0L;
private Handler customHandler=new Handler();
long timeInMilliseconds=0L;
long timeSwapBuff=0L;
long updateTime=0L;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(TextView)findViewById(R.id.timer);
b1=(Button)findViewById(R.id.start);
b2=(Button)findViewById(R.id.pause);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startTime= SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timeSwapBuff +=timeInMilliseconds;
customHandler.removeCallbacks(updateTimerThread);
}
});

}
private Runnable updateTimerThread=new Runnable() {
@Override
public void run() {
timeInMilliseconds=SystemClock.uptimeMillis()-startTime;
updateTime=timeSwapBuff+timeInMilliseconds;
int sec=(int) (updateTime/600);
int mins=sec/60;
sec=sec%60;
int milliseconds=(int) (updateTime%100);
t1.setText(""+ mins + ":"+ String.format("%02d",sec)+ ":"+String.format("%03d",milliseconds));
customHandler.postDelayed(this,0);
}
};
}




Output of Time App

Best Way to Create Timer App in Android

Conclusion

So you got information about the best way to create a timer app in android. I hope you understand the method to create a timer app in android. Thank you for reading this article till the end. If you love this article then please share this article in your social media platforms. And share your thought in the comment section below. If you have any question regarding this article then write your question in the comment section. I will try to give the answer to them.




android tutorial skillmaking

Android App Design Template

Android App Design Template

 

android template



<?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"
    tools:context="sumit.net.java_tutorial.tutorials.Home">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alignmentMode="alignMargins"
        android:columnOrderPreserved="false"
        android:background="@drawable/background"
        android:layout_weight="8"
        android:padding="14dp"
        android:rowCount="3"
        android:columnCount="2">
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp"
            >




            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="150dp"
                    android:src="@drawable/tutorial1"
                    android:layout_gravity="center_horizontal"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tutorials"
                    android:textAlignment="center"
                    android:textColor="@android:color/black"
                    android:textSize="18dp"
                    android:textStyle="bold"

                    />
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp"
            >
            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="150dp"
                    android:src="@drawable/program"
                    android:layout_gravity="center_horizontal"/>



                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Learn Programs"
                    android:textAlignment="center"
                    android:textColor="@android:color/black"
                    android:textSize="18dp"
                    android:textStyle="bold"

                    />
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp"
            >
            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/aboutus"
                    android:layout_gravity="center_horizontal"/>
            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp"
            >



            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="150dp"
                    android:src="@drawable/share"
                    android:layout_gravity="center_horizontal"/>
            </LinearLayout>
        </android.support.v7.widget.CardView>



    </GridLayout>
</LinearLayout>

 

android tutorial skillmaking

How To Create a Web View in Android App

How To Create a Web View in Android App

 

If you want to know that how to create a Web View in Android App then you should read this article till end. Here I will explain to you that how can you make a web view in your android app. I hope this article may helpful for you.



Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="sumit.net.web.MainActivity">

<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>




 MainActivity.java

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends ActionBarActivity {
private WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://example.com");
myWebView.setWebViewClient(new WebViewClient());
}

I hope this code will help you to create a web view in the Android app. If you got any solution by this code then you please share your thoughts about this article in the comment section. If you got any problem then also post a comment, i will try to give the answer them.



android tutorial skillmaking

How to Create Splash Screen in Android

How to Create Splash Screen in Android





If you are an android developer. And also want to learn that how to create splash screen in Android then you should read this article till end. Here you can get all information with coding about splash screen in android.

If you want to create an android app who has also Splash screen then you should read this article which is given below. You need two activities. The fist one is used to create a splash screen and the second one is used to create a activity_main.xml

Step 1:

Create two activities. First one is activity_main.xml and the second one is activity_second.xml.

Step 2:

Copy an image and paste into a drawable folder.

Step 3:

Set the background image in activity_main.xml.



Step 4:

Open MainActivity.java and write this code.

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

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i=new Intent(MainActivity.this,Second.class);
                startActivity(i);
            }
        },3000);
    }
}

Step 5:

Run this app in your mobile.



Output:

splash screen in android

Note: Random Number Generator

AutoComplete Text View

Alert Dialog Box in Android

android tutorial skillmaking

How to Create Alert Dialog Box in Android

How to Create Alert Dialog Box in Android

If you want to create an Alert Dialog Box in android then you should read this article till end. Here you can get all the information about this topic.



activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="sumit.net.alert_dialog.MainActivity">

    <Button
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:id="@+id/btn1"
        android:text="exit"
        android:textSize="22dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginStart="89dp"
        android:layout_marginTop="193dp" />

</RelativeLayout>




MainActivity.java

package sumit.net.alert_dialog;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
Button b1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button)findViewById(R.id.btn1);
        new AlertDialog.Builder(MainActivity.this)
                .setIcon(R.mipmap.ic_launcher)
                .setTitle("game")
                .setMessage("do you want surf this page")
                .setPositiveButton("Yes",null)
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent i=new Intent(MainActivity.this,Splash.class);
                startActivity(i);
            }
        }).show();
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(MainActivity.this)
                        .setIcon(R.mipmap.ic_launcher)
                    .setTitle("Exit")
                        .setMessage("do you want exit")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        }).setNegativeButton("No",null)
                        .show();


            }
        });
    }

    @Override
    public void onBackPressed() {
        new AlertDialog.Builder(MainActivity.this)
                .setIcon(R.mipmap.ic_launcher)
                .setTitle("game")
                .setMessage("dO you want exit this application")
                .setPositiveButton("yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        moveTaskToBack(true);

                    }
                }).setNegativeButton("no",null)
                .show();

    }
}




OUTPUT

dialog box in android alert dialog box in android

random-number-generator

How to Create Random Number Generator in Android

How to Create Random Number Generator in Android

 

If you want to create an application which can generate random numbers then you should read this article. Here you can get all information about random number generator in android with all xml code and java code. Here you will also get output of this application.



activity_main.xml of Random Number Generator in Android

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="sumit.net.random.MainActivity">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Generated Number"
        android:textSize="75sp"
        android:textColor="#ff0000"
        >
    </TextView>
    <Button
        android:id="@+id/push_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Here"
        android:textSize="20sp"
        android:layout_below="@id/text_view"
        >
    </Button>

</RelativeLayout>




MainActivity.java of Random Number Generator in Android

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView tv = (TextView) findViewById(R.id.text_view);
    final Button b=(Button)findViewById(R.id.push_button);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Random r = new Random();
                        int randomNumber = r.nextInt(100);
                        tv.setText(String.valueOf(randomNumber));
                    }
                },2000);

            }
        });

    }
}

The output of Random Number Generator in Android

random number generator             random number generator