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.
21 namespace MyCSharpExample
23 class Example : NUIApplication
30 protected override void OnCreate()
36 public void Initialize()
40 for (int i = 0; i < num; i++)
43 view[i].Size = new Size(200, 200, 0);
44 view[i].BackgroundColor = Color.Blue;
45 view[i].Position = new Position(300 + i * 300, 300, 0);
46 view[i].Name = "MyView" + i;
47 view[i].Focusable = true;
48 Stage.Instance.GetDefaultLayer().Add(view[i]);
49 view[i].FocusGained += FocusNavigationSample_FocusGained;
50 view[i].FocusLost += FocusNavigationSample_FocusLost;
51 view[i].KeyEvent += FocusNavigationSample_KeyEvent;
54 view[0].RightFocusableView = view[1];
55 view[0].LeftFocusableView = view[1];
56 view[1].RightFocusableView = view[0];
57 view[1].LeftFocusableView = view[0];
59 FocusManager.Instance.SetCurrentFocusView(view[0]);
60 FocusManager.Instance.PreFocusChange += Instance_PreFocusChange;
62 Stage.Instance.Touch += Instance_Touch;
65 private void Instance_Touch(object sender, Stage.TouchEventArgs e)
67 Tizen.Log.Debug("NUI", "stage touched! set key focus as view[0]!");
68 FocusManager.Instance.SetCurrentFocusView(view[0]);
71 private bool FocusNavigationSample_KeyEvent(object source, View.KeyEventArgs e)
73 Tizen.Log.Debug("NUI", "...");
74 View view = source as View;
76 Tizen.Log.Debug("NUI", "NUI-1 " + "View-" + view.Name + ", Pressed-" + e.Key.KeyPressedName + e.Key.State.ToString());
81 private void FocusNavigationSample_FocusLost(object sender, EventArgs e)
83 Tizen.Log.Debug("NUI", "...");
84 View view = sender as View;
85 view.BackgroundColor = Color.Blue;
86 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
88 Tizen.Log.Debug("NUI", "NUI-2 " + "FocusLost-" + view.Name);
91 private void FocusNavigationSample_FocusGained(object sender, EventArgs e)
93 Tizen.Log.Debug("NUI", "...");
94 View view = sender as View;
95 view.BackgroundColor = Color.Red;
96 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
98 Tizen.Log.Debug("NUI", "NUI-3 " + "FocusGained-" + view.Name);
101 private View Instance_PreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
103 Tizen.Log.Debug("NUI", "...");
104 View currentView = (e.CurrentView) ?? lastFocusedView;
105 View nextView = null;
107 Tizen.Log.Debug("NUI", "NUI-4 " + "PreFocusChange-" + e.Direction);
109 if (currentView != null && currentView.HasBody())
110 Tizen.Log.Debug("NUI", "NUI-5 " + " Current-" + currentView.Name);
116 case View.FocusDirection.Left:
117 nextView = currentView.LeftFocusableView;
118 if (nextView == null)
119 Tizen.Log.Debug("NUI", "NUI-6 " + "LeftFocusableView is NULL!!!!");
121 Tizen.Log.Debug("NUI", "NUI-7 " + currentView.Name + ".LeftFocusableView =" + nextView.Name);
123 case View.FocusDirection.Right:
124 nextView = currentView.RightFocusableView;
125 if (nextView == null)
126 Tizen.Log.Debug("NUI", "NUI-8 " + "RightFocusableView is NULL!!!!");
128 Tizen.Log.Debug("NUI", "NUI-9 " + currentView.Name + ".RightFocusableView =" + nextView.Name);
130 case View.FocusDirection.Up:
131 nextView = currentView.UpFocusableView;
132 if (nextView == null)
133 Tizen.Log.Debug("NUI", "NUI-10 " + "UpFocusableView is NULL!!!!");
135 Tizen.Log.Debug("NUI", "NUI-11 " + currentView.Name + ".UpFocusableView =" + nextView.Name);
137 case View.FocusDirection.Down:
138 nextView = currentView.DownFocusableView;
139 if (nextView == null)
140 Tizen.Log.Debug("NUI", "NUI-12 " + "DownFocusableView is NULL!!!!");
142 Tizen.Log.Debug("NUI", "NUI-13 " + currentView.Name + ".DownFocusableView =" + nextView.Name);
145 nextView = null; //added
150 if (e.ProposedView == null)
152 Tizen.Log.Debug("NUI", "NUI-14 " + "ProposedView in NULL!!");
154 else if (e.ProposedView.HasBody())
156 Tizen.Log.Debug("NUI", "NUI-15 " + "ProposedView-" + e.ProposedView.Name);
160 Tizen.Log.Debug("NUI", "NUI-16 " + "ProposedView does NOT have body!!!" + e.ProposedView);
163 nextView = nextView ?? (e.ProposedView) ?? currentView;
164 lastFocusedView = nextView;
166 if (nextView != null && nextView.HasBody())
167 Tizen.Log.Debug("NUI", "NUI-17 " + "Next-" + nextView.Name);
173 static void _Main(string[] args)
175 Example example = new Example();