Skip to content

Commit

Permalink
Egg horn app.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharun Reddy Chinthala authored and Tharun Reddy Chinthala committed Sep 11, 2017
1 parent 8ec34a9 commit 8a9e696
Show file tree
Hide file tree
Showing 31 changed files with 713 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Binary file added app/app-release.apk
Binary file not shown.
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.tharunreddychinthala.eggtimer"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/tharunreddychinthala/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.tharunreddychinthala.eggtimer;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.example.tharunreddychinthala.eggtimer", appContext.getPackageName());
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tharunreddychinthala.eggtimer">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package com.example.tharunreddychinthala.eggtimer;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

// Max time in timer is 10 min or 600 sec.
private static final int MAX_SEC = 600;
// Seconds in min 60.
private static final int SECONDS_IN_MIN = 60;
// Base Unit is sec in millsec
private static final int BASE_TIME_UNIT = 1000;
// Default Time in sec.
private static final int DEFAULT_TIME = 30;
private static final String GO = "GO";
private static final String STOP = "STOP";
private static String CLOCK_VIEW_STRING = "%s:%s";

// previousEggClockState : true - Go
// previousEggClockState : false - Stop
private boolean previousEggClockState = false;

private CountDownTimer countDownTimer;

// current time remaining in timer.
private int timerTime;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setOnClickListnerForSeekBar();
setSeekBarMax(MAX_SEC);
setSeekBar(DEFAULT_TIME);
setEggTimerButtonStateToGo();
}

private void setOnClickListnerForSeekBar() {
SeekBar seekBar = getEggSeekBar();
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
setClockTextView(seekBar.getProgress());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do Nothing.
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do Nothing.
}
});
}

/**
* Will stopState the timer to 30.
*/
public void reset(View view) {
if (previousEggClockState) {
// When the button if click to Go.
stopState();
} else {
goState();
}
}

private void goState() {
previousEggClockState = true;
timerTime = getSeekBarProgress();
setClockTextView(timerTime);

setEggTimerButtonStateToStop();

startCountDown(timerTime);

disableSeekBar();
}


private void stopState() {
previousEggClockState = false;
setSeekBar(DEFAULT_TIME);
setClockTextView(DEFAULT_TIME);
setEggTimerButtonStateToGo();

stopCountDown();

enableSeekBar();
}

private void startCountDown(int eggClockTimeInSec) {
final Context context = this;
final int eggClockTimeInMilliSec = eggClockTimeInSec * BASE_TIME_UNIT;
countDownTimer = new CountDownTimer(eggClockTimeInMilliSec, BASE_TIME_UNIT) {
@Override
public void onTick(long l) {
timerTime--;
setSeekBar(timerTime);
setClockTextView(timerTime);

}

@Override
public void onFinish() {
// Play sound.
final MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.airhorn);
mediaPlayer.start();
}
};

countDownTimer.start();
}

private void stopCountDown() {
countDownTimer.cancel();
}


/**
* Takes the time in sec and converts that to min and sec and shows it in the text view.
* @param timeInSec time in seconds.
*/
private void setClockTextView(int timeInSec) {
int min = timeInSec/60;

String eggTimer = String.format(CLOCK_VIEW_STRING,
getRemainingMin(timeInSec), getRemainingSecInDoubleDigit(timeInSec));;

TextView eggTimerClock = (TextView) findViewById(R.id.eggTimerClock);

eggTimerClock.setText(eggTimer);
}

private String getRemainingMin(int timeInSec) {
return String.valueOf(timeInSec/60);
}

/**
* Will give the sec after removeing the min.
* @param timeInSec time in seconds
* @return remaining sec after min are removed.
*/
private String getRemainingSecInDoubleDigit(int timeInSec) {
int remainingSec = timeInSec%60;
if (remainingSec < 10) {
return String.format("0" + remainingSec);
} else {
return String.valueOf(remainingSec);
}
}

/**
* Will set the eggTimerSeekBar to given progress.
* @param progress progress
*/
private void setSeekBar(int progress) {
getEggSeekBar().setProgress(progress);
}

private void setSeekBarMax(int progress) {
getEggSeekBar().setMax(progress);
}

private int getSeekBarProgress() {
return getEggSeekBar().getProgress();
}

private void setEggTimerButtonStateToGo() {
getEggTimerButton().setText(GO);
}

private void setEggTimerButtonStateToStop() {
getEggTimerButton().setText(STOP);
}

private void disableSeekBar() {
getEggSeekBar().setEnabled(false);
}

private void enableSeekBar() {
getEggSeekBar().setEnabled(true);
}

private Button getEggTimerButton() {
return (Button) findViewById(R.id.eggTimerButton);
}

private SeekBar getEggSeekBar() {
return (SeekBar) findViewById(R.id.eggTimerSeekBar);
}
}
Binary file added app/src/main/res/drawable/eggtimer.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.example.tharunreddychinthala.eggtimer.MainActivity">

<SeekBar
android:id="@+id/eggTimerSeekBar"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/eggTimerImage"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/eggTimerImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="@drawable/eggtimer"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="1.0" />

<TextView
android:id="@+id/eggTimerClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="170dp"
android:background="@color/colorAccent"
android:text="0:30"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="@+id/eggTimerButton"
app:layout_constraintLeft_toLeftOf="@+id/eggTimerImage"
app:layout_constraintRight_toRightOf="@+id/eggTimerImage"
app:layout_constraintTop_toTopOf="@+id/eggTimerImage"
app:layout_constraintVertical_bias="0.017" />

<Button
android:id="@+id/eggTimerButton"
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/black"
android:onClick="reset"
android:text="Go"
app:layout_constraintBottom_toBottomOf="@+id/eggTimerImage"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/eggTimerImage"
app:layout_constraintVertical_bias="0.94" />
</android.support.constraint.ConstraintLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/raw/airhorn.mp3
Binary file not shown.
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#ff4081</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">EggTimer</string>
</resources>
Loading

0 comments on commit 8a9e696

Please sign in to comment.