protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var bike = new FontImageSource
            {
                FontFamily = Fonts.SolidIcons,
                Glyph      = FontAwesomeIcons.Bicycle,
                Color      = Color.Black
            };

            var station = new FontImageSource
            {
                FontFamily = Fonts.SolidIcons,
                Glyph      = FontAwesomeIcons.Home,
            };

            var annotationView = base.GetViewForAnnotation(mapView, annotation);
            var pin            = GetPinForAnnotation(annotation);

            switch (pin?.BindingContext)
            {
            case Bike _:
                annotationView.Image = GetUIImageFromImageSource(bike);
                break;

            case Station _:
                annotationView.Image = GetUIImageFromImageSource(station);
                break;
            }

            return(annotationView);
        }
Пример #2
0
 private void OnSourceChanged(object oldValue, object newValue)
 {
     if (newValue is FontImageSource src)
     {
         Source = src;
     }
 }
Пример #3
0
 protected override void Init()
 {
     Title      = "Shell";
     FlyoutIcon = new FontImageSource
     {
         Glyph        = "\uf2fb",
         FontFamily   = DefaultFontFamily(),
         Size         = 20,
         AutomationId = _idIconElement
     };
     FlyoutIcon.SetValue(AutomationProperties.HelpTextProperty, "This as Shell FlyoutIcon");
     FlyoutIcon.SetValue(AutomationProperties.NameProperty, "Shell Icon");
     Items.Add(new FlyoutItem
     {
         Title = _titleElement,
         Items =
         {
             new Tab                 {
                 Title = "library",
                 Items =
                 {
                     new ContentPage {
                         Title = "Library", Content = new ScrollView{
                             Content = new Label{
                                 Text = "Turn accessibility on and make sure the help text is read on iOS, on Android it will read the AutomationID if specified and then the HelpText this allows UITest to work "
                             }
                         }
                     }
                 }
             }
         }
     });
 }
Пример #4
0
        protected override void Init()
        {
            var fontFamily = "";

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                fontFamily = "Ionicons";
                break;

            case Device.UWP:
                fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
                break;

            case Device.Android:
            default:
                fontFamily = "fonts/ionicons.ttf#";
                break;
            }
            FlyoutIcon = new FontImageSource
            {
                Glyph        = "\uf2fb",
                FontFamily   = fontFamily,
                Size         = 20,
                AutomationId = "shellIcon"
            };

            FlyoutIcon.SetAutomationPropertiesHelpText("This as Shell FlyoutIcon");
            FlyoutIcon.SetAutomationPropertiesName("SHELLMAINFLYOUTICON");
            Routing.RegisterRoute("demo", typeof(DemoShellPage));
            Routing.RegisterRoute("demo/demo", typeof(DemoShellPage));
        }
