<?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="@drawable/workout2"
tools:context=".MainActivity">
<ImageView
android:id="@+id/ivSplash"
android:layout_width="169dp"
android:layout_height="83dp"
android:layout_marginTop="90dp"
android:scaleType="centerCrop"
android:src="@drawable/logo1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvSplash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="280dp"
android:layout_marginEnd="8dp"
android:text="Running StopWatch"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="23sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ivSplash" />
<TextView
android:id="@+id/tvSubSplash"
android:text="Even a stopped clock is right twice a day..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="3dp"
android:textColor="#fff"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvSplash"/>
<Button
android:id="@+id/bSplash"
android:layout_width="288dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="80dp"
android:background="@drawable/bgbutton"
android:text="Get Started"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/tDeveloper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="8dp"
android:text="Design and Developed By"
android:textColor="#fff"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bSplash" />
<TextView
android:id="@+id/tDeveloperName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="1dp"
android:text="Al Rubyat"
android:textColor="#fff"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tDeveloper" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package rubyat13.shuvho13.stopwatch;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
//Design and Development By Al Rubyat
import static android.graphics.Typeface.*;
public class MainActivity extends AppCompatActivity {
TextView tvSplash, tvSubSplash;
Button bSplash;
Animation atg;
ImageView ivSplash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvSplash = findViewById(R.id.tvSplash);
tvSubSplash = findViewById(R.id.tvSubSplash);
bSplash = findViewById(R.id.bSplash);
ivSplash = findViewById(R.id.ivSplash);
atg = AnimationUtils.loadAnimation(this, R.anim.atg);
//Passing Animation
ivSplash.startAnimation(atg);
//Passing Activity event (Get Started button)
bSplash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a = new Intent(MainActivity.this, StopWatchActivity.class);
a.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(a);
}
});
//Import font
Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/MLight.ttf");
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MMedium.ttf");
Typeface MRegular = Typeface.createFromAsset(getAssets(), "fonts/MRegular.ttf");
// Customize font
tvSplash.setTypeface(MRegular);
tvSubSplash.setTypeface(MLight);
bSplash.setTypeface(MMedium);
}
}
Stop_watch_activity.xml
<?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="@color/colorPrimaryDark"
tools:context=".MainActivity">
<ImageView
android:id="@+id/bgcircle"
android:layout_width="276dp"
android:layout_height="247dp"
android:layout_marginStart="73dp"
android:layout_marginTop="60dp"
android:src="@drawable/bgcircle"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.464"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="73dp" />
<ImageView
android:id="@+id/icanchor"
android:layout_width="358dp"
android:layout_height="357dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:src="@drawable/icanchor"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="8dp"
android:layout_marginLeft="30dp" />
<Chronometer
android:id="@+id/timerHere"
android:layout_width="206dp"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:textColor="#FFF"
android:textSize="62sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bgcircle" />
<Button
android:id="@+id/bStart"
android:layout_width="288dp"
android:layout_height="55dp"
android:layout_marginBottom="130dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Start"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="20sp"
android:background="@drawable/bgbutton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
/>
<Button
android:id="@+id/bStop"
android:layout_width="288dp"
android:layout_height="55dp"
android:layout_marginBottom="50dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Finish"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="20sp"
android:background="@drawable/buttonstop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
stop_watch_activity.java
package rubyat13.shuvho13.stopwatch;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.logging.Logger;
/*
Copyright (c) 2020, Al Rubyat Shuvho
*/
public class StopWatchActivity extends AppCompatActivity {
Button bStart, bStop;
ImageView icanchor;
Animation roundingicon;
Chronometer timerHere;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stop_watch);
bStart =findViewById(R.id.bStart);
bStop =findViewById(R.id.bStop);
icanchor =findViewById(R.id.icanchor);
timerHere =findViewById(R.id.timerHere);
//creaete optional animation
bStop.setAlpha(0);
//load animation
roundingicon = AnimationUtils.loadAnimation(this,R.anim.roundingicon);
//Import font
Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MMedium.ttf");
//Customize font
bStart.setTypeface(MMedium);
bStop.setTypeface(MMedium);
bStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//passing Animation
icanchor.startAnimation(roundingicon);
bStop.animate().alpha(1).translationY(-80).setDuration(300).start();
bStart.animate().alpha(0).setDuration(300).start();
//Start time
timerHere.setBase(SystemClock.elapsedRealtime());
timerHere.start();
bStop.setVisibility(View.VISIBLE);
bStart.setVisibility(View.INVISIBLE);
}
});
bStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timerHere.stop();
timerHere.setBase(SystemClock.elapsedRealtime());
icanchor.startAnimation(roundingicon);
bStart.animate().alpha(1).setDuration(300).start();
bStop.animate().alpha(0).setDuration(300).start();
bStart.setVisibility(View.VISIBLE);
bStop.setVisibility(View.INVISIBLE);
}
});
}
}