private async Task <ToFileResult?> GeneratePdfDocument()
        {
            if (ToPdfService.IsAvailable)
            {
                var pdfResult = await WebView.ToPdfAsync("rapport");

                if (pdfResult.IsError)
                {
                    using (Toast.Create("PDF Failure", pdfResult.Result))
                    {
                    }
                }
                else
                {
                    return(pdfResult);
                }
            }
            else
            {
                using (Toast.Create(null, "PDF Export is not available on this device"))
                {
                }
            }

            return(null);
        }
Esempio n. 2
0
    private async UniTask InitModules()
    {
        new ProjectReferences();

        ProjectReferences.I.Canvas = (await Addressables.InstantiateAsync("canvas"))
                                     .GetComponent <Transform>();
        ProjectReferences.I.Canvas.GetComponent <Canvas>().sortingOrder = 10;

        new Repository();
        new BlockingOperationManager();
        await Background.Create();

        await Toast.Create();
    }
Esempio n. 3
0
 private async void btnPNG_Clicked(object sender, EventArgs e)
 {
     if (await webView.ToPngAsync(fileName) is ToFileResult result)
     {
         if (result.IsError)
         {
             using (Toast.Create("Falha ao tentar exportar", result.Result)) { }
         }
         else
         {
             await Xamarin.Essentials.Share.RequestAsync(new Xamarin.Essentials.ShareFileRequest
             {
                 Title = "Compartilhe seu arquivo",
                 File  = new Xamarin.Essentials.ShareFile(result.Result, "image/png"),
             });
         }
     }
 }
Esempio n. 4
0
 private async void btnPDF_Clicked(object sender, EventArgs e)
 {
     if (Forms9Patch.ToPdfService.IsAvailable)
     {
         if (await webView.ToPdfAsync(fileName) is ToFileResult result)
         {
             if (result.IsError)
             {
                 using (Toast.Create("Falha ao tentar exportar", result.Result)) { }
             }
             else
             {
                 await Xamarin.Essentials.Share.RequestAsync(new Xamarin.Essentials.ShareFileRequest
                 {
                     Title = "Compartilhe seu arquivo",
                     File  = new Xamarin.Essentials.ShareFile(result.Result, "application/pdf"),
                 });
             }
         }
     }
 }
Esempio n. 5
0
        public IEnumerator ItemShops_Interactive() => UniTask.ToCoroutine(async() =>
        {
            await LoadEss();

            new ProjectReferences()
            {
                Canvas = canvas
            };

            Controller.I = new Mock <IController>().Object;
            new Repository();
            await Toast.Create();
            new BlockingOperationManager();

            await UniTask.DelayFrame(2);

            Repository.I.PersonalFullInfo = new PersonalFullUserInfo()
            {
                SelectedCardback   = 2,
                SelectedBackground = 3,

                OwnedBackgroundsIds = new List <int>()
                {
                    1, 3
                },
                OwnedCardBackIds = new List <int>()
                {
                    0, 2, 3, 9
                },

                Money = 1000,
            };

            Repository.I.PersonalFullInfo.DecreaseMoneyAimTimeLeft().Forget();

            await Shop.Create(canvas, ItemType.Cardback);
            await Shop.Create(canvas, ItemType.Background);

            await UniTask.Delay(int.MaxValue);
        });
 async void ShareButton_Clicked(object sender, EventArgs e)
 {
     if (Forms9Patch.ToPdfService.IsAvailable)
     {
         if (await webView.ToPdfAsync("output.pdf") is ToFileResult pdfResult)
         {
             if (pdfResult.IsError)
             {
                 using (Toast.Create("PDF Failure", pdfResult.Result)) { }
             }
             else
             {
                 var collection = new Forms9Patch.MimeItemCollection();
                 collection.AddBytesFromFile("application/pdf", pdfResult.Result);
                 Forms9Patch.Sharing.Share(collection, shareButton);
             }
         }
     }
     else
     {
         using (Toast.Create(null, "PDF Export is not available on this device")) { }
     }
 }
