예제 #1
0
        public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
        {
            if (_drawableClass == null)
            {
                throw new Exception(
                          $"{nameof(CustomIconProvider)}.{nameof(Init)} must be called before this method can be used.");
            }


            var iconName = shortcutIcon.IconName;

            if (File.Exists(iconName))
            {
                var bitmap = BitmapFactory.DecodeFile(iconName);

                if (bitmap != null)
                {
                    return(null);
                }

                return(Icon.CreateWithBitmap(bitmap));
            }
            else
            {
                var resourceId = IdFromTitle(iconName);
                var ic         = Icon.CreateWithResource(Application.Context, resourceId);
                return(ic);
            }
        }
예제 #2
0
 public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
 {
     return(await Task.Run(() =>
     {
         var uri = $"ms-appx:///{shortcutIcon.IconName}";
         return new Uri(uri);
     }));
 }
        public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
        {
            var iconFileName = string.Format(DarkIconUriFormat, shortcutIcon.IconName.ToLower());

            var uri = await _embeddedImageHelper.CopyEmbeddedImageToAppData(iconFileName);

            return(uri);
        }
        private async Task <Uri> GetIconUri(IShortcutIcon shortcutIcon)
        {
            if (shortcutIcon is CustomIcon)
            {
                return(await _customIconProvider.CreatePlatformIcon(shortcutIcon) as Uri);
            }

            return(await _embeddedIconProvider.CreatePlatformIcon(shortcutIcon) as Uri);
        }
        public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
        {
            var iconTypeString = shortcutIcon.IconName.ToLower();
            var iconName       = $"ic_plugin_sc_{iconTypeString}";
            var resourceId     = (int)(typeof(Plugin.AppShortcuts.Resource.Drawable).GetField(iconName)?.GetValue(null) ?? 0);
            var icon           = Icon.CreateWithResource(Application.Context, resourceId);

            return(icon);
        }
예제 #6
0
 private async Task AddShortcut(IShortcutIcon icon)
 {
     var sc = new Shortcut
     {
         Icon        = icon,
         Label       = $"{icon.IconName}_L",
         Description = $"{icon.IconName}_D",
         Uri         = $"stc://AppShortcutTests/Tests/{icon.IconName}"
     };
     await CrossAppShortcuts.Current.AddShortcut(sc);
 }
        private async Task <Icon> CreateIcon(IShortcutIcon icon)
        {
            try
            {
                if (icon is CustomIcon)
                {
                    return(await _customIconProvider.CreatePlatformIcon(icon) as Icon);
                }

                return(await _embeddedIconProvider.CreatePlatformIcon(icon) as Icon);
            }
            catch (Exception ex)
            {
                Log.Error(nameof(AppShortcutsImplementation), ex.Message, ex);
                return(null);
            }
        }
예제 #8
0
        public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
        {
            if (string.IsNullOrWhiteSpace(shortcutIcon.IconName))
            {
                return(null);
            }

            UIApplicationShortcutIcon icon = null;

            new NSObject().BeginInvokeOnMainThread(() =>
            {
                icon = UIApplicationShortcutIcon.FromTemplateImageName(shortcutIcon.IconName);
            });

            await Task.Delay(200);

            return(icon);
        }
예제 #9
0
        public async Task <object> CreatePlatformIcon(IShortcutIcon shortcutIcon)
        {
            var isParseSuccessful = Enum.TryParse(shortcutIcon.IconName, out UIApplicationShortcutIconType type);

            if (!isParseSuccessful)
            {
                type = UIApplicationShortcutIconType.Favorite;
            }

            UIApplicationShortcutIcon icon = null;

            new NSObject().BeginInvokeOnMainThread(() =>
            {
                icon = UIApplicationShortcutIcon.FromType(type);
            });

            await Task.Delay(200);

            return(icon);
        }