package com.itti7.itimeu;


import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * A simple {@link Fragment} subclass.
 */
public class TimerFragment extends Fragment {
    /*timer components*/
    private TextView mTimeText;
    private ProgressBar mProgressBar;
    private Button mStateBttn;
    /*button state value*/
    final boolean STATE_PLAY=true;
    final boolean STATE_STOP=false;
    private boolean state=STATE_STOP;
    /*progressBar state value*/
    private Handler handler;
    private int progressBarValue = 0;
    /*timer calc*/
    private CountDownTimer mCalcTimer;
    public TimerFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View timerView = inflater.inflate(R.layout.activity_timer, container, false);

        /*progressBar button init*/
        mProgressBar = (ProgressBar)timerView.findViewById(R.id.progressBar);
        mStateBttn = (Button)timerView.findViewById(R.id.state_bttn_view);
        mStateBttn.setOnClickListener(stateChecker);

        /*Time Text Initialize */
        mTimeText = (TextView)timerView.findViewById(R.id.time_txt_view);
        int time = Integer.parseInt(getString(R.string.time).split(":")[1]);
        mProgressBar.setMax(time);
        mCalcTimer = new CountDownTimer(time*1000*60,1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                String hour = String.format("%02d",(millisUntilFinished / (1000*60*60)) );
                String min = String.format("%02d",(millisUntilFinished / (1000*60)) );

                mTimeText.setText(hour+":"+min);
                /*mTimeText.setText("seconds remaining: " + millisUntilFinished / 1000); //TesterCode*/
            }

            @Override
            public void onFinish() {
                        /*alarm or vibration*/
                mTimeText.setText("done!");
            }
        };
        handler = new Handler()
        {
            public void handleMessage(android.os.Message msg)
            {
                if(state)
                {
                    progressBarValue++;
                }
                mProgressBar.setProgress(progressBarValue);
                handler.sendEmptyMessageDelayed(0, 1000*60); //increase by min
            }
        };

        handler.sendEmptyMessage(0);
        return timerView;
    }

    Button.OnClickListener stateChecker =new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            state=!state;
            if(state==STATE_PLAY){
                mCalcTimer.start();
                mStateBttn.setText(R.string.stop);
            }
            else{
                progressBarValue=0;
                mTimeText.setText("");
                mCalcTimer.cancel();
                mStateBttn.setText(R.string.start);
            }
        }
    };
}

@@ -21,16 +21,49 @@
 imeu;%0A%0A%0A
+import android.app.AlarmManager;%0A
 import a
@@ -80,16 +80,16 @@
 Bundle;%0A
-
 import a
@@ -401,16 +401,98 @@
 Toast;%0A%0A
+import java.util.Calendar;%0A%0Aimport static android.content.Context.ALARM_SERVICE;%0A%0A
 /**%0A * A
@@ -1670,16 +1670,18 @@
         
+/*
 int time
@@ -1740,16 +1740,18 @@
 :%22)%5B1%5D);
+*/
 %0A       
@@ -1755,33 +1755,20 @@
     
-mProgressBar.setMax(time)
+int time = 2
 ;%0A  
@@ -1903,24 +1903,26 @@
 Finished) %7B%0A
+/*
             
@@ -2087,13 +2087,14 @@
 60))
++1
  );%0A
-%0A
     
@@ -2137,16 +2137,18 @@
 :%22+min);
+*/
 %0A       
@@ -2156,18 +2156,16 @@
         
-/*
 mTimeTex
@@ -2239,18 +2239,16 @@
 sterCode
-*/
 %0A       
@@ -2358,24 +2358,91 @@
 ibration*/%0A 
+               // We want the alarm to go off 30 seconds from now.%0A
             
@@ -2832,19 +2832,16 @@
 (0, 1000
-*60
 ); //inc
@@ -3442,17 +3442,19 @@
       %7D%0A
-
     %7D;%0A
+%0A%0A
 %7D%0A

add time countdown function to timer