// Open archive button private async void OpenArchiveButton_OnClicked(object sender, EventArgs e) { var file = await _browser.BrowseForLoad(); if (file == null) { return; } try { // Load Archive in the background var archive = await Task.Run(() => Archive.Archive.Open(file)); foreach (var session in archive.Sessions) { session.Register(); } } catch (Exception ex) { Debug.WriteLine($"ERROR OPENING ARCHIVE: {ex.Message} \n{ex}"); await XamarinHelpers.GetCurrentPage().DisplayAlert("Open error", $"Could not open archive:\n{ex.Message}", "OK"); } }
public bool ExitShouldBeInterrupted(bool ret, Action exitCommand) { if (_isSaving) { var displayTask = DisplayAlert("Saving in progress", "Saving is in progress.\nQuitting might corrupt the archive being saved.\nDo you want to quit anyways?", "Quit", "Wait"); displayTask.ContinueWith(task => { if (displayTask.Result) { // Switch back to player page (main page) XamarinHelpers.EnsureMainThread(exitCommand); } }); return(true); } if (_treeMightHaveChanged) { var displayAlert = DisplayAlert("Unsaved data", "There might be unsaved data.\n\nAre sure you want to quit?", "Quit", "Cancel"); displayAlert.ContinueWith(task => { if (displayAlert.Result) { // Switch back to player page (main page) XamarinHelpers.EnsureMainThread(exitCommand); } }); return(true); } return(false); }
private static void MoveElementInsideTree(DataTreeView target, BranchView branchItem) { if (target.Tree.Children.Count == 0) { return; } if (branchItem.Element.DataStructure == null) { Debug.Write("Can not remove datapoints, only datastructures"); return; } var ix = target.Tree.Children.IndexOf(branchItem.Element.DataStructure); if (ix != -1) { if (ix == target.Tree.Children.Count - 1) { return; } target.Tree.Children.Move(ix, target.Tree.Children.Count - 1); return; } var branchParent = XamarinHelpers.GetTypedElementFromParents <BranchView>(branchItem.Parent); branchParent.Element.DataStructure.Children.Remove(branchItem.Element.DataStructure); target.Tree.Children.Add(branchItem.Element.DataStructure); }
/// <summary> /// Load the view from from the provided JSON /// </summary> /// <param name="root">The JSON-object containing the serialized view</param> /// <param name="archive">Optional archive that the data points should be loaded from</param> /// <returns></returns> public async Task DeserializeView(JObject root, IDataStructure archive = null) { if (!await SerializableViewHelper.EnsureViewType(root, this, false, true)) { return; } var figures = XamarinHelpers.GetAllChildElements <FigureView>(PlayerContainer); foreach (var figure in figures) { figure.RemoveThisView(); } PlayerContainer.ViewerContext = ViewerContext; FigureView.DeserializationFailedWarned = false; if (root["player_container"] is JObject playerContainerJson) { await PlayerContainer.DeserializeView(playerContainerJson, archive); } if (root["playbar"] is JObject playbarJson) { await Playbar.DeserializeView(playbarJson, archive); } }
private void SliderOnOffsetChanged(object sender, ValueChangedEventArgs e) { OffsetChanged?.Invoke(sender, e); if (sender != SliderEntry) { XamarinHelpers.EnsureMainThread(() => { SliderEntry.Text = e.NewValue.ToString(CultureInfo.InvariantCulture); }); } }
private void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { if (!(XamarinHelpers.GetCurrentPage() is SavingPage savingPage)) { return; } e.Handled = savingPage.ExitShouldBeInterrupted(e.Handled, ForceClose); }
private void RootFrameOnPreviewKeyDown(object sender, KeyRoutedEventArgs e) { if (XamarinHelpers.GetCurrentPage() is KeypressPage keyPage) { var keyArgs = KeypressHandler.VirtualKeyToKeyEvent(e.Key, e.Handled, true); KeypressHandler.KeyPageKeyDown(keyPage, keyArgs); e.Handled = keyArgs.Handled; } }
public CustomNavigationBar() { InitializeComponent(); _browser = DependencyService.Get <IFileBrowser>(); if (_browser == null) { XamarinHelpers.GetCurrentPage(Navigation).DisplayAlert("Critical error", "Could get file browser. Will not be able to open and save files.", "OK"); } }
private static bool IsOwnParent(BranchView target, BranchView item) { var parent = XamarinHelpers.GetTypedElementFromParents <BranchView>(target.Parent); while (parent != null) { if (parent == item) { return(true); } parent = XamarinHelpers.GetTypedElementFromParents <BranchView>(parent.Parent); } return(false); }
public PlayerPage() { InitializeComponent(); _browser = DependencyService.Get <IFileBrowser>(); if (_browser == null) { XamarinHelpers.GetCurrentPage(Navigation).DisplayAlert("Critical error", "Could get file browser. Will not be able to open and save files.", "OK"); } NavigationBar.MainPageButton.BackgroundColor = Color.FromHex("23A2B1"); ViewerContext?.SetSynchronizedToWorldClock(true); Appearing += OnAppearing; Disappearing += OnDisappearing; }
public async Task AddLine(IDataPoint datapoint) { var line = await CreateLineDrawer(datapoint); if (line == null) { throw new ArgumentException("Could not create line"); } AddLine(line); DataPoints.Add(datapoint); var container = XamarinHelpers.GetFigureContainerFromParents(Parent); container?.InvokeDatapointAdded(datapoint, _context); }
private static void MoveElementInsideTree(BranchView target, BranchView item) { if (target.Element.DataPoint != null || item.Element.DataPoint != null) { Debug.WriteLine("Reordering of data points not implemented yet"); return; } if (IsOwnParent(target, item)) { Debug.WriteLine("You shouldn't become your own grandmother."); return; } // If immediate element of parent, move to top if (target.Element.DataStructure.Children.Contains(item.Element.DataStructure)) { var ix = target.Element.DataStructure.Children.IndexOf(item.Element.DataStructure); if (ix == 0) { return; } target.Element.DataStructure.Children.Move(ix, 0); return; } var parent = XamarinHelpers.GetTypedElementFromParents <BranchView>(item.Parent); if (parent != null) { parent.Element.DataStructure.Children.Remove(item.Element.DataStructure); } else { var treeParent = XamarinHelpers.GetTypedElementFromParents <DataTreeView>(item.Parent); if (treeParent == null) { Debug.WriteLine("Unknown parent"); return; } treeParent.Tree.Children.Remove(item.Element.DataStructure); } target.Element.DataStructure.Children.Add(item.Element.DataStructure); }
// Import files handling private static async void DoImportFiles(IEnumerable <IReadSeekStreamFactory> files) { var pluginPages = new Dictionary <IImportPlugin, (List <IReadSeekStreamFactory>, ImportParametersPage)>(); foreach (var file in files) { var ext = file.Extension.ToLower(); // FIXME: This should probably be handled somewhere else? // FIXME: This should also handle a case where multiple importers are possible // TODO: Should probably be run on a background thread... // Find the proper import plugin to use var plugins = PluginService.GetAll <IImportPlugin>(ext); if (!plugins.Any()) { await XamarinHelpers.GetCurrentPage().DisplayAlert("Import error", $"Could not find a plugin for extension \"{ext}\" files", "OK"); continue; } foreach (var plugin in plugins) { try { if (!(await plugin.CanParse(file))) { continue; } } catch (Exception ex) { await ShowError(file.Name, ex); } try { List <IReadSeekStreamFactory> streamFactoryList; if (!pluginPages.TryGetValue(plugin, out var listPage)) { var parameters = new Dictionary <string, (object, string)> {
public SavingPage() { InitializeComponent(); NavigationBar.SaveArchiveButton.BackgroundColor = Color.FromHex("23A2B1"); DataRegistry.ProviderAdded += el => DataTree.Tree.Children.Add(el); DataRegistry.ProviderRemoved += el => DataTree.Tree.Children.Remove(el); // Add current items foreach (var dataProvider in DataRegistry.Providers) { DataTree.Tree.Children.Add(dataProvider); } SavingTree.ItemDroppedOn += SavingTreeOnItemDroppedOn; RemovalTree.ItemDroppedOn += RemovalTreeOnItemDroppedOn; _browser = DependencyService.Get <IFileBrowser>(); if (_browser == null) { XamarinHelpers.GetCurrentPage(Navigation).DisplayAlert("Critical error", "Could get file browser. Will not be able to open and save files.", "OK"); } }
public static async Task <bool> EnsureViewType(JObject root, ISerializableView view, bool throwException = true, bool showMessage = false) { var viewType = root["type"].Value <string>(); if (viewType == view.ViewType) { return(true); } if (throwException) { throw new SerializationException("Could not deserialize view - wrong view type detected."); } if (showMessage) { await XamarinHelpers.ShowOkMessage("Wrong page or view type detected", $"Expected {view.ViewType.Split('.').Last()} but found {viewType.Split('.').Last()}\n\n\n" + $"(Full types \"{view.ViewType}\" != \"{viewType}\")"); } return(false); }
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { e.Handled = true; var errMsg = XamarinHelpers.ShowOkMessage("Error", $"An unexpected error occurred: \n{e.Exception}"); }
private void VideoPlayerOnPositionChanged(object sender, PositionChangedEventArgs args) { var allowedOffset = _videoPlayer.AllowedOffset; XamarinHelpers.EnsureMainThread(() => SetVideoPosition(args.Time, allowedOffset)); }