Implement back key event handling for the image viewer
authorGeunsun, Lee <gs86.lee@samsung.com>
Fri, 28 Apr 2017 02:12:48 +0000 (11:12 +0900)
committerGeunSun Lee <gs86.lee@samsung.com>
Fri, 28 Apr 2017 02:31:40 +0000 (11:31 +0900)
Change-Id: I7e2bfe112199d4026b23f6091fd86da5a1077091

TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs

index 1f4a14b..024d053 100755 (executable)
@@ -40,6 +40,11 @@ namespace TVMediaHub.Tizen.Views
         private bool isSpeedOptionPopupShowing = false;
         private bool isEffectOptionPopupShowing = false;
         private bool isNaviRunning = false;
+
+        private ContextPopup optionPopup = null;
+        private ContextPopup speedOptionPopup = null;
+        private ContextPopup effectOptionPopup = null;
+
         NaviDirection naviDirection = default(NaviDirection);
 
         private object focusedButton = null;
@@ -49,7 +54,6 @@ namespace TVMediaHub.Tizen.Views
         private ImageViewerInfomation prevContent = null;
 
         public static readonly BindableProperty SavedRotationCommandProperty = BindableProperty.Create("SavedRotationCommand", typeof(ICommand), typeof(ImageViewer), default(ICommand));
-
         public ICommand SavedRotationCommand
         {
             get { return (ICommand)GetValue(SavedRotationCommandProperty); }
@@ -322,18 +326,21 @@ namespace TVMediaHub.Tizen.Views
 
         private void InitializeButtonFocusImage()
         {
+            int focusedSacle = 3;
+            int unfocusedScale = 1;
+
             RotateBtn.Focused += (s, e) =>
             {
                 focusedButton = s;
 
-                RotateBg.ScaleTo(3, 250);
+                RotateBg.ScaleTo(focusedSacle, 250);
                 RotateBg.FadeTo(1, 250);
             };
             ZoomBtn.Focused += (s, e) =>
             {
                 focusedButton = s;
 
-                ZoomBg.ScaleTo(3, 250);
+                ZoomBg.ScaleTo(focusedSacle, 250);
                 ZoomBg.FadeTo(1, 250);
             };
             LeftNaviBtn.Focused += (s, e) =>
@@ -341,59 +348,59 @@ namespace TVMediaHub.Tizen.Views
                 focusedButton = s;
 
                 LeftNaviBg.TranslationX = 7;
-                LeftNaviBg.ScaleTo(3, 250);
+                LeftNaviBg.ScaleTo(focusedSacle, 250);
                 LeftNaviBg.FadeTo(1, 250);
             };
             RightNaviBtn.Focused += (s, e) =>
             {
                 focusedButton = s;
 
-                RightNaviBg.ScaleTo(3, 250);
+                RightNaviBg.ScaleTo(focusedSacle, 250);
                 RightNaviBg.FadeTo(1, 250);
             };
             SlideShowBtn.Focused += (s, e) =>
             {
                 focusedButton = s;
 
-                SlideShowBg.ScaleTo(3, 250);
+                SlideShowBg.ScaleTo(focusedSacle, 250);
                 SlideShowBg.FadeTo(1, 250);
             };
             OptionBtn.Focused += (s, e) =>
             {
                 focusedButton = s;
 
-                OptionBG.ScaleTo(3, 250);
+                OptionBG.ScaleTo(focusedSacle, 250);
                 OptionBG.FadeTo(1, 250);
             };
 
             RotateBtn.Unfocused += (s, e) =>
             {
-                RotateBg.ScaleTo(1, 250);
+                RotateBg.ScaleTo(unfocusedScale, 250);
                 RotateBg.FadeTo(0, 250);
             };
             ZoomBtn.Unfocused += (s, e) =>
             {
-                ZoomBg.ScaleTo(1, 250);
+                ZoomBg.ScaleTo(unfocusedScale, 250);
                 ZoomBg.FadeTo(0, 250);
             };
             LeftNaviBtn.Unfocused += (s, e) =>
             {
-                LeftNaviBg.ScaleTo(1, 250);
+                LeftNaviBg.ScaleTo(unfocusedScale, 250);
                 LeftNaviBg.FadeTo(0, 250);
             };
             RightNaviBtn.Unfocused += (s, e) =>
             {
-                RightNaviBg.ScaleTo(1, 250);
+                RightNaviBg.ScaleTo(unfocusedScale, 250);
                 RightNaviBg.FadeTo(0, 250);
             };
             SlideShowBtn.Unfocused += (s, e) =>
             {
-                SlideShowBg.ScaleTo(1, 250);
+                SlideShowBg.ScaleTo(unfocusedScale, 250);
                 SlideShowBg.FadeTo(0, 250);
             };
             OptionBtn.Unfocused += (s, e) =>
             {
-                OptionBG.ScaleTo(1, 250);
+                OptionBG.ScaleTo(unfocusedScale, 250);
                 OptionBG.FadeTo(0, 250);
             };
         }
