예제 #1
0
        private void CheckService(object parameter)
        {
            if (!(parameter is CancellationToken token))
            {
                return;
            }

            while (!token.IsCancellationRequested)
            {
                try
                {
                    var sc = new ServiceController(ServiceName);
                    _hub.PublishAsync(new ServiceStateMessage(this, sc.Status));
                }
                catch (OperationCanceledException)
                {
                    // This is ok.
                    return;
                }
                catch (ThreadAbortException)
                {
                    // This is ok.
                    return;
                }
                catch (Exception)
                {
                    _hub.PublishAsync(new ServiceStateMessage(this, null));
                }
                Thread.Sleep(500);
            }
        }
예제 #2
0
        private void SendBacklightState(LightLevel?lightLevel)
        {
            if (lightLevel.HasValue)
            {
                Status status;
                switch (lightLevel.Value)
                {
                case LightLevel.Off:
                    status = Status.BacklightStateOff;
                    break;

                case LightLevel.Low:
                    status = Status.BacklightStateLow;
                    break;

                case LightLevel.High:
                    status = Status.BacklightStateHigh;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                _hub.PublishAsync(new SendStatusRequestMessage(this, status));
            }
        }
예제 #3
0
        private void OnStatusReceived(OnStatusReceivedMessage message)
        {
            // Read status from client
            switch (message.Status)
            {
            case Status.Close:     // Not used, can be removed.
                Stop();
                return;

            case Status.EnableBacklight:
                _hub.PublishAsync(new ActivateBacklightRequestMessage(this));
                break;

            case Status.DisableBacklight:
                _hub.PublishAsync(new DeactivateBacklightRequestMessage(this));
                break;

            case Status.UpdateConfig:
                _hub.PublishAsync(new ConfigReloadRequestMessage(this));
                break;

            case Status.RequestBacklightState:
                _hub.PublishAsync(new GetBacklightStateRequestMessage(this));
                break;

            default:
                _logger.Error($"Status message '{message.Status}' not recognized.");
                return;
            }
        }
예제 #4
0
 public void ShowSettingsForm()
 {
     Show();
     ShowInTaskbar = true;
     TopMost       = true;
     BringToFront();
     Focus();
     _hub.Publish(new FormOpenedMessage(this));
     _hub.PublishAsync(new SendStatusRequestMessage(this, Status.RequestBacklightState));
     TopMost = false;
 }
예제 #5
0
        /// <summary>
        /// Restarts the Idletimer and resets the interval (in case it has changed).
        /// </summary>
        private void RestartTimer()
        {
            if (_idleTimer == null)
            {
                return;
            }
            _idleTimer.Stop();
            _idleTimer.Start();

            //enable backlight if it was off
            if (!_backLightOn)
            {
                // Send the message to enable the backlight using a thread
                _hub.PublishAsync(new SendStatusRequestMessage(this, Status.EnableBacklight));
            }
        }
예제 #6
0
        /// <inheritdoc/>
        public void SendAsync <TMessage>(
            TMessage message) where TMessage : class, ITinyMessage
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message is IMessageSendDataWriter writer)
            {
                writer.SequenceNumber = _currentMessageId++;
                writer.TimeStamp      = _dateTimeServices.Now.Ticks;
            }

            _messageHub.PublishAsync(message);
        }
예제 #7
0
        public void GetPeople()
        {
            var request = new GetPeopleRequest();

            Client.ExecuteAsync(request, x =>
            {
                var people = JsonConvert.DeserializeObject <List <Person> > (x.Content);
                _messageHub.PublishAsync(new PeopleMessage(this, people));
            });
        }
