// Update the Now Playing pagetext fields public void updateTextFields(LcdDevice device, LcdGdiPage page, LcdGdiScrollViewer scrollViewer, LcdGdiScrollViewer scrollViewer2, LcdGdiScrollViewer scrollViewer3, LcdGdiText playTime) { LcdGdiText track = (LcdGdiText)scrollViewer.Child; track.Text = m_playerDetails.currentTrack; LcdGdiText album = (LcdGdiText)scrollViewer2.Child; album.Text = m_playerDetails.currentAlbum; LcdGdiText artist = (LcdGdiText)scrollViewer3.Child; artist.Text = m_playerDetails.currentArtist; playTime.Text = m_playerDetails.playTime; }
private void createMono() { titleGdi_ = new LcdGdiText(this.title_, font_); titleGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center; titleGdi_.Margin = new MarginF(-2, -1, 0, 0); artistGdi_ = new LcdGdiText(this.artist_, font_); artistGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center; artistGdi_.VerticalAlignment = LcdGdiVerticalAlignment.Top; artistGdi_.Margin = new MarginF(-2, 12, 0, 0); positionGdi_ = new LcdGdiText(Conversions.timetoString(this.position_), font2_); positionGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Left; positionGdi_.Margin = new MarginF(10, 26, 0, 0); ratingGdi_ = new LcdGdiText("", font2_); ratingGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Center; ratingGdi_.Margin = new MarginF(0, 26, 0, 0); if (this.rating_ != 0) { ratingGdi_.Text = this.rating_.ToString() + " / 5"; } else { ratingGdi_.Text = ""; } durationGdi_ = new LcdGdiText(Conversions.timetoString(this.duration_), font2_); durationGdi_.HorizontalAlignment = LcdGdiHorizontalAlignment.Right; durationGdi_.Margin = new MarginF(0, 26, 13, 0); progressBarGdi_ = new LcdGdiProgressBar(); progressBarGdi_.Size = new SizeF(136, 5); progressBarGdi_.Margin = new MarginF(12, 38, 0, 0); progressBarGdi_.Minimum = 0; progressBarGdi_.Maximum = 100; 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; this.Children.Add(titleGdi_); this.Children.Add(artistGdi_); this.Children.Add(titleScroll_); this.Children.Add(artistScroll_); this.Children.Add(positionGdi_); this.Children.Add(ratingGdi_); this.Children.Add(durationGdi_); this.Children.Add(progressBarGdi_); }
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; } } } }