Guest User

Untitled

a guest
Jan 14th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.68 KB | None | 0 0
  1. import android.annotation.SuppressLint;
  2. import android.annotation.TargetApi;
  3. import android.graphics.Typeface;
  4. import android.os.Bundle;
  5. import android.os.CountDownTimer;
  6. import android.os.SystemClock;
  7. import android.support.design.widget.FloatingActionButton;
  8. import android.support.design.widget.Snackbar;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.support.v7.widget.Toolbar;
  11. import android.view.View;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.os.Build;
  15. import android.widget.Button;
  16. import android.widget.TextView;
  17. import java.util.concurrent.TimeUnit;
  18. import android.media.MediaPlayer;
  19.  
  20. @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  21. @SuppressLint("NewApi")
  22.  
  23. public class MainActivity extends AppCompatActivity {
  24.  
  25.     Button btnStart, btnStop, btn24, btn14, btnSound;
  26.     TextView textView1;
  27.     Integer timerVal;
  28.     long lastTime = 0, currentTime = 0;
  29.     CountDownTimer timer14, timer24;
  30.     boolean hasEnd, isPaused = false;
  31.  
  32.     @Override
  33.     protected void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         setContentView(R.layout.activity_main);
  36.  
  37.         btnStart = (Button) findViewById(R.id.btnStart);
  38.         btnStop = (Button) findViewById(R.id.btnStop);
  39.         btn14 = (Button) findViewById(R.id.btn14);
  40.         btnSound = (Button) this.findViewById(R.id.btnSound);
  41.         btn24 = (Button) findViewById(R.id.btn24);
  42.  
  43.         Typeface font = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
  44.         btn14.setTypeface(font);
  45.  
  46.         Typeface font2 = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
  47.         btn24.setTypeface(font2);
  48.  
  49.         Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "LCDAT&TPhoneTimeDate.ttf");
  50.         textView1 = (TextView)findViewById(R.id.textViewTime);
  51.         textView1.setTypeface(myTypeFace);
  52.         textView1.setText("00");
  53.  
  54.         final MediaPlayer dzwiekMP = MediaPlayer.create(this, R.raw.buzzer);
  55.  
  56.         btnStart.setOnClickListener(new View.OnClickListener() {
  57.             @Override
  58.             public void onClick(View v) {
  59.                 if(timerVal == 14) {
  60.                     timer14 = new CountDownTimer(timerVal - 1 * 1000, 1000) {
  61.                         @Override
  62.                         public void onTick(long millisUntilFinished) {
  63.                             lastTime = (millisUntilFinished / 1000);
  64.                             textView1.setText(String.valueOf(lastTime));
  65.                         }
  66.  
  67.                         @Override
  68.                         public void onFinish() {
  69.                             dzwiekMP.start();
  70.                         }
  71.                     };
  72.                     timer14.start();
  73.                 }
  74.  
  75. //                if(timerVal == 24)
  76. //                {
  77. //                   timer24 = new CountDownTimer((lastTime * 1000 != timerVal - 1 ? lastTime * 1000 : timerVal - 1 * 1000), 1000) {
  78. //                        @Override
  79. //                        public void onTick(long millisUntilFinished) {
  80. //                            lastTime = (millisUntilFinished / 1000);
  81. //                            currentTime = lastTime;
  82. //                            textView1.setText(String.valueOf(currentTime));
  83. //                        }
  84. //
  85. //                        @Override
  86. //                        public void onFinish() {
  87. //                            dzwiekMP.start();
  88. //                            hasEnd = true;
  89. //                        }
  90. //                    };
  91. //                    timer24.start();
  92. //                }
  93. //
  94. //                //if(hasEnd == false)
  95. //                   // timer24.start();
  96. //
  97. //                else {
  98. //                    timerVal = 0;
  99. //                    hasEnd = false;
  100. //                    return;
  101. //                }
  102.             }
  103.         });
  104.  
  105.         btnStop.setOnClickListener(new View.OnClickListener() {
  106.             @Override /** Nadpisanie metody */
  107.             public void onClick(View v) {
  108.                 if(!isPaused) {
  109.                     if (timerVal == 14)
  110.                         timer14.cancel();
  111.  
  112.                     if (timerVal == 24)
  113.                         timer24.cancel();
  114.  
  115.                     lastTime = currentTime;
  116.                     isPaused = true;
  117.                 }
  118.             }
  119.         });
  120.  
  121.         btnSound.setOnClickListener(new View.OnClickListener() {
  122.             @Override
  123.             public void onClick(View v) {
  124.                 dzwiekMP.start();
  125.             }
  126.         });
  127.  
  128.         btn14.setOnClickListener(new View.OnClickListener(){
  129.             @Override
  130.             public void onClick(View v) {
  131.                 timerVal = 14;
  132.                 textView1.setText("14");
  133.             }
  134.         });
  135.  
  136.         btn24.setOnClickListener(new View.OnClickListener(){
  137.             @Override
  138.             public void onClick(View v) {
  139.                 timerVal = 24;
  140.                 textView1.setText("24");
  141.             }
  142.         });
  143.     }
  144.  
  145. //    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  146. //    @SuppressLint("NewApi")
  147. //    public class CounterClass extends CountDownTimer {
  148. //
  149. //        long millisToCount, countDownInt;
  150. //
  151. //        public CounterClass(long millisInFuture, long countDownInterval) {
  152. //            super(millisInFuture, countDownInterval);
  153. //
  154. //
  155. //        }
  156. //
  157. //        @SuppressLint("NewApi")
  158. //        @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  159. //        @Override
  160. //        public void onTick(long millisUntilFinished) {
  161. //
  162. //            long cnt = millisUntilFinished / 1000;
  163. //            textView1.setText(cnt + "");
  164. //        }
  165. //
  166. //        @Override
  167. //        public void onFinish() {
  168. //
  169. //        }
  170. //    }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment