/// <summary>
        ///  選択されているアイテムをスタート画面からピン留めを外す.
        /// </summary>
        /// <param name="buttonPosition">呼び出し元ボタンの場所</param>
        private async void UnPinSelectedItemToStartAsync(Point buttonPosition)
        {
            var item = GetSelectedItem();

            if (item == null)
            {
                return;
            }

            var tile = await Tile.GetSecondaryTileForItem(item);

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

                    item.Setting.TileId = null;
                }
                UpdatePinUnPinToStartBottomAppBarButtons();
                return;
            }

            string tileId = tile.SecondaryTile.TileId;
            var    re     = new Rect(buttonPosition.X, buttonPosition.Y, 100, 100);

            if (await tile.SecondaryTile.RequestDeleteForSelectionAsync(re))
            {
                item.Setting.TileId = null;
                App.Current.LockscreenItemList.SaveItemsToSetting();
                await TileHelper.RemoveTileRegistrationAsync(tileId);

                UpdatePinUnPinToStartBottomAppBarButtons();
            }
        }
        /// <summary>
        ///  選択されているアイテムをスタート画面にピン留めする.
        /// </summary>
        /// <param name="buttonPosition">呼び出し元ボタンの場所</param>
        private async void PinSelectedItemToStartAsync(Point buttonPosition)
        {
            var item = GetSelectedItem();

            if (item == null)
            {
                return;
            }

            var tile = await Tile.CreateSecodaryTileForItem(item);

            if (tile == null)
            {
                return;
            }

            tile.SecondaryTile.DisplayName = String.Format("{0} - {1}", App.MyResource["AppName"], item.Name);
            var re = new Rect(buttonPosition.X, buttonPosition.Y, 100, 100);

            if (await tile.SecondaryTile.RequestCreateForSelectionAsync(re))
            {
                await TileHelper.CleanupUnusedTileIdsAsync();

                item.Setting.TileId = tile.SecondaryTile.TileId;
                App.Current.LockscreenItemList.SaveItemsToSetting();
                TileHelper.SaveTileRegistration(tile);
                UpdatePinUnPinToStartBottomAppBarButtons();
            }
            else
            {
                await tile.DeleteTileImageCacheFilesAsync();
            }
        }
        /// <summary>
        ///  セカンダリタイルから起動された時の処理.
        /// </summary>
        /// <param name="tileId"></param>
        public async void SecondaryTile_LaunchedAsync(string tileId)
        {
            var secondaryTile = await TileHelper.GetSecondaryTileFromTileIdAsync(tileId);

            if (secondaryTile == null)
            {
                App.Current.LaunchedFromSecondaryTile = false;
                return;
            }

            await App.Current.LoadAllItemsAsync();

            var item = App.Current.LockscreenItemList.FirstOrDefault(x => tileId.Equals(x.Setting.TileId, StringComparison.Ordinal));

            if (item == null)
            {
                // delete from start
                if (await secondaryTile.RequestDeleteAsync())
                {
                    await TileHelper.RemoveTileRegistrationAsync(tileId);
                }
                App.Current.LaunchedFromSecondaryTile = false;
                return;
            }
            else
            {
                var succeedToSet = await SetSelectedItemToLockscreenAsync(item);

                LoadCurrentLockscreenImageAsync();
                App.Current.LaunchedFromSecondaryTile = false;
            }
        }
Esempio n. 4
0
        /// <summary>
        ///  セカンダリタイル用の画像ファイルを削除する.
        /// </summary>
        /// <returns></returns>
        public async Task DeleteTileImageCacheFilesAsync()
        {
            if (this.SecondaryTile == null)
            {
                throw new InvalidOperationException();
            }

            await TileHelper.DeleteSecondaryTileLogoFileAsync(this.SecondaryTile);
        }
 /// <summary>
 ///  <c>CoreWindow</c>の可視状態が変わった時のイベント処理.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 async void CoreWindow_Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
 {
     // 小細工
     if (this.wasSavedState && e.Visible)
     {
         this.wasSavedState = false;
         LoadCurrentLockscreenImageAsync();
         DoUpdateOnAppLaunchAsync();
         await TileHelper.CleanupUnusedTileIdsAsync();
     }
 }
