Implement ContextPopup for Apps
authorGeunsun, Lee <gs86.lee@samsung.com>
Wed, 5 Apr 2017 12:10:50 +0000 (21:10 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:52 +0000 (18:34 +0900)
Change-Id: Ie406b7f0b886940e146678b5cc56d097f108b2da

TVApps/TVApps.TizenTV/TVApps.TizenTV.cs
TVApps/TVApps.TizenTV/TVApps.TizenTV.project.json
TVApps/TVApps/Controls/AppItemCell.xaml
TVApps/TVApps/Controls/TVButton.xaml.cs
TVApps/TVApps/TVApps.csproj
TVApps/TVApps/Views/FooterNormalStatus.xaml
TVApps/TVApps/Views/FooterNormalStatus.xaml.cs
TVApps/TVApps/packages.config

index 2944fb9..c065409 100644 (file)
  * limitations under the License.
  */
 
-using System;
 using LibTVRefCommonPortable.Utils;
 using LibTVRefCommonTizen.Ports;
 using Tizen.Applications;
-using System.Threading;
+using Tizen.Xamarin.Forms.Extension.Renderer;
 
 namespace TVApps.TizenTV
 {
@@ -143,6 +142,7 @@ namespace TVApps.TizenTV
             Xamarin.Forms.DependencyService.Register<FileSystemPort>();
 
             Xamarin.Forms.Platform.Tizen.Forms.Init(instance);
+            TizenFormsExtension.Init();
 
             instance.Run(args);
         }
index 927c4fe..4489f13 100644 (file)
@@ -9,6 +9,7 @@
     "ElmSharp": "1.1.0-beta-018",
     "Microsoft.NETCore.App": "1.1.0",
     "Tizen.Library": "1.0.0-pre3",
+    "Tizen.Xamarin.Forms.Extension": "2.3.4-r214-001",
     "Xamarin.Forms": "2.3.4.214-pre5",
     "Xamarin.Forms.Platform.Tizen": "2.3.4-r214-002"
   },
index 51aff86..f53cb3b 100755 (executable)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+          xmlns:Control="clr-namespace:TVApps.Controls"
           x:Class="TVApps.Controls.AppItemCell">
 
     <RelativeLayout HeightRequest="342"
                 <RowDefinition Height="*" />
             </Grid.RowDefinitions>
             <Grid.RowSpacing>0</Grid.RowSpacing>
-            <Button x:Name="OptionMenuPinToggleButton"
-                    Grid.Row="0"
-                    Command="{Binding OptionMenuPinToggleCommand}"
-                    Text="UNPIN" />
-            <Button x:Name="OptionMenuDeleteButton"
-                    Grid.Row="1"
-                    Command="{Binding OptionMenuDeleteCommand}"
-                    Text="DELETE" />
+          <Control:TVButton x:Name="OptionMenuPinToggleButton"
+                            Grid.Row="0"
+                            Command="{Binding OptionMenuPinToggleCommand}"
+                            Text="UNPIN" />
+          <Control:TVButton x:Name="OptionMenuDeleteButton"
+                            Grid.Row="1"
+                            Command="{Binding OptionMenuDeleteCommand}"
+                            Text="DELETE" />
         </Grid>
 
     </RelativeLayout>
index 00f1a51..d669d9c 100644 (file)
@@ -34,6 +34,8 @@ namespace TVApps.Controls
             set { TitleText.Text = value; }
         }
 
+        public event EventHandler Clicked;
+
         /// <summary>
         /// Identifies the Command bindable property
         /// </summary>
@@ -117,6 +119,7 @@ namespace TVApps.Controls
                 {
                     ButtonGrid.BackgroundColor = Color.FromRgb(255, 255, 255);
                     Command?.Execute(CommandParameter);
+                    Clicked?.Invoke(sender, e);
                 });
             });
         }
index 87434d4..226bd81 100644 (file)
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
+    <Reference Include="Tizen.Xamarin.Forms.Extension, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\..\packages\Tizen.Xamarin.Forms.Extension.2.3.4-r214-001\lib\portable-win+net45+wp80+win81+wpa81\Tizen.Xamarin.Forms.Extension.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <HintPath>..\..\packages\Xamarin.Forms.2.3.4.214-pre5\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll</HintPath>
       <Private>True</Private>
