Ejemplo n.º 1
0
        internal static ShortcutInfo ToShortcutInfo(this AppAction action)
        {
            var context = Application.Context;

            var shortcut = new ShortcutInfo.Builder(context, action.Id)
                           .SetShortLabel(action.Title);

            if (!string.IsNullOrWhiteSpace(action.Subtitle))
            {
                shortcut.SetLongLabel(action.Subtitle);
            }

            if (!string.IsNullOrWhiteSpace(action.Icon))
            {
                var iconResId = context.Resources.GetIdentifier(action.Icon, "drawable", context.PackageName);

                shortcut.SetIcon(Icon.CreateWithResource(context, iconResId));
            }

            var intent = new Intent(AppActionsImplementation.IntentAction);

            intent.SetPackage(context.PackageName);
            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            intent.PutExtra(extraAppActionId, action.Id);
            intent.PutExtra(extraAppActionTitle, action.Title);
            intent.PutExtra(extraAppActionSubtitle, action.Subtitle);
            intent.PutExtra(extraAppActionIcon, action.Icon);

            shortcut.SetIntent(intent);

            return(shortcut.Build());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a dynamic shortcut that will open the app and display the relevant info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="flightNumber"></param>
        public void CreateFlightShortcut(object sender, string flightNumber)
        {
            // Create a shortcut builder
            var shortcutBuilder = new ShortcutInfo.Builder(this, flightNumber);

            // Set the shortcut info
            shortcutBuilder.SetIcon(Android.Graphics.Drawables.Icon.CreateWithResource(this, Resource.Drawable.flight));
            shortcutBuilder.SetShortLabel($"Flight {flightNumber}");
            shortcutBuilder.SetLongLabel($"Flight {flightNumber}");
            Intent openFlightInfoIntent = new Intent(
                Intent.ActionView,                                                      // Action
                Android.Net.Uri.Parse($"content:////actions//flight-{flightNumber}"),   // Intent data
                this,                                                                   // Context
                typeof(MainActivity));                                                  // Activity class

            shortcutBuilder.SetIntent(openFlightInfoIntent);

            // Build the shortcut
            ShortcutInfo myFlightShortcut = shortcutBuilder.Build();

            // Get the shortcut manager
            ShortcutManager shortcutManager = (ShortcutManager)this.GetSystemService(Java.Lang.Class.FromType(typeof(ShortcutManager)));

            // Set the list of shortcuts as the App's shortcut
            shortcutManager.SetDynamicShortcuts(new System.Collections.Generic.List <ShortcutInfo>()
            {
                myFlightShortcut
            });
        }
        ShortcutInfo.Builder SetSiteInformation(ShortcutInfo.Builder b, Uri uri)
        {
            // TODO Get the actual site <title> and use it.
            // TODO Set the current locale to accept-language to get localized title.
            b.SetShortLabel(uri.Host);
            b.SetLongLabel(uri.ToString());

            var bmp = FetchFavicon(uri);

            b.SetIcon(bmp != null ? Icon.CreateWithBitmap(bmp) : Icon.CreateWithResource(mContext, Resource.Drawable.link));

            return(b);
        }
        public async Task AddShortcut(Shortcut shortcut)
        {
            if (!_isShortcutsSupported)
            {
                throw new NotSupportedOnDeviceException(NOT_SUPPORTED_ERROR_MESSAGE);
            }


            var context = Application.Context;
            var builder = new ShortcutInfo.Builder(context, shortcut.ShortcutId);

            var uri = AUri.Parse(shortcut.Uri);

            builder.SetIntent(new Intent(Intent.ActionView, uri));
            builder.SetShortLabel(shortcut.Label);
            builder.SetLongLabel(shortcut.Description);

            var icon = await CreateIcon(shortcut.Icon);

            if (icon != null)
            {
                builder.SetIcon(icon);
            }

            var scut = builder.Build();

            if (_manager.DynamicShortcuts == null || !_manager.DynamicShortcuts.Any())
            {
                _manager.SetDynamicShortcuts(new List <ShortcutInfo> {
                    scut
                });
            }
            else
            {
                _manager.AddDynamicShortcuts(new List <ShortcutInfo> {
                    scut
                });
            }
        }
Ejemplo n.º 5
0
        internal static async Task <ShortcutInfo> ToShortcutInfoAsync(this JumpListItem jumpListItem)
        {
            var builder = new ShortcutInfo.Builder(Application.Context, jumpListItem.Arguments);
            var pm      = Application.Context.PackageManager;
            var intent  = pm.GetLaunchIntentForPackage(Application.Context.PackageName);

            intent.PutExtra(JumpListItem.ArgumentsExtraKey, jumpListItem.Arguments);
            builder.SetIntent(intent);
            builder.SetShortLabel(
                !string.IsNullOrEmpty(jumpListItem.DisplayName) ?
                jumpListItem.DisplayName : " ");                         //Android requires non-empty DisplayName
            if (!string.IsNullOrEmpty(jumpListItem.Description))
            {
                builder.SetLongLabel(jumpListItem.Description);
            }

            var persistableBundle = new PersistableBundle();

            persistableBundle.PutString(JumpListItem.UnoShortcutKey, "true");

            if (jumpListItem.Logo != null)
            {
                persistableBundle.PutString(JumpListItem.ImagePathKey, jumpListItem.Logo.ToString());
                var imageResourceId = DrawableHelper.FindResourceId(jumpListItem.Logo.LocalPath);
                if (imageResourceId != null)
                {
                    var bitmap = await BitmapFactory.DecodeResourceAsync(
                        ContextHelper.Current.Resources,
                        imageResourceId.Value,
                        new BitmapFactory.Options());

                    builder.SetIcon(Icon.CreateWithBitmap(bitmap));
                }
            }

            builder.SetExtras(persistableBundle);

            return(builder.Build());
        }