public TimeSetEditPage(TimeSet timeSet)
        {
            TimeSet = timeSet;
            ViewModel=new TimeSet()
            {
                Duration = TimeSet.Duration,Id = TimeSet.Id,Name = TimeSet.Name,SecendsToReady = TimeSet.SecendsToReady,
                StagesDataString = TimeSet.StagesDataString,VoiceEngine = TimeSet.VoiceEngine
            };
            Title = "修改倒计时方案";

            BackgroundColor = Color.FromHex("#eee");

            //ViewModel.AddStage(new FilnalStage(60));
            //ViewModel.AddStage(new Stage(100, 5, ""));
            BindingContext = ViewModel;
            var ts = TimeSpan.FromSeconds(ViewModel.Duration);
            Hours = ts.Hours;
            Minutes = ts.Minutes;
            Seconds = ts.Seconds;
            ToolbarItems.Add(new ToolbarItem()
            {
                Icon = "ic_done_white_24dp.png",
                Text = "保存",
                Command = new Command(() =>
                {
                    saveButton_Clicked(this, EventArgs.Empty);
                })
            });
            InitView();
        }
 public AddStagePage(TimeSet timeSet)
 {
     Title = "新增普通阶段";
     BackgroundColor = Color.FromHex("#eee");
     TimeSet = timeSet;
     ViewModel = new Stage();
     BindingContext = ViewModel;
     InitView();
 }
 public AddFinalStagePage(TimeSet timeSet)
 {
     Title = "新增冲刺阶段";
     BackgroundColor = Color.FromHex("#eee");
     TimeSet = timeSet;
     ViewModel = new Stage()
     {
         VoiceInterval = 1
     };
     BindingContext = ViewModel;
     InitView();
 }
 public EditStagePage(TimeSet timeSet, Stage stage)
 {
     Title = "修改普通阶段";
     BackgroundColor = Color.FromHex("#eee");
     TimeSet = timeSet;
     ViewModel = stage;
     BindingContext = ViewModel;
     var ts = TimeSpan.FromSeconds(ViewModel.StagePoint);
     Hours = ts.Hours;
     Minutes = ts.Minutes;
     Seconds = ts.Seconds;
     InitView();
 }
        public TimeSetRunPage(TimeSet timeSet)
        {
            this.TimeSet = timeSet;
            _isEnglish = timeSet.IsEnglish;
            Title = "执行倒计时";
            BackgroundColor = Color.FromHex("#eee");
            _textToSpeech = DependencyService.Get<ITextToSpeech>().New();
            _textToSpeech.Inited += _textToSpeech_Init;
            _textToSpeech.InitedError += _textToSpeech_InitedError;
            _textToSpeech.Init(TimeSet.VoiceEngine);

            _soundService = DependencyService.Get<ISoundService>();

            //
            _performer = new Performer(this.TimeSet);
            _performer.Speak += performer_Speak;
            _performer.PrepareTick += performer_PrepareTick;
            _performer.Tick += performer_HeartBeat;
            _performer.CurrentSecondChanged += performer_CurrentSecondChanged;
            _performer.StageChanged += performer_StageChanged;
            InitView();
            //_textToSpeech.Speak(timeSet.Name);
        }
        public Performer(TimeSet timeSet)
        {
            this.TimeSet = timeSet;
            currentSecond = this.TimeSet.Duration;
            stages = this.TimeSet.ObservableStages.OrderByDescending(w => w.StagePoint).ToList();
            //mxaStagePoint = stages.Max(w => w.StagePoint);

            _readyCountDownCount = timeSet.SecendsToReady;
            var tm = DependencyService.Get<ITimer>();
            _heartBeatTimer = tm.New();
            _readyCountDownTimer = tm.New();
            _stageTimer = tm.New();

            //var b = _heartBeatTimer.Equals(_readyCountDownTimer);

            _heartBeatTimer.Interval = 1000;
            _heartBeatTimer.OnTick(HeartBeats);

            _readyCountDownTimer.Interval = 1000;
            _readyCountDownTimer.OnTick((t) =>
            {
                ReadyCountDown(t, () =>
                {
                    //stageTimer.Enabled = true;
                    //stageTimer.Start();
                    StartCountDown();
                    _heartBeatTimer.Enabled = true;
                    _heartBeatTimer.Start();
                });
            });

            _stageTimer.Interval = 1000;
            _stageTimer.OnTick((t) =>
            {
                StageCountDown(t);
            });
        }