Esempio n. 7
0
        public IEnumerator MoneyAid() => UniTask.ToCoroutine(async() =>
        {
            await LoadEss();

            Repository.I = new Repository
            {
                PersonalFullInfo = new PersonalFullUserInfo
                {
                    Money              = 11,
                    Name               = "Holy Hanaka",
                    Picture            = Texture2D.linearGrayTexture,
                    Xp                 = 5742,
                    MoneyAimTimePassed = null,
                    MoneyAidRequested  = 2,
                }
            };

            Repository.I.PersonalFullInfo.DecreaseMoneyAimTimeLeft().Forget();

            Controller.I = new Mock <IController>().Object;

            LobbyReferences.I = new LobbyReferences {
                Canvas = canvas
            };
            ProjectReferences.I = new ProjectReferences {
                Canvas = canvas
            };

            await Toast.Create();

            RoomSettings.I = new RoomSettings(0, 0, null, 0);

            await PersonalActiveUserView.Create();

            await UniTask.Delay(int.MaxValue);
        });
Esempio n. 8
0
        public PopupsPage()
        {
            Padding = 20;
            _hzLayoutOptions.SelectIndex(1);
            _vtLayoutOptions.SelectIndex(1);

            #region ModalPopup
            cancelModalButton.Clicked += async(sender, e) => await _modalPopup.CancelAsync();

            popPushModalButton.Clicked += (sender, e) =>
            {
                _modalPopup.IsVisible = false;
                _modalPopup.IsVisible = true;
            };
            showModalButton.Clicked += (sender, e) =>
            {
                _modalPopup.HasShadow         = _hasShadow;
                _modalPopup.ShadowInverted    = _shadowInverted;
                _modalPopup.OutlineWidth      = _blueOutline ? 1 : 0;
                _modalPopup.IsVisible         = true;
                _modalPopup.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                _modalPopup.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region BubblePopups


            var showBubbleLeftButton = new Forms9Patch.Button(bubbleLeftText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleRightButton = new Forms9Patch.Button(bubbleRightText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleUpButton = new Forms9Patch.Button(bubbleUpText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleDownButton = new Forms9Patch.Button(bubbleDownText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleHzButton = new Forms9Patch.Button(bubbleHzText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleVtButton = new Forms9Patch.Button(bubbleVtText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleAnyButton = new Forms9Patch.Button(bubbleAnyText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleNoneButton = new Forms9Patch.Button(bubbleNoneText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };

            var bubblePointerDirectionControl = new SegmentedControl
            {
                Segments =
                {
                    new Segment("←"),
                    new Segment("↑"),
                    new Segment("→"),
                    new Segment("↓"),
                    new Segment("↔"),
                    new Segment("↕"),
                    new Segment("↔ ↕"),
                    new Segment(" ")
                },
                SyncSegmentFontSizes = false,
            };

            var cancelBubbleButton = new Forms9Patch.Button("CANCEL");

            var bubbleTarget = new Forms9Patch.Frame
            {
                OutlineWidth      = 1,
                OutlineColor      = Color.Black,
                OutlineRadius     = 4,
                Content           = new Forms9Patch.Label("BUBBLE TARGET"),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
            };

            bubble = new BubblePopup(bubbleTarget)
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new Forms9Patch.Label("BubblePopup")
                        {
                            FontAttributes = FontAttributes.Bold
                        },
                        bubblePointerDirectionControl,
                        cancelBubbleButton
                    },
                },
            };

            bubblePointerDirectionControl.SegmentTapped += (sender, e) =>
            {
                switch (e.Segment.Text)
                {
                case "←": bubble.PointerDirection = PointerDirection.Left; break;

                case "↑": bubble.PointerDirection = PointerDirection.Up; break;

                case "→": bubble.PointerDirection = PointerDirection.Right; break;

                case "↓": bubble.PointerDirection = PointerDirection.Down; break;

                case "↔": bubble.PointerDirection = PointerDirection.Horizontal; break;

                case "↕": bubble.PointerDirection = PointerDirection.Vertical; break;

                case "↔↕": bubble.PointerDirection = PointerDirection.Any; break;

                case " ": bubble.PointerDirection = PointerDirection.None; break;
                }
            };

            cancelBubbleButton.Clicked += async(sender, e) => await bubble.CancelAsync();

            showBubbleLeftButton.Clicked  += OnBubbleButtonClicked;
            showBubbleRightButton.Clicked += OnBubbleButtonClicked;
            showBubbleUpButton.Clicked    += OnBubbleButtonClicked;
            showBubbleDownButton.Clicked  += OnBubbleButtonClicked;
            showBubbleHzButton.Clicked    += OnBubbleButtonClicked;
            showBubbleVtButton.Clicked    += OnBubbleButtonClicked;
            showBubbleAnyButton.Clicked   += OnBubbleButtonClicked;
            showBubbleNoneButton.Clicked  += OnBubbleButtonClicked;
            #endregion


            #region ActivityPopup
            Forms9Patch.Button showActivityPopupButton = new Forms9Patch.Button("ActivityIndicatorPopup")
            {
                BackgroundColor = Color.White
            };
            showActivityPopupButton.Clicked += (sender, e) =>
            {
                //var activity = Forms9Patch.ActivityIndicatorPopup.Create();
                _activity.CancelOnPageOverlayTouch = true;
                _activity.IsVisible = true;
            };
            #endregion


            #region PermissionPopup
            var showPermissionButton = new Forms9Patch.Button("PermissionPopup")
            {
                BackgroundColor = Color.White
            };
            showPermissionButton.Clicked += (sender, e) =>
            {
                var permission = PermissionPopup.Create("PermissionPopup", "Do you agree?");
                permission.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                permission.VerticalOptions   = LayoutOption(_vtLayoutOptions);
                permission.OutlineColor      = Color.Blue;
                permission.HasShadow         = _hasShadow;
                permission.ShadowInverted    = _shadowInverted;
                permission.OutlineWidth      = _blueOutline ? 1 : 0;
            };
            #endregion


            #region Toast
            var showToastButton = new Forms9Patch.Button("Toast")
            {
                BackgroundColor = Color.White
            };
            showToastButton.Clicked += (sender, e) =>
            {
                var toast = Toast.Create("Toast", "... of the town!");
                toast.OutlineColor      = Color.Blue;
                toast.HasShadow         = _hasShadow;
                toast.ShadowInverted    = _shadowInverted;
                toast.OutlineWidth      = _blueOutline ? 1 : 0;
                toast.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                toast.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region TargetedToast
            var showTargetedToash = new Forms9Patch.Button("TargetedToast")
            {
                BackgroundColor = Color.White
            };
            showTargetedToash.Clicked += (sender, e) =>
            {
                var toast = TargetedToast.Create(showTargetedToash, "TargetedToast", "... has the far getted most!");
                toast.OutlineColor      = Color.Blue;
                toast.HasShadow         = _hasShadow;
                toast.ShadowInverted    = _shadowInverted;
                toast.OutlineWidth      = _blueOutline ? 1 : 0;
                toast.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                toast.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region TargetedMenu
            showTargetedMenu = new Forms9Patch.Button("TargetedMenu")
            {
                BackgroundColor = Color.White
            };
            var targetedMenu = new Forms9Patch.TargetedMenu(showTargetedMenu)
            {
                Segments =
                {
                    new Segment("Copy",       "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14D;</font>"),
                    new Segment("Cut",        "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14E;</font>"),
                    new Segment("Paste",      "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14F;</font>"),
                    new Segment("Segment A"),
                    new Segment("Segment B"),
                    new Segment("Segment C"),
                    new Segment("Segment D"),
                    new Segment("Segment E"),
                    new Segment("Segment F"),
                    new Segment("Segment G"),
                    new Segment("Segment H"),
                },
                TextColor = Color.White
            };
            showTargetedMenu.Clicked += (s, e) =>
            {
                targetedMenu.IsVisible      = true;
                targetedMenu.HasShadow      = _hasShadow;
                targetedMenu.ShadowInverted = _shadowInverted;
                targetedMenu.IsVisible      = true;
            };
            targetedMenu.SegmentTapped += (s, e) => System.Diagnostics.Debug.WriteLine("TargetedMenu.SegmentTapped: " + e.Segment.Text);
            #endregion


            #region Vertical TargetedMenu
            var showVerticalTargetedMenu = new Forms9Patch.Button("Vertical TargetedMenu")
            {
                BackgroundColor = Color.White
            };
            var verticalTargetedMenu = new Forms9Patch.TargetedMenu(showVerticalTargetedMenu)
            {
                Orientation = StackOrientation.Vertical,
                Segments    =
                {
                    new Segment("Copy",       "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14D;</font>"),
                    new Segment("Cut",        "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14E;</font>"),
                    new Segment("Paste",      "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14F;</font>"),
                    new Segment("Segment A"),
                    new Segment("Segment B"),
                    new Segment("Segment C"),
                    new Segment("Segment D"),
                    new Segment("Segment E"),
                    new Segment("Segment F"),
                    new Segment("Segment G"),
                    new Segment("Segment H"),
                },
            };
            showVerticalTargetedMenu.Clicked += (s, e) =>
            {
                //verticalTargetedMenu.OutlineColor = Color.Blue;
                verticalTargetedMenu.IsVisible      = true;
                verticalTargetedMenu.HasShadow      = _hasShadow;
                verticalTargetedMenu.ShadowInverted = _shadowInverted;
                verticalTargetedMenu.IsVisible      = true;
            };
            verticalTargetedMenu.SegmentTapped += (s, e) => System.Diagnostics.Debug.WriteLine("TargetedMenu.SegmentTapped: " + e.Segment.Text);
            #endregion


            #region SoftwareKeyboardTest

            var yearPicker = new Xamarin.Forms.Picker
            {
                Title       = "SELECT YEAR",
                ItemsSource = new List <string> {
                    "SELECT YEAR", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2006", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"
                },
                SelectedItem  = "SELECT YEAR",
                SelectedIndex = 0,
                TextColor     = Color.LightGray,
            };
            yearPicker.SelectedIndexChanged += (s, e) => yearPicker.TextColor = yearPicker.SelectedIndex == 0 ? Color.LightGray : Color.Blue;

            var monthPicker = new Xamarin.Forms.Picker
            {
                Title       = "SELECT MONTH",
                ItemsSource = new List <string> {
                    "SELECT MONTH", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
                },
                SelectedItem = "SELECT MONTH",
                TextColor    = Color.LightGray,
            };
            monthPicker.SelectedIndexChanged += (s, e) => monthPicker.TextColor = monthPicker.SelectedIndex == 0 ? Color.LightGray : Color.Blue;


            var softwareKeyboardTestButton = new Forms9Patch.Button("Software Keyboard Test")
            {
                BackgroundColor = Color.White
            };
            var softwareKeyboardTestPopup = new ModalPopup
            {
                HorizontalOptions = LayoutOption(_hzLayoutOptions),
                VerticalOptions   = LayoutOption(_vtLayoutOptions),
                Content           =
                    new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        yearPicker,
                        monthPicker,
                        new Xamarin.Forms.Entry
                        {
                            Placeholder      = "ENTER FIRST NAME",
                            TextColor        = Color.Blue,
                            PlaceholderColor = Color.LightGray,
                        },
                        new Xamarin.Forms.Entry
                        {
                            Placeholder      = "ENTER LAST NAME",
                            TextColor        = Color.Blue,
                            PlaceholderColor = Color.LightGray,
                        },
                    }
                }
            };
            softwareKeyboardTestButton.Clicked += (s, e) =>
            {
                softwareKeyboardTestPopup.OutlineColor      = Color.Blue;
                softwareKeyboardTestPopup.HasShadow         = _hasShadow;
                softwareKeyboardTestPopup.ShadowInverted    = _shadowInverted;
                softwareKeyboardTestPopup.OutlineWidth      = _blueOutline ? 1 : 0;
                softwareKeyboardTestPopup.IsVisible         = true;
                softwareKeyboardTestPopup.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                softwareKeyboardTestPopup.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion

            Content = new Xamarin.Forms.ScrollView
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new BoxView {
                            HeightRequest = 1
                        },
                        _decoration,
                        new Forms9Patch.Label("HZ LAYOUT ALIGNMENT:"),
                        _hzLayoutOptions,
                        new Forms9Patch.Label("VT LAYOUT ALIGNMENT:"),
                        _vtLayoutOptions,
                        new BoxView {
                            HeightRequest = 1
                        },
                        showModalButton,
                        showBubbleLeftButton,
                        showBubbleRightButton,
                        showBubbleUpButton,
                        showBubbleDownButton,
                        showBubbleHzButton,
                        showBubbleVtButton,
                        showBubbleAnyButton,
                        showBubbleNoneButton,
                        bubbleTarget,
                        showActivityPopupButton,
                        showPermissionButton,
                        showToastButton,
                        showTargetedToash,
                        showTargetedMenu,
                        showVerticalTargetedMenu,
                        softwareKeyboardTestButton,
                        new BoxView {
                            HeightRequest = 1
                        },
                    }
                }
            };

            _decoration.SegmentTapped += (s, e) =>
            {
                switch (e.Segment.Text)
                {
                case _hasShadowText:
                    _hasShadow = !_hasShadow;
                    break;

                case _shadowInvertedText:
                    _shadowInverted = !_shadowInverted;
                    break;

                case _blueOutlineText:
                    _blueOutline = !_blueOutline;
                    break;
                }
            };

            BackgroundColor = Color.LightSlateGray;
        }
Esempio n. 9
0
        /// <summary>
        /// This is the event handler for PrintManager.PrintTaskRequested.
        /// </summary>
        /// <param name="sender">PrintManager</param>
        /// <param name="e">PrintTaskRequestedEventArgs </param>
        protected virtual void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
        {
            PrintTask printTask = null;

            printTask = e.Request.CreatePrintTask(JobName, sourceRequestedArgs =>
            {
                var deferral = sourceRequestedArgs.GetDeferral();

                PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);
                IList <string> displayedOptions             = printTask.Options.DisplayedOptions;
                displayedOptions.Clear();
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies);
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation);
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.PrintQuality);
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.MediaSize);
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Collation);
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Duplex);

                // Preset the default value of the printer option
                printTask.Options.MediaSize = PrintMediaSize.NorthAmericaLetter;

                // Create a new list option
                PrintCustomItemListOptionDetails margins = printDetailedOptions.CreateItemListOption("Margins", "Margins");

                /*
                 * if (Forms9Patch.OsInfoService.Version >= new Version(10, 0, 17134, 0))
                 * {
                 *  margins.AddItem("WideMargins", "Wide", "Each margin is 20% of the paper size", await wideMarginsIconTask);
                 *  margins.AddItem("ModerateMargins", "Moderate", "Each margin is 10% of the paper size", await moderateMarginsIconTask);
                 *  margins.AddItem("NarrowMargins", "Narrow", "Each margin is 5% of the paper size", await narrowMarginsIconTask);
                 *  // App tells the user some more information about what the feature means.
                 *  margins.Description = "The space between the content of your document and the edge of the paper";
                 * }
                 * else
                 */
                {
                    margins.AddItem("WideMargins", "Wide");
                    margins.AddItem("ModerateMargins", "Moderate");
                    margins.AddItem("NarrowMargins", "Narrow");
                }
                // The default is ModerateMargins
                ApplicationContentMarginTop  = 0.1;
                ApplicationContentMarginLeft = 0.1;
                margins.TrySetValue("ModerateMargins");


                // Add the custom option to the option list
                displayedOptions.Add("Margins");

                printDetailedOptions.OptionChanged += OnPrintDetailOptionChanged;

                // Print Task event handler is invoked when the print job is completed.
                printTask.Completed += (s, args) =>
                {
                    Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
                    {
                        // Notify the user when the print operation fails.
                        if (args.Completion == PrintTaskCompletion.Failed)
                        {
                            using (Toast.Create("Printing Failed", null)) { }
                        }
                        //else if (args.Completion == PrintTaskCompletion.Canceled)
                        //    using (Toast.Create("Printing Cancelled", null)) { }
                        else if (args.Completion == PrintTaskCompletion.Submitted)
                        {
                            using (Toast.Create("Printing ...", "Print job submitted to printer.", TimeSpan.FromSeconds(5))) { }
                        }
                        else if (args.Completion == PrintTaskCompletion.Abandoned)
                        {
                            using (Toast.Create("Printing Abandoned", null)) { }
                        }
                    });
                    UnregisterForPrinting();
                };

                sourceRequestedArgs.SetSource(printDocumentSource);

                deferral.Complete();
            });
        }
