Beispiel #1
0
        // A function that reads a mobile style file and builds a list for each of three symbol categories.
        private async Task ReadMobileStyle()
        {
            // Open a mobile style file.
            _emojiStyle = await SymbolStyle.OpenAsync(_mobileStyleFilePath);

            // Get the default style search parameters.
            SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

            // Search the style with the default parameters to return all symbol results.
            IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

            // Loop through the results and put symbols into the appropriate list according to category.
            foreach (SymbolStyleSearchResult result in styleResults)
            {
                // Get the symbol from the result.
                MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                // Create an image from the symbol swatch.
                RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                UIImage symbolImage = await swatch.ToImageSourceAsync();

                // Create an instance of the custom SymbolLayerInfo class to store info about this symbol: name, swatch image, unique ID (key).
                SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                // Check the category for this result and place it into the correct list.
                switch (result.Category)
                {
                case "Eyes":
                {
                    //
                    _eyeSymbolInfos.Add(symbolInfo);
                    break;
                }

                case "Mouth":
                {
                    _mouthSymbolInfos.Add(symbolInfo);
                    break;
                }

                case "Hat":
                {
                    _hatSymbolInfos.Add(symbolInfo);
                    break;
                }
                }
            }
        }
Beispiel #2
0
        // A function to update the current multilayer symbol based on selections in the dialog.
        private async Task UpdateSymbol()
        {
            // Call a function to read the current settings and create the appropriate symbol.
            // Assign the symbol to the public SelectedSymbol property.
            SelectedSymbol = await GetCurrentSymbol();

            if (SelectedSymbol != null)
            {
                // Create an image of the symbol swatch to display as a preview.
                RuntimeImage swatch = await SelectedSymbol.CreateSwatchAsync(80, 80, 96, System.Drawing.Color.White);

                UIImage symbolImage = await swatch.ToImageSourceAsync();

                _symbolPreviewImageView.Image = symbolImage;
            }
        }
        // Get the current symbol and update the preview image.
        private async Task UpdateSymbol()
        {
            // Call a function to get the currrent multilayer point symbol from the selected layers.
            MultilayerPointSymbol emojiSymbol = await GetCurrentSymbol();

            try
            {
                // Use a swatch from the symbol to create an image.
                RuntimeImage swatch = await emojiSymbol.CreateSwatchAsync(100, 100, 96, System.Drawing.Color.White);

                Bitmap symbolImage = await swatch.ToImageSourceAsync();

                // Display the preview image.
                _symbolPreviewImage.SetImageBitmap(symbolImage);
            }
            catch (Exception ex)
            {
                // Show the exception message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(Activity);
                alertBuilder.SetTitle("Error creating preview");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
Beispiel #4
0
        private async Task ReadMobileStyle(string stylePath)
        {
            try
            {
                // Open the mobile style file at the provided path.
                _emojiStyle = await SymbolStyle.OpenAsync(stylePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return all symbol results.
                IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Create an empty placeholder image to represent "no symbol" for each category.
                ImageSource emptyImage = null;

                // Create lists to contain the available symbol layers for each category of symbol and add an empty entry as default.
                List <SymbolLayerInfo> eyeSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", emptyImage, "")
                };
                List <SymbolLayerInfo> mouthSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", emptyImage, "")
                };
                List <SymbolLayerInfo> hatSymbolInfos = new List <SymbolLayerInfo>()
                {
                    new SymbolLayerInfo("", emptyImage, "")
                };

                // Loop through the results and put symbols into the appropriate list according to category.
                foreach (SymbolStyleSearchResult result in styleResults)
                {
                    // Get the symbol for this result.
                    MultilayerPointSymbol multiLayerSym = await result.GetSymbolAsync() as MultilayerPointSymbol;

                    // Create a swatch image from the symbol.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                    ImageSource symbolImage = await swatch.ToImageSourceAsync();

                    // Create a symbol layer info object to represent the symbol in the list.
                    // The symbol key will be used to retrieve the symbol from the style.
                    SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                    // Add the symbol layer info to the correct list for its category.
                    switch (result.Category)
                    {
                    case "Eyes":
                    {
                        eyeSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Mouth":
                    {
                        mouthSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Hat":
                    {
                        hatSymbolInfos.Add(symbolInfo);
                        break;
                    }
                    }
                }

                // Show the symbols in the category list boxes.
                EyeSymbolList.ItemsSource   = eyeSymbolInfos;
                MouthSymbolList.ItemsSource = mouthSymbolInfos;
                HatSymbolList.ItemsSource   = hatSymbolInfos;

                // Call a function to construct the current symbol (default yellow circle).
                Symbol faceSymbol = await GetCurrentSymbol();

                // Call a function to show a preview image of the symbol.
                await UpdateSymbolPreview(faceSymbol);
            }
            catch (Exception ex)
            {
                // Report the exception.
                MessageDialog dialog = new MessageDialog("Error reading symbols from style: " + ex.Message);
                await dialog.ShowAsync();
            }
        }
        private async void ReadMobileStyle(string mobileStyleFilePath)
        {
            try
            {
                // Make sure the file exists.
                if (!System.IO.File.Exists(mobileStyleFilePath))
                {
                    throw new System.IO.FileNotFoundException("Mobile style file not found at " + mobileStyleFilePath);
                }

                // Open the mobile style file at the path provided.
                _emojiStyle = await SymbolStyle.OpenAsync(mobileStyleFilePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return a list of all symbol results.
                IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Loop through the results and put symbols into the appropriate list according to category (eyes, mouth, hat).
                foreach (SymbolStyleSearchResult result in styleResults)
                {
                    // Get the result symbol as a multilayer point symbol.
                    MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                    // Create a swatch for the symbol and use it to create a bitmap image.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                    Bitmap symbolImage = await swatch.ToImageSourceAsync();

                    // Check the symbol category.
                    switch (result.Category)
                    {
                    // Add a new SymbolLayerInfo to represent the symbol and add it to its category list.
                    // SymbolLayerInfo is a custom class with properties for the symbol name, swatch image, and unique key.
                    case "Eyes":
                    {
                        _eyeSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Mouth":
                    {
                        _mouthSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Hat":
                    {
                        _hatSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Face":
                    {
                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                // Show the exception message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(Activity);
                alertBuilder.SetTitle("Error reading style");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
        private async Task ReadMobileStyle(string stylePath)
        {
            try
            {
                // Open the mobile style file at the provided path.
                _emojiStyle = await SymbolStyle.OpenAsync(stylePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return all symbol results.
                IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Create lists to contain the available symbol layers for each category of symbol and add an empty entry as default.
                List <SymbolLayerInfo> eyeSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", null, "")
                };
                List <SymbolLayerInfo> mouthSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", null, "")
                };
                List <SymbolLayerInfo> hatSymbolInfos = new List <SymbolLayerInfo>()
                {
                    new SymbolLayerInfo("", null, "")
                };

                // Loop through the results and put symbols into the appropriate list according to category.
                foreach (SymbolStyleSearchResult result in styleResults)
                {
                    // Get the symbol for this result.
                    MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                    // Create a swatch image from the symbol.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync(30, 30, 96, Color.White);

                    // Create an image source from the swatch.
                    Stream imageBuffer = await swatch.GetEncodedBufferAsync();

                    byte[] imageData = new byte[imageBuffer.Length];
                    imageBuffer.Read(imageData, 0, imageData.Length);
                    ImageSource symbolImage = ImageSource.FromStream(() => new MemoryStream(imageData));

                    // Create a symbol layer info object to represent the symbol in the list.
                    // The symbol key will be used to retrieve the symbol from the style.
                    SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                    // Add the symbol layer info to the correct list for its category.
                    switch (result.Category)
                    {
                    case "Eyes":
                    {
                        eyeSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Mouth":
                    {
                        mouthSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Hat":
                    {
                        hatSymbolInfos.Add(symbolInfo);
                        break;
                    }
                    }
                }

                // Show the symbols in the category list boxes.
                EyesListView.ItemsSource  = eyeSymbolInfos;
                MouthListView.ItemsSource = mouthSymbolInfos;
                HatListView.ItemsSource   = hatSymbolInfos;

                // Call a function to construct the current symbol (default yellow circle).
                Symbol faceSymbol = await GetCurrentSymbol();

                // Call a function to show a preview image of the symbol.
                await UpdateSymbolPreview(faceSymbol);
            }
            catch (Exception ex)
            {
                // Report the exception.
                await DisplayAlert("Error reading style", ex.Message, "OK");
            }
        }