I am trying to convert Xamarin.Android app to Xamarin.Forms, I nedd to have a countdown timer for exam format which will keep updating a label while we use the app. Once timer goes off message is displayed and another activity is opened. I had used follwoing code for Xamarin.Android app.
Can anyone help me understand how i can add this functionality to xamarin.forms app.
public delegate void TickEvent(long millisUntilFinished);
public delegate void FinishEvent();
public class CountDown : CountDownTimer
{
public event TickEvent Tick;
public event FinishEvent Finish;
Activity m_owner;
public CountDown(long totaltime, long interval, Activity owner): base(totaltime, interval)
{
m_owner = owner;
}
public override void OnTick(long millisUntilFinished)
{
if (Tick != null)
Tick(millisUntilFinished);
long millis = millisUntilFinished;
long hours = millis / (60 * 60 * 1000);
long min = (millis / (60 * 1000)) % 60;
long sec = (millis / 1000) % 60;
TextView txtTime = m_owner.FindViewById<TextView>(Resource.Id.textTime);
txtTime.Text = hours.ToString("00") + ":" + min.ToString("00") + ":" + sec.ToString("00");
}
public override void OnFinish()
{
var bulider = new AlertDialog.Builder(m_owner);
bulider.SetMessage("Exam Time over");
bulider.SetCancelable(false);
bulider.SetPositiveButton("OK", delegate { });
var dialog1 = bulider.Create();
dialog1.Show();
int res = 0;
//start another activity
m_owner.StartActivity (intent);
if (Finish != null)
Finish();
}