Пример #1
0
        public static void AddToRecents(EmojiDataItem emojiDataItem)
        {
            if (Recents == null)
            {
                LoadRecents();
                if (Recents == null)
                {
                    Recents = new List <EmojiDataItem>();
                }
            }

            var prevItem = Recents.FirstOrDefault(x => x.Code == emojiDataItem.Code);

            if (prevItem != null)
            {
                Recents.Remove(prevItem);
                Recents.Insert(0, prevItem);
            }
            else
            {
                Recents.Insert(0, emojiDataItem);
                Recents = Recents.Take(42).ToList();
            }

            SaveRecents();
        }
Пример #2
0
        public static void LoadRecents()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.FileExists("EmojiRecents"))
                {
                    return;
                }
                using (var stream = new IsolatedStorageFileStream("EmojiRecents", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite, store))
                {
                    if (stream.Length <= 0)
                    {
                        return;
                    }

                    using (var br = new BinaryReader(stream))
                    {
                        var count = br.ReadInt32();

                        Recents = new List <EmojiDataItem>();

                        for (var i = 0; i < count; i++)
                        {
                            var emoji = new EmojiDataItem(br.ReadString(), br.ReadUInt64());
                            emoji.Uri = EmojiDataItem.BuildUri(emoji.String);
                            Recents.Add(emoji);
                        }
                    }
                }
            }
        }
Пример #3
0
        public static EmojiDataItem GetByIndex(int categoryIndex, int spriteIndex, int itemIndex)
        {
            var category   = EmojiData.CodesByCategory[categoryIndex];
            var emojiIndex = spriteIndex * EmojiData.ItemsInSprite + itemIndex;

            if (category.Length <= emojiIndex)
            {
                return(null);                               // out of bounds
            }
            ulong code = category[emojiIndex];

            var result = new EmojiDataItem
            {
                Code   = code,
                String = BuildString(code)
            };

            result.Uri = BuildUri(result.String);

            return(result);
        }
Пример #4
0
        private void ViewOnTap(object sender, GestureEventArgs args)
        {
            var point  = args.GetPosition(View);
            var column = (int)Math.Ceiling(point.X / 79);
            var row    = (int)Math.Ceiling(point.Y / 70);

            if (column <= 0 || row <= 0)
            {
                return;
            }

            //Debug.WriteLine("{0}-{1}", column, row);

            var itemIndex = (row - 1) * EmojiData.ItemsInRow + (column - 1);

            var emoji = EmojiDataItem.GetByIndex(CategoryIndex, SpriteOffset, itemIndex);

            if (emoji != null)
            {
                EmojiSelected(this, new EmojiSelectedEventArgs {
                    DataItem = emoji
                });
            }
        }