From a2bf6b7e80bde3f17e7a70273cb3136d7fecadbf Mon Sep 17 00:00:00 2001 From: Heonjae Jang Date: Thu, 25 May 2017 18:02:11 +0900 Subject: Change Animation in TVHome Change-Id: I63cc71df474636e0ace7c01f115402ec5fd29c58 Signed-off-by: Heonjae Jang --- TVHome/TVHome/Controls/MainPanelButton.xaml | 3 +- TVHome/TVHome/ViewModels/MainPageViewModel.cs | 163 +++++++------------------- TVHome/TVHome/Views/MainPage.xaml | 8 +- TVHome/TVHome/Views/MainPage.xaml.cs | 36 ++++-- TVHome/TVHome/Views/MainPanel.xaml | 11 +- TVHome/TVHome/Views/MainPanel.xaml.cs | 46 +++++++- TVHome/TVHome/Views/Panel.cs | 10 +- TVHome/TVHome/Views/SubPanel.xaml | 4 +- TVHome/TVHome/Views/SubPanel.xaml.cs | 65 ++++++---- TVHome/TVHome/Views/SubThumbnailPanel.xaml | 10 +- TVHome/TVHome/Views/SubThumbnailPanel.xaml.cs | 73 ++++++++---- 11 files changed, 215 insertions(+), 214 deletions(-) diff --git a/TVHome/TVHome/Controls/MainPanelButton.xaml b/TVHome/TVHome/Controls/MainPanelButton.xaml index 9f017d4..5306d7d 100755 --- a/TVHome/TVHome/Controls/MainPanelButton.xaml +++ b/TVHome/TVHome/Controls/MainPanelButton.xaml @@ -4,7 +4,8 @@ xmlns:Controls="clr-namespace:TVHome.Controls" x:Class="TVHome.Controls.MainPanelButton" HorizontalOptions="Center" - VerticalOptions="Center"> + VerticalOptions="Center" + Status="{Binding Status}"> public enum HomeStatus { - Default = 0, - MainPanelFocused, + MainPanelFocused = 0, SubPanelFocused, - UnPin, + ShowOptions, Move, + Iconified }; /// @@ -53,6 +53,31 @@ namespace TVHome.ViewModels /// public class MainPageViewModel : INotifyPropertyChanged, IHomeViewModel { + /// + /// Gets or set CurrentStatus of HomeStatus + /// + public HomeStatus CurrentStatus { get; private set; } + + private HomeMenuItem selectedMenuName = HomeMenuItem.Apps; + /// + /// Gets or set SelectedMenuName of HomeMenuItem + /// + public HomeMenuItem SelectedMenuName + { + get + { + return selectedMenuName; + } + set + { + if(selectedMenuName != value) + { + selectedMenuName = value; + ChangeSelectedPanelName(value, true); + } + } + } + /// /// Gets or set MainList for MainPanel /// @@ -76,7 +101,7 @@ namespace TVHome.ViewModels /// /// A command for executing when MainPanel is focused. /// - public Command MainPanelFocusedCommand { get; set; } + public Command ChangeStatusCommand { get; set; } /// /// A command for executing when SubPanel is focused. @@ -113,16 +138,6 @@ namespace TVHome.ViewModels /// public Command OnClearAllCommand { get; set; } - /// - /// Gets or set CurrentStatus of HomeStatus - /// - public HomeStatus CurrentStatus { get; private set; } - - /// - /// Gets or set SelectedMenuName of HomeMenuItem - /// - public HomeMenuItem SelectedMenuName { get; private set; } - /// /// A flag indicates whether "No recent info" in Recent SubPanel to be displayed or not /// @@ -133,74 +148,6 @@ namespace TVHome.ViewModels /// public event PropertyChangedEventHandler PropertyChanged; - /// - /// Main panel icon's width - /// - public int MainPanelIconWidth - { - get - { - return SizeUtils.GetWidthSize(236); - } - } - - /// - /// Sub panel's padding size - /// - public Thickness SubPanelPadding - { - get - { - int lr = SizeUtils.GetWidthSize(74); - return new Thickness(lr, 0, lr, SizeUtils.GetWidthSize(26)); - } - } - - /// - /// Apps, Settings sub panel's spacing size - /// - public int SubPanelSpacing - { - get - { - // TODO : set proper size - return SizeUtils.GetWidthSize(34); - } - } - - /// - /// Recent sub panel's spacing size - /// - public double SubThumbPanelSpacing - { - get - { - // TODO : set proper size - return SizeUtils.GetWidthSizeDouble(27.5); - } - } - - /// - /// Information text font size. - /// - public int NoContentInformationFontSize - { - get - { - return SizeUtils.GetFontSize(28); - } - } - - /// - /// Sub thumbnail panel's padding size - /// - public Thickness SubThumbNailPanelPadding - { - get - { - return new Thickness(SizeUtils.GetWidthSize(96), SizeUtils.GetWidthSize(32)); - } - } /// /// Constructor @@ -241,10 +188,16 @@ namespace TVHome.ViewModels MakeRecentButtons(); break; case TVHomeStatus.OnSleep: - ChangeCurrentStatus(HomeStatus.Default, true); + ChangeCurrentStatus(HomeStatus.MainPanelFocused, true); break; } }); + PropertyChanged += MainPageViewModelPropertyChanged; + } + + private void MainPageViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) + { + DebuggingUtils.Dbg(e.PropertyName); } /// @@ -252,7 +205,8 @@ namespace TVHome.ViewModels /// private void InitStatus() { - ChangeCurrentStatus(HomeStatus.Default, true); + ChangeSelectedPanelName(HomeMenuItem.Apps, true); + ChangeCurrentStatus(HomeStatus.MainPanelFocused, true); } /// @@ -260,26 +214,9 @@ namespace TVHome.ViewModels /// private void InitCommands() { - MainPanelFocusedCommand = new Command((key) => - { - DebuggingUtils.Dbg(key.ToString()); - ChangeCurrentStatus(HomeStatus.MainPanelFocused); - ChangeSelectedPanelName(key); - }); - - SubPanelFocusedCommand = new Command(() => - { - ChangeCurrentStatus(HomeStatus.SubPanelFocused); - }); - - SetMoveStatusCommand = new Command(() => - { - ChangeCurrentStatus(HomeStatus.Move); - }); - - SetUnpinStatusCommand = new Command(() => + ChangeStatusCommand = new Command((status) => { - ChangeCurrentStatus(HomeStatus.UnPin); + ChangeCurrentStatus(status); }); OnMoveCommand = new Command>((moveList) => @@ -531,25 +468,7 @@ namespace TVHome.ViewModels CurrentStatus.CompareTo(newStatus) != 0) { CurrentStatus = newStatus; - if (CurrentStatus.CompareTo(HomeStatus.Default) == 0) - { - foreach (HomeMenuAppShortcutInfo item in MainList) - { - if (item.CurrentStateDescription.Label.CompareTo("Apps") == 0) - { - DebuggingUtils.Dbg(item.CurrentStateDescription.Label + " To Focused"); - item.ChangeStatus("focused"); - } - else - { - DebuggingUtils.Dbg(item.CurrentStateDescription.Label + " To Default"); - item.ChangeStatus("default"); - } - } - - ChangeSelectedPanelName(HomeMenuItem.Apps, isForceUpdate); - } - else if (CurrentStatus.CompareTo(HomeStatus.MainPanelFocused) == 0) + if (CurrentStatus.CompareTo(HomeStatus.MainPanelFocused) == 0) { HomeMenuItem index = HomeMenuItem.Recent; foreach (HomeMenuAppShortcutInfo item in MainList) diff --git a/TVHome/TVHome/Views/MainPage.xaml b/TVHome/TVHome/Views/MainPage.xaml index 984104b..dd41bbe 100755 --- a/TVHome/TVHome/Views/MainPage.xaml +++ b/TVHome/TVHome/Views/MainPage.xaml @@ -27,14 +27,14 @@ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.22}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.6537}" - OnFocusedCommand="{Binding MainPanelFocusedCommand}" + ChangeStatusCommand="{Binding ChangeStatusCommand}" ItemsSource="{Binding MainList}"/> @@ -53,7 +53,7 @@ RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.2370}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.8833}" - OnFocusedCommand="{Binding SubPanelFocusedCommand}" + ChangeStatusCommand="{Binding ChangeStatusCommand}" ItemsSource="{Binding SettingsList}" /> diff --git a/TVHome/TVHome/Views/MainPage.xaml.cs b/TVHome/TVHome/Views/MainPage.xaml.cs index 8479f6e..9daf994 100755 --- a/TVHome/TVHome/Views/MainPage.xaml.cs +++ b/TVHome/TVHome/Views/MainPage.xaml.cs @@ -22,7 +22,6 @@ using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace TVHome.Views { - using System.Runtime.CompilerServices; using Tizen = Xamarin.Forms.PlatformConfiguration.Tizen; /// /// A custom view for displaying main page of TV Home @@ -46,7 +45,7 @@ namespace TVHome.Views /// /// Identifies the SelectedMenuName bindable property /// - public static readonly BindableProperty SelectedMenuNameProperty = BindableProperty.Create("SelectedMenuName", typeof(HomeMenuItem), typeof(MainPage), default(HomeMenuItem)); + public static readonly BindableProperty SelectedMenuNameProperty = BindableProperty.Create("SelectedMenuName", typeof(HomeMenuItem), typeof(MainPage), default(HomeMenuItem), defaultBindingMode: BindingMode.TwoWay); /// /// Gets or sets selected HomeMenuItem @@ -184,10 +183,15 @@ namespace TVHome.Views break; } }); - PageMainPanel.OnItemSelectedHandler += (id) => + PageMainPanel.OnItemFocusedHandler += (selectedItem) => { - DebuggingUtils.Dbg("Selected Item " + id); - switch (id) + SelectedMenuName = selectedItem; + DebuggingUtils.Dbg("test" + SelectedMenuName); + }; + + PageMainPanel.OnItemSelectedHandler += (selectedItem) => + { + switch (selectedItem) { case HomeMenuItem.Recent: RecentSubPanel.FocusPanel(); @@ -248,10 +252,12 @@ namespace TVHome.Views Button appsMainPanelButton = PageMainPanel.GetButtonToFocusing(1); Button settingMainPanelButton = PageMainPanel.GetButtonToFocusing(2); + recentMainPanelButton.On().SetNextFocusLeftView(recentMainPanelButton); recentMainPanelButton.On().SetNextFocusRightView(appsMainPanelButton); appsMainPanelButton.On().SetNextFocusLeftView(recentMainPanelButton); appsMainPanelButton.On().SetNextFocusRightView(settingMainPanelButton); settingMainPanelButton.On().SetNextFocusLeftView(appsMainPanelButton); + settingMainPanelButton.On().SetNextFocusRightView(settingMainPanelButton); } /// @@ -262,6 +268,11 @@ namespace TVHome.Views List recentSubPanelButtons = new List(RecentSubPanel.GetSubPanelButtons()); Button recentMainPanelButton = PageMainPanel.GetButtonToFocusing(0); + if (recentSubPanelButtons.Count > 1) + { + recentMainPanelButton.On().SetNextFocusDownView(recentSubPanelButtons[0].FindByName public partial class MainPanel : Panel { + public delegate void FocusEventHandler(HomeMenuItem item); public delegate void SelectEventHandler(HomeMenuItem item); + /// + /// A EventHandler for Item focused event + /// + public FocusEventHandler OnItemFocusedHandler; + /// /// A EventHandler for Item selected event /// public SelectEventHandler OnItemSelectedHandler; + /// + /// Main panel icon's width + /// + private int mainPanelIconWidth = SizeUtils.GetWidthSize(236); + + /// + /// Main panel icon's width + /// + private int mainPanelColumnSpacing = SizeUtils.GetWidthSize(-94); + /// /// MainPanel icon's transition height value when it focused. /// @@ -48,9 +62,23 @@ namespace TVHome.Views public MainPanel() { InitializeComponent(); + InitializeSize(); PropertyChanged += OnItemsSourcePropertyChanged; } + private void InitializeSize() + { + PanelButtonGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); + PanelButtonGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(mainPanelIconWidth) }); + PanelButtonGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(mainPanelIconWidth) }); + PanelButtonGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(mainPanelIconWidth) }); + PanelButtonGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); + + PanelButtonGrid.ColumnSpacing = mainPanelColumnSpacing; + + PanelButtonGrid.ForceLayout(); + } + /// /// An event handler for handling property changed event /// @@ -73,8 +101,9 @@ namespace TVHome.Views HomeMenuItem ItemName = menuIndex; button.OnFocusedCommand = new Command(() => { + ChangeStatusCommand?.Execute(HomeStatus.MainPanelFocused); + OnItemFocusedHandler?.Invoke(ItemName); FocusPanel(); - OnFocusedCommand.Execute(ItemName); }); button.OnClickedCommand = new Command(() => { @@ -113,9 +142,14 @@ namespace TVHome.Views /// /// A method for translating when panel is focused /// - public override async void FocusPanel() + public override void FocusPanel() { - await this.TranslateTo(0, 0, 300); + AnimationExtensions.AbortAnimation(this, "PanelAnimation"); + var currentTranslationY = TranslationY; + Animation animation = new Animation(); + Animation translateAnimation = new Animation(v => TranslationY = (currentTranslationY * (1 - v))); + animation.Add(0, 1, translateAnimation); + animation.Commit(this, "PanelAnimation", length: 300); } /// @@ -131,7 +165,7 @@ namespace TVHome.Views /// public void SelectPanel() { - AnimationExtensions.AbortAnimation(this,"PanelAnimation"); + AnimationExtensions.AbortAnimation(this, "PanelAnimation"); var currentTranslationY = TranslationY; var diff = selectTransitionHeight - currentTranslationY; Animation animation = new Animation(); diff --git a/TVHome/TVHome/Views/Panel.cs b/TVHome/TVHome/Views/Panel.cs index 1c8b1f8..61e9bbe 100755 --- a/TVHome/TVHome/Views/Panel.cs +++ b/TVHome/TVHome/Views/Panel.cs @@ -28,17 +28,17 @@ namespace TVHome.Views public abstract class Panel : ContentView { /// - /// Identifies the OnFocusedCommand bindable property + /// Identifies the ChangeStatusCommand bindable property /// - public static readonly BindableProperty OnFocusedCommandProperty = BindableProperty.Create("OnFocusedCommand", typeof(ICommand), typeof(MainPanel)); + public static readonly BindableProperty ChangeStatusCommandProperty = BindableProperty.Create("ChangeStatusCommand", typeof(ICommand), typeof(MainPanel)); /// /// A command is executed when panel is focused /// - public ICommand OnFocusedCommand + public ICommand ChangeStatusCommand { - get { return (ICommand)GetValue(OnFocusedCommandProperty); } - set { SetValue(OnFocusedCommandProperty, value); } + get { return (ICommand)GetValue(ChangeStatusCommandProperty); } + set { SetValue(ChangeStatusCommandProperty, value); } } /// diff --git a/TVHome/TVHome/Views/SubPanel.xaml b/TVHome/TVHome/Views/SubPanel.xaml index 9e89e08..8a0115c 100755 --- a/TVHome/TVHome/Views/SubPanel.xaml +++ b/TVHome/TVHome/Views/SubPanel.xaml @@ -7,9 +7,7 @@ Orientation="Horizontal" HorizontalOptions="Center"> + Orientation="Horizontal"> \ No newline at end of file diff --git a/TVHome/TVHome/Views/SubPanel.xaml.cs b/TVHome/TVHome/Views/SubPanel.xaml.cs index 283fb96..630dd7e 100755 --- a/TVHome/TVHome/Views/SubPanel.xaml.cs +++ b/TVHome/TVHome/Views/SubPanel.xaml.cs @@ -23,6 +23,7 @@ using System.Windows.Input; using System.Collections.Generic; using LibTVRefCommonPortable.Utils; using System; +using TVHome.ViewModels; namespace TVHome.Views { @@ -72,9 +73,17 @@ namespace TVHome.Views ButtonList = new List(); ButtonViewList = new List(); + + InitializeSize(); PropertyChanged += OnItemsSourcePropertyChanged; } + private void InitializeSize() + { + PanelButtonStack.Spacing = SizeUtils.GetWidthSize(34); + PanelButtonStack.Padding = new Thickness(SizeUtils.GetWidthSize(74), 0, SizeUtils.GetWidthSize(74), SizeUtils.GetWidthSize(26)); + } + /// /// A method for handling when menu key is pressed /// @@ -176,8 +185,8 @@ namespace TVHome.Views button.BindingContext = item; button.OnFocusedCommand = new Command(() => { + ChangeStatusCommand?.Execute(HomeStatus.SubPanelFocused); FocusPanel(); - if (SizeUtils.GetWidthSize((int)button.X) - SizeUtils.GetWidthSize((int)PanelScrollView.ScrollX) < 0) { ScrollToLeft(); @@ -265,7 +274,7 @@ namespace TVHome.Views /// /// A method for hiding the panel /// - public override async void HidePanel() + public override void HidePanel() { isFocused = false; foreach (var item in PanelButtonStack.Children) @@ -273,19 +282,24 @@ namespace TVHome.Views item.IsEnabled = false; } -#pragma warning disable CS4014 PanelScrollView.ScrollToAsync(0, 0, true); - this.TranslateTo(0, selectTransitionHeight, 300); -#pragma warning restore CS4014 - await this.FadeTo(0, 300); + AnimationExtensions.AbortAnimation(this, "PanelAnimation"); + var currentTranslationY = TranslationY; + var diff = selectTransitionHeight - currentTranslationY; + var currentOpacity = Opacity; + Animation animation = new Animation(); + Animation translateAnimation = new Animation(v => TranslationY = (currentTranslationY + diff * v)); + Animation fadeAnimation = new Animation(v => Opacity = currentOpacity * (1 - v)); + animation.Add(0, 1, translateAnimation); + animation.Add(0, 1, fadeAnimation); + animation.Commit(this, "PanelAnimation", length: 300); } /// /// A method for showing the panel /// - public override async void ShowPanel() + public override void ShowPanel() { -#pragma warning disable CS4014 isFocused = false; foreach (var item in PanelButtonStack.Children) { @@ -294,28 +308,28 @@ namespace TVHome.Views //item.FindByName("ButtonDimmedImage").ScaleTo(1.0, 300); } - this.TranslateTo(0, 0, 300); -#pragma warning restore CS4014 - await this.FadeTo(1, 300); + AnimationExtensions.AbortAnimation(this, "PanelAnimation"); + var currentTranslationY = TranslationY; + var currentOpacity = Opacity; + var diff = 1 - currentOpacity; + Animation animation = new Animation(); + Animation translateAnimation = new Animation(v => TranslationY = (currentTranslationY * (1 - v))); + Animation fadeAnimation = new Animation(v => Opacity = currentOpacity + diff * v); + animation.Add(0, 1, translateAnimation); + animation.Add(0, 1, fadeAnimation); + animation.Commit(this, "PanelAnimation", length: 300); } /// /// A method for handling panel focused event /// - public override async void FocusPanel() + public override void FocusPanel() { if (isFocused) { - if (!isMoveMode) - { - OnFocusedCommand.Execute(""); - } - return; } - OnFocusedCommand.Execute(""); - isFocused = true; var button = PanelButtonStack.Children[1]; button.FindByName