Esempio n. 1
0
            public ScrollView(List <libAppStart.App> appList, bool configEnabled)
            {
                // Get Data
                _appList      = appList;
                _configButton = configEnabled;

                // Init Labels
                _item1 = new LcdGdiText();
                _item2 = new LcdGdiText();
                _item3 = new LcdGdiText();

                _item1.Font = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Regular);
                _item2.Font = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Regular);
                _item3.Font = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Regular);

                _item1.Margin = new MarginF(10, 0, 0, 0);
                _item2.Margin = new MarginF(10, 11, 0, 0);
                _item3.Margin = new MarginF(10, 22, 0, 0);

                // Fill In Data
                FillData(0);

                // Init Images
                _imgSelector        = new LcdGdiImage(Properties.Resources.ArrowRight_Inverted);
                _imgSelector.Margin = new MarginF(0, 0, 0, 0);

                _imgControls0        = new LcdGdiImage(Properties.Resources.BottomScreenCommand_Up);
                _imgControls0.Margin = new MarginF(0, 33, 0, 0);
                _imgControls1        = new LcdGdiImage(Properties.Resources.BottomScreenCommand_Down);
                _imgControls1.Margin = new MarginF(40, 33, 0, 0);
                _imgControls2        = new LcdGdiImage(Properties.Resources.BottomScreenCommand_OK);
                _imgControls2.Margin = new MarginF(80, 33, 0, 0);

                _imgControls3 = _4thButton(_configButton);
            }
Esempio n. 2
0
        // Event handler for the page update (invoked indirectly by DoUpdateAndDraw)
        public void updateNowPlayingMinPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            if (m_playerDetails.privateSession == true)
            {
                page.Device.CurrentPage = m_privatePage;
            }
            else if (m_showTitles == true)
            {
                page.Device.CurrentPage = m_nowPlayingPage;
            }
            else
            {
                page.Device.CurrentPage = m_nowPlayingNoTitlesPage;
            }

            updateTextFields(page.Device,
                             page,
                             (LcdGdiScrollViewer)page.Children[1],
                             (LcdGdiScrollViewer)page.Children[2],
                             (LcdGdiScrollViewer)page.Children[3],
                             (LcdGdiText)page.Children[4]);

            // Turn on/off the playing symbol
            LcdGdiPolygon polygon = (LcdGdiPolygon)page.Children[5];

            polygon.Brush = m_playerDetails.playing ? Brushes.Black : Brushes.White;
            polygon.Pen   = m_playerDetails.playing ? Pens.Black : Pens.White;

            // Show offline or not
            LcdGdiImage image = (LcdGdiImage)page.Children[0];

            image.Image = m_playerDetails.online ? m_imageOnline : m_imageOffline;
        }
Esempio n. 3
0
        private static void Page_Updating(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            if (_lastUpdate == 0 || (e.ElapsedTotalTime.TotalSeconds - _lastUpdate > 10) || _forceUpdate)
            {
                LcdGdiImage updateImage = (LcdGdiImage)page.Children[0];
                updateImage.Image = (Image)GenerateMap();
                ((LcdGdiPage)sender).Invalidate();
                _lastUpdate  = e.ElapsedTotalTime.TotalSeconds;
                _forceUpdate = false;
            }
        }
Esempio n. 4
0
            private LcdGdiImage _4thButton(bool enabled)
            {
                LcdGdiImage img = new LcdGdiImage();

                if (enabled)
                {
                    img.Image = Properties.Resources.BottomScreenCommand_Config;
                }
                else
                {
                    img.Image = Properties.Resources.BottomScreenCommand_Cancel;
                }

                img.Margin = new MarginF(120, 33, 0, 0);
                return(img);
            }