Esempio n. 10
0
    void OnGUI()
    {
        // secondary tile and toast can pass arguments to application,
        //which we can use to determine, if application was activated via secondary tile or toast notification
        string activationMode;

        if (UnityEngine.WSA.Application.arguments == "--secondary")
        {
            activationMode = "Activated via secondary tile";
        }
        else if (UnityEngine.WSA.Application.arguments == "--toast")
        {
            activationMode = "Activated via toast notification";
        }
        else
        {
            activationMode = "Activated normally";
        }
        GUILayout.Label(activationMode);


        text = GUILayout.TextField(text);


        // Update main tile with text, screenshot of both
        // we can't read screen here, to we just set flags to do so
        if (GUILayout.Button("Update tile (image only)"))
        {
            screenshotToTile = true;
            textToTile       = false;
        }
        if (GUILayout.Button("Update Tile (text only)"))
        {
            Tile.main.Update("", "", "", text);
        }
        if (GUILayout.Button("Update Tile (image and text)"))
        {
            screenshotToTile = true;
            textToTile       = true;
        }


        // Secondary tile first has to be create
        // then you can update it just like you would update main tile
        if (GUILayout.Button("Secondary tile (text only)"))
        {
            // first try to find existing secondary tile by it's id
            if (secondaryTile == null)
            {
                secondaryTile = Tile.GetSecondary("secondary");
            }
            // Note that user can destroy tile by unpinning it
            // so you should check secondaryTile.exists
            if (secondaryTile == null || !secondaryTile.exists)
            {
                // Create the tile, if it does not exist
                // id, arguments and 150x150 logo are required, when creating
                SecondaryTileData tileData = new SecondaryTileData("secondary", "Secondary Tile Example");
                tileData.arguments         = "--secondary";          // these arguments will be passed to application, when secondary tile is clicked
                tileData.square150x150Logo = "ms-appx:///Assets/SquareTile.png";
                secondaryTile = Tile.CreateOrUpdateSecondary(tileData);
                // at this moment user is presented with pop-up to pin secondary tile
                // there is no tile yet, so no updates can be performed
            }
            else if (secondaryTile.exists && secondaryTile.hasUserConsent)
            {
                // remember to check secondaryTile.hasUserConsent
                // if it's false, tile is not yet created
                // if user agrees, both exists and hasUserConsent are true
                secondaryTile.Update("", "", "", text);
                secondaryTile.UpdateBadgeNumber(++secondaryTileBadge);
            }
            else if (!secondaryTile.exists)
            {
                secondaryTile = null;
            }
        }


        if (GUILayout.Button("Show toast notification"))
        {
            // Create and show toast notification
            // remember to set application "Toast Capable" in appxmanifest
            Toast toast = Toast.Create("", "This is toast notification");
            toast.arguments = "--toast";              // these arguments will be passed to application, when user clicks on notification
            toast.Show();
        }
    }
