/// <summary>
        ///  アイテムをロック画面に設定する.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private async Task <bool> SetSelectedItemToLockscreenAsync(LockscreenImageItem item)
        {
            bool succeedToSet = false;

            try
            {
                await LockScreen.SetImageFileAsync(item.Item);

                succeedToSet = true;
            }
            catch (UnauthorizedAccessException)
            {
                // 画像ファイルを貼り付けしてその直後に
                // ロック画面に設定しようとすると↑はアクセス拒否で失敗する。
                // その場合でも↓で問題ないのでそれを試す。
                // もしかしたら常に↓でよいのかもしれない...
            }

            if (!succeedToSet)
            {
                using (var strm = await item.Item.OpenReadAsync())
                {
                    await LockScreen.SetImageStreamAsync(strm);

                    succeedToSet = true;
                }
            }

            return(succeedToSet);
        }
Пример #2
0
        /// <summary>
        ///  セカンダリタイル用のロゴ画像のファイルを作成する.
        /// </summary>
        /// <param name="item">ロック画面に設定するアイテム</param>
        /// <returns></returns>
        private async Task CreateLogoImageFileForTileAsync(LockscreenImageItem item, string tileId)
        {
            System.Diagnostics.Debug.Assert(item != null);
            if ((this.normalLogoImageFile != null) || (this.wideLogoImageFile != null))
            {
                throw new InvalidOperationException("Already created");
            }

            using (var inStream = await item.Item.OpenReadAsync())
            {
                var decoder = await BitmapDecoder.CreateAsync(inStream);

                var pixelDataProvider = await decoder.GetPixelDataAsync(
                    BitmapPixelFormat.Rgba8,
                    BitmapAlphaMode.Premultiplied,
                    new BitmapTransform(),
                    ExifOrientationMode.RespectExifOrientation,
                    ColorManagementMode.ColorManageToSRgb);

                var pixelData = pixelDataProvider.DetachPixelData();

                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(TileImageCacheSubFolderName, CreationCollisionOption.OpenIfExists);

                if (folder == null)
                {
                    return;
                }

                var normalFile = await CreateTileImageCacheFileAsync(
                    folder,
                    String.Format(TileImageCacheFileNameFormatForNormal, tileId),
                    150,
                    150,
                    decoder,
                    pixelData);

                var wideFile = await CreateTileImageCacheFileAsync(
                    folder,
                    String.Format(TileImageCacheFileNameFormatForWide, tileId),
                    310,
                    150,
                    decoder,
                    pixelData);

                this.normalLogoImageFile = normalFile;
                this.wideLogoImageFile   = wideFile;
            }
        }
Пример #3
0
        /// <summary>
        ///  「ロック画面に設定するアイテム」を登録解除する.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static async Task Remove(LockscreenImageItem item)
        {
            if (StorageApplicationPermissions.FutureAccessList.ContainsItem(item.Setting.Token))
            {
                StorageApplicationPermissions.FutureAccessList.Remove(item.Setting.Token);
            }

            if (item.Setting.IsTemporary)
            {
                await item.Item.DeleteAsync();
            }

            if (!String.IsNullOrEmpty(item.Setting.TileId))
            {
                await TileHelper.RemoveTileRegistrationAsync(item.Setting.TileId);

                item.Setting.TileId = null;
            }
        }
Пример #4
0
        /// <summary>
        ///  ロック画面に設定するアイテムのセカンダリタイルを取得する.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static async Task <Tile> GetSecondaryTileForItem(LockscreenImageItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var secondaryTile = await TileHelper.GetSecondaryTileFromTileIdAsync(item.Setting.TileId);

            if (secondaryTile == null)
            {
                return(null);
            }

            return(new Tile()
            {
                SecondaryTile = secondaryTile,
            });
        }
Пример #5
0
        /// <summary>
        ///  セカンダリタイルを作成する.
        /// </summary>
        /// <param name="item"></param>
        public static async Task <Tile> CreateSecodaryTileForItem(LockscreenImageItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var tileId = TileHelper.GetNewTileId();

            if (tileId == null)
            {
                throw new InvalidOperationException("Too many tiles");
            }

            var tile = new Tile();
            await tile.CreateLogoImageFileForTileAsync(item, tileId);

            if (!tile.IsTileLogoImageCreated)
            {
                return(null);
            }

            Uri normalLogoUri = new Uri(TileImageCacheUriPrefix + tile.normalLogoImageFile.Name);
            Uri wideLogoUri   = new Uri(TileImageCacheUriPrefix + tile.wideLogoImageFile.Name);

            tile.SecondaryTile = new SecondaryTile(
                tileId,
                item.Name,
                Windows.ApplicationModel.Package.Current.Id.Name,
                TileHelper.TileArgumentsSetLockscreen,
                TileOptions.ShowNameOnLogo | TileOptions.ShowNameOnWideLogo,
                normalLogoUri,
                wideLogoUri);

            return(tile);
        }