コード例 #1
0
        public Task <bool> LoadImageAsync(ElmImage image, ImageSource imageSource, CancellationToken cancelationToken = default(CancellationToken))
        {
            ImageSource newSource = null;

            switch (imageSource)
            {
            case SKImageImageSource imageImageSource:
                newSource = ImageSource.FromStream(() => ToStream(imageImageSource.Image));
                break;

            case SKBitmapImageSource bitmapImageSource:
                newSource = ImageSource.FromStream(() => ToStream(SKImage.FromBitmap(bitmapImageSource.Bitmap)));
                break;

            case SKPixmapImageSource pixmapImageSource:
                newSource = ImageSource.FromStream(() => ToStream(SKImage.FromPixels(pixmapImageSource.Pixmap)));
                break;

            case SKPictureImageSource pictureImageSource:
                newSource = ImageSource.FromStream(() => ToStream(SKImage.FromPicture(pictureImageSource.Picture, pictureImageSource.Dimensions)));
                break;
            }

            return(handler.LoadImageAsync(image, newSource, cancelationToken));
        }
コード例 #2
0
        public static void ApplyAspect(this EImage image, Aspect aspect)
        {
            Aspect _aspect = aspect;

            switch (_aspect)
            {
            case Aspect.AspectFit:
                image.IsFixedAspect  = true;
                image.CanFillOutside = false;
                break;

            case Aspect.AspectFill:
                image.IsFixedAspect  = true;
                image.CanFillOutside = true;
                break;

            case Aspect.Fill:
                image.IsFixedAspect  = false;
                image.CanFillOutside = false;
                break;

            default:
                Log.Warn("Invalid Aspect value: {0}", _aspect);
                break;
            }
        }
コード例 #3
0
 public static bool LoadFromFile(this EImage image, string file)
 {
     if (!string.IsNullOrEmpty(file))
     {
         return(image.Load(ResourcePath.GetPath(file)));
     }
     return(false);
 }
コード例 #4
0
        void UpdateSecondButton()
        {
            _secondButton?.Hide();

            if (SecondButton != null)
            {
                _secondButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/right"
                };

                if (!string.IsNullOrEmpty(SecondButton.Text))
                {
                    _secondButton.Text = SecondButton.Text;
                }

                if (!SecondButton.IconImageSource.IsNullOrEmpty())
                {
                    var iconSource = SecondButton.IconImageSource as FileImageSource;
                    if (!iconSource.IsNullOrEmpty())
                    {
                        var buttonImage = new ElmSharp.Image(_secondButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconSource));
                        buttonImage.Show();
                        _secondButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _secondButton.Clicked += (s, e) =>
                {
                    ((IMenuItemController)SecondButton).Activate();
                };

                if (_secondButtonBgColor != Color.Default)
                {
                    Log.Debug(FormsCircularUI.Tag, $"TwoButtonPopup set second button background color:{_secondButtonBgColor.ToNative()}");
                    _secondButton.BackgroundColor = _secondButtonBgColor.ToNative();
                }

                _popUp.SetPartContent("button2", _secondButton);
            }
            else
            {
                /* This is workaround fix for Left button occupied whole window when right button is null*/
                _secondButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/right"
                };
                _popUp.SetPartContent("button2", _secondButton);
                _secondButton.Unrealize();
                _secondButton = null;
            }
        }
コード例 #5
0
        public Task <bool> LoadImageAsync(EImage image, ImageSource imageSource, CancellationToken cancelationToken = default(CancellationToken))
        {
            var urisource = imageSource as UriImageSource;

            if (urisource != null && urisource.Uri != null)
            {
                return(image.LoadAsync(urisource.Uri, cancelationToken));
            }

            return(Task.FromResult <bool>(false));
        }
コード例 #6
0
 void UpdateIcon()
 {
     if (Icon != null)
     {
         var path  = ResourcePath.GetPath(_icon);
         var image = new ElmSharp.Image(_control);
         image.LoadAsync(path);
         image.Show();
         _control.SetPartContent(IconPart, image);
     }
 }
