I am writing an Android application in which I am using timer android. It is working perfectly, now I want to make it like it should vibrate on every second until the completion of the time.
My code is given below:
public class TimerActivity extends Activity {
Button btnStart, btnStop;
TextView textViewTime;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_responders_timer);
btnStop = (Button)findViewById(R.id.CanelButton);
textViewTime = (TextView)findViewById(R.id.textViewTime);
textViewTime.setText("10");
textViewTime.setTextSize(120);
final CounterClass timer = new CounterClass(10000,1000);
textViewTime.setTextSize(120);
timer.start();
btnStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timer.cancel();
}
});
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class CounterClass extends CountDownTimer {
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
textViewTime.setTextSize(50);
textViewTime.setText("Completed.");
}
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onTick(long millisUntilFinished) {
textViewTime.setText(""+millisUntilFinished / 1000);
}
}