Пример #1
0
        /// <summary>
        /// Called when activity is created.
        /// </summary>
        /// <returns>The create.</returns>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.AudioPlayerPage);

            _seekBar = FindViewById <CustomSeekBar>(Resource.Id.seekBar);
            _seekBar.ValueChanged += HandleValueChanged;

            playButton = FindViewById <ImageButton>(Resource.Id.PlayButton);
            playButton.SetColorFilter(Color.White);
            playButton.Click += HandlePlayClick;

            var rewindButton = FindViewById <ImageButton>(Resource.Id.RewindButton);

            rewindButton.SetColorFilter(Color.White);
            rewindButton.Click += HandleRewindForwardClick;

            var forwardButton = FindViewById <ImageButton>(Resource.Id.ForwardButton);

            forwardButton.SetColorFilter(Color.White);
            forwardButton.Click += HandleRewindForwardClick;

            model = (AudioPlayerPageViewModel)ViewModel;
        }
Пример #2
0
        public AudioPlayerPage(string id)
        {
            NavigationPage.SetHasNavigationBar(this, false);

            this._id = id;

            _model = new AudioPlayerPageViewModel();

            this.BindingContext = _model;

            _model.Loading = true;

            DaisyPlayer.Instance.TimeCodeUpdate += Instance_TimeCodeUpdate;
            DaisyPlayer.Instance.StatusUpdate   += Instance_StatusUpdate;
            DaisyPlayer.Instance.ChapterUpdate  += Instance_ChapterUpdate;

            Instance_StatusUpdate(DaisyPlayer.Instance.GetPlayerInfo());

            InitializeComponent();
        }
Пример #3
0
        /// <summary>
        /// Views the did load.
        /// </summary>
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var mainView = new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.White
            };

            var buttonView = new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.Clear
            };

            var imageView = new UIImageView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentMode = UIViewContentMode.ScaleAspectFit,
                Image       = new UIImage("moby.png")
            };

            var descriptionLabel = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextAlignment = UITextAlignment.Center
            };

            var currentLabel = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextAlignment = UITextAlignment.Left,
            };

            var endLabel = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextAlignment = UITextAlignment.Right,
            };

            progressSlider = new UISlider()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                MinValue = 0
            };

            progressSlider.ValueChanged += progressSliderValueChanged;

            playButton = new UIButton(UIButtonType.Custom)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };
            playButton.TouchUpInside += handlePlayButton;
            playButton.SetImage(UIImage.FromFile("play.png"), UIControlState.Normal);

            var rewindButton = new UIButton(UIButtonType.Custom)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            rewindButton.TouchUpInside += handleRewindForwardButton;
            rewindButton.SetImage(UIImage.FromFile("rewind.png"), UIControlState.Normal);

            var fastForwardButton = new UIButton(UIButtonType.Custom)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            fastForwardButton.TouchUpInside += handleRewindForwardButton;
            fastForwardButton.SetImage(UIImage.FromFile("fast_forward.png"), UIControlState.Normal);

            var views = new DictionaryViews()
            {
                { "mainView", mainView },
                { "buttonView", buttonView },
                { "imageView", imageView },
                { "descriptionLabel", descriptionLabel },
                { "currentLabel", currentLabel },
                { "endLabel", endLabel },
                { "progressSlider", progressSlider },
                { "playButton", playButton },
                { "rewindButton", rewindButton },
                { "fastForwardButton", fastForwardButton }
            };

            View.Add(mainView);

            mainView.Add(imageView);
            mainView.Add(descriptionLabel);
            mainView.Add(buttonView);
            mainView.Add(currentLabel);
            mainView.Add(endLabel);
            mainView.Add(progressSlider);

            buttonView.Add(playButton);
            buttonView.Add(rewindButton);
            buttonView.Add(fastForwardButton);

            View.AddConstraints(
                NSLayoutConstraint.FromVisualFormat("V:|[mainView]|", NSLayoutFormatOptions.DirectionLeftToRight, null, views)
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|[mainView]|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .ToArray());

            mainView.AddConstraints(
                NSLayoutConstraint.FromVisualFormat("V:|-100-[imageView(200)]-[descriptionLabel(30)]-[buttonView(50)]-[currentLabel(30)]-[progressSlider]", NSLayoutFormatOptions.DirectionLeftToRight, null, views)
                .Concat(NSLayoutConstraint.FromVisualFormat("V:|-100-[imageView(200)]-[descriptionLabel(30)]-[buttonView(50)]-[endLabel(30)]-[progressSlider]", NSLayoutFormatOptions.DirectionLeftToRight, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|-20-[progressSlider]-20-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|-25-[currentLabel(100)]", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:[endLabel(100)]-25-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|-5-[descriptionLabel]-5-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|-5-[imageView]-5-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(new[] { NSLayoutConstraint.Create(buttonView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.CenterX, 1, 0) })
                .ToArray());

            buttonView.AddConstraints(
                NSLayoutConstraint.FromVisualFormat("V:|-5-[rewindButton]-5-|", NSLayoutFormatOptions.AlignAllTop, null, views)
                .Concat(NSLayoutConstraint.FromVisualFormat("V:|-5-[playButton]-5-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("V:|-5-[fastForwardButton]-5-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .Concat(NSLayoutConstraint.FromVisualFormat("H:|-20-[rewindButton]-[playButton(100)]-[fastForwardButton]-20-|", NSLayoutFormatOptions.AlignAllTop, null, views))
                .ToArray());

            // create the binding set
            var set = this.CreateBindingSet <AudioPlayerPage, AudioPlayerPageViewModel>();

            set.Bind(this).For("Title").To(vm => vm.Title);
            set.Bind(descriptionLabel).To(vm => vm.DescriptionMessage);
            set.Bind(currentLabel).To(vm => vm.CurrentTimeStr);
            set.Bind(endLabel).To(vm => vm.EndTimeStr);
            set.Bind(progressSlider).For(v => v.Value).To(vm => vm.CurrentTime).TwoWay().Apply();
            set.Bind(progressSlider).For(v => v.MaxValue).To(vm => vm.EndTime);
            set.Bind(playButton).To(vm => vm.PlayPauseCommand);
            set.Bind(rewindButton).To(vm => vm.RewindCommand);
            set.Bind(fastForwardButton).To(vm => vm.ForwardCommand);
            set.Apply();

            model = (AudioPlayerPageViewModel)DataContext;
        }