Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.annotation.SuppressLint;
- import android.annotation.TargetApi;
- import android.graphics.Typeface;
- import android.os.Bundle;
- import android.os.CountDownTimer;
- import android.os.SystemClock;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.Snackbar;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.View;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.os.Build;
- import android.widget.Button;
- import android.widget.TextView;
- import java.util.concurrent.TimeUnit;
- import android.media.MediaPlayer;
- @TargetApi(Build.VERSION_CODES.GINGERBREAD)
- @SuppressLint("NewApi")
- public class MainActivity extends AppCompatActivity {
- Button btnStart, btnStop, btn24, btn14, btnSound;
- TextView textView1;
- Integer timerVal;
- long lastTime = 0, currentTime = 0;
- CountDownTimer timer14, timer24;
- boolean hasEnd, isPaused = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- btnStart = (Button) findViewById(R.id.btnStart);
- btnStop = (Button) findViewById(R.id.btnStop);
- btn14 = (Button) findViewById(R.id.btn14);
- btnSound = (Button) this.findViewById(R.id.btnSound);
- btn24 = (Button) findViewById(R.id.btn24);
- Typeface font = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
- btn14.setTypeface(font);
- Typeface font2 = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
- btn24.setTypeface(font2);
- Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
- textView1 = (TextView)findViewById(R.id.textViewTime);
- textView1.setTypeface(myTypeFace);
- textView1.setText("00");
- final MediaPlayer dzwiekMP = MediaPlayer.create(this, R.raw.buzzer);
- btnStart.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(timerVal == 14) {
- timer14 = new CountDownTimer(timerVal - 1 * 1000, 1000) {
- @Override
- public void onTick(long millisUntilFinished) {
- lastTime = (millisUntilFinished / 1000);
- textView1.setText(String.valueOf(lastTime));
- }
- @Override
- public void onFinish() {
- dzwiekMP.start();
- }
- };
- timer14.start();
- }
- // if(timerVal == 24)
- // {
- // timer24 = new CountDownTimer((lastTime * 1000 != timerVal - 1 ? lastTime * 1000 : timerVal - 1 * 1000), 1000) {
- // @Override
- // public void onTick(long millisUntilFinished) {
- // lastTime = (millisUntilFinished / 1000);
- // currentTime = lastTime;
- // textView1.setText(String.valueOf(currentTime));
- // }
- //
- // @Override
- // public void onFinish() {
- // dzwiekMP.start();
- // hasEnd = true;
- // }
- // };
- // timer24.start();
- // }
- //
- // //if(hasEnd == false)
- // // timer24.start();
- //
- // else {
- // timerVal = 0;
- // hasEnd = false;
- // return;
- // }
- }
- });
- btnStop.setOnClickListener(new View.OnClickListener() {
- @Override /** Nadpisanie metody */
- public void onClick(View v) {
- if(!isPaused) {
- if (timerVal == 14)
- timer14.cancel();
- if (timerVal == 24)
- timer24.cancel();
- lastTime = currentTime;
- isPaused = true;
- }
- }
- });
- btnSound.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dzwiekMP.start();
- }
- });
- btn14.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- timerVal = 14;
- textView1.setText("14");
- }
- });
- btn24.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- timerVal = 24;
- textView1.setText("24");
- }
- });
- }
- // @TargetApi(Build.VERSION_CODES.GINGERBREAD)
- // @SuppressLint("NewApi")
- // public class CounterClass extends CountDownTimer {
- //
- // long millisToCount, countDownInt;
- //
- // public CounterClass(long millisInFuture, long countDownInterval) {
- // super(millisInFuture, countDownInterval);
- //
- //
- // }
- //
- // @SuppressLint("NewApi")
- // @TargetApi(Build.VERSION_CODES.GINGERBREAD)
- // @Override
- // public void onTick(long millisUntilFinished) {
- //
- // long cnt = millisUntilFinished / 1000;
- // textView1.setText(cnt + "");
- // }
- //
- // @Override
- // public void onFinish() {
- //
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment