Languages

Menu
Sites
Language
Sweeping Second WatchHand

Hello together,

can anyone here help me with the second Hand in Watchface?

I´m trying to program an Watchface with an sweeping seond Hand. As Basic I used the example Code in Visual Studio. Here the Watchdace get the Time by using the OnTick Mothode in the Main Class. The Rotation will be set in an Class called ClockViewModel. Here my Question: How can I manage that the watchface get the time permanently, so I can use the millisendos for calculating the rotationangle, not only once a second by using the TimeTick Event?

Perhabs someone of you have another Idea how to manage it?

In the uploaded picture is an part of the code.

Yours,

Chris

 

( If you don´t see the Pic, here´s the code:

MainCalss:

  class Program : FormsWatchface
    {
        ClockViewModel _viewModel;

        protected override void OnCreate()
        {
            base.OnCreate();
            var watchfaceApp = new TextWatchApplication();
            _viewModel = new ClockViewModel();
            watchfaceApp.BindingContext = _viewModel;
            LoadWatchface(watchfaceApp);
        }

        protected override void OnTick(TimeEventArgs time)
        {
            base.OnTick(time);
            if (_viewModel != null)
            {
                _viewModel.Time = time.Time.UtcTimestamp;
            }
        }

        protected override void OnAmbientChanged(AmbientEventArgs mode)
        {
            base.OnAmbientChanged(mode);
        }

        protected override void OnAmbientTick(TimeEventArgs time)
        {
            base.OnAmbientTick(time);
        }

        static void Main(string[] args)
        {
            var app = new Program();
            Forms.Init(app);
            FormsCircularUI.Init();
            app.Run(args);
        }
    }

 

 

ClockViewModell-Calss:

    public class ClockViewModel : INotifyPropertyChanged
    {
        DateTime _time;

        public double HrRot { get; private set; }
        public double MiRot { get; private set; }
        public double SeRot { get; private set; }
        public int BatPercentage { get; private set; }
        public float LuxWert { get; }

        public DateTime Time
        {
            get => _time;
            set
            {
                if (_time == value) return;
                _time = value;

                var Hr_rot = (_time.Hour + (double) _time.Minute / 60) * 30 ;
                if (Hr_rot != HrRot) { HrRot = Hr_rot; OnPropertyChanged(nameof(HrRot)); }

                var Mi_rot = (_time.Minute + (double)_time.Second / 60) * 6;
                if (Mi_rot != MiRot) { MiRot = Mi_rot; OnPropertyChanged(nameof(MiRot)); }

                var Se_rot = _time.Second * 6;
                if (Se_rot != SeRot) { SeRot = Se_rot; OnPropertyChanged(nameof(SeRot)); }

                    
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public ClockViewModel() 
        {

            BatPercentage = Battery.Percent;
            Battery.PercentChanged += OnBatPercChanged;

            var LuxWert1 = new Lichtsensor();
            LuxWert = LuxWert1.LuxLevel;

        }

        private void OnBatPercChanged(object sender, BatteryPercentChangedEventArgs e) 
        {
            BatPercentage = e.Percent;
            OnPropertyChanged(nameof(BatPercentage));      
        }

        protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Edited by: Christian Homeier on 27 Jun, 2021