2 * Copyright (c) 2016 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.
19 using System.Runtime.InteropServices;
22 namespace MyCSharpExample
24 // A spin control (for continously changing values when users can easily predict a set of values)
28 private Dali.Application _application;
29 private Spin _spinYear; // spin control for year
30 private Spin _spinMonth; // spin control for month
31 private Spin _spinDay; // spin control for day
32 private Builder _builder; // DALi Builder
34 public Example(Dali.Application application)
36 _application = application;
37 _application.Initialized += Initialize;
40 public void Initialize(object source, NUIApplicationInitEventArgs e)
43 Stage stage = Stage.GetCurrent();
44 stage.BackgroundColor = Color.White;
46 // load date JSON template...
48 _builder = new Builder ();
50 // Optional constant to see logging information coming out
51 // of DALi JSON parser (builder)
52 Property.Map constants = new Property.Map();
53 constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL", new Property.Value( "Verbose") );
54 _builder.AddConstants( constants );
56 _builder.LoadFromFile( "./json/date-picker.json" );
58 // create the date-picker from the template in the json file
59 BaseHandle handle = _builder.Create( "date-picker");
61 Actor actorTree = Actor.DownCast( handle );
63 stage.Add( actorTree );
65 Actor year = actorTree.FindChildByName("Year");
66 Actor month = actorTree.FindChildByName("Month" );
67 Actor day = actorTree.FindChildByName("Day");
69 // need to get the actual C# View associated with the actor,
70 _spinYear = (Spin ) ViewRegistry.GetCustomViewFromActor( year );
71 _spinMonth = (Spin ) ViewRegistry.GetCustomViewFromActor( month );
72 _spinDay = (Spin ) ViewRegistry.GetCustomViewFromActor( day );
74 _spinYear.Value = 2099;
79 _spinYear.SetKeyboardFocusable(true);
80 _spinMonth.SetKeyboardFocusable(true);
81 _spinDay.SetKeyboardFocusable(true);
84 FocusManager keyboardFocusManager = FocusManager.Instance;
85 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
86 keyboardFocusManager.FocusedActorEnterKeyPressed += OnFocusedActorEnterKeyPressed;
90 private Actor OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
92 Actor nextFocusActor = e.Proposed;
94 // When nothing has been focused initially, focus the text field in the first spin
95 if (!e.Current && !e.Proposed)
97 nextFocusActor = _spinYear.SpinText;
99 else if(e.Direction == View.KeyboardFocus.Direction.LEFT)
101 // Move the focus to the spin in the left of the current focused spin
102 if(e.Current == _spinMonth.SpinText)
104 nextFocusActor = _spinYear.SpinText;
106 else if(e.Current == _spinDay.SpinText)
108 nextFocusActor = _spinMonth.SpinText;
111 else if(e.Direction == View.KeyboardFocus.Direction.RIGHT)
113 // Move the focus to the spin in the right of the current focused spin
114 if(e.Current == _spinYear.SpinText)
116 nextFocusActor = _spinMonth.SpinText;
118 else if(e.Current == _spinMonth.SpinText)
120 nextFocusActor = _spinDay.SpinText;
124 return nextFocusActor;
127 private void OnFocusedActorEnterKeyPressed(object source, FocusManager.FocusedActorEnterKeyEventArgs e)
129 // Make the text field in the current focused spin to take the key input
130 KeyInputFocusManager manager = KeyInputFocusManager.Get();
132 if (e.Actor == _spinYear.SpinText)
134 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
136 manager.SetFocus(_spinYear.SpinText);
139 else if (e.Actor == _spinMonth.SpinText)
141 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
143 manager.SetFocus(_spinMonth.SpinText);
146 else if (e.Actor == _spinDay.SpinText)
148 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
150 manager.SetFocus(_spinDay.SpinText);
155 public void MainLoop()
157 _application.MainLoop ();
161 /// The main entry point for the application.
164 static void Main(string[] args)
166 Example example = new Example(Application.NewApplication());