protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            time      = FindViewById <TextView>(Resource.Id.time);
            startStop = FindViewById <Button>(Resource.Id.start_stop);
            reset     = FindViewById <Button>(Resource.Id.reset);

            model = (StopwatchViewModel)ViewModelProviders.Of(this).Get(Java.Lang.Class.FromType(typeof(StopwatchViewModel)));
            model.running.Observe(this, new OnChangedHandler(() =>
            {
                startStop.Text = GetString(model.Running ? Resource.String.stop : Resource.String.start);
                reset.Enabled  = !model.Running;
            }));
            model.diff.Observe(this, new OnChangedHandler(() =>
            {
                time.Text = F.Format(new Date(model.Diff));
            }));
            StopwatchLifecycleObserver observer = new StopwatchLifecycleObserver(model);

            startStopClicked = (object sender, EventArgs e) =>
            {
                model.Running = !model.Running;
                if (model.Running)
                {
                    observer.ScheduleAtFixedRate();
                }
                else
                {
                    observer.Stop();
                }
            };
            startStop.Click += startStopClicked;

            resetClicked = (object sender, EventArgs e) => { model.Diff = 0; };
            reset.Click += resetClicked;

            Lifecycle.AddObserver(observer);
            UpdateButtons();
            UpdateTime();
        }
Beispiel #2
0
 public StopwatchLifecycleObserver(StopwatchViewModel model,
                                   Handler handler)
 {
     this.model   = model;
     this.handler = handler;
 }
Beispiel #3
0
 public MyTimerTask(Handler handler, StopwatchViewModel model)
 {
     this.handler = handler;
     this.model   = model;
 }
 public StopwatchLifecycleObserver(StopwatchViewModel model)
 {
     this.model = model;
 }
 public MyTimerTask(StopwatchViewModel model)
 {
     this.model = model;
 }