@@ -474,17 +481,17 @@ namespace TVMediaHub.Tizen.Views
                 return;
             }
 
-            ContextPopup popup = new ContextPopup
+            optionPopup = new ContextPopup
             {
                 IsAutoHidingEnabled = true,
                 Orientation = ContextPopupOrientation.Vertical,
                 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
             };
 
-            popup.Items.Add(new ContextPopupItem("  SLIDE SHOW SPEED  "));
-            popup.Items.Add(new ContextPopupItem("  SLIDE SHOW EFFECT  "));
+            optionPopup.Items.Add(new ContextPopupItem("  SLIDE SHOW SPEED  "));
+            optionPopup.Items.Add(new ContextPopupItem("  SLIDE SHOW EFFECT  "));
 
-            popup.SelectedIndexChanged += (s, args) =>
+            optionPopup.SelectedIndexChanged += (s, args) =>
             {
                 var ctxPopup = s as ContextPopup;
 
@@ -503,15 +510,15 @@ namespace TVMediaHub.Tizen.Views
                         break;
                 }
 
-                popup.Dismiss();
+                optionPopup.Dismiss();
             };
 
-            popup.Dismissed += (s, args) =>
+            optionPopup.Dismissed += (s, args) =>
             {
                 isOptionPopupShowing = false;
             };
 
-            popup.Show(PopupAnchor, (340 / 2), 144);
+            optionPopup.Show(PopupAnchor, (PopupAnchor.Width / 2), PopupAnchor.Height);
             isOptionPopupShowing = true;
         }
 
@@ -522,16 +529,17 @@ namespace TVMediaHub.Tizen.Views
                 return;
             }
 
-            ContextPopup speedOptionPopup = new ContextPopup
+            speedOptionPopup = new ContextPopup
             {
                 IsAutoHidingEnabled = true,
                 Orientation = ContextPopupOrientation.Vertical,
                 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
             };
 
-            speedOptionPopup.Items.Add(new ContextPopupItem("               Normal               "));
-            speedOptionPopup.Items.Add(new ContextPopupItem("               Slow               "));
-            speedOptionPopup.Items.Add(new ContextPopupItem("               Fast               "));
+            speedOptionPopup.Items.Add(new ContextPopupItem("              NORMAL             "));
+            speedOptionPopup.Items.Add(new ContextPopupItem("              SLOW              "));
+            speedOptionPopup.Items.Add(new ContextPopupItem("              FAST              "));
+
 
             speedOptionPopup.SelectedIndexChanged += (s, e) =>
             {
@@ -567,7 +575,7 @@ namespace TVMediaHub.Tizen.Views
                 createOptionPopup();
             };
 
-            speedOptionPopup.Show(PopupAnchor, (340 / 2), 144);
+            speedOptionPopup.Show(PopupAnchor, (PopupAnchor.Width / 2), PopupAnchor.Height);
             isSpeedOptionPopupShowing = true;
         }
 
@@ -578,15 +586,15 @@ namespace TVMediaHub.Tizen.Views
                 return;
             }
 
-            ContextPopup effectOptionPopup = new ContextPopup
+            effectOptionPopup = new ContextPopup
             {
                 IsAutoHidingEnabled = true,
                 Orientation = ContextPopupOrientation.Vertical,
                 DirectionPriorities = new ContextPopupDirectionPriorities(ContextPopupDirection.Up, ContextPopupDirection.Right, ContextPopupDirection.Left, ContextPopupDirection.Down),
             };
 
-            effectOptionPopup.Items.Add(new ContextPopupItem("              Dissolve              "));
-            effectOptionPopup.Items.Add(new ContextPopupItem("              Fade out              "));
+            effectOptionPopup.Items.Add(new ContextPopupItem("            DISSOLVE            "));
+            effectOptionPopup.Items.Add(new ContextPopupItem("            FADE OUT            "));
 
             effectOptionPopup.SelectedIndexChanged += (s, e) =>
             {
@@ -619,7 +627,7 @@ namespace TVMediaHub.Tizen.Views
 
             };
 
-            effectOptionPopup.Show(PopupAnchor, (340 / 2), 144);
+            effectOptionPopup.Show(PopupAnchor, (PopupAnchor.Width / 2), PopupAnchor.Height);
             isEffectOptionPopupShowing = true;
         }
 
@@ -657,5 +665,33 @@ namespace TVMediaHub.Tizen.Views
             focusedBtnBG.Opacity = 0;
             focusedCustomImageBtn.OnButtonReleased();
         }
+
+        protected override bool OnBackButtonPressed()
+        {
+            if (isOptionPopupShowing)
+            {
+                optionPopup.Dismiss();
+
+                return true;
+            }
+
+            if (isSpeedOptionPopupShowing)
+            {
+                speedOptionPopup.Dismiss();
+
+                return true;
+            }
+
+            if (isEffectOptionPopupShowing)
+            {
+                effectOptionPopup.Dismiss();
+
+                return true;
+            }
+
+            Navigation.PopAsync();
+
+            return true;
+        }
     }
 }