Beispiel #7
0
        public MainPage()
        {

            var settings = DbHelper.GetSettings();
            if (settings == null)
            {
                var tts = DependencyService.Get<ITextToSpeech>().New().Init();
                var engines = tts.GetEngines();
                tts.Dispose();
                var engine = "";
                if (engines.Count == 1)
                {
                    engine = engines[0].Name;
                }
                else if (engines.Count > 1)
                {
                    engine = engines[1].Name;
                }
                //1
                var ts1 = new TimeSet()
                {
                    Duration = 120,
                    Name = "单手撑地2分钟 是男人就得坚持 你坚持住了吗",
                    SecendsToReady = 5,
                    VoiceEngine = engine//"com.google.android.tts",

                };
                ts1.AddStage(new Stage(120, 10, ""));
                ts1.AddStage(new Stage(60, 5, ""));
                ts1.AddStage(new Stage(20, 1, ""));
                ts1.ListToStagesDataString();
                DbHelper.AddTimeSet(ts1);
                //2
                var ts2 = new TimeSet()
                {
                    Duration = 60,
                    Name = "这是示例方案 你可以修改也可以删除",
                    SecendsToReady = 5,
                    VoiceEngine = engine//"com.google.android.tts",

                };
                ts2.AddStage(new Stage(60, 5, ""));
                ts2.AddStage(new Stage(10, 1, ""));
                ts2.ListToStagesDataString();
                DbHelper.AddTimeSet(ts2);
                //3
                var ts3 = new TimeSet()
                {
                    Duration = 30,
                    Name = "这是示例方案 你可以修改也可以删除",
                    SecendsToReady = 0,
                    VoiceEngine = engine//"com.google.android.tts",

                };
                ts3.AddStage(new Stage(30, 5, ""));
                ts3.AddStage(new Stage(10, 1, ""));
                ts3.ListToStagesDataString();
                DbHelper.AddTimeSet(ts3);
                settings = new Settings()
                {
                    IsFirstRun = false
                };
                DbHelper.AddSettings(settings);
                if (engines.Count == 0)
                {
                    var uds = DependencyService.Get<IUserDialogService>();
                    uds.Confirm(new ConfirmConfig()
                    {
                        CancelText = "取消",
                        OkText = "确定",
                        Message = "你的设备没有安装语音引擎,可能不能正常使用本应用,是否现在下载安装语音引擎?",
                        Title = "提示",
                        OnConfirm = (r) =>
                        {
                            if (r)
                                //Device.BeginInvokeOnMainThread(() =>
                                //{
                                    uds.ActionSheet(new ActionSheetConfig()
                                    {
                                        Title = "安装语音引擎",
                                        Options =
                                        {
                                            new ActionSheetOption("下载安装讯飞语音+", () =>
                                            {
                                                var url = "http://zhushou.360.cn/detail/index/soft_id/676960";
                                                Device.OpenUri(new Uri(url));
                                            }),
                                            new ActionSheetOption("下载安装灵犀语音助手", () =>
                                            {
                                                var url = "http://zhushou.360.cn/detail/index/soft_id/194066";
                                                Device.OpenUri(new Uri(url));
                                            }),
                                            new ActionSheetOption("下载安装Google文字转语音 英语", () =>
                                            {
                                                var url = "http://zhushou.360.cn/detail/index/soft_id/885077";
                                                Device.OpenUri(new Uri(url));
                                
                                            }),
                                        }
                                    });
                                //});
                        }
                    });
                }
                else if (engines.Count == 1 && (engines[0].Name.Contains("google") || engines[0].Name.Contains("pico")))
                {
                    var uds = DependencyService.Get<IUserDialogService>();
                    uds.Confirm(new ConfirmConfig()
                    {
                        CancelText = "取消",
                        OkText = "确定",
                        Message = "你的设备可能没有安装中文语音引擎,将不能使用中文播报功能,是否现在下载并安装?",
                        Title = "提示",
                        OnConfirm = (r) =>
                        {
                            if (r)
                                //Device.BeginInvokeOnMainThread(() =>
                                //{
                                    uds.ActionSheet(new ActionSheetConfig()
                                    {
                                        Title = "安装语音引擎",
                                        Options =
                                        {
                                            new ActionSheetOption("下载安装讯飞语音+", () =>
                                            {
                                                var url = "http://zhushou.360.cn/detail/index/soft_id/676960";
                                                Device.OpenUri(new Uri(url));
                                            }),
                                            new ActionSheetOption("下载安装灵犀语音助手", () =>
                                            {
                                                var url = "http://zhushou.360.cn/detail/index/soft_id/194066";
                                                Device.OpenUri(new Uri(url));
                                            }),
                                            //new ActionSheetOption("下载安装Google文字转语音 英语", () =>
                                            //{
                                            //    var url = "http://zhushou.360.cn/detail/index/soft_id/885077";
                                            //    Device.OpenUri(new Uri(url));
                                
                                            //}),
                                        }
                                    });
                                //});
                        }
                    });
                }
            }
            DbHelper.CloseConnection();
            Title = "语音倒计时";
            BackgroundColor = Color.FromHex("#eee");

            ToolbarItem addToolbarItem = new ToolbarItem()
            {
                Icon = "ic_add_white_36dp.png",
                Text = "新建倒计时方案"
            };
            ToolbarItems.Add(addToolbarItem);
            addToolbarItem.Clicked += delegate
            {
                var page = new TimeSetCreatePage();
                Navigation.PushAsync(page, true);
            };
            ToolbarItem aboutToolbarItem = new ToolbarItem()
            {
                Icon = "ic_info_outline_white_36dp.png",
                Text = "关于"
            };
            ToolbarItems.Add(aboutToolbarItem);
            aboutToolbarItem.Clicked += delegate
            {
                var page = new AboutPage();
                Navigation.PushAsync(page, true);
            };
            TimeSets = new ObservableCollection<TimeSet>();
            TimeSets.CollectionChanged += TimeSets_CollectionChanged; ;
            _listView = new ListView
            {
                BindingContext = TimeSets,
                RowHeight = RowHeight,
                VerticalOptions = LayoutOptions.FillAndExpand,
                SeparatorVisibility = SeparatorVisibility.Default,
                SeparatorColor = Color.FromHex("#fff"),
                ItemTemplate = new DataTemplate(typeof(ListViewCell))
            };
            _listView.SetBinding(ListView.ItemsSourceProperty, ".");
            _listView.ItemTapped += listView_ItemTapped;
            _listView.Footer = _footerLabel;

            Content = new ScrollView()
            {
                Padding = new Thickness(10, 0),
                BackgroundColor = Color.FromHex("#eee"),
                Content = new StackLayout()
                {
                    Children = { new StackLayout()
            {
                BackgroundColor = Color.FromHex("#eee"),
                Orientation = StackOrientation.Vertical,
                
                Children =
                {
                    new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Children =
                {
                     new Label()
                        {
                            Text = "倒计时方案",
                            HeightRequest = 32,
                            FontSize = 16,
                            YAlign = TextAlignment.End,
                            TextColor = Color.FromHex("#666"),
                
                        },
                        new Label()
                        {
                            Text =Device.OnPlatform("左滑可修改或删除","(长按可修改或删除)","") ,
                            HeightRequest = 32,
                            FontSize = 12,
                            YAlign = TextAlignment.End,
                            TextColor = Color.FromHex("#999"),
                
                        }
                }
            }
                }
            },
            _listView
                    }
                }

            };
            LoadData();
        }