Esempio n. 5
0
            public MessageBox_YesNo(string title, string message)
            {
                _title        = new LcdGdiText();
                _title.Font   = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Bold);
                _title.Margin = new MarginF(0, 0, 0, 0);
                _title.Text   = title;

                _message        = new LcdGdiText();
                _message.Font   = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Regular);
                _message.Margin = new MarginF(0, 10, 0, 0);
                _message.Text   = message;

                _controlYes        = new LcdGdiImage(Properties.Resources.BottomScreenCommand_OK);
                _controlYes.Margin = new MarginF(0, 33, 0, 0);

                _controlNo        = new LcdGdiImage(Properties.Resources.BottomScreenCommand_Cancel);
                _controlNo.Margin = new MarginF(120, 33, 0, 0);
            }
        public Screen(LcdDevice device, LcdDeviceType type, string backgroundGdi, Plugin musicBeePlugin, int index)
            : base(device)
        {
            plugin_ = musicBeePlugin;
            type_   = type;
            device_ = device;
            index_  = index;

            if (device.DeviceType == LcdDeviceType.Qvga && String.IsNullOrEmpty(backgroundGdi))
            {
                backgroundImage_ = (Image)Resource.G19Background;
                backgroundGdi_   = new LcdGdiImage(backgroundImage_);
                this.Children.Add(backgroundGdi_);
            }
            else if (device.DeviceType == LcdDeviceType.Qvga && backgroundGdi != "")
            {
                backgroundImage_ = Image.FromFile(backgroundGdi, true);
                backgroundGdi_   = new LcdGdiImage(backgroundImage_);
                this.Children.Add(backgroundGdi_);
            }
        }
