Exemplo n.º 1
0
        private static List <StickerSpriteItem> CreateStickerSetSprites(TLStickerSetBase stickerSet)
        {
            if (stickerSet == null)
            {
                return(null);
            }

            const int stickersPerRow = 4;
            var       sprites        = new List <StickerSpriteItem>();
            var       stickers       = new List <TLStickerItem>();

            for (var i = 1; i <= stickerSet.Stickers.Count; i++)
            {
                stickers.Add((TLStickerItem)stickerSet.Stickers[i - 1]);

                if (i % stickersPerRow == 0 || i == stickerSet.Stickers.Count)
                {
                    var item = new StickerSpriteItem(stickersPerRow, stickers, 96.0, 438.0, true);
                    sprites.Add(item);
                    stickers.Clear();
                }
            }

            return(sprites);
        }
Exemplo n.º 2
0
        public StickerHeaderSpriteItem(TLStickerSetBase stickerSetBase, double panelWidth)
        {
            var label = new TextBlock {
                FontSize = 17.778, Margin = new Thickness(12.0, 6.0, 12.0, 6.0), Text = stickerSetBase.Title.ToString(), Style = (Style)Application.Current.Resources["PhoneTextSubtleStyle"]
            };

            Children.Add(label);

            View.Width            = panelWidth;
            View.IsHitTestVisible = false;
        }
Exemplo n.º 3
0
        private static void ShowMessagePrompt(bool isCancelVisible, TLStickerSetBase stickerSet, Action <PopUpResult> callback)
        {
            if (stickerSet == null)
            {
                return;
            }

            var scrollViewer = new ScrollViewer();

            scrollViewer.Height = 400.0;
            var panel = new MyVirtualizingPanel {
                VerticalAlignment = VerticalAlignment.Top
            };

            scrollViewer.Content = panel;
            panel.InitializeWithScrollViewer(scrollViewer);
            var       sprites          = CreateStickerSetSprites(stickerSet);
            const int firstSliceLength = 4;

            var messagePrompt = new MessagePrompt();

            messagePrompt.Title             = stickerSet.Title.ToString();
            messagePrompt.VerticalAlignment = VerticalAlignment.Center;
            messagePrompt.Message           = (string)new StickerSetToCountStringConverter().Convert(stickerSet, null, null, null);
            messagePrompt.Body = new TextBlock
            {
                Height = scrollViewer.Height,
                Text   = AppResources.Loading,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Style = (Style)Application.Current.Resources["PhoneTextGroupHeaderStyle"]
            };
            messagePrompt.IsCancelVisible = isCancelVisible;
            messagePrompt.IsAppBarVisible = true;
            if (!isCancelVisible)
            {
                messagePrompt.ActionPopUpButtons.Clear();
                var cancelButton = new RoundButton();
                cancelButton.Click += (sender, args) =>
                {
                    messagePrompt.OnCompleted(new PopUpEventArgs <string, PopUpResult> {
                        PopUpResult = PopUpResult.Cancelled
                    });
                };
                cancelButton.Content = CreateXamlCancel(cancelButton);
                messagePrompt.ActionPopUpButtons.Add(cancelButton);
            }
            messagePrompt.Opened += (o, args) =>
            {
                Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.1), () =>
                {
                    messagePrompt.Body = scrollViewer;
                    panel.AddItems(sprites.Take(firstSliceLength).Cast <VListItemBase>());
                    Execute.BeginOnUIThread(() =>
                    {
                        panel.AddItems(sprites.Skip(firstSliceLength).Cast <VListItemBase>());
                    });
                });
            };
            messagePrompt.Completed += (o, e) =>
            {
                callback.SafeInvoke(e.PopUpResult);
            };
            _lastMessagePrompt = messagePrompt;
            messagePrompt.Show();
        }
Exemplo n.º 4
0
        public FeaturedStickerSpriteItem(TLStickerSetBase stickerSetBase, int columns, IList <TLStickerItem> stickers, double stickerHeight, double panelWidth, MouseEventHandler onStickerMouseEnter, bool showEmoji = false)
        {
            _stickerSet = stickerSetBase;

            FeaturedStickerSetControl captionPanel = null;
            var stickerSet32 = stickerSetBase as TLStickerSet32;

            if (stickerSet32 != null)
            {
                captionPanel             = new FeaturedStickerSetControl();
                captionPanel.DataContext = stickerSetBase;
                captionPanel.Added      += (o, e) => RaiseStickerSetAdded();
                captionPanel.Opened     += (o, e) => RaiseStickerSetOpened();
            }

            Stickers = stickers;

            _stickerHeight = stickerHeight;

            var panelMargin      = new Thickness(4.0, 0.0, 4.0, 0.0);
            var panelActualWidth = panelWidth - panelMargin.Left - panelMargin.Right;
            //472, 438

            var stackPanel = new Grid {
                Width = panelActualWidth, Margin = panelMargin, Background = new SolidColorBrush(Colors.Transparent)
            };

            for (var i = 0; i < columns; i++)
            {
                stackPanel.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (var i = 0; i < stickers.Count; i++)
            {
                var binding = new Binding
                {
                    Mode               = BindingMode.OneWay,
                    Path               = new PropertyPath("Self"),
                    Converter          = new DefaultPhotoConverter(),
                    ConverterParameter = StickerHeight
                };

                var stickerImage = new Image
                {
                    Height            = StickerHeight,
                    Margin            = new Thickness(0, 12, 0, 12),
                    VerticalAlignment = VerticalAlignment.Top,
                    CacheMode         = new BitmapCache()
                };
                if (onStickerMouseEnter != null)
                {
                    stickerImage.MouseEnter += onStickerMouseEnter;
                }
                stickerImage.SetBinding(Image.SourceProperty, binding);
                StickerImage = stickerImage;

                var grid = new Grid();
                grid.Children.Add(stickerImage);

                if (showEmoji)
                {
                    var document22 = stickers[i].Document as TLDocument22;
                    if (document22 != null)
                    {
                        var bytes    = Encoding.BigEndianUnicode.GetBytes(document22.Emoticon);
                        var bytesStr = BrowserNavigationService.ConvertToHexString(bytes);

                        var emojiImage = new Image
                        {
                            Height = 32,
                            Width  = 32,
                            Margin = new Thickness(12, 12, 12, 12),
                            HorizontalAlignment = HorizontalAlignment.Right,
                            VerticalAlignment   = VerticalAlignment.Bottom,
                            Source = new BitmapImage(new Uri(string.Format("/Assets/Emoji/Separated/{0}.png", bytesStr), UriKind.RelativeOrAbsolute))
                        };
                        grid.Children.Add(emojiImage);
                    }
                }

                var listBoxItem = new ListBoxItem {
                    Content = grid, DataContext = stickers[i]
                };
                Microsoft.Phone.Controls.TiltEffect.SetIsTiltEnabled(listBoxItem, true);
                listBoxItem.Tap += FeaturedSticker_OnTap;
                //grid.DataContext = stickers[i];
                Grid.SetColumn(listBoxItem, i);
                stackPanel.Children.Add(listBoxItem);
            }

            if (captionPanel != null)
            {
                var panel = new StackPanel();
                panel.Children.Add(captionPanel);
                panel.Children.Add(stackPanel);

                Children.Add(panel);
            }
            else
            {
                Children.Add(stackPanel);
            }

            View.Width = panelWidth;
        }