public async Task<bool> AddTileAsync(BandTile tile)
        {
            bool result = false;
#if __ANDROID__
            result = await ActivityWrappedActionExtensions.WrapActionAsync(activity =>
            {
                return Native.AddTileTaskAsync(activity, tile.ToNative());
            });
#elif __IOS__
            try
            {
                await Native.AddTileTaskAsync(tile.ToNative());
                result = true;
            }
            catch (BandException ex)
            {
                if (ex.Code == (int)BandNSErrorCodes.UserDeclinedTile)
                {
                    result = false;
                }
                else 
                {
                    throw;
                }
            }
#elif WINDOWS_PHONE_APP
            result = await Native.AddTileAsync(tile.ToNative());
#endif
            return result;
        }
示例#2
0
        public static Task <bool> AddTileAsync(this NativeBandTileManager tileManager, BandTile tile)
        {
            var tcs = new TaskCompletionSource <bool>();

            // show the add tile dialog
            listeners.TryAdd(tile.Id.ToString(), async activity =>
            {
                try
                {
                    // show the dialog
                    if (activity != null)
                    {
                        // show the dialog and add the tile
                        var result = await BandTileManagerExtensions.AddTileTaskAsync(tileManager, activity, tile.ToNative());

                        // end the waiting
                        tcs.SetResult(result);
                    }
                    else
                    {
                        // end the waiting
                        tcs.SetResult(false);
                    }
                }
                catch (Exception ex)
                {
                    // end the waiting
                    tcs.SetException(ex);
                }
            });

            // start the activity
            var context = Application.Context;
            var intent  = new Intent(context, typeof(AddTileActivity));

            intent.PutExtra(TileIdExtra, tile.Id.ToString());
            intent.AddFlags(ActivityFlags.NewTask);
            context.StartActivity(intent);

            // wait for the delegate to be fired
            return(tcs.Task);
        }