コード例 #7
0
        void UpdateSecondButton()
        {
            _secondButton?.Hide();

            if (SecondButton != null)
            {
                _secondButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/right"
                };

                if (!string.IsNullOrEmpty(SecondButton.Text))
                {
                    _secondButton.Text = SecondButton.Text;
                }

                if (SecondButton.Icon != null)
                {
                    var iconPath = SecondButton.Icon.File;
                    if (!string.IsNullOrEmpty(iconPath))
                    {
                        var buttonImage = new ElmSharp.Image(_secondButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconPath));
                        buttonImage.Show();
                        _secondButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _secondButton.Clicked += (s, e) =>
                {
                    SecondButton.Activate();
                };

                _popUp.SetPartContent("button2", _secondButton);
            }
            else
            {
                /* This is workaround fix for Left button occupied whole window when right button is null*/
                _secondButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/right"
                };
                _popUp.SetPartContent("button2", _secondButton);
                _secondButton.Unrealize();
                _secondButton = null;
            }
        }
コード例 #8
0
        public Task <bool> LoadImageAsync(EImage image, ImageSource imageSource, CancellationToken cancelationToken = default(CancellationToken))
        {
            var filesource = imageSource as FileImageSource;

            if (filesource != null)
            {
                string file = filesource.File;
                if (!string.IsNullOrEmpty(file))
                {
                    return(image.LoadAsync(ResourcePath.GetPath(file), cancelationToken));
                }
            }
            return(Task.FromResult <bool>(false));
        }
コード例 #9
0
        void UpdateButton()
        {
            _bottomButton?.Hide();

            if (BottomButton != null)
            {
                _bottomButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "bottom"
                };

                if (!string.IsNullOrEmpty(BottomButton.Text))
                {
                    _bottomButton.Text = BottomButton.Text;
                }

                if (BottomButton.Icon != null)
                {
                    var iconPath = BottomButton.Icon.File;
                    if (!string.IsNullOrEmpty(iconPath))
                    {
                        var buttonImage = new ElmSharp.Image(_bottomButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconPath));
                        buttonImage.Show();
                        _bottomButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _bottomButton.Clicked += (s, e) =>
                {
                    ((IMenuItemController)BottomButton).Activate();
                };

                if (_buttonBgColor != Color.Default)
                {
                    Log.Debug(FormsCircularUI.Tag, $"InformationPopup set button background color:{_buttonBgColor.ToNative()}");
                    _bottomButton.BackgroundColor = _buttonBgColor.ToNative();
                }
            }
            else
            {
                _bottomButton.Unrealize();
                _bottomButton = null;
            }

            _popUp.SetPartContent("button1", _bottomButton);
        }
コード例 #10
0
        void UpdateFirstButton()
        {
            _firstButton?.Hide();

            if (FirstButton != null)
            {
                _firstButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/left"
                };

                if (!string.IsNullOrEmpty(FirstButton.Text))
                {
                    _firstButton.Text = FirstButton.Text;
                }

                if (FirstButton.Icon != null)
                {
                    var iconPath = FirstButton.Icon.File;
                    if (!string.IsNullOrEmpty(iconPath))
                    {
                        var buttonImage = new ElmSharp.Image(_firstButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconPath));
                        buttonImage.Show();
                        _firstButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _firstButton.Clicked += (s, e) =>
                {
                    FirstButton.Activate();
                };

                if (_firstButtonBgColor != Color.Default)
                {
                    Console.WriteLine($"TwoButtonPopup set first button background color:{_firstButtonBgColor.ToNative()}");
                    _firstButton.BackgroundColor = _firstButtonBgColor.ToNative();
                }
            }
            else
            {
                _firstButton = null;
            }

            _popUp.SetPartContent("button1", _firstButton);
        }
コード例 #11
0
        void UpdateFirstButton()
        {
            _firstButton?.Hide();

            if (FirstButton != null)
            {
                _firstButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/left"
                };

                if (!string.IsNullOrEmpty(FirstButton.Text))
                {
                    _firstButton.Text = FirstButton.Text;
                }

                if (!FirstButton.IconImageSource.IsNullOrEmpty())
                {
                    var iconSource = FirstButton.IconImageSource as FileImageSource;
                    if (!iconSource.IsNullOrEmpty())
                    {
                        var buttonImage = new ElmSharp.Image(_firstButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconSource));
                        buttonImage.Show();
                        _firstButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _firstButton.Clicked += (s, e) =>
                {
                    ((IMenuItemController)FirstButton).Activate();
                };

                if (_firstButtonBgColor != Color.Default)
                {
                    Log.Debug(FormsCircularUI.Tag, $"TwoButtonPopup set first button background color:{_firstButtonBgColor.ToNative()}");
                    _firstButton.BackgroundColor = _firstButtonBgColor.ToNative();
                }
            }
            else
            {
                _firstButton = null;
            }

            _popUp.SetPartContent("button1", _firstButton);
        }
