Implement Focus chaining for Apps
authorHyerim Kim <rimi.kim@samsung.com>
Tue, 18 Apr 2017 11:38:21 +0000 (20:38 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:53 +0000 (18:34 +0900)
Change-Id: Iee83059dddde0f9adb612cba64ca6e338cd987ca
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com>
TVApps/TVApps/Controls/AppItemCell.xaml
TVApps/TVApps/Controls/AppItemCell.xaml.cs
TVApps/TVApps/Controls/AppListView.xaml.cs [changed mode: 0644->0755]
TVApps/TVApps/TVApps.csproj [changed mode: 0644->0755]
TVApps/TVApps/Views/FooterDeleteStatus.xaml.cs [changed mode: 0644->0755]
TVApps/TVApps/Views/FooterNormalStatus.xaml.cs [changed mode: 0644->0755]
TVApps/TVApps/Views/FooterPinStatus.xaml.cs [changed mode: 0644->0755]
TVApps/TVApps/Views/MainPage.xaml.cs [changed mode: 0644->0755]
TVApps/TVApps/packages.config [changed mode: 0644->0755]

index c000848..79a3e46 100755 (executable)
           <Control:TVButton x:Name="OptionMenuPinToggleButton"
                             Grid.Row="0"
                             Command="{Binding OptionMenuPinToggleCommand}"
+                            IsEnabled="false"
                             Text="UNPIN" />
           <Control:TVButton x:Name="OptionMenuDeleteButton"
                             Grid.Row="1"
                             Command="{Binding OptionMenuDeleteCommand}"
+                            IsEnabled="false"
                             Text="DELETE" />
         </Grid>
 
index c007185..dfa5516 100755 (executable)
@@ -236,6 +236,8 @@ namespace TVApps.Controls
             TextArea.TranslateTo(0, (isShow) ? -height90 : 0, 100);
             TextArea.FadeTo((isShow) ? 0.0 : 0.99, 100);
             OptionMenuArea.TranslateTo(0, (isShow) ? -height144 : 0, 100);
+            OptionMenuPinToggleButton.IsEnabled = (isShow) ? true : false;
+            OptionMenuDeleteButton.IsEnabled = (isShow) ? true : false;
         }
 
         /// <summary>
old mode 100644 (file)
new mode 100755 (executable)
index b7763d0..79c9b3f
@@ -136,6 +136,16 @@ namespace TVApps.Controls
             }
         }
 
+        public IList<View> GetAppsUpperList()
+        {
+            return AppUpperList.Children;
+        }
+
+        public IList<View> GetAppsLowerList()
+        {
+            return AppLowerList.Children;
+        }
+
         /// <summary>
         /// A method creates and adds AppItemCells binded with ItemsSource
         /// </summary>
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 0c6926f..8b20858
@@ -46,5 +46,10 @@ namespace TVApps.Views
                 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(762)),
                 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(96 + 1130 + 300 + 2)));
         }
+
+        public Button GetCancelButton()
+        {
+            return CancelButton.FindByName<Button>("HiddenButton");
+        }
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 7b67ddb..56cd6c1
@@ -72,6 +72,11 @@ namespace TVApps.Views
             CreateOptionButton();
         }
 
+        public DropdownList GetSortDropdownList()
+        {
+            return SortButton;
+        }
+
         private void CreateOptionButton()
         {
             OptionButton = new TVButton()
old mode 100644 (file)
new mode 100755 (executable)
index bd42dfe..a2f83c6
@@ -91,6 +91,11 @@ namespace TVApps.Views
                 xConstraint: Constraint.Constant(SizeUtils.GetWidthSize(96 + 1130 + 300 + 2)));
         }
 
+        public Button GetDoneButton()
+        {
+            return DoneButton.FindByName<Button>("HiddenButton");
+        }
+
         private void FooterPinStatusPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
             if (e.PropertyName.Equals("SumOfCheckedApp"))
old mode 100644 (file)
new mode 100755 (executable)
index 6f28424..42b30ef
@@ -23,14 +23,23 @@ using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Input;
 using System.Collections.Generic;