Esempio n. 7
0
        private void createColor()
        {
            volumeBarGdi_         = new LcdGdiProgressBar();
            volumeBarGdi_.Minimum = 0;
            volumeBarGdi_.Maximum = 100;
            volumeBarGdi_.Size    = new SizeF(310, 20);
            volumeBarGdi_.Margin  = new MarginF(5, 150, 5, 0);

            highVolumeImage_    = (Image)Resource.highVolumeG19;
            highVolumeImageGdi_ = new LcdGdiImage(highVolumeImage_);
            highVolumeImageGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Right;
            highVolumeImageGdi_.Margin = new MarginF(0, 90, 5, 0);

            lowVolumeImage_    = (Image)Resource.lowVolumeG19;
            lowVolumeImageGdi_ = new LcdGdiImage(lowVolumeImage_);
            lowVolumeImageGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Left;
            lowVolumeImageGdi_.Margin = new MarginF(5, 90, 5, 0);

            this.Children.Add(backgroundGdi_);
            this.Children.Add(highVolumeImageGdi_);
            this.Children.Add(lowVolumeImageGdi_);
            this.Children.Add(volumeBarGdi_);
        }
        private void createColor()
        {
            artistGdi_ = new LcdGdiText(this.artist_, font3_);
            artistGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center;
            artistGdi_.Margin = new MarginF(5, 5, 5, 0);

            titleGdi_ = new LcdGdiText(this.title_, font3_);
            titleGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center;
            titleGdi_.Margin = new MarginF(5, 30, 5, 0);

            albumGdi_ = new LcdGdiText(this.album_, font3_);
            albumGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center;
            albumGdi_.Margin = new MarginF(5, 55, 5, 0);

            positionGdi_ = new LcdGdiText(Conversions.timetoString(this.position_), font4_);
            positionGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Left;
            positionGdi_.Margin = new MarginF(5, 105, 0, 0);

            durationGdi_ = new LcdGdiText(Conversions.timetoString(this.duration_), font4_);
            durationGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Right;
            durationGdi_.Margin = new MarginF(0, 105, 5, 0);

            artworkGdi_ = new LcdGdiImage(Conversions.Base64ToImage(artwork_));
            artworkGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center;
            artworkGdi_.Size   = new SizeF(130, 130);
            artworkGdi_.Margin = new MarginF(0, 105, 0, 0);

            progressBarGdi_         = new LcdGdiProgressBar();
            progressBarGdi_.Minimum = 0;
            progressBarGdi_.Maximum = 100;
            progressBarGdi_.Size    = new SizeF(310, 20);
            progressBarGdi_.Margin  = new MarginF(5, 80, 5, 0);

            titleScroll_                     = new LcdGdiScrollViewer(titleGdi_);
            titleScroll_.AutoScrollX         = true;
            titleScroll_.AutoScrollY         = false;
            titleScroll_.AutoScrollSpeedY    = 0;
            titleScroll_.AutoScrollSpeedX    = 10;
            titleScroll_.HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch;
            titleScroll_.VerticalAlignment   = LcdGdiVerticalAlignment.Top;

            artistScroll_                     = new LcdGdiScrollViewer(artistGdi_);
            artistScroll_.AutoScrollY         = false;
            artistScroll_.AutoScrollX         = true;
            artistScroll_.AutoScrollSpeedY    = 0;
            artistScroll_.AutoScrollSpeedX    = 10;
            artistScroll_.HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch;
            artistScroll_.VerticalAlignment   = LcdGdiVerticalAlignment.Top;

            albumScroll_                     = new LcdGdiScrollViewer(albumGdi_);
            albumScroll_.AutoScrollY         = false;
            albumScroll_.AutoScrollX         = true;
            albumScroll_.AutoScrollSpeedY    = 0;
            albumScroll_.AutoScrollSpeedX    = 10;
            albumScroll_.HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch;
            albumScroll_.VerticalAlignment   = LcdGdiVerticalAlignment.Top;

            fullStarImage_  = (Image)Resource.star_rating_full;
            halfStarImage_  = (Image)Resource.star_rating_half;
            emptyStarImage_ = (Image)Resource.star_rating_empty;
            emptyImage_     = (Image)Resource.empty;

            this.Children.Add(backgroundGdi_);
            this.Children.Add(titleGdi_);
            this.Children.Add(titleScroll_);
            this.Children.Add(artistGdi_);
            this.Children.Add(artistScroll_);
            this.Children.Add(positionGdi_);
            this.Children.Add(durationGdi_);
            this.Children.Add(progressBarGdi_);
            this.Children.Add(albumGdi_);
            this.Children.Add(albumScroll_);
            this.Children.Add(artworkGdi_);

            ratingColorGdi_ = new LcdGdiImage[5];

            float tempRating = this.rating_;

            for (int i = 0; i < 5; i++)
            {
                if (this.rating_ != 0)
                {
                    if (tempRating - 1 >= 0)
                    {
                        ratingColorGdi_[i] = new LcdGdiImage(fullStarImage_);
                        tempRating--;
                    }

                    else if (tempRating - 0.5f == 0)
                    {
                        ratingColorGdi_[i] = new LcdGdiImage(halfStarImage_);
                        tempRating        -= 0.5f;
                    }

                    else
                    {
                        ratingColorGdi_[i] = new LcdGdiImage(emptyStarImage_);
                    }
                }
                else
                {
                    ratingColorGdi_[i] = new LcdGdiImage(emptyStarImage_);
                }
                ratingColorGdi_[i].HorizontalAlignment = LcdGdiHorizontalAlignment.Left;
                ratingColorGdi_[i].Margin = new MarginF((18 * i) + 5, 215, 0, 0);
                this.Children.Add(ratingColorGdi_[i]);
            }
        }
        /// <summary>
        /// Event handler for button press on a device.
        /// </summary>
        /// <param name="sender">Device on which button was pressed</param>
        /// <param name="e">Button event arguments</param>
        private static void DeviceSoftButtonsChanged(object sender, LcdSoftButtonsEventArgs e)
        {
            LcdDeviceMonochrome device = (LcdDeviceMonochrome)sender;

            // First button
            if ((e.SoftButtons & LcdSoftButtons.Button0) == LcdSoftButtons.Button0)
            {
                if (button0Up)
                {
                    button0Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        DecrementListState(ref devicesList);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        DecrementListState(ref entriesList);
                    }
                }
            }
            else
            {
                button0Up = true;
            }

            // Second button
            if ((e.SoftButtons & LcdSoftButtons.Button1) == LcdSoftButtons.Button1)
            {
                if (button1Up)
                {
                    button1Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        IncrementListState(ref devicesList, 3);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        IncrementListState(ref entriesList, 3);
                    }
                }
            }
            else
            {
                button1Up = true;
            }

            // Third button
            if ((e.SoftButtons & LcdSoftButtons.Button2) == LcdSoftButtons.Button2)
            {
                if (button2Up)
                {
                    button2Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        lock (devicesList.Lock)
                        {
                            if (devicesList.Items != null && devicesList.Items.Length > 0)
                            {
                                actions.Add(Action.Connect);
                                device.Pages[1].SetAsCurrentDevicePage();
                            }
                        }
                    }
                    else if (device.CurrentPage == device.Pages[1] && ccid == null)
                    {
                        actions.Add(Action.Connect);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        lock (entriesList.Lock)
                        {
                            if (entryCode.HasValue && !entryCode.Value.Credential.Name.Equals(entriesList.Items[entriesList.Selected].Name))
                            {
                                // Reset code object
                                entryCode = null;

                                // Reset text elements
                                LcdGdiPage         page       = (LcdGdiPage)device.Pages[3];
                                LcdGdiScrollViewer scrollView = (LcdGdiScrollViewer)page.Children[4];
                                LcdGdiText         textName   = (LcdGdiText)scrollView.Child;
                                LcdGdiText         textCode   = (LcdGdiText)page.Children[5];
                                textName.Text = null;
                                textCode.Text = null;
                            }
                        }

                        device.Pages[3].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        lock (entriesList.Lock)
                        {
                            LcdGdiPage  page        = (LcdGdiPage)device.Pages[3];
                            LcdGdiImage refreshIcon = (LcdGdiImage)page.Children[0];

                            if (refreshIcon.IsVisible)
                            {
                                entryCode = null;
                            }
                        }
                    }
                }
            }
            else
            {
                button2Up = true;
            }

            // Fourth button
            if ((e.SoftButtons & LcdSoftButtons.Button3) == LcdSoftButtons.Button3)
            {
                if (button3Up)
                {
                    button3Up = false;

                    if (device.CurrentPage == device.Pages[1] || device.CurrentPage == device.Pages[2])
                    {
                        device.Pages[0].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        device.Pages[2].SetAsCurrentDevicePage();
                    }
                }
            }
            else
            {
                button3Up = true;
            }
        }
        /// <summary>
        /// Updates the code page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateEntryPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage         page        = (LcdGdiPage)sender;
            LcdGdiImage        refreshIcon = (LcdGdiImage)page.Children[0];
            LcdGdiProgressBar  progressBar = (LcdGdiProgressBar)page.Children[2];
            LcdGdiScrollViewer scrollView  = (LcdGdiScrollViewer)page.Children[4];
            LcdGdiText         textName    = (LcdGdiText)scrollView.Child;
            LcdGdiText         textCode    = (LcdGdiText)page.Children[5];

            lock (entriesList.Lock)
            {
                progressBar.IsVisible = false;

                if (!entryCodeRequested && !entryCode.HasValue)
                {
                    textName.Text      = entriesList.Items[entriesList.Selected].Name;
                    entryCodeRequested = true;

                    if (entriesList.Items[entriesList.Selected].Touch)
                    {
                        textCode.Text         = "Touch your YubiKey...";
                        refreshIcon.IsVisible = false;
                        return;
                    }
                }
                entryCodeRequested = false;

                DateTime time      = DateTime.UtcNow;
                Int32    timestamp = (Int32)(time.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                if (!entryCode.HasValue || entryCode.Value.ValidTo != 0 && entryCode.Value.ValidTo < timestamp && entriesList.Items[entriesList.Selected].Type == OATHController.Type.TOTP && !entriesList.Items[entriesList.Selected].Touch)
                {
                    try
                    {
                        entryCode     = oath.Calculate(entriesList.Items[entriesList.Selected], time);
                        textCode.Text = entryCode.Value.Value;
                    }
                    catch (UnexpectedResponseException ex)
                    {
                        entryCode = new OATHController.Code(); // Hack: Set empty code object to prevent code regen
                        if (ex.SW == APDUResponse.StatusWord.AUTH_REQUIRED)
                        {
                            textCode.Text = "Touch timeout.";
                        }
                        else
                        {
                            textCode.Text = "Error: " + ex.SW.ToString();
                        }
                        refreshIcon.IsVisible = true;
                        return;
                    }
                }

                if (entriesList.Items[entriesList.Selected].Type == OATHController.Type.TOTP && entryCode.HasValue && entryCode.Value.ValidTo != 0)
                {
                    if (entryCode.Value.ValidTo > timestamp)
                    {
                        progressBar.IsVisible = true;
                        progressBar.Value     = (int)(((float)(entryCode.Value.ValidTo - timestamp) / entriesList.Items[entriesList.Selected].Period) * 100);
                    }
                    else if (entriesList.Items[entriesList.Selected].Touch)
                    {
                        textCode.Text         = "Code expired.";
                        progressBar.IsVisible = false;
                        refreshIcon.IsVisible = true;
                    }
                }
            }
        }
        /// <summary>
        /// Updates the connection status page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateConnectionStatusPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage         page             = (LcdGdiPage)sender;
            LcdGdiImage        refreshButton    = (LcdGdiImage)page.Children[0];
            LcdGdiImage        backButton       = (LcdGdiImage)page.Children[1];
            LcdGdiScrollViewer deviceScrollView = (LcdGdiScrollViewer)page.Children[3];
            LcdGdiText         deviceText       = (LcdGdiText)deviceScrollView.Child;
            LcdGdiText         statusText       = (LcdGdiText)page.Children[4];

            if (oath != null && oath.HasChallenge())
            {
                using (var dialog = new PasswordDialog())
                {
                    dialog.OKButton.Click += (_sender, _e) =>
                    {
                        try
                        {
                            oath.Validate(dialog.PasswordBox.Text);
                            statusText.Text = "Connected.";
                            CreateTimer("ConnectionStatusSwitchPage", 2);
                        }
                        catch (UnexpectedResponseException)
                        {
                            statusText.Text = "Invalid password, try again...";
                        }
                        dialog.Close();
                    };
                    dialog.CancelButton.Click += (_sender, _e) =>
                    {
                        oath = null;
                        ccid = null;
                        page.Device.Pages[0].SetAsCurrentDevicePage();
                        dialog.Close();
                    };
                    dialog.ShowDialog();
                }
            }

            if (CheckTimer("ConnectionStatusSwitchPage"))
            {
                // Update list items
                lock (entriesList.Lock)
                {
                    entriesList.Items   = oath.List();
                    entriesList.Changed = true;

                    // Calculate all keys and update touch info
                    var codes = oath.CalculateAll();
                    foreach (var code in codes)
                    {
                        if (code.Credential.Touch)
                        {
                            var idx = entriesList.Items.FindIndex(item => item.Name.Equals(code.Credential.Name));
                            if (idx != -1)
                            {
                                var item = entriesList.Items[idx];
                                item.Touch             = code.Credential.Touch;
                                entriesList.Items[idx] = item;
                            }
                        }
                    }
                }

                // Switch page
                page.Device.Pages[2].SetAsCurrentDevicePage();
                return;
            }

            lock (devicesList.Lock)
            {
                while (actions.TryTake(out Action a))
                {
                    switch (a)
                    {
                    case Action.Connect:
                        try
                        {
                            ccid                    = CCIDDriver.OpenDevice(devicesList.Items[devicesList.Selected]);
                            oath                    = new OATHController(ccid);
                            deviceText.Text         = devicesList.Items[devicesList.Selected];
                            backButton.IsVisible    = false;
                            refreshButton.IsVisible = false;

                            if (oath.HasChallenge())
                            {
                                statusText.Text = "Waiting for password...";
                            }
                            else
                            {
                                statusText.Text = "Connected.";
                                CreateTimer("ConnectionStatusSwitchPage", 2);
                            }
                        }
                        catch (ConnectionException)
                        {
                            oath                    = null;
                            ccid                    = null;
                            deviceText.Text         = devicesList.Items[devicesList.Selected];
                            statusText.Text         = "Unable to connect.";
                            backButton.IsVisible    = true;
                            refreshButton.IsVisible = true;
                        }
                        break;
                    }
                }
            }
        }
 private void createColor()
 {
     backgroundImage_ = (Image)Resource.G19logo;
     backgroundGdi_   = new LcdGdiImage(backgroundImage_);
     this.Children.Add(backgroundGdi_);
 }