Implement Menu key event for Apps
authorGeunsun, Lee <gs86.lee@samsung.com>
Wed, 22 Mar 2017 10:29:01 +0000 (19:29 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:49 +0000 (18:34 +0900)
Change-Id: I6233e0f77d345d3f971809cf9caf119a24a1497b

LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs
TVApps/TVApps.TizenTV/TVApps.TizenTV.cs
TVApps/TVApps/Controls/AppItemCell.xaml
TVApps/TVApps/Controls/AppItemCell.xaml.cs
TVApps/TVApps/Controls/AppListView.xaml.cs
TVApps/TVApps/TVApps.cs
TVApps/TVApps/ViewModels/AppsHolder.cs
TVApps/TVApps/ViewModels/MainPageViewModel.cs
TVApps/TVApps/Views/MainPage.xaml
TVApps/TVApps/Views/MainPage.xaml.cs

index 4ef066a..8652033 100644 (file)
  */
 
 using System;
-using System.Collections.Generic;
 using System.Xml.Serialization;
 
-
 namespace LibTVRefCommonPortable.DataModels
 {
     public class AppShortcutInfo : ShortcutInfo
@@ -92,6 +90,27 @@ namespace LibTVRefCommonPortable.DataModels
         }
 
         [XmlIgnore]
+        private bool isFocused { get; set; }
+
+        [XmlIgnore]
+        public bool IsFocused
+        {
+            get
+            {
+                return isFocused;
+            }
+
+            set
+            {
+                if (isFocused != value)
+                {
+                    isFocused = value;
+                    OnPropertyChanged("IsFocused");
+                }
+            }
+        }
+
+        [XmlIgnore]
         private bool isDim;
 
         [XmlIgnore]
index 1fc292d..050b7e5 100644 (file)
@@ -18,6 +18,7 @@ using System;
 using LibTVRefCommonPortable.Utils;
 using LibTVRefCommonTizen.Ports;
 using Tizen.Applications;
+using System.Threading;
 
 namespace TVApps.TizenTV
 {
@@ -25,6 +26,7 @@ namespace TVApps.TizenTV
     {
         private static Program instance;
         private IPlatformNotification notification;
+        private Timer timerForKeyGrab;
 
         public static string AppResourcePath
         {
@@ -37,6 +39,13 @@ namespace TVApps.TizenTV
             get;
             private set;
         }
+        private void CallbackForKeyGrab(Object state)
+        {
+            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
+            timerForKeyGrab.Dispose();
+            timerForKeyGrab = null;
+            DebuggingUtils.Dbg("KeyGrab finished");
+        }
 
         protected override void OnCreate()
         {
@@ -51,6 +60,23 @@ namespace TVApps.TizenTV
             LoadApplication(app);
 
             PackageManagerPort.RegisterCallbacks(notification);
+
+            MainWindow.KeyUp += KeyUpListener;
+
+            TimerCallback timerDelegate = new TimerCallback(CallbackForKeyGrab);
+            timerForKeyGrab = new Timer(timerDelegate, MainWindow, 3000, 0);
+        }
+
+        private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        {
+            DebuggingUtils.Dbg("[TVApps.TizenTV.cs] Key Pressed :" + e.KeyName);
+            if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
+            {
+                if (notification != null)
+                {
+                    notification.OnMenuKeyPressed();
+                }
+            }
         }
 
         protected override void OnTerminate()
@@ -60,6 +86,8 @@ namespace TVApps.TizenTV
             notification = null;
             PackageManagerPort.DeregisterCallbacks();
             MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName);
+            MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
+
         }
 
         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
index 8632379..a5fd78d 100755 (executable)
@@ -80,7 +80,7 @@
       <Button Grid.Row="1" Text="DELETE" />
     </Grid>
 
-    <!-- This BoxView is temporary code for Long Press test -->
+    <!-- TODO: This BoxView is temporary code for Long Press test -->
     <BoxView x:Name="ItemDim"
              Color="Black"
              Opacity="0.0"
index 8a26a9f..0016b6a 100755 (executable)
@@ -61,6 +61,13 @@ namespace TVApps.Controls
             set { SetValue(IsDimProperty, value); }
         }
 
+        public static readonly BindableProperty IsFocusedProperty = BindableProperty.Create("IsFocused", typeof(bool), typeof(AppItemCell), default(bool), BindingMode.TwoWay);
+        public bool IsFocused
+        {
+            get { return (bool)GetValue(IsFocusedProperty); }
+            set { SetValue(IsFocusedProperty, value); }
+        }
+
         public AppItemCell()
         {
             InitializeComponent();
@@ -105,11 +112,7 @@ namespace TVApps.Controls
             }
             else if (e.PropertyName.CompareTo("IsShowOptions") == 0)
             {
-
-                // Set the icon status to default
-                ButtonImage.ScaleTo(1.0, 50);
-                ButtonImage.TranslateTo(0.0, 0.0, 100);
-                TextArea.TranslateTo(0.0, 0.0, 50);
+                changeDefaultIconSize();
 
                 if (IsShowOptions)
                 {
@@ -139,6 +142,33 @@ namespace TVApps.Controls
             }
         }
 
