2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
21 namespace MyCSharpExample
\r
23 class Example : NUIApplication
\r
28 View lastFocusedView;
\r
30 protected override void OnCreate()
\r
36 public void Initialize()
\r
40 for (int i = 0; i < num; i++)
\r
42 view[i] = new View();
\r
43 view[i].Size = new Size(200, 200, 0);
\r
44 view[i].BackgroundColor = Color.Blue;
\r
45 view[i].Position = new Position(300 + i * 300, 300, 0);
\r
46 view[i].Name = "MyView" + i;
\r
47 view[i].Focusable = true;
\r
48 Stage.Instance.GetDefaultLayer().Add(view[i]);
\r
49 view[i].FocusGained += FocusNavigationSample_FocusGained;
\r
50 view[i].FocusLost += FocusNavigationSample_FocusLost;
\r
51 view[i].KeyEvent += FocusNavigationSample_KeyEvent;
\r
54 view[0].RightFocusableView = view[1];
\r
55 view[0].LeftFocusableView = view[1];
\r
56 view[1].RightFocusableView = view[0];
\r
57 view[1].LeftFocusableView = view[0];
\r
59 FocusManager.Instance.SetCurrentFocusView(view[0]);
\r
60 FocusManager.Instance.PreFocusChange += Instance_PreFocusChange;
\r
62 Stage.Instance.Touch += Instance_Touch;
\r
65 private void Instance_Touch(object sender, Stage.TouchEventArgs e)
\r
67 Tizen.Log.Debug("NUI", "stage touched! set key focus as lastFocusedView!");
\r
68 FocusManager.Instance.SetCurrentFocusView(lastFocusedView);
\r
71 private bool FocusNavigationSample_KeyEvent(object source, View.KeyEventArgs e)
\r
73 Tizen.Log.Debug("NUI", "...");
\r
74 View view = source as View;
\r
76 Tizen.Log.Debug("NUI", "NUI-1 " + "View-" + view.Name + ", Pressed-" + e.Key.KeyPressedName + e.Key.State.ToString());
\r
81 private void FocusNavigationSample_FocusLost(object sender, EventArgs e)
\r
83 Tizen.Log.Debug("NUI", "...");
\r
84 View view = sender as View;
\r
85 view.BackgroundColor = Color.Blue;
\r
86 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
\r
88 Tizen.Log.Debug("NUI", "NUI-2 " + "FocusLost-" + view.Name);
\r
91 private void FocusNavigationSample_FocusGained(object sender, EventArgs e)
\r
93 Tizen.Log.Debug("NUI", "...");
\r
94 View view = sender as View;
\r
95 view.BackgroundColor = Color.Red;
\r
96 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
\r
98 Tizen.Log.Debug("NUI", "NUI-3 " + "FocusGained-" + view.Name);
\r
101 private View Instance_PreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
\r
103 Tizen.Log.Debug("NUI", "...");
\r
104 View currentView = (e.CurrentView) ?? lastFocusedView;
\r
105 View nextView = null;
\r
107 Tizen.Log.Debug("NUI", "NUI-4 " + "PreFocusChange-" + e.Direction);
\r
109 if (currentView != null && currentView.HasBody())
\r
110 Tizen.Log.Debug("NUI", "NUI-5 " + " Current-" + currentView.Name);
\r
114 switch (e.Direction)
\r
116 case View.FocusDirection.Left:
\r
117 nextView = currentView.LeftFocusableView;
\r
118 if (nextView == null)
\r
119 Tizen.Log.Debug("NUI", "NUI-6 " + "LeftFocusableView is NULL!!!!");
\r
121 Tizen.Log.Debug("NUI", "NUI-7 " + currentView.Name + ".LeftFocusableView =" + nextView.Name);
\r
123 case View.FocusDirection.Right:
\r
124 nextView = currentView.RightFocusableView;
\r
125 if (nextView == null)
\r
126 Tizen.Log.Debug("NUI", "NUI-8 " + "RightFocusableView is NULL!!!!");
\r
128 Tizen.Log.Debug("NUI", "NUI-9 " + currentView.Name + ".RightFocusableView =" + nextView.Name);
\r
130 case View.FocusDirection.Up:
\r
131 nextView = currentView.UpFocusableView;
\r
132 if (nextView == null)
\r
133 Tizen.Log.Debug("NUI", "NUI-10 " + "UpFocusableView is NULL!!!!");
\r
135 Tizen.Log.Debug("NUI", "NUI-11 " + currentView.Name + ".UpFocusableView =" + nextView.Name);
\r
137 case View.FocusDirection.Down:
\r
138 nextView = currentView.DownFocusableView;
\r
139 if (nextView == null)
\r
140 Tizen.Log.Debug("NUI", "NUI-12 " + "DownFocusableView is NULL!!!!");
\r
142 Tizen.Log.Debug("NUI", "NUI-13 " + currentView.Name + ".DownFocusableView =" + nextView.Name);
\r
145 nextView = null; //added
\r
150 if (e.ProposedView == null)
\r
152 Tizen.Log.Debug("NUI", "NUI-14 " + "ProposedView in NULL!!");
\r
154 else if (e.ProposedView.HasBody())
\r
156 Tizen.Log.Debug("NUI", "NUI-15 " + "ProposedView-" + e.ProposedView.Name);
\r
160 Tizen.Log.Debug("NUI", "NUI-16 " + "ProposedView does NOT have body!!!" + e.ProposedView);
\r
163 nextView = nextView ?? (e.ProposedView) ?? currentView;
\r
164 lastFocusedView = nextView;
\r
166 if (nextView != null && nextView.HasBody())
\r
167 Tizen.Log.Debug("NUI", "NUI-17 " + "Next-" + nextView.Name);
\r
173 static void _Main(string[] args)
\r
175 Example example = new Example();
\r