Esempio n. 6
0
        /// <summary>
        ///  登録されているアイテムを読み込む(実装).
        /// </summary>
        /// <returns></returns>
        private async Task LoadAllItemsAsyncCore()
        {
            var itemsState = AppSettings.Instance.GetItemsState();

            if (itemsState == null)
            {
                return;
            }

            foreach (var setting in LockscreenImageItemSettingHelper.DeserializeItems(itemsState))
            {
                if (!StorageApplicationPermissions.FutureAccessList.ContainsItem(setting.Token))
                {
                    continue;
                }

                bool succeeded = false;
                try
                {
                    var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(setting.Token);

                    var item = new LockscreenImageItem(file)
                    {
                        Setting = setting
                    };
                    Add(item);
                    succeeded = true;
                }
                catch (System.IO.FileNotFoundException)
                {
                    succeeded = false;
                }
                if (!succeeded)
                {
                    StorageApplicationPermissions.FutureAccessList.Remove(setting.Token);

                    if (!String.IsNullOrEmpty(setting.TileId))
                    {
                        await TileHelper.RemoveTileRegistrationAsync(setting.TileId);
                    }

                    continue;
                }
            }
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
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,
            });
        }
        /// <summary>
        ///  AppBarの<c>Loaded</c>イベントを処理する.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BottomAppBar_Loaded(object sender, RoutedEventArgs e)
        {
            var itemsView = GetItemsView();

            this.ItemsSelected = (itemListView != null) ? (itemsView.SelectedItem != null) : false;

            (sender as AppBar).DataContext = this;

            var panel = (sender as AppBar).Content as Panel;

            foreach (var ui in panel.Children)
            {
                base.StartLayoutUpdates(ui, new RoutedEventArgs());
            }

            PreparePastePopupContentsAsync();

            await TileHelper.CleanupUnusedTileIdsAsync();

            UpdatePinUnPinToStartBottomAppBarButtons();
        }
        /// <summary>
        /// このページには、移動中に渡されるコンテンツを設定します。前のセッションからページを
        /// 再作成する場合は、保存状態も指定されます。
        /// </summary>
        /// <param name="navigationParameter">このページが最初に要求されたときに
        /// <see cref="Frame.Navigate(Type, Object)"/> に渡されたパラメーター値。
        /// </param>
        /// <param name="pageState">前のセッションでこのページによって保存された状態の
        /// ディクショナリ。ページに初めてアクセスするとき、状態は null になります。</param>
        protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // TODO: バインド可能なアイテムのコレクションを this.DefaultViewModel["Items"] に割り当てます
            this.DefaultViewModel["Items"] = App.Current.LockscreenItemList;

            SettingsPane.GetForCurrentView().CommandsRequested += LockscreenItemsPage_CommandsRequested;
            Window.Current.VisibilityChanged += CoreWindow_Current_VisibilityChanged;

            LoadCurrentLockscreenImageAsync();
            await App.Current.LoadAllItemsAsync();

            DoUpdateOnAppLaunchAsync();

            if (App.Current.LockscreenItemList.IsEmpty)
            {
                await Task.Delay(1000);

                ShowAppHelpPopup(new Uri(HelpPageUriString));
            }

            await TileHelper.CleanupUnusedTileIdsAsync();
        }
        /// <summary>
        ///  pin / unpinのアプリバーボタンの表示状態を更新する.
        /// </summary>
        private void UpdatePinUnPinToStartBottomAppBarButtons()
        {
            var item = GetSelectedItem();

            if (item != null)
            {
                if (!TileHelper.IsTileRegistered(item.Setting.TileId))
                {
                    this.PinToStartAppBarButton.Visibility     = Windows.UI.Xaml.Visibility.Visible;
                    this.UnPinFromStartAppBarButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                }
                else
                {
                    this.PinToStartAppBarButton.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                    this.UnPinFromStartAppBarButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
            }
            else
            {
                this.PinToStartAppBarButton.Visibility     = Windows.UI.Xaml.Visibility.Visible;
                this.UnPinFromStartAppBarButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }
Esempio n. 12
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);
        }