+        public void changeDefaultIconSize()
+        {
+            ButtonImage.ScaleTo(1.0, 50);
+            ButtonImage.TranslateTo(0.0, 0.0, 100);
+            TextArea.TranslateTo(0.0, 0.0, 50);
+        }
+
+        public void ShowOptionMenu()
+        {
+            changeDefaultIconSize();
+
+            ButtonImage.TranslateTo(0, -90, 100);
+            TextArea.TranslateTo(0, -90, 100);
+            TextArea.FadeTo(0.0, 100);
+            OptionMenuArea.TranslateTo(0, -144, 100);
+        }
+
+        public void HideOptionMenu()
+        {
+            changeDefaultIconSize();
+
+            ButtonImage.TranslateTo(0, 0, 100);
+            TextArea.TranslateTo(0, 0, 100);
+            TextArea.FadeTo(0.99, 100);
+            OptionMenuArea.TranslateTo(0, 0, 100);
+        }
+
         private void ButtonTitle_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName == "Width")
@@ -154,6 +184,9 @@ namespace TVApps.Controls
 
         private void OnFocused(object sender, EventArgs e)
         {
+            IsFocused = true;
+            OnPropertyChanged("IsFocused");
+
             OnFocusedCommand?.Execute("");
             ButtonImage.ScaleTo(1.32, 300);
             ButtonImage.TranslateTo(0.0, 2.0, 300);
@@ -169,6 +202,9 @@ namespace TVApps.Controls
 
         private void OnUnFocused(object sender, EventArgs e)
         {
+            IsFocused = false;
+            OnPropertyChanged("IsFocused");
+
             ButtonImage.ScaleTo(1.0, 300);
             ButtonImage.TranslateTo(0.0, 0.0, 300);
             TextArea.TranslateTo(0.0, 0.0, 300);
index 1d03da4..e607abc 100644 (file)
@@ -48,6 +48,12 @@ namespace TVApps.Controls
         }
 
         private int AppCount;
+        private ViewCell FocusedItem;
+
+        public ViewCell GetFocusedItem()
+        {
+            return FocusedItem;
+        }
 
         public bool IsFirstItemFocused
         {
@@ -58,11 +64,10 @@ namespace TVApps.Controls
                     return true;
                 }
 
-                return AppUpperList.Children[0].IsFocused;
+                return AppUpperList.Children[0].FindByName<Button>("ButtonFocusArea").IsFocused;
             }
         }
 
