2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using Tizen.NUI.BaseComponents;
22 namespace MyCSharpExample
24 class Example : NUIApplication
31 protected override void OnCreate()
37 public void Initialize()
41 for (int i = 0; i < num; i++)
44 view[i].Size2D = new Size2D(200, 200);
45 view[i].BackgroundColor = Color.Blue;
46 view[i].Position = new Position(300 + i * 300, 300, 0);
47 view[i].Name = "MyView" + i;
48 view[i].Focusable = true;
49 Window.Instance.Add(view[i]);
50 view[i].FocusGained += FocusNavigationSample_FocusGained;
51 view[i].FocusLost += FocusNavigationSample_FocusLost;
52 view[i].KeyEvent += FocusNavigationSample_KeyEvent;
55 view[0].RightFocusableView = view[1];
56 view[0].LeftFocusableView = view[1];
57 view[1].RightFocusableView = view[0];
58 view[1].LeftFocusableView = view[0];
60 FocusManager.Instance.SetCurrentFocusView(view[0]);
61 FocusManager.Instance.PreFocusChange += Instance_PreFocusChange;
63 Window.Instance.TouchEvent += Instance_Touch;
66 private void Instance_Touch(object sender, Window.TouchEventArgs e)
68 Tizen.Log.Debug("NUI", "window touched! set key focus as view[0]!");
69 FocusManager.Instance.SetCurrentFocusView(view[0]);
72 private bool FocusNavigationSample_KeyEvent(object source, View.KeyEventArgs e)
74 Tizen.Log.Debug("NUI", "...");
75 View view = source as View;
77 Tizen.Log.Debug("NUI", "NUI-1 " + "View-" + view.Name + ", Pressed-" + e.Key.KeyPressedName + e.Key.State.ToString());
82 private void FocusNavigationSample_FocusLost(object sender, EventArgs e)
84 Tizen.Log.Debug("NUI", "...");
85 View view = sender as View;
86 view.BackgroundColor = Color.Blue;
87 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
89 Tizen.Log.Debug("NUI", "NUI-2 " + "FocusLost-" + view.Name);
92 private void FocusNavigationSample_FocusGained(object sender, EventArgs e)
94 Tizen.Log.Debug("NUI", "...");
95 View view = sender as View;
96 view.BackgroundColor = Color.Red;
97 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
99 Tizen.Log.Debug("NUI", "NUI-3 " + "FocusGained-" + view.Name);
102 private View Instance_PreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
104 Tizen.Log.Debug("NUI", "...");
105 View currentView = (e.CurrentView) ?? lastFocusedView;
106 View nextView = null;
108 Tizen.Log.Debug("NUI", "NUI-4 " + "PreFocusChange-" + e.Direction);
110 if (currentView != null && currentView.HasBody())
111 Tizen.Log.Debug("NUI", "NUI-5 " + " Current-" + currentView.Name);
117 case View.FocusDirection.Left:
118 nextView = currentView.LeftFocusableView;
119 if (nextView == null)
120 Tizen.Log.Debug("NUI", "NUI-6 " + "LeftFocusableView is NULL!!!!");
122 Tizen.Log.Debug("NUI", "NUI-7 " + currentView.Name + ".LeftFocusableView =" + nextView.Name);
124 case View.FocusDirection.Right:
125 nextView = currentView.RightFocusableView;
126 if (nextView == null)
127 Tizen.Log.Debug("NUI", "NUI-8 " + "RightFocusableView is NULL!!!!");
129 Tizen.Log.Debug("NUI", "NUI-9 " + currentView.Name + ".RightFocusableView =" + nextView.Name);
131 case View.FocusDirection.Up:
132 nextView = currentView.UpFocusableView;
133 if (nextView == null)
134 Tizen.Log.Debug("NUI", "NUI-10 " + "UpFocusableView is NULL!!!!");
136 Tizen.Log.Debug("NUI", "NUI-11 " + currentView.Name + ".UpFocusableView =" + nextView.Name);
138 case View.FocusDirection.Down:
139 nextView = currentView.DownFocusableView;
140 if (nextView == null)
141 Tizen.Log.Debug("NUI", "NUI-12 " + "DownFocusableView is NULL!!!!");
143 Tizen.Log.Debug("NUI", "NUI-13 " + currentView.Name + ".DownFocusableView =" + nextView.Name);
146 nextView = null; //added
151 if (e.ProposedView == null)
153 Tizen.Log.Debug("NUI", "NUI-14 " + "ProposedView in NULL!!");
155 else if (e.ProposedView.HasBody())
157 Tizen.Log.Debug("NUI", "NUI-15 " + "ProposedView-" + e.ProposedView.Name);
161 Tizen.Log.Debug("NUI", "NUI-16 " + "ProposedView does NOT have body!!!" + e.ProposedView);
164 nextView = nextView ?? (e.ProposedView) ?? currentView;
165 lastFocusedView = nextView;
167 if (nextView != null && nextView.HasBody())
168 Tizen.Log.Debug("NUI", "NUI-17 " + "Next-" + nextView.Name);
174 static void _Main(string[] args)
176 Example example = new Example();