d55de30de2d0486386df5aa5e7ca2b370b5258b3
[platform/core/csapi/tizenfx.git] / test / NUITestSample / NUIXAMLTestSample / TestAmbient / WeatherPage.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.BaseComponents;
19 using Tizen.NUI.UIComponents;
20
21 namespace Tizen.NUI.Examples
22 {
23     public class WeatherPage : ContentPage
24     {
25         private Vector2 bezierPointIn1 = new Vector2(0.21f, 2);
26         private Vector2 bezierPointIn2 = new Vector2(0.14f, 1);
27         private Vector2 bezierPointOut1 = new Vector2(0.19f, 1);
28         private Vector2 bezierPointOut2 = new Vector2(0.22f, 1);
29         private Animation scaleInAni = null;
30         private Animation scaleOutAni = null;
31         private TableView listTable = null;
32
33         public WeatherPage(Window win) : base (win)
34         {
35             Content.BackgroundImage = "/home/tengxb/GitRepo/nui-xaml/TestXaml/res/images/weather/bg.bmp";
36             // Content.BackgroundColor = Color.Green;
37         }
38
39         /// <summary>
40         /// To make the ContentPage instance be disposed.
41         /// </summary>
42         protected override void Dispose(DisposeTypes type)
43         {
44             if (disposed)
45             {
46                 return;
47             }
48
49             if (type == DisposeTypes.Explicit)
50             {
51             }
52
53             scaleInAni?.Dispose();
54             scaleInAni = null;
55             scaleOutAni?.Dispose();
56             scaleOutAni = null;
57             FocusManager.Instance.PreFocusChange -= OnPreFocusChange;
58
59             base.Dispose(type);
60         }
61
62         public override void SetFocus()
63         {
64             listTable = Content.FindChildByName("ListTable") as TableView;
65
66             FocusManager.Instance.FocusIndicator = new View();
67             FocusManager.Instance.SetCurrentFocusView(listTable.GetChildAt(0));
68             FocusManager.Instance.PreFocusChange += OnPreFocusChange;
69         }
70
71         private View OnPreFocusChange(object obj, FocusManager.PreFocusChangeEventArgs e)
72         {
73             if (!e.ProposedView && !e.CurrentView)
74             {
75                 e.ProposedView = listTable.GetChildAt(new TableView.CellPosition(0, 0)); ;
76             }
77             return e.ProposedView;
78         }
79
80         private void OnFocusGained(object obj, EventArgs e)
81         {
82             ImageView view = obj as ImageView;
83
84             view.RaiseToTop();
85             if (scaleInAni == null)
86             {
87                 scaleInAni = new Animation();
88             }
89             scaleInAni.Clear();
90             scaleInAni.EndAction = Animation.EndActions.StopFinal;
91             scaleInAni.AnimateTo(view, "Scale", new Vector3(1.2f, 1.2f, 0), 0, 1100, new AlphaFunction(bezierPointIn1, bezierPointIn2));
92             scaleInAni.Play();
93         }
94
95         private void OnFocusLost(object obj, EventArgs e)
96         {
97             ImageView view = obj as ImageView;
98
99             if (scaleOutAni == null)
100             {
101                 scaleOutAni = new Animation();
102             }
103             scaleOutAni.Clear();
104             scaleOutAni.EndAction = Animation.EndActions.StopFinal;
105             scaleOutAni.AnimateTo(view, "Scale", new Vector3(1.0f, 1.0f, 0), 0, 850, new AlphaFunction(bezierPointOut1, bezierPointOut2));
106             scaleOutAni.Play();
107         }
108     }
109 }