-
         public AppListView()
         {
             InitializeComponent();
@@ -99,6 +104,7 @@ namespace TVApps.Controls
                 viewCell.SetBinding(AppItemCell.IsCheckedProperty, new Binding("BindingContext.IsChecked", source: viewCell.View));
                 viewCell.SetBinding(AppItemCell.IsShowOptionsProperty, new Binding("BindingContext.IsShowOptions", source: viewCell.View));
                 viewCell.SetBinding(AppItemCell.IsDimProperty, new Binding("BindingContext.IsDim", source: viewCell.View));
+                viewCell.SetBinding(AppItemCell.IsFocusedProperty, new Binding("BindingContext.IsFocused", mode: BindingMode.TwoWay, source: viewCell.View));
                 viewCell.OnClickedCommand = new Command(() =>
 
                 {
@@ -107,6 +113,7 @@ namespace TVApps.Controls
                 var index = AppCount / 2;
                 viewCell.OnFocusedCommand = new Command(() =>
                 {
+                    FocusedItem = viewCell;
                     ScrollToIndex(index);
                 });
                 if (AppCount % 2 == 0)
index 33d3d16..d5948b4 100755 (executable)
@@ -28,6 +28,7 @@ namespace TVApps
 
     public class App : Application, IPlatformNotification
     {
+        private static EventHandler<TVAppsEventArgs> MenuKeyListener;
         private static EventHandler<TVAppsEventArgs> AppInstalledListener;
         private static EventHandler<TVAppsEventArgs> AppUninstalledListener;
         private static EventHandler<TVAppsEventArgs> PinAppRequestListener;
@@ -52,6 +53,11 @@ namespace TVApps
 
         }
 
+        public static void SetMenuKeyListener(EventHandler<TVAppsEventArgs> listener)
+        {
+            MenuKeyListener += listener;
+        }
+
         public static void SetAppInstalledListener(EventHandler<TVAppsEventArgs> listener)
         {
             AppInstalledListener += listener;
@@ -101,6 +107,12 @@ namespace TVApps
 
         public void OnMenuKeyPressed()
         {
+            DebuggingUtils.Dbg("[APPS] Menu Key is pressed");
+            MenuKeyListener.Invoke(this, new TVAppsEventArgs()
+            {
+                arg = "",
+            });
         }
+
     }
 }
index 603ddcc..fd46813 100644 (file)
@@ -213,7 +213,14 @@ namespace TVApps.ViewModels
                         item.IsChecked = item.IsPinned;
                         break;
                     case AppsStatus.LongPress:
-                        item.IsDim = true;
+                        if (item.IsFocused)
+                        {
+                            item.IsShowOptions = true;
+                        }
+                        else
+                        {
+                            item.IsDim = true;
+                        }
                         break;
                     case AppsStatus.Delete:
                         item.IsChecked = false;
index 0e5fb1b..755e5c6 100644 (file)
@@ -153,31 +153,12 @@ namespace TVApps.ViewModels
 
             SetLongPressCommand = new Command((appId) =>
             {
-                DebuggingUtils.Dbg(" === Set LongPress AppID : " + appId);
-
-                // 1. Change Apps status to LongPress
-                // LongPress of AppsStatus will change ItemCell to be dimmed
                 ChangeCurrentStatus(AppsStatus.LongPress);
-
-                // 2. The selected icon on apps list will be moved
-                appsHolder.ShowLongPressOption(appId.ToString());
-
-                // 3. The option menu will be shown
-
             });
 
             UnSetLongPressCommand = new Command((appId) =>
             {
-                DebuggingUtils.Dbg(" === Unset LongPress AppID : " + appId);
-
-                // 1. change Apps status to Default
-                // Default of AppsStatus will change ItemCell to be normal
-                // 2. The option menu will be hidden
                 ChangeCurrentStatus(AppsStatus.Default);
-
-                // 3. The selected icon will be moved
-                //appsHolder.HideLongPressOption(appId.ToString());
-
             });
 
 
index e7a3ec9..459ccd9 100755 (executable)
@@ -79,7 +79,7 @@
         <ColumnDefinition Width="50*" />
       </Grid.ColumnDefinitions>
 
-      <!-- This StackLayout is temporary code for Long Press test -->
+      <!-- TODO: This StackLayout is temporary code for Long Press test -->
       <Button Grid.Row="0" Grid.Column="1"
               Style="{StaticResource button}"
               Command="{Binding SetLongPressCommand}"
@@ -89,7 +89,6 @@
       <Button Grid.Row="2" Grid.Column="1"
               Style="{StaticResource button}"
               Command="{Binding UnSetLongPressCommand}"
-              CommandParameter="org.tizen.example.TVHome.TizenTV"
               VerticalOptions="FillAndExpand"
               HorizontalOptions="FillAndExpand"/>
 
index efbcf99..8561189 100644 (file)
@@ -22,6 +22,7 @@ using System.ComponentModel;
 using LibTVRefCommonPortable.Utils;
 using System.Threading;
 using System.Threading.Tasks;
+using TVApps.Controls;
 
 namespace TVApps.Views
 {
@@ -42,6 +43,17 @@ namespace TVApps.Views
             InitializeComponent();
             PropertyChanged += MainPage_PropertyChanged;
             SetCurrntStatus(AppsStatus.Default);
+
+            // TODO: This code is temporary for menu option test
+            App.SetMenuKeyListener((e, arg) =>
+            {
+                DebuggingUtils.Dbg("[Apps] Menu key is pressed");
+
+                if (CurrentStatus != AppsStatus.LongPress)
+                {
+                    MessagingCenter.Send<MainPage, string>(this, "ChangeCurrentStatus", AppsStatus.LongPress.ToString());
+                }
+            });
         }
 
         private void SetCurrntStatus(AppsStatus status)
@@ -53,6 +65,7 @@ namespace TVApps.Views
                     FooterPin.IsVisible = false;
                     FooterDelete.IsVisible = false;
                     BackKeyInfo.Text = "Quit";
+                    AppList.InitializeFocus();
                     break;
                 case AppsStatus.Pin:
                     FooterNormal.IsVisible = false;
@@ -73,8 +86,6 @@ namespace TVApps.Views
                     BackKeyInfo.Text = "Back";
                     break;
             }
-
-            AppList.InitializeFocus();
         }
 
         private void MainPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -85,9 +96,6 @@ namespace TVApps.Views
             }
         }
 
-        // TODO : remove this
-        private static bool IsBackKeyPressed;
-
         private async Task<bool> OnBackKeyPressedAtMain()
         {
             DebuggingUtils.Dbg("OnBackKeyPressedAtMain - first item focused? " + AppList.IsFirstItemFocused);
@@ -97,10 +105,8 @@ namespace TVApps.Views
                 MessagingCenter.Send<MainPage, string>(this, "ChangeCurrentStatus", AppsStatus.Default.ToString());
             }
 
-            if (!AppList.IsFirstItemFocused &&
-                IsBackKeyPressed == false)
+            if (!AppList.IsFirstItemFocused)
             {
-                IsBackKeyPressed = true;
                 DebuggingUtils.Dbg("OnBackKeyPressedAtMain - focus move");
                 AppList.InitializeFocus();
                 return true;