Пример #5
0
        public static Task <SKImage?> ToSKImageAsync(this ImageSource imageSource, CancellationToken cancellationToken = default)
        {
            if (imageSource == null)
            {
                throw new ArgumentNullException(nameof(imageSource));
            }

            return(imageSource switch
            {
                // 1. first try SkiaSharp sources
                SKImageImageSource iis => FromSkia(iis.Image),
                SKBitmapImageSource bis => FromSkia(SKImage.FromBitmap(bis.Bitmap)),
                SKPixmapImageSource xis => FromSkia(SKImage.FromPixels(xis.Pixmap)),
                SKPictureImageSource pis => FromSkia(SKImage.FromPicture(pis.Picture, pis.Dimensions)),

                // 2. then try Stream sources
                StreamImageSource stream => FromStream(stream.Stream.Invoke(cancellationToken)),
                UriImageSource uri => FromStream(uri.GetStreamAsync(cancellationToken)),

                // 3. finally, use the handlers
                FileImageSource file => FromHandler(PlatformToSKImageAsync(file, cancellationToken)),
                FontImageSource font => FromHandler(PlatformToSKImageAsync(font, cancellationToken)),

                // 4. all is lost
                _ => throw new ArgumentException("Unable to determine the type of image source.", nameof(imageSource))
            });
Пример #6
0
        string GetFontSource(FontImageSource fontImageSource)
        {
            if (fontImageSource == null)
            {
                return(string.Empty);
            }

            var fontFamily = fontImageSource.FontFamily.ToFontFamily();

            string fontSource = fontFamily.Source;

            var allFamilies = fontFamily.Source.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (allFamilies.Length > 1)
            {
                // There's really no perfect solution to handle font families with fallbacks (comma-separated)
                // So if the font family has fallbacks, only one is taken, because CanvasTextFormat
                // only supports one font family
                string source = fontImageSource.FontFamily;

                foreach (var family in allFamilies)
                {
                    if (family.Contains(source))
                    {
                        fontSource = family;
                        break;
                    }
                }
            }

            return(fontSource);
        }
Пример #7
0
        protected override void Init()
        {
            var fontFamily = "";

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                fontFamily = "Ionicons";
                break;

            case Device.UWP:
                fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
                break;

            case Device.Android:
            default:
                fontFamily = "fonts/ionicons.ttf#";
                break;
            }
            FlyoutIcon = new FontImageSource
            {
                Glyph      = "\uf2fb",
                FontFamily = fontFamily,
                Size       = 20
            };
            CurrentItem = _storeItem;
            Routing.RegisterRoute("demo", typeof(DemoShellPage));
            Routing.RegisterRoute("demo/demo", typeof(DemoShellPage));
        }
        private void ShowSymbol()
        {
            this.daSymbol.IsVisible = true;

            // Set symbol
            FontImageSource tt = this.daSymbol.Source as FontImageSource;

            tt.Glyph = ExistingHLinkMedia.HomeSymbol;
            tt.Color = ExistingHLinkMedia.HomeSymbolColour;

            if (tt.Glyph == null)
            {
                DataStore.CN.NotifyError("MediaImageSkia (" + ExistingHLinkMedia.HLinkKey + ") Null Glyph");
            }

            if (tt.Color == null)
            {
                DataStore.CN.NotifyError("MediaImageSkia (" + ExistingHLinkMedia.HLinkKey + ") Null Colour");
            }

            this.daSymbol.Source = tt;

            if (UConHideSymbol)
            {
                this.daSymbol.IsVisible = true;
            }
        }
        private static UIImage GetUIImageFromImageSource(FontImageSource source)
        {
            var handler = new FontImageSourceHandler();

            // LoadImageAsync is not async, it just returns Task.FromResult
            return(handler.LoadImageAsync(source).Result);
        }
Пример #10
0
        public mma_calc()
        {
            resultLabel     = MakeLabel("", 25);
            Title           = "MMA";
            IconImageSource = new FontImageSource {
                FontFamily = "fa.otf#fa", Glyph = FontAwesomeIcons.FontAwesomeIcons.Car
            };

            Grid thisGrid = new Grid {
                RowSpacing = 0
            };

            thisGrid.Children.Add(new StackLayout
            {
                Padding         = new Thickness(20, 20, 20, 20),
                BackgroundColor = App.colours[2],
                Spacing         = 20,
                Children        =
                {
                    MakeLabel("Use the tool below to calculate what the Motor Mileage Allowance (MMA)   is for a given journey.", 20),
                    MakeLabel("Enter mileage:",                                                                                   18),
                    mileageEntry(),
                    calcButton(),
                    resultLabel
                }
            }, 0, 1, 0, 9);
            thisGrid.Children.Add(App.FooterGrid(), 0, 1, 9, 10);

            Content = thisGrid;
        }
 public static FontImageSource Configure(this FontImageSource image, Color color, string fontFamily, string glyph, double size)
 {
     image.Color      = color;
     image.FontFamily = fontFamily;
     image.Glyph      = glyph;
     image.Size       = size;
     return(image);
 }
Пример #12
0
        internal static ImageSource GetImageSourceFromFont(String id)
        {
            String name;
            Color  color    = Color.White;
            String colorStr = "#FFFFFF";

            if (id.StartsWith("font_", StringComparison.InvariantCultureIgnoreCase))
            {
                name = id.Substring(5);
            }
            else
            {
                name = id;
            }

            // Do we have a color specified ?
            int index = name.IndexOf("|");

            if (index > 0)
            {
                colorStr = name.Substring(index + 1);
                name     = name.Substring(0, index);
            }

            // Is-it a color define in hexa ?
            if (colorStr.StartsWith("#"))
            {
                color = Color.FromHex(colorStr);
            }
            else
            {
                color = GetResourceDictionaryById <Color>(colorStr);
            }

            FontImageSource result = new FontImageSource();

            result.FontFamily = "FontAwesomeSolid5";
            result.Color      = color;

            if (iconsFont.ContainsKey(name))
            {
                result.Glyph = iconsFont[name];
            }
            else
            {
                try
                {
                    //Need to transform "f060" to "\uf060" ...
                    result.Glyph = System.Text.RegularExpressions.Regex.Unescape("\\u" + name);
                }
                catch
                {
                    result.Glyph = "\uf128"; // => Question glyph
                }
            }
            return(result);
        }
 public static IImageSourceHandler GetImageSourceHandler(this ImageSource source)
 {
     return(source switch
     {
         FileImageSource _ => new FileImageSourceHandler(),
         StreamImageSource _ => new StreamImagesourceHandler(),
         FontImageSource _ => new FontImageSourceHandler(),
         _ => new ImageLoaderSourceHandler(),
     });
Пример #14
0
 static ImageColorToggleButton CreateButton(FontImageSource source, Action <ToggleButton> action, bool state = false)
 {
     return(new ImageColorToggleButton {
         Source = source,
         HorizontalOptions = LayoutOptions.FillAndExpand,
         VerticalOptions = LayoutOptions.Center,
         Toggled = state,
         Tapped = action,
     });
 }
Пример #15
0
 static ImageToggleButton CreateButton(FontImageSource onImage, FontImageSource offImage, Action <ToggleButton> action)
 {
     return(new ImageToggleButton {
         OnImageSource = onImage,
         OffImageSource = offImage,
         HorizontalOptions = LayoutOptions.Center,
         VerticalOptions = LayoutOptions.Center,
         Tapped = action,
     });
 }
        /// <summary>
        /// Generate Font Image Source.
        /// </summary>
        /// <param name="fontFamily">Font Family.</param>
        /// <param name="glyph">Glyph.</param>
        /// <param name="size">Size.</param>
        /// <returns>FontImageSource.</returns>
        public static FontImageSource GenerateFontImageSource(string fontFamily, string glyph, int size = 24)
        {
            var fontImageSource = new FontImageSource()
            {
                FontFamily = fontFamily, Size = size, Glyph = glyph
            };

            fontImageSource.SetDynamicResource(FontImageSource.ColorProperty, ResourceHelper.DynamicTextColor);
            return(fontImageSource);
        }
        public static FontImageSource SetIcon(this FontImageSource imageSource, string icon, Color?color = null)
        {
            if (FontRegistry.HasFont(icon, out var font))
            {
                imageSource.Glyph      = font.GetGlyph(icon);
                imageSource.FontFamily = font.FontFileName;
                imageSource.Color      = color ?? Color.Default;
            }

            return(imageSource);
        }
        void FixIssue6996()
        {
            var oldSource = EnabledDarkThemeSwitchCell.IconSource as FontImageSource;
            var newSource = new FontImageSource()
            {
                Glyph = oldSource.Glyph,
            };

            newSource.SetDynamicResource(FontImageSource.FontFamilyProperty, "MaterialFont");
            newSource.SetDynamicResource(FontImageSource.ColorProperty, "TextColor");
            EnabledDarkThemeSwitchCell.IconSource = newSource;
        }
Пример #19
0
        /// <summary>
        /// Helper method to serialize <see cref="ImageSource" /> objects.
        /// </summary>
        public static string ImageSourceToString(ImageSource imageSource)
        {
            if (imageSource is null)
            {
                throw new ArgumentNullException(nameof(imageSource));
            }

            return(imageSource switch
            {
                FileImageSource fileImageSource => string.Format(CultureInfo.InvariantCulture, "{0}:{1}", FileImageSourcePrefix, fileImageSource.File),
                FontImageSource fontImageSource => SerializeFontImageSource(fontImageSource),
                UriImageSource uriImageSource => string.Format(CultureInfo.InvariantCulture, "{0}:{1}", UriImageSourcePrefix, uriImageSource.Uri.ToString()),
                _ => throw new NotSupportedException($"Unsupported ImageSource type: {imageSource.GetType().FullName}."),
            });
Пример #20
0
        static FontFamily GetFontFamily(FontImageSource fontImageSource)
        {
            var        privateFontCollection = new PrivateFontCollection();
            FontFamily fontFamily;

            if (fontImageSource.FontFamily.Contains("#"))
            {
                var fontPathAndFamily = fontImageSource.FontFamily.Split('#');
                privateFontCollection.AddFontFile(fontPathAndFamily[0]);
                fontFamily = fontPathAndFamily.Length > 1 ?
                             privateFontCollection.Families.FirstOrDefault(f => f.Name.Equals(fontPathAndFamily[1], StringComparison.InvariantCultureIgnoreCase)) ?? privateFontCollection.Families[0] :
                             privateFontCollection.Families[0];
            }
            else
            {
                privateFontCollection.AddFontFile(fontImageSource.FontFamily);
                fontFamily = privateFontCollection.Families[0];
            }

            return(fontFamily);
        }
        public OverviewMapRenderer(Context context) : base(context)
        {
            Task.Run(async() =>
            {
                var bikeSource = new FontImageSource
                {
                    FontFamily = Fonts.SolidIcons,
                    Glyph      = FontAwesomeIcons.Bicycle,
                    Color      = Color.Black
                };

                var stationSource = new FontImageSource
                {
                    FontFamily = Fonts.SolidIcons,
                    Glyph      = FontAwesomeIcons.Home,
                    Color      = Color.Black
                };

                var loader               = new FontImageSourceHandler();
                _bikeBitmapDescriptor    = BitmapDescriptorFactory.FromBitmap(await loader.LoadImageAsync(bikeSource, context));
                _stationBitmapDescriptor = BitmapDescriptorFactory.FromBitmap(await loader.LoadImageAsync(stationSource, context));
            });
        }
        private static View CreateActivityIndicatorContent(double indicatorSize, Color indicatorColor, Boolean useDeviceActivityIndicator)
        {
            // Create activity indicator
            View activityIndicator;

            if (useDeviceActivityIndicator)
            {
                activityIndicator = new ActivityIndicator {
                    Color = indicatorColor
                };
            }
            else
            {
                FontImageSource fontImageSource = new FontImageSource
                {
                    FontFamily = "FontAwesomeSolid5",
                    Color      = indicatorColor,
                    Glyph      = Helper.GetGlyph("Spinner"),
                    Size       = (double)indicatorSize
                };

                activityIndicator = new Image {
                    Source = fontImageSource
                };
            }

            // Set common properties
            activityIndicator.Margin            = 0;
            activityIndicator.BackgroundColor   = Color.Transparent;
            activityIndicator.WidthRequest      = indicatorSize;
            activityIndicator.HeightRequest     = indicatorSize;
            activityIndicator.HorizontalOptions = LayoutOptions.Center;
            activityIndicator.VerticalOptions   = LayoutOptions.Center;

            return(activityIndicator);
        }
        public mylsa_calc()
        {
            resultLabel     = MakeLabel("", 25);
            Title           = "LSA";
            IconImageSource = new FontImageSource {
                FontFamily = "fa.otf#fa", Glyph = FontAwesomeIcons.FontAwesomeIcons.Plane
            };

            Grid thisGrid = new Grid {
                RowSpacing = 0
            };

            thisGrid.Children.Add(new ScrollView
            {
                Content = new StackLayout
                {
                    Padding         = new Thickness(20, 20, 20, 20),
                    BackgroundColor = App.colours[2],
                    Spacing         = 20,
                    Children        =
                    {
                        MakeLabel("Use the tool below to calculate how much Longer Separation Allowance (LSA) you'll earn on a deployment.", 20),
                        MakeLabel("Select LSA level:",                                                                                       18),
                        LSAPicker(),
                        MakeLabel("Deployment length (days):",                                                                               18),
                        dayEntry(),
                        calcButton(),
                        resultLabel,
                        new BoxView()
                    }
                }
            }, 0, 1, 0, 9);
            thisGrid.Children.Add(App.FooterGrid(), 0, 1, 9, 10);

            Content = thisGrid;
        }
Пример #24
0
        private void ShowSymbol(HLinkHomeImageModel argHLMediaModel)
        {
            // Input valid so start work
            daSymbol.IsVisible = true;
            daImage.IsVisible  = false;

            // Set symbol
            FontImageSource tt = this.daSymbol.Source as FontImageSource;

            tt.Glyph = argHLMediaModel.HomeSymbol;
            tt.Color = argHLMediaModel.HomeSymbolColour;

            if (tt.Glyph == null)
            {
                DataStore.CN.NotifyError("MediaImageSkia (" + argHLMediaModel.HLinkKey + ") Null Glyph");
            }

            if (tt.Color == null)
            {
                DataStore.CN.NotifyError("MediaImageSkia (" + argHLMediaModel.HLinkKey + ") Null Colour");
            }

            this.daSymbol.Source = tt;
        }
Пример #25
0
 public static void PlaceholderFromFontImageSource(FontImageSource fontImageSource) =>
 PlaceholderImageSource = fontImageSource;
 public static FontImageSource Color(this FontImageSource image, Color color)
 {
     image.Color = color;
     return(image);
 }
 public static FontImageSource Glyph(this FontImageSource image, string glyph)
 {
     image.Glyph = glyph;
     return(image);
 }
 public static FontImageSource Size(this FontImageSource image, double size)
 {
     image.Size = size;
     return(image);
 }
Пример #29
0
        public ToolbarItems()
        {
            var label = new Label {
                Text = "Hello ContentPage", AutomationId = "label_id"
            };

            var command = new Command((obj) =>
            {
                label.Text = "button 4 new text";
            }, (obj) => _isEnable);
            var tb1 = new ToolbarItem("tb1", "menuIcon.png", () =>
            {
                label.Text = "tb1";
            }, ToolbarItemOrder.Primary);

            tb1.IsEnabled    = _isEnable;
            tb1.AutomationId = "toolbaritem_primary";

            var fis = new FontImageSource()
            {
                FontFamily = GetFontFamily(),
                Glyph      = '\uf101'.ToString(),
                Color      = Color.Red
            };

            var tb2 = new ToolbarItem("tb2 font", null, () =>
            {
                label.Text = "tb2";
            }, ToolbarItemOrder.Primary);

            tb2.IconImageSource = fis;
            tb2.AutomationId    = "toolbaritem_primary2";
            var tb6 = new ToolbarItem("tb6 long long text", null, () =>
            {
                label.Text = "tb6";
            }, ToolbarItemOrder.Primary);

            tb6.AutomationId = "toolbaritem_primary6";

            var tb3 = new ToolbarItem("tb3", "bank.png", () =>
            {
                label.Text = "tb3";
                _isEnable  = !_isEnable;
                command.ChangeCanExecute();
            }, ToolbarItemOrder.Secondary);

            tb3.AutomationId = "toolbaritem_secondary";

            var tb4 = new ToolbarItem();

            tb4.Text            = "tb4";
            tb4.Order           = ToolbarItemOrder.Secondary;
            tb4.Command         = command;
            tb4.IconImageSource = "coffee";
            tb4.AutomationId    = "toolbaritem_secondary2";

            var tb5 = new ToolbarItem();

            tb5.Text            = "tb5";
            tb5.IconImageSource = "bank.png";
            tb5.Order           = ToolbarItemOrder.Secondary;
            tb5.Command         = new Command(async() => {
                await Navigation.PushAsync(new ToolbarItems());
            });
            tb5.AutomationId = "toolbaritem_secondary5";

            ToolbarItems.Add(tb1);
            ToolbarItems.Add(tb2);
            ToolbarItems.Add(tb3);
            ToolbarItems.Add(tb4);
            ToolbarItems.Add(tb5);
            ToolbarItems.Add(tb6);

            Content = new StackLayout
            {
                Children =
                {
                    label
                }
            };
        }
 public static FontImageSource FontFamily(this FontImageSource image, string fontFamily)
 {
     image.FontFamily = fontFamily;
     return(image);
 }