index 1b49ed0..0a023cf 100644 (file)
@@ -2,7 +2,9 @@
 <Grid xmlns="http://xamarin.com/schemas/2014/forms"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:Control="clr-namespace:TVApps.Controls"
-      x:Class="TVApps.Views.FooterNormalStatus">
+      x:Class="TVApps.Views.FooterNormalStatus"
+      PinAppCommand="{Binding ButtonPinAppCommand}"
+      DeleteAppCommand="{Binding ButtonDeleteAppCommand}">
 
   <Grid.Resources>
     <ResourceDictionary>
@@ -29,7 +31,8 @@
   </Grid.ColumnDefinitions>
 
   <StackLayout Grid.Row="0" Grid.Column="1"
-               Orientation="Horizontal">
+               Orientation="Horizontal"
+               HorizontalOptions="End">
 
     <Picker Title="SORT BY" SelectedIndex="{Binding SortOptionIndex}">
       <Picker.Items>
       </Picker.Items>
     </Picker>
 
-    <Control:TVButton Text="PIN"
-                      Command="{Binding ButtonPinAppCommand}"/>
-
-    <Control:TVButton Text="DELETE"
-                      Command="{Binding ButtonDeleteAppCommand}"/>
+    <Control:TVButton Text="Options"
+            Clicked="OnOptionsClicked" />
 
   </StackLayout>
 </Grid>
\ No newline at end of file
index 744a4f4..adb9031 100644 (file)
  */
 
 using Xamarin.Forms;
+using Tizen.Xamarin.Forms.Extension;
+using LibTVRefCommonPortable.Utils;
+using System.Windows.Input;
+using System;
 
 namespace TVApps.Views
 {
@@ -23,12 +27,77 @@ namespace TVApps.Views
     /// </summary>
     public partial class FooterNormalStatus : Grid
     {
+        static ContextPopup popup;
+        private bool isPopupShowing = false;
+
+        public static readonly BindableProperty PinAppCommandProperty = BindableProperty.Create("PinAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
+        public ICommand PinAppCommand
+        {
+            get { return (ICommand)GetValue(PinAppCommandProperty); }
+            set { SetValue(PinAppCommandProperty, value); }
+        }
+
+        public static readonly BindableProperty DeleteAppCommandProperty = BindableProperty.Create("DeleteAppCommand", typeof(Command), typeof(FooterNormalStatus), null);
+        public ICommand DeleteAppCommand
+        {
+            get { return (ICommand)GetValue(DeleteAppCommandProperty); }
+            set { SetValue(DeleteAppCommandProperty, value); }
+        }
+
+
         /// <summary>
         /// A constructor
         /// </summary>
         public FooterNormalStatus()
         {
             InitializeComponent();
+
+            popup = new ContextPopup
+            {
+                IsAutoHidingEnabled = true,
+                Orientation = ContextPopupOrientation.Vertical,
+                DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
+            };
+
+            popup.Items.Add(new ContextPopupItem("PIN"));
+            popup.Items.Add(new ContextPopupItem("DELETE"));
+
+            //TODO: need to change the event callback
+            popup.SelectedIndexChanged += (s, e) =>
+            {
+                var ctxPopup = s as ContextPopup;
+
+                DebuggingUtils.Dbg("selected item : " + (ctxPopup.SelectedItem as ContextPopupItem).Label + " (" + ctxPopup.SelectedIndex + ")");
+                switch (ctxPopup.SelectedIndex)
+                {
+                    case 0: //PIN
+                        PinAppCommand?.Execute("");
+                        break;
+                    case 1: //DELETE
+                        DeleteAppCommand?.Execute("");
+                        break;
+                    default:
+                        break;
+                }
+
+                popup.Dismiss();
+            };
+
+            popup.Dismissed += (s, e) =>
+            {
+                isPopupShowing = false;
+            };
+        }
+
+        void OnOptionsClicked(object sender, EventArgs e)
+        {
+            if (isPopupShowing)
+            {
+                return;
+            }
+
+            popup.Show(sender as View);
+            isPopupShowing = true;
         }
     }
 }
index a5712a9..5d1f186 100644 (file)
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="Tizen.Xamarin.Forms.Extension" version="2.3.4-r214-001" targetFramework="portable45-net45+win8+wp8+wpa81" />
   <package id="Xamarin.Forms" version="2.3.4.214-pre5" targetFramework="portable45-net45+win8+wp8+wpa81" />
 </packages>
\ No newline at end of file