예제 #8
0
        public SettingsForm(ITinyMessengerHub hub, SysTray sysTray, IdleTimerControl idleTimer, DisplayHook displayHook, NamedPipeServer pipeServer)
        {
            _hub         = hub;
            _sysTray     = sysTray;
            _idleTimer   = idleTimer;
            _displayHook = displayHook;
            _pipeServer  = pipeServer;

            InitializeComponent();
            _ctx = SynchronizationContext.Current;
            try
            {
                var sc = new ServiceController("LenovoBacklightControl");
                if (sc.Status == ServiceControllerStatus.Running)
                {
                    //Do nothing, this is to allow the app to catch the exception if the service is not present
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Could not find service. Please install.", "Service Error!", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                Close();
            }

            _hub.Subscribe <OnConfigLoadedMessage>(x => ExecuteOnUi(OnConfigLoaded, x));
            _hub.Subscribe <ServiceStateMessage>(x => ExecuteOnUi(CheckService, x));
            _hub.Subscribe <FormOpenRequestMessage>(x => ExecuteOnUi(ShowSettingsForm));
            _hub.Subscribe <DisplayStateMessage>(x =>
            {
                if (x.State == DisplayState.On)
                {
                    _hub.PublishAsync(new SendStatusRequestMessage(this, Status.EnableBacklight));
                }
            });
            _hub.Subscribe <OnStatusReceivedMessage>(x => ExecuteOnUi(OnStatus, x));
            _pipeServer.Start();
            _hub.PublishAsync(new SendStatusRequestMessage(this, Status.RequestBacklightState));
        }
예제 #9
0
        private async void ProcessMessages(object parameter)
        {
            if (!(parameter is CancellationToken token))
            {
                return;
            }

            while (!token.IsCancellationRequested)
            {
                try
                {
                    using (var server = CreateServer(_pipeName))
                    {
                        await server.WaitForConnectionAsync(token);

                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        string line;
                        // Read data from client
                        using (var reader = new StreamReader(server))
                        {
                            line = await reader.ReadToEndAsync();
                        }

                        var status = line.ParseStatus();
                        _hub.PublishAsync(new OnStatusReceivedMessage(this, status));

                        if (server.IsConnected)
                        {
                            server.Disconnect();
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    // This is ok.
                    return;
                }
                catch (ThreadAbortException)
                {
                    // This is ok.
                    return;
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Error reading from NamedPipe '{_pipeName}'", 50915);
                }
            }
        }
예제 #10
0
        protected override void OnCreate(Bundle bundle)
        {
            Console.WriteLine("MainActivity - OnCreate");
            base.OnCreate(bundle);

            _messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>();
            _messengerHub.Subscribe<MobileLibraryBrowserItemClickedMessage>(MobileLibraryBrowserItemClickedMessageReceived);

            RequestWindowFeature(WindowFeatures.ActionBar);
            SetContentView(Resource.Layout.Main);
            _actionBarSpinnerAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.action_list, Resource.Layout.actionbar_spinner_item);
            ActionBar.NavigationMode = ActionBarNavigationMode.List;
            ActionBar.Title = string.Empty;
            ActionBar.SetListNavigationCallbacks(_actionBarSpinnerAdapter, this);
            ActionBar.SetSelectedNavigationItem(1);

            _viewFlipper = FindViewById<ViewFlipper>(Resource.Id.main_viewflipper);
            _miniPlayer = FindViewById<LinearLayout>(Resource.Id.main_miniplayer);
            _miniPlaylist = FindViewById<LinearLayout>(Resource.Id.main_miniplaylist);
            _lblArtistName = FindViewById<TextView>(Resource.Id.main_miniplayer_lblArtistName);
            _lblAlbumTitle = FindViewById<TextView>(Resource.Id.main_miniplayer_lblAlbumTitle);
            _lblSongTitle = FindViewById<TextView>(Resource.Id.main_miniplayer_lblSongTitle);
            //_lblNextArtistName = FindViewById<TextView>(Resource.Id.main_miniplaylist_lblNextArtistName);
            //_lblNextAlbumTitle = FindViewById<TextView>(Resource.Id.main_miniplaylist_lblNextAlbumTitle);
            //_lblNextSongTitle = FindViewById<TextView>(Resource.Id.main_miniplaylist_lblNextSongTitle);
            _lblPlaylistCount = FindViewById<TextView>(Resource.Id.main_miniplaylist_lblPlaylistCount);
            _btnPrevious = FindViewById<ImageButton>(Resource.Id.main_miniplayer_btnPrevious);
            _btnPlayPause = FindViewById<ImageButton>(Resource.Id.main_miniplayer_btnPlayPause);
            _btnNext = FindViewById<ImageButton>(Resource.Id.main_miniplayer_btnNext);
            _btnPlaylist = FindViewById<ImageButton>(Resource.Id.main_miniplaylist_btnPlaylist);
            _btnShuffle = FindViewById<ImageButton>(Resource.Id.main_miniplaylist_btnShuffle);
            _btnRepeat = FindViewById<ImageButton>(Resource.Id.main_miniplaylist_btnRepeat);
            _btnLeft = FindViewById<ImageButton>(Resource.Id.main_miniplaylist_btnLeft);
            _cboPlaylist = FindViewById<Spinner>(Resource.Id.main_miniplaylist_cboPlaylist);
            _btnRight = FindViewById<ImageButton>(Resource.Id.main_miniplayer_btnRight);
            _imageAlbum = FindViewById<SquareImageView>(Resource.Id.main_miniplayer_imageAlbum);
            _miniPlayer.Click += (sender, args) => _messengerHub.PublishAsync<MobileNavigationManagerCommandMessage>(new MobileNavigationManagerCommandMessage(this, MobileNavigationManagerCommandMessageType.ShowPlayerView));
            _btnLeft.SetOnTouchListener(this);
            _btnRight.SetOnTouchListener(this);
            _btnPrevious.SetOnTouchListener(this);
            _btnPlayPause.SetOnTouchListener(this);
            _btnNext.SetOnTouchListener(this);
            _btnPlaylist.SetOnTouchListener(this);
            _btnShuffle.SetOnTouchListener(this);
            _btnRepeat.SetOnTouchListener(this);
            _btnPrevious.Click += (sender, args) => OnPlayerPrevious();
            _btnPlayPause.Click += (sender, args) => OnPlayerPlayPause();
            _btnNext.Click += (sender, args) => OnPlayerNext();
            _btnPlaylist.Click += (sender, args) => OnOpenPlaylist();
            _btnShuffle.Click += (sender, args) => OnPlayerShuffle();
            _btnRepeat.Click += (sender, args) => OnPlayerRepeat();
            _btnLeft.Click += BtnLeftOnClick;
            _btnRight.Click += BtnRightOnClick;

            // Set initial view flipper item
            int realIndex = _viewFlipper.IndexOfChild(_miniPlayer);
            _viewFlipper.DisplayedChild = realIndex;

            // Create bitmap cache
            Point size = new Point();
            WindowManager.DefaultDisplay.GetSize(size);
            int maxMemory = (int)(Runtime.GetRuntime().MaxMemory() / 1024);
            int cacheSize = maxMemory / 16;
            BitmapCache = new BitmapCache(this, cacheSize, size.X / 6, size.X / 6);

            _playlistSpinnerAdapter = new ArrayAdapter<string>(this, Resource.Layout.playlist_spinner_item, new string[2] {"Hello", "World"});
            _cboPlaylist.Adapter = _playlistSpinnerAdapter;
            _cboPlaylist.ItemSelected += CboPlaylistOnItemSelected;

            Console.WriteLine("MainActivity - OnCreate - Binding presenters...");
            var navigationManager = (AndroidNavigationManager)Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
            navigationManager.MainActivity = this; // Watch out, this can lead to memory leaks!
            navigationManager.BindOptionsMenuView(this);
            navigationManager.BindPlayerStatusView(this);
            navigationManager.BindMobileMainView(this);
        }
 public void Publish <TMessage>(TMessage evt) where TMessage : class
 {
     _hub.PublishAsync(new GenericTinyMessage <TMessage>(this, evt));
 }
예제 #12
0
        protected override void OnCreate(Bundle bundle)
        {
            Console.WriteLine("PlayerActivity - OnCreate");

            _messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>(); 
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Player);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeButtonEnabled(true);

            _navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
            _fragments = new List<Fragment>();
            _viewPager = FindViewById<ViewPager>(Resource.Id.player_pager);
            _viewPager.OffscreenPageLimit = 4;
            _viewPagerAdapter = new ViewPagerAdapter(FragmentManager, _fragments, _viewPager);
            _viewPagerAdapter.OnPageChanged += ViewPagerAdapterOnOnPageChanged;
            _viewPager.Adapter = _viewPagerAdapter;
            _viewPager.SetOnPageChangeListener(_viewPagerAdapter);

            _waveFormScrollView = FindViewById<WaveFormScrollView>(Resource.Id.player_waveFormScrollView);
            _imageViewAlbumArt = FindViewById<SquareImageView>(Resource.Id.player_imageViewAlbumArt);
            _lblPosition = FindViewById<TextView>(Resource.Id.player_lblPosition);
            _lblLength = FindViewById<TextView>(Resource.Id.player_lblLength);
            _btnPlayPause = FindViewById<ImageButton>(Resource.Id.player_btnPlayPause);
            _btnPrevious = FindViewById<ImageButton>(Resource.Id.player_btnPrevious);
            _btnNext = FindViewById<ImageButton>(Resource.Id.player_btnNext);
            _btnShuffle = FindViewById<ImageButton>(Resource.Id.player_btnShuffle);
            _btnRepeat = FindViewById<ImageButton>(Resource.Id.player_btnRepeat);
            _btnPlaylist = FindViewById<ImageButton>(Resource.Id.player_btnPlaylist);
            _seekBar = FindViewById<SeekBar>(Resource.Id.player_seekBar);
            _carrouselDot1 = FindViewById<Button>(Resource.Id.player_carrouselDot1);
            _carrouselDot2 = FindViewById<Button>(Resource.Id.player_carrouselDot2);
            _carrouselDot3 = FindViewById<Button>(Resource.Id.player_carrouselDot3);
            _carrouselDot4 = FindViewById<Button>(Resource.Id.player_carrouselDot4);
            _carrouselDot5 = FindViewById<Button>(Resource.Id.player_carrouselDot5);
            _btnPlayPause.Click += BtnPlayPauseOnClick;            
            _btnPrevious.Click += BtnPreviousOnClick;
            _btnNext.Click += BtnNextOnClick;
            _btnPlaylist.Click += BtnPlaylistOnClick;
            _btnRepeat.Click += BtnRepeatOnClick;
            _btnShuffle.Click += BtnShuffleOnClick;
            _btnPlayPause.SetOnTouchListener(this);
            _btnPrevious.SetOnTouchListener(this);
            _btnNext.SetOnTouchListener(this);
            _btnPlaylist.SetOnTouchListener(this);
            _btnRepeat.SetOnTouchListener(this);
            _btnShuffle.SetOnTouchListener(this);
            _seekBar.StartTrackingTouch += SeekBarOnStartTrackingTouch;
            _seekBar.StopTrackingTouch += SeekBarOnStopTrackingTouch;
            _seekBar.ProgressChanged += SeekBarOnProgressChanged;

            // Get screen size
            Point size = new Point();
            WindowManager.DefaultDisplay.GetSize(size);

            // Create bitmap cache
            int maxMemory = (int)(Runtime.GetRuntime().MaxMemory() / 1024);
            int cacheSize = maxMemory / 12;
            _bitmapCache = new BitmapCache(this, cacheSize, size.X, size.X); // The album art takes the whole screen width

            // Match height with width (cannot do that in xml)
            //_imageViewAlbumArt.LayoutParameters = new ViewGroup.LayoutParams(_imageViewAlbumArt.Width, _imageViewAlbumArt.Width);

            if (bundle != null)
            {
                string state = bundle.GetString("key", "value");
                Console.WriteLine("PlayerActivity - OnCreate - State is {0} - isInitialized: {1}", state, _isInitialized);
            }
            else
            {

                Console.WriteLine("PlayerActivity - OnCreate - State is null - isInitialized: {0}", _isInitialized);
            }

            // Don't try to check the bundle contents, if the activity wasn't destroyed, it will be null.
            //if (bundle != null)
            //    Console.WriteLine("PlayerActivity - OnCreate - Bundle isn't null - value: {0}", bundle.GetString("key", "null"));
            //else
            //    Console.WriteLine("PlayerActivity - OnCreate - Bundle is null!");

            // When Android stops an activity, it recalls OnCreate after, even though the activity is not destroyed (OnDestroy). It actually goes through creating a new object (the ctor is called).
            //((AndroidNavigationManager)_navigationManager).SetPlayerActivityInstance(this);
            _navigationManager.BindPlayerView(MobileNavigationTabType.Playlists, this);

            // Activate lock screen if not already activated
            _messengerHub.PublishAsync<ActivateLockScreenMessage>(new ActivateLockScreenMessage(this, true));

            _messengerHub.Subscribe<ApplicationCloseMessage>(message =>
            {
                Console.WriteLine("PlayerActivity - Received ApplicationCloseMessage; closing activity of type {0}", this.GetType().FullName);
            });

        }
예제 #13
0
        public SessionsNavigationController(MobileNavigationTabType tabType) : base(typeof(SessionsNavigationBar), typeof(UIToolbar))
        {
            TabType = tabType;
            WeakDelegate = this;

            // Create messenger hub to listen to player changes
            _messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>();
            _messengerHub.Subscribe<PlayerPlaylistIndexChangedMessage>((message) => {
                //Console.WriteLine("NavCtrl (" + TabType.ToString() + ") - PlayerPlaylistIndexChangedMessage");
                UpdateNowPlayingView();
            });
            _messengerHub.Subscribe<PlayerStatusMessage>((message) => {
                //Console.WriteLine("NavCtrl (" + TabType.ToString() + ") - PlayerStatusMessage - Status=" + message.Status.ToString());
                if(message.Status == PlayerStatusType.Playing ||
                   message.Status == PlayerStatusType.Paused)
                    _isPlayerPlaying = true;
                else
                    _isPlayerPlaying = false;
                
                UpdateNowPlayingView();
            });

            // Create controls
            _lblTitle = new UILabel(new RectangleF(60, 4, UIScreen.MainScreen.Bounds.Width - 120, 20));
            _lblTitle.TextColor = UIColor.White;
            _lblTitle.BackgroundColor = UIColor.Clear;
            _lblTitle.Text = "";
            _lblTitle.TextAlignment = UITextAlignment.Center;
            _lblTitle.AdjustsFontSizeToFitWidth = true;
            _lblTitle.MinimumScaleFactor = 14f/16f; // min:14pt max:16pt
            _lblTitle.Font = UIFont.FromName("HelveticaNeue", 16);

            _imageViewIcon = new UIImageView();
            _imageViewIcon.Image = UIImage.FromBundle("Images/Nav/album");
            _imageViewIcon.BackgroundColor = UIColor.Clear;

            _btnBack = new SessionsFlatButton();
            _btnBack.Alpha = 0;
            _btnBack.Frame = new RectangleF(0, 0, 70, 44);
            _btnBack.OnButtonClick += () =>  {

                var viewController = (BaseViewController)VisibleViewController;
                if (viewController.ConfirmBackButton && !_confirmedViewPop)
                {
                    var alertView = new UIAlertView(viewController.ConfirmBackButtonTitle, viewController.ConfirmBackButtonMessage, null, "OK", new string[1] { "Cancel" });
                    alertView.Clicked += (object sender, UIButtonEventArgs e) => {
                        Console.WriteLine("AlertView button index: {0}", e.ButtonIndex);
                        switch(e.ButtonIndex)
                        {
                            case 0:
                                viewController.ConfirmedBackButton();
                                _confirmedViewPop = true;
								Console.WriteLine("NavCtrl - PopViewController A");
                                PopViewControllerAnimated(true);
                                break;
                            default:
                                break;
                        }
                    };
                    alertView.Show();
                    return;
                }

                _confirmedViewPop = false;
                if(ViewControllers.Length > 1)
				{
					Console.WriteLine("NavCtrl - PopViewController B");
                    PopViewControllerAnimated(true);
				}
            };

            _btnPlaylist = new SessionsFlatButton();
            _btnPlaylist.LabelAlignment = UIControlContentHorizontalAlignment.Right;
			_btnPlaylist.Frame = new RectangleF(UIScreen.MainScreen.Bounds.Width - 80, 0, 80, 44);
            _btnPlaylist.Alpha = 0;
            _btnPlaylist.Label.TextAlignment = UITextAlignment.Right;
			_btnPlaylist.Label.Text = "Playlist";
			_btnPlaylist.Label.Frame = new RectangleF(0, 0, 54, 44);
            _btnPlaylist.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron_blue");
			_btnPlaylist.ImageChevron.Frame = new RectangleF(80 - 22, 0, 22, 44);
            _btnPlaylist.OnButtonClick += () => {
				_messengerHub.PublishAsync<MobileNavigationManagerCommandMessage>(new MobileNavigationManagerCommandMessage(this, MobileNavigationManagerCommandMessageType.ShowPlaylistView));
            };

            _btnNowPlaying = new SessionsFlatButton();
            _btnNowPlaying.LabelAlignment = UIControlContentHorizontalAlignment.Right;
            _btnNowPlaying.Frame = new RectangleF(UIScreen.MainScreen.Bounds.Width - 70, 0, 70, 44);
            _btnNowPlaying.Alpha = 0;
            _btnNowPlaying.Label.TextAlignment = UITextAlignment.Right;
            _btnNowPlaying.Label.Frame = new RectangleF(0, 0, 44, 44);
            _btnNowPlaying.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron_blue");
            _btnNowPlaying.ImageChevron.Frame = new RectangleF(70 - 22, 0, 22, 44);
            _btnNowPlaying.Label.Text = "Player";
            _btnNowPlaying.OnButtonClick += () => {
                _messengerHub.PublishAsync<MobileNavigationManagerCommandMessage>(new MobileNavigationManagerCommandMessage(this, MobileNavigationManagerCommandMessageType.ShowPlayerView));
            };

            this.NavigationBar.AddSubview(_btnBack);
            this.NavigationBar.AddSubview(_btnPlaylist);
            this.NavigationBar.AddSubview(_btnNowPlaying);
            this.NavigationBar.AddSubview(_lblTitle);
            this.NavigationBar.AddSubview(_imageViewIcon);
        }