Esempio n. 11
0
#pragma warning disable 1998
        internal static async Task <F9PImageData> FetchF9pImageData(this Xamarin.Forms.ImageSource imageSource, SkiaRoundedBoxAndImageView view, CancellationToken cancellationToken = new CancellationToken())
#pragma warning restore 1998
        {
            F9PImageData f9pImageData = null;

            var key = imageSource.ImageSourceKey();

            if (key != null)
            {
                if (_cache.ContainsKey(key))
                {
                    _views[key].Add(view);
                    f9pImageData = _cache[key];
                    if (f9pImageData == null)
                    {
                        throw new InvalidDataContractException();
                    }
                }
                else
                {
                    if (!_locks.ContainsKey(key))
                    {
                        //_locks[key] = new object();
                        _locks[key] = new SemaphoreSlim(1, 1);
                    }
                    //lock (_locks[key])
                    await _locks[key].WaitAsync();
                    try
                    {
                        //SKBitmap skBitmap = null;
                        string path = null;
                        if (key.StartsWith("eri:", StringComparison.Ordinal))
                        {
                            var assembly   = (Assembly)imageSource.GetValue(ImageSource.AssemblyProperty);
                            var resourceId = key.Substring(4);

                            using (var stream = await P42.Utils.EmbeddedResourceCache.GetStreamAsync(resourceId, assembly, Forms9Patch.Image.EmbeddedResourceImageCacheFolderName))
                            {
                                if (stream == null)
                                {
                                    Toast.Create("Cannot find EmbeddedResource", "Cannot find EmbeddedResource with Id of [" + resourceId + "] in Assembly [" + assembly + "]");
                                    return(null);
                                }

                                /*
                                 * using (var skStream = new SKManagedStream(stream))
                                 *  skBitmap = SKBitmap.Decode(skStream);
                                 */
                                f9pImageData = F9PImageData.Create(stream, key);
                            }
                        }
                        else if (key.StartsWith("uri:", StringComparison.Ordinal))
                        {
                            path = await P42.Utils.DownloadCache.DownloadAsync(key.Substring(4), Forms9Patch.Image.UriImageCacheFolderName);

                            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                                f9pImageData = F9PImageData.Create(stream, key);
                        }
                        else if (key.StartsWith("file:", StringComparison.Ordinal))  // does this work for Windows or iOS?
                        {
                            //path = key.Substring(5);
                            string filePath = ((FileImageSource)imageSource).File;

                            /*
                             * if (File.Exists(filePath))
                             *  skBitmap = SKBitmap.Decode(filePath);
                             #if __DROID__
                             * else
                             * {
                             *  var nativeBitmap = Settings.Context.Resources.GetBitmap(filePath);
                             *  skBitmap = nativeBitmap.ToSKBitmap();
                             * }
                             #endif
                             */
                            f9pImageData = F9PImageData.Create(filePath, key);
                        }
                        else
                        {
                            throw new InvalidDataContractException();
                        }

                        /*
                         * if (skBitmap != null)
                         * {
                         *  f9pImageData = F9PImageData.Create(skBitmap, key);
                         *
                         *  _cache[key] = f9pImageData;
                         *  if (!_views.ContainsKey(key))
                         *      _views[key] = new List<SkiaRoundedBoxAndImageView>();
                         *  _views[key].Add(view);
                         * }
                         */
                        if (f9pImageData != null)
                        {
                            _cache[key] = f9pImageData;
                            if (!_views.ContainsKey(key))
                            {
                                _views[key] = new List <SkiaRoundedBoxAndImageView>();
                            }
                            _views[key].Add(view);
                        }
                    }
                    finally
                    {
                        _locks[key].Release();
                        if ((f9pImageData?.SKBitmap == null || f9pImageData?.SKSvg == null))
                        {
                            _locks.Remove(key);
                        }
                    }
                }
            }
            else
            {
                // it's a Xamarin.Forms StreamSource that doesn't have any information that could be used for caching
                if (imageSource is StreamImageSource streamsource && streamsource.Stream != null)
                {
                    using (Stream stream = await((IStreamImageSource)streamsource).GetStreamAsync(cancellationToken))
                    {
                        if (stream == null)
                        {
                            return(null);
                        }
                        using (var skStream = new SKManagedStream(stream))
                        {
                            var skBitmap = SKBitmap.Decode(skStream);
                            f9pImageData = F9PImageData.Create(skBitmap, null);
                        }
                    }
                }
Esempio n. 12
0
        public PopupsPage()
        {
            Padding = 20;

            var showModalButton   = new Forms9Patch.Button("ModalPopup");
            var cancelModalButton = new Forms9Patch.Button("CANCEL");
            var modal             = new ModalPopup
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new Forms9Patch.Label("ModalPopup")
                        {
                            FontAttributes = FontAttributes.Bold
                        },
                        cancelModalButton
                    }
                }
            };

            cancelModalButton.Clicked += (sender, e) => modal.Cancel();
            showModalButton.Clicked   += (sender, e) => modal.IsVisible = true;

            var showBubbleButton   = new Forms9Patch.Button("BubblePopup");
            var cancelBubbleButton = new Forms9Patch.Button("CANCEL");
            var bubble             = new BubblePopup(showBubbleButton)
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new Forms9Patch.Label("BubblePopup")
                        {
                            FontAttributes = FontAttributes.Bold
                        },
                        cancelBubbleButton
                    }
                }
            };

            cancelBubbleButton.Clicked += (sender, e) => bubble.Cancel();
            showBubbleButton.Clicked   += (sender, e) => bubble.IsVisible = true;

            var showActivityButton = new Forms9Patch.Button("ActivityIndicatorPopup");

            showActivityButton.Clicked += (sender, e) =>
            {
                var activity = Forms9Patch.ActivityIndicatorPopup.Create();
                activity.CancelOnPageOverlayTouch = true;
            };

            var showPermissionButton = new Forms9Patch.Button("PermissionPopup");

            showPermissionButton.Clicked += (sender, e) =>
            {
                var permission = PermissionPopup.Create("PermissionPopup", "Do you agree?");
            };

            var showToastButton = new Forms9Patch.Button("Toast");

            showToastButton.Clicked += (sender, e) => Toast.Create("Toast", "... of the town!");

            var showTargetedToash = new Forms9Patch.Button("TargetedToast");

            showTargetedToash.Clicked += (sender, e) => TargetedToast.Create(showTargetedToash, "TargetedToast", "... has the far getted most!");

            Content = new Xamarin.Forms.StackLayout
            {
                Children = { showModalButton, showBubbleButton, showActivityButton, showPermissionButton, showToastButton, showTargetedToash }
            };
        }