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.
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-template.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# Spin object associated with the actor,
70 _spinYear = View.DownCast<Spin>( year );
71 _spinMonth = View.DownCast<Spin>( month );
72 _spinDay = View.DownCast<Spin>( day );
74 _spinYear.Value = 2099;
78 _spinYear.SetKeyboardFocusable(true);
79 _spinMonth.SetKeyboardFocusable(true);
80 _spinDay.SetKeyboardFocusable(true);
82 FocusManager keyboardFocusManager = FocusManager.Instance;
83 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
84 keyboardFocusManager.FocusedActorEnterKeyPressed += OnFocusedActorEnterKeyPressed;
88 private Actor OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
90 Actor nextFocusActor = e.Proposed;
92 // When nothing has been focused initially, focus the text field in the first spin
93 if (!e.Current && !e.Proposed)
95 nextFocusActor = _spinYear.SpinText;
97 else if(e.Direction == View.KeyboardFocus.Direction.LEFT)
99 // Move the focus to the spin in the left of the current focused spin
100 if(e.Current == _spinMonth.SpinText)
102 nextFocusActor = _spinYear.SpinText;
104 else if(e.Current == _spinDay.SpinText)
106 nextFocusActor = _spinMonth.SpinText;
109 else if(e.Direction == View.KeyboardFocus.Direction.RIGHT)
111 // Move the focus to the spin in the right of the current focused spin
112 if(e.Current == _spinYear.SpinText)
114 nextFocusActor = _spinMonth.SpinText;
116 else if(e.Current == _spinMonth.SpinText)
118 nextFocusActor = _spinDay.SpinText;
122 return nextFocusActor;
125 private void OnFocusedActorEnterKeyPressed(object source, FocusManager.FocusedActorEnterKeyEventArgs e)
127 // Make the text field in the current focused spin to take the key input
128 KeyInputFocusManager manager = KeyInputFocusManager.Get();
130 if (e.Actor == _spinYear.SpinText)
132 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
134 manager.SetFocus(_spinYear.SpinText);
137 else if (e.Actor == _spinMonth.SpinText)
139 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
141 manager.SetFocus(_spinMonth.SpinText);
144 else if (e.Actor == _spinDay.SpinText)
146 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
148 manager.SetFocus(_spinDay.SpinText);
153 public void MainLoop()
155 _application.MainLoop ();
159 /// The main entry point for the application.
162 static void Main(string[] args)
164 Example example = new Example(Application.NewApplication());