+using System.Linq;
+using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using TVApps.Controls;
+using Tizen.Xamarin.Forms.Extension;
 
 namespace TVApps.Views
 {
+    using Tizen = Xamarin.Forms.PlatformConfiguration.Tizen;
     /// <summary>
     /// A custom view for displaying main page of TV Apps
     /// </summary>
     public partial class MainPage : ContentPage
     {
+        private DropdownList sortList;
+        private Button doneButton;
+        private Button cancelButton;
+
         /// <summary>
         /// SubPanel icon's transition height value when it focused.
         /// </summary>
@@ -169,6 +178,121 @@ namespace TVApps.Views
             PageDimBox.IsVisible = false;
             await Task.Delay(1);
             AppList.InitializeFocus();
+
+            List<View> upperList = AppList.GetAppsUpperList().ToList();
+            List<View> lowerList = AppList.GetAppsLowerList().ToList();
+
+            int upperCount = upperList.Count;
+            int lowerCount = lowerList.Count;
+
+            Button prevButton;
+            Button button;
+            Button nextButton;
+
+            for (int i = 1; i < upperCount-1; i++)
+            {
+                prevButton = upperList[i-1].FindByName<Button>("ButtonFocusArea");
+                button = upperList[i].FindByName<Button>("ButtonFocusArea");
+                nextButton = upperList[i + 1].FindByName<Button>("ButtonFocusArea");
+
+                SetFocusChainingLeftAndRight(prevButton, button);
+                SetFocusChainingLeftAndRight(button, nextButton);
+
+                if (i == 1)
+                {
+                    prevButton?.On<Tizen>()?.SetNextFocusDownView(
+                        lowerList[i - 1].FindByName<Button>("ButtonFocusArea"));
+                }
+
+                button?.On<Tizen>()?.SetNextFocusDownView(
+                    lowerList[i].FindByName<Button>("ButtonFocusArea"));
+
+                if (i == upperCount-2)
+                {
+                    button?.On<Tizen>()?.SetNextFocusDownView(lowerList[i].FindByName<Button>("ButtonFocusArea"));
+
+                    nextButton?.On<Tizen>()?.SetNextFocusRightView(nextButton);
+                    nextButton?.On<Tizen>()?.SetNextFocusDownView(
+                        lowerList[lowerCount - 1].FindByName<Button>("ButtonFocusArea"));
+                }
+            }
+
+            for (int i = 1; i < lowerCount - 1; i++)
+            {
+                prevButton = lowerList[i - 1].FindByName<Button>("ButtonFocusArea");
+                button = lowerList[i].FindByName<Button>("ButtonFocusArea");
+                nextButton = lowerList[i + 1].FindByName<Button>("ButtonFocusArea");
+
+                SetFocusChainingLeftAndRight(prevButton, button);
+                SetFocusChainingLeftAndRight(button, nextButton);
+
+                if (i == 1)
+                {
+                    prevButton?.On<Tizen>()?.SetNextFocusUpView(
+                        upperList[i - 1].FindByName<Button>("ButtonFocusArea"));
+                }
+
+                button?.On<Tizen>()?.SetNextFocusUpView(
+                    upperList[i].FindByName<Button>("ButtonFocusArea"));
+
+                if (i == lowerCount-2)
+                {
+                    nextButton?.On<Tizen>()?.SetNextFocusUpView(upperList[i+1].FindByName<Button>("ButtonFocusArea"));
+
+                    if (upperCount > lowerCount)
+                    {
+                        nextButton?.On<Tizen>()?.SetNextFocusRightView(upperList[upperCount-1].FindByName<Button>("ButtonFocusArea"));
+                    }
+                    else
+                    {
+                        nextButton?.On<Tizen>()?.SetNextFocusRightView(nextButton);
+                    }
+                }
+            }
+
+            SetFocusChainingUpAndDownForDefaultMode();
+        }
+
+        private void SetFocusChainingLeftAndRight(Button left, Button right)
+        {
+            left?.On<Tizen>()?.SetNextFocusRightView(right);
+            right?.On<Tizen>()?.SetNextFocusLeftView(left);
+        }
+
+        private void SetFocusChainingUpAndDownForDefaultMode()
+        {
+            List<View> lowerList = AppList.GetAppsLowerList().ToList();
+            sortList = FooterNormal.GetSortDropdownList();
+
+            foreach (var item in lowerList)
+            {
+                Button button = item.FindByName<Button>("ButtonFocusArea");
+                button?.On<Tizen>()?.SetNextFocusDownView(sortList);
+            }
+        }
+
+        private void SetFocusChainingUpAndDownForDeleteMode()
+        {
+            List<View> lowerList = AppList.GetAppsLowerList().ToList();
+            cancelButton = FooterDelete.GetCancelButton();
+
+            foreach (var item in lowerList)
+            {
+                Button button = item.FindByName<Button>("ButtonFocusArea");
+                button?.On<Tizen>()?.SetNextFocusDownView(cancelButton);
+            }
+        }
+
+        private void SetFocusChainingUpAndDownForPinMode()
+        {
+            List<View> lowerList = AppList.GetAppsLowerList().ToList();
+            doneButton = FooterPin.GetDoneButton();
+
+            foreach (var item in lowerList)
+            {
+                Button button = item.FindByName<Button>("ButtonFocusArea");
+                button?.On<Tizen>()?.SetNextFocusDownView(doneButton);
+            }
         }
 
         /// <summary>
@@ -186,17 +310,20 @@ namespace TVApps.Views
                     FooterDelete.IsVisible = false;
                     BackKeyInfo.Text = "Quit";
                     AppList.InitializeFocus();
+                    SetFocusChainingUpAndDownForDefaultMode();
                     break;
                 case AppsStatus.Pin:
                     FooterNormal.IsVisible = false;
                     FooterPin.IsVisible = true;
                     FooterDelete.IsVisible = false;
+                    SetFocusChainingUpAndDownForPinMode();
                     BackKeyInfo.Text = "Back";
                     break;
                 case AppsStatus.Delete:
                     FooterNormal.IsVisible = false;
                     FooterPin.IsVisible = false;
                     FooterDelete.IsVisible = true;
+                    SetFocusChainingUpAndDownForDeleteMode();
                     BackKeyInfo.Text = "Back";
                     break;
                 case AppsStatus.LongPress:
old mode 100644 (file)
new mode 100755 (executable)