[NUI] Sync dalihub and Samsung TizenFX (#349)
[platform/core/csapi/tizenfx.git] / test / NUITestSample / NUIXAMLTestSample / TestMyContents / MediaHubPage.xaml.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using Tizen.NUI;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.UIComponents;
21
22 namespace Tizen.NUI.Examples
23 {
24     public class MediaHubPage : ContentPage
25     {
26         private Vector2 bezierPointIn1 = new Vector2(0.21f, 2);
27         private Vector2 bezierPointIn2 = new Vector2(0.14f, 1);
28         private Vector2 bezierPointOut1 = new Vector2(0.19f, 1);
29         private Vector2 bezierPointOut2 = new Vector2(0.22f, 1);
30         private Animation scaleInAni = null;
31         private Animation scaleOutAni = null;
32         private TableView contentTable = null;
33         private TableView optionList = null;
34
35         public MediaHubPage(Window win) : base (win)
36         {
37             Root.BackgroundImage = "/home/owner/apps_rw/org.tizen.example.NUIXAMLTestSample/res/images/mc_bg.png";
38             ClearEvent += OnClearEvent;
39         }
40
41         /// <summary>
42         /// To make the ContentPage instance be disposed.
43         /// </summary>
44         protected override void Dispose(DisposeTypes type)
45         {
46             if (disposed)
47             {
48                 return;
49             }
50
51             if (type == DisposeTypes.Explicit)
52             {
53                 //Called by User
54                 //Release your own managed resources here.
55                 //You should release all of your own disposable objects here.
56             }
57
58             //Release your own unmanaged resources here.
59             //You should not access any managed member here except static instance.
60             //because the execution order of Finalizes is non-deterministic.
61             scaleInAni?.Dispose();
62             scaleInAni = null;
63             scaleOutAni?.Dispose();
64             scaleOutAni = null;
65             FocusManager.Instance.PreFocusChange -= OnPreFocusChange;
66             ClearEvent -= OnClearEvent;
67
68             base.Dispose(type);
69         }
70
71         public override void SetFocus()
72         {
73         }
74
75         private void OnClearEvent(object obj, EventArgs e)
76         {
77             Root.BackgroundImage = "/home/owner/apps_rw/org.tizen.example.NUIXAMLTestSample/res/images/mc_bg.png";
78         }
79
80         private View OnPreFocusChange(object obj, FocusManager.PreFocusChangeEventArgs e)
81         {
82             if (e.CurrentView != null && !e.ProposedView)
83             {
84                 if (e.Direction == View.FocusDirection.Down)
85                 {
86                     e.ProposedView = optionList;//.GetChildAt(0);
87                 }
88                 if (e.Direction == View.FocusDirection.Up)
89                 {
90                     e.ProposedView = contentTable;//.GetChildAt(0);
91                 }
92                 Tizen.Log.Fatal("NUISamples", "proposed view is null ");
93                 // Console.WriteLine("==================  Proposed view null");
94             }
95             if (!e.ProposedView && !e.CurrentView)
96             {
97                 e.ProposedView = contentTable;//.GetChildAt(0);
98             }
99             return e.ProposedView;
100         }
101
102         private bool OnClicked(object sender, EventArgs e)
103         {
104             if (sender is Button)
105             {
106                 Button button = sender as Button;
107                 button.LabelText = "Click Me";
108             }
109             return true;
110         }
111
112         private void OnFocusGained(object obj, EventArgs e)
113         {
114             View view = obj as View;
115             view.RaiseToTop();
116              if (scaleInAni == null)
117             {
118                 scaleInAni = new Animation();
119             }
120             scaleInAni.Clear();
121             scaleInAni.EndAction = Animation.EndActions.StopFinal;
122             scaleInAni.AnimateTo(view, "Scale", new Vector3(1.2f, 1.2f, 0), 0, 1100, new AlphaFunction(bezierPointIn1, bezierPointIn2));
123             scaleInAni.Play();
124         }
125
126         private void OnFocusLost(object obj, EventArgs e)
127         {
128             View view = obj as View;
129             if (scaleOutAni == null)
130             {
131                 scaleOutAni = new Animation();
132             }
133             scaleOutAni.Clear();
134             scaleOutAni.EndAction = Animation.EndActions.StopFinal;
135             scaleOutAni.AnimateTo(view, "Scale", new Vector3(1.0f, 1.0f, 0), 0, 850, new AlphaFunction(bezierPointOut1, bezierPointOut2));
136             scaleOutAni.Play();
137         }
138
139         private void OnOptionsFocusGained(object obj, EventArgs e)
140         {
141             ImageView view = obj as ImageView;
142             view.ResourceUrl = "/home/owner/apps_rw/org.tizen.example.NUIXAMLTestSample/res/images/r_highlight_bg_focus_9patch.png";
143             view.Border = new Rectangle(14,14,20,20);
144             view.RaiseToTop();
145              if (scaleInAni == null)
146             {
147                 scaleInAni = new Animation();
148             }
149             scaleInAni.Clear();
150             scaleInAni.EndAction = Animation.EndActions.StopFinal;
151             scaleInAni.AnimateTo(view, "Scale", new Vector3(1.2f, 1.2f, 0), 0, 1100, new AlphaFunction(bezierPointIn1, bezierPointIn2));
152             scaleInAni.Play();
153         }
154
155         private void OnOptionsFocusLost(object obj, EventArgs e)
156         {
157             ImageView view = obj as ImageView;
158             view.ResourceUrl = "/home/owner/apps_rw/org.tizen.example.NUIXAMLTestSample/res/images/c_basic_button_white_bg_normal.9.png";
159             view.Border = new Rectangle(4,4,5,5);
160             if (scaleOutAni == null)
161             {
162                 scaleOutAni = new Animation();
163             }
164             scaleOutAni.Clear();
165             scaleOutAni.EndAction = Animation.EndActions.StopFinal;
166             scaleOutAni.AnimateTo(view, "Scale", new Vector3(1.0f, 1.0f, 0), 0, 850, new AlphaFunction(bezierPointOut1, bezierPointOut2));
167             scaleOutAni.Play();
168         }
169     }
170 }