コード例 #12
0
        public async Task <bool> LoadImageAsync(EImage image, ImageSource imageSource, CancellationToken cancelationToken = default(CancellationToken))
        {
            var streamsource = imageSource as StreamImageSource;

            if (streamsource != null && streamsource.Stream != null)
            {
                using (var streamImage = await((IStreamImageSource)streamsource).GetStreamAsync(cancelationToken))
                {
                    if (streamImage != null)
                    {
                        return(await image.LoadAsync(streamImage, cancelationToken));
                    }
                }
            }
            return(false);
        }
コード例 #13
0
 /// <summary>
 /// Gets the scaling mode for the image.
 /// </summary>
 /// <param name="view">Target view</param>
 /// <returns>A Aspect representing the scaling mode of the image.</returns>
 public static Aspect GetAspect(this EImage view)
 {
     if (view.IsFixedAspect && !view.CanFillOutside)
     {
         return(Aspect.AspectFit);
     }
     if (view.IsFixedAspect && view.CanFillOutside)
     {
         return(Aspect.AspectFill);
     }
     if (!view.IsFixedAspect)
     {
         return(Aspect.Fill);
     }
     return(Aspect.AspectFit);
 }
コード例 #14
0
        public static async Task <bool> LoadFromImageSourceAsync(this EImage image, ImageSource source)
        {
            IImageSourceHandler handler;
            bool isLoadComplate = false;

            if (source != null && (handler = Forms.GetHandlerForObject <IImageSourceHandler>(source)) != null)
            {
                isLoadComplate = await handler.LoadImageAsync(image, source);
            }
            if (!isLoadComplate)
            {
                //If it fails, call the Load function to remove the previous image.
                image.Load(string.Empty);
            }

            return(isLoadComplate);
        }
コード例 #15
0
ファイル: PageRenderer.cs プロジェクト: redjaguar/maui
        protected virtual FormsMoreOptionItem CreateMoreOptionItem(ToolbarItem item)
        {
            var moreOptionItem = new FormsMoreOptionItem
            {
                MainText    = item.Text,
                ToolbarItem = item
            };
            var icon = item.IconImageSource as FileImageSource;

            if (icon != null)
            {
                var img = new ElmSharp.Image(_moreOption.Value);
                img.Load(ResourcePath.GetPath(icon));
                moreOptionItem.Icon = img;
            }
            return(moreOptionItem);
        }
コード例 #16
0
        void UpdateFirstButton()
        {
            _firstButton?.Hide();

            if (FirstButton != null)
            {
                _firstButton = new ElmSharp.Button(_popUp)
                {
                    WeightX = 1.0,
                    WeightY = 1.0,
                    Style   = "popup/circle/left"
                };

                if (!string.IsNullOrEmpty(FirstButton.Text))
                {
                    _firstButton.Text = FirstButton.Text;
                }

                if (FirstButton.Icon != null)
                {
                    var iconPath = FirstButton.Icon.File;
                    if (!string.IsNullOrEmpty(iconPath))
                    {
                        var buttonImage = new ElmSharp.Image(_firstButton);
                        buttonImage.LoadAsync(ResourcePath.GetPath(iconPath));
                        buttonImage.Show();
                        _firstButton.SetPartContent("elm.swallow.content", buttonImage);
                    }
                }

                _firstButton.Clicked += (s, e) =>
                {
                    FirstButton.Activate();
                };
            }
            else
            {
                _firstButton = null;
            }

            _popUp.SetPartContent("button1", _firstButton);
        }
        public async Task <bool> LoadImageAsync(Image image, ImageSource imageSource, CancellationToken cancelationToken = default)
        {
            var fileInfo = await LoadInternal(imageSource, 1, Application.Current.DirectoryInfo.Cache);

            try
            {
                await semaphore.WaitAsync();

                if (fileInfo?.Exists ?? false)
                {
                    return(image.LoadFromFile(fileInfo.FullName));
                }
            }
            finally
            {
                semaphore.Release();
            }

            return(false);
        }
コード例 #18
0
        /// <summary>
        /// Sets the scaling mode for the image.
        /// </summary>
        /// <param name="view">Target view</param>
        /// <param name="aspect">A Aspect representing the scaling mode of the image.</param>
        public static void SetAspect(this EImage view, Aspect aspect)
        {
            switch (aspect)
            {
            case Aspect.AspectFit:
                view.IsFixedAspect  = true;
                view.CanFillOutside = false;
                break;

            case Aspect.AspectFill:
                view.IsFixedAspect  = true;
                view.CanFillOutside = true;
                break;

            case Aspect.Fill:
                view.IsFixedAspect  = false;
                view.CanFillOutside = false;
                break;

            default:
                break;
            }
        }
コード例 #19
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && viewReady && !isDrawn)
            {
                Control.RemoveAll();

                var scale        = ElmSharp.Elementary.GetScale();
                int windowWidth  = (int)Math.Round(OverlayWidth * scale);
                int windowHeight = (int)Math.Round(OverlayHeight * scale);

                foreach (var pin in customPins)
                {
                    var coordinates = new Geocoordinates(pin.Position.Latitude, pin.Position.Longitude);

                    Control.Add(new TPin(coordinates, PinPath));

                    int width  = windowWidth;
                    int height = windowHeight;

                    var window = new ElmSharp.Box(Control);
                    window.Show();

                    {
                        var overlay = new ElmSharp.Box(window)
                        {
                            BackgroundColor = XamarinLogoColor,
                        };
                        overlay.SetAlignment(-1.0, -1.0);                     // fill
                        overlay.SetWeight(1.0, 0.0);                          // expand on X axis
                        overlay.Show();
                        window.PackEnd(overlay);

                        if (pin.Id == XamarinId)
                        {
                            var xamarin = new ElmSharp.Image(overlay);
                            xamarin.Load(XamarinPath);
                            xamarin.SetAlignment(-1.0, -1.0);                              // fill
                            var size = xamarin.ObjectSize;
                            xamarin.MinimumWidth  = size.Width;
                            xamarin.MinimumHeight = size.Height;
                            xamarin.Show();
                            overlay.PackEnd(xamarin);

                            height += size.Height;
                        }

                        {
                            var infoBox = new ElmSharp.Box(overlay)
                            {
                                IsHorizontal = true,
                            };
                            infoBox.SetAlignment(-1.0, -1.0);                         // fill
                            infoBox.SetWeight(1.0, 0.0);                              // expand on X axis
                            infoBox.Show();
                            overlay.PackEnd(infoBox);

                            {
                                var monkey = new ElmSharp.Image(infoBox);
                                monkey.Load(MonkeyPath);
                                monkey.SetAlignment(-1.0, -1.0);                             // fill
                                monkey.SetWeight(1.0, 0.0);                                  // expand on X axis
                                monkey.Show();
                                infoBox.PackEnd(monkey);
                            }

                            {
                                var textBox = new ElmSharp.Box(infoBox);
                                textBox.SetAlignment(-1.0, -1.0);                             // fill
                                textBox.SetWeight(1.0, 0.0);                                  // expand on X axis
                                textBox.Show();
                                infoBox.PackEnd(textBox);

                                {
                                    var title = new NLabel(textBox)
                                    {
                                        Text           = pin.Label,
                                        FontAttributes = FontAttributes.Bold,
                                        TextColor      = ElmSharp.Color.White,
                                    };
                                    title.SetAlignment(-1.0, -1.0);                                 // fill
                                    title.SetWeight(1.0, 0.0);                                      // expand on X axis
                                    title.Show();
                                    textBox.PackEnd(title);
                                }

                                {
                                    var subtitle = new NLabel(textBox)
                                    {
                                        Text      = pin.Address,
                                        TextColor = ElmSharp.Color.White,
                                    };
                                    subtitle.SetAlignment(-1.0, -1.0);                                 // fill
                                    subtitle.SetWeight(1.0, 0.0);                                      // expand on X axis
                                    subtitle.Show();
                                    textBox.PackEnd(subtitle);
                                }
                            }

                            {
                                var info = new ElmSharp.Image(infoBox);
                                info.Load(InfoPath);
                                info.SetAlignment(-1.0, -1.0);                             // fill
                                info.SetWeight(1.0, 0.0);                                  // expand on X axis
                                info.Show();
                                infoBox.PackEnd(info);
                            }
                        }
                    }

                    {
                        var expander = new ElmSharp.Box(window);
                        expander.SetAlignment(-1.0, -1.0);                     // fill
                        expander.SetWeight(1.0, 1.0);                          // expand
                        expander.Show();
                        window.PackEnd(expander);
                    }

                    window.Resize(width, height);

                    Control.Add(new Overlay(coordinates, window));
                }

                isDrawn = true;
            }
        }
コード例 #20
0
 /// <summary>
 /// Set animation playing state
 /// </summary>
 /// <param name="view">Image view</param>
 /// <param name="value">playing state</param>
 /// <remarks>Should be called after image loading</remarks>
 public static void SetIsAnimationPlaying(this EImage view, bool value)
 {
     view.IsAnimated         = value;
     view.IsAnimationPlaying = value;
 }
コード例 #21
0
        protected override ElmSharp.EvasObject OnGetContent(Cell cell, string part)
        {
            if (part != MainContentPart)
            {
                return(null);
            }
            NativeCell viewCell      = (NativeCell)cell;
            var        minimumHeight = PageHeight > 800 ? 96 : 76;

            ElmSharp.Box mainBox = new ElmSharp.Box(Forms.NativeParent);
            mainBox.BackgroundColor = Color.LightYellow.ToNative();
            mainBox.MinimumHeight   = minimumHeight;
            mainBox.IsHorizontal    = false;
            mainBox.SetAlignment(-1, -1);
            mainBox.Show();

            ElmSharp.Box contentBox = new ElmSharp.Box(Forms.NativeParent);
            contentBox.MinimumHeight = minimumHeight;
            contentBox.IsHorizontal  = true;
            contentBox.SetAlignment(-1, -1);
            contentBox.Show();

            ElmSharp.Box left = new ElmSharp.Box(Forms.NativeParent);
            left.IsHorizontal = false;
            left.Show();
            left.SetWeight(4.0, 1);
            left.SetAlignment(-1, -1);
            contentBox.PackEnd(left);

            ElmSharp.Label titleName = new ElmSharp.Label(Forms.NativeParent);
            left.PackEnd(titleName);
            titleName.Show();
            titleName.Text         = $"<span font_size=34 font_style=italic color=#7F3300>   {viewCell.Name}</span>";
            titleName.MinimumWidth = 250;
            titleName.SetAlignment(-1, -1);

            ElmSharp.Label titleCategory = new ElmSharp.Label(Forms.NativeParent);
            left.PackEnd(titleCategory);
            titleCategory.Show();
            titleCategory.Text = $"<span align=center font_size=24 color=#008000>{viewCell.Category}</span>";
            titleCategory.SetAlignment(-1, -1);

            ElmSharp.Box right = new ElmSharp.Box(Forms.NativeParent);
            right.Show();
            right.MinimumWidth  = 96;
            right.MinimumHeight = minimumHeight;
            right.SetWeight(1, 1);
            right.SetAlignment(-1, 0);

            ElmSharp.Image image;

            if (viewCell.ImageFilename != "")
            {
                image = new ElmSharp.Image(right);
                image.Load(global::Tizen.Applications.Application.Current.DirectoryInfo.Resource + viewCell.ImageFilename + ".jpg");
                image.SetAlignment(0.5, 0.5);
                image.MinimumHeight = minimumHeight;
                image.MinimumWidth  = minimumHeight;
                image.Show();
                right.PackEnd(image);
            }

            ElmSharp.Rectangle rec = new ElmSharp.Rectangle(left);
            rec.MinimumHeight = 1;
            rec.MinimumWidth  = 400;
            rec.AlignmentX    = -1;
            rec.Color         = ElmSharp.Color.Gray;
            rec.Show();

            contentBox.PackEnd(right);

            mainBox.PackEnd(contentBox);
            mainBox.PackEnd(rec);

            return(mainBox);
        }