2 using Tizen.NUI.UIComponents;
3 using Tizen.NUI.BaseComponents;
5 using System.Runtime.InteropServices;
6 using System.Collections.Generic;
7 using Tizen.NUI.Constants;
11 public class FirstScreenApp : NUIApplication
13 //private Application _application; // Reference to Dali Application.
14 private Stage _stage; // Reference to Dali stage.
15 private Size2D _stageSize; // Reference to Dali stage size.
17 private View _topContainer; // Top Container added to the Stage will contain Poster ScrollContainers.
18 private View _bottomContainer; // Bottom Container added to the Stage will contain Menu ScrollContainer.
19 private int _currentPostersContainerID; // Current Poster Container ID visible on the Top Container / Stage.
20 private int _totalPostersContainers; // Number of Poster ScrollContainers to be added on Top Container.
21 private List<ScrollContainer> _postersContainer; // List collection of Poster ScrollContainers used on the Top Container in this demo application.
22 private ScrollContainer _menuContainer; // Menu ScrollContainer used on the Bottom Container in this demo application.
23 private Layer _bottomClipLayer; // Clip layer (Dali Clip Layer instance) used for Bottom Container.
24 private Layer _topClipLayer; // Clip layer (Dali Clip Layer instance) used for Top Container.
26 private FocusEffect _focusEffect; // FocusEffect is used to apply Focus animation effect on any supplied item/image.
27 private string _imagePath; // Contains the physical location of all images used in the demo application.
29 private ImageView _keyboardFocusIndicator; // Reference to the ImageView (Keyboard Focus indicator) applied to the focused item on ScrollContainer.
30 private ImageView _launcherSeparator; // Reference to the ImageView used for launcher separation (Launcher consists of three image icons on left of Menu ScrollContainer).
31 private ImageView[] launcherIcon; // ImageViews used for launcher Icons.
32 private Animation _showBottomContainerAnimation; // Animation used to show/unhide Bottom Container (Menu ScrollContainer) when it is focused.
33 private Animation _hideBottomContainerAnimation; // Animation used to hide Bottom Container (Menu ScrollContainer) when it is focused.
34 private Animation _showAnimation; // Animation used to move Poster scrollContainer from bottom to top and make it non-transparent.
35 private Animation _hideAnimation; // Animation used to make the unused specified Poster scrollContainer transparent.
36 private ScrollContainer _hideScrollContainer; // The unused Poster scrollContainer which needs to be transparent.
37 FocusManager _keyboardFocusManager; // Reference to Dali KeyboardFocusManager.
39 protected override void OnCreate()
46 // Create Items for Poster ScrollContainer
47 private void CreatePosters()
49 for (int j = 0; j < _totalPostersContainers; j++)
51 View posterContainer = _postersContainer[j].Container;
52 for (int i = 0; i < Constants.PostersItemsCount; i++)
54 if (j % _totalPostersContainers == 0)
56 View item = new ImageView(_imagePath + "/poster" + j + "/" + (i % 14) + ".jpg");
57 item.Name = ("poster-item-" + _postersContainer[j].ItemCount);
58 _postersContainer[j].Add(item);
62 View item = new ImageView(_imagePath + "/poster" + j + "/" + (i % 6) + ".jpg");
63 item.Name = ("poster-item-" + _postersContainer[j].ItemCount);
64 _postersContainer[j].Add(item);
70 Show(_postersContainer[j]);
74 Hide(_postersContainer[j]);
77 _postersContainer[j].SetFocused(false);
80 _currentPostersContainerID = 0;
83 // Create Items for Menu ScrollContainer
84 private void CreateMenu()
86 View menuContainer = _menuContainer.Container;
87 menuContainer.Position = new Position(Constants.LauncherWidth, 0.0f, 0.0f);
89 for (int i = 0; i < Constants.MenuItemsCount; i++)
91 View menuItem = new ImageView(_imagePath + "/menu/" + i % 7 + ".png");
92 menuItem.Name = ("menu-item-" + _menuContainer.ItemCount);
93 _menuContainer.Add(menuItem);
97 private View OnKeyboardPreFocusChangeSignal(object source, FocusManager.PreFocusChangeEventArgs e)
99 if (!e.CurrentView && !e.ProposedView)
101 return _menuContainer;
104 Actor actor = _menuContainer.Container;
106 if (e.Direction == View.FocusDirection.Up)
108 // Move the Focus to Poster ScrollContainer and hide Bottom Container (Menu ScrollContainer)
109 if (_menuContainer.IsFocused)
111 actor = _postersContainer[_currentPostersContainerID].GetCurrentFocusedActor();
112 _menuContainer.SetFocused(false);
113 _postersContainer[_currentPostersContainerID].SetFocused(true);
114 HideBottomContainer();
116 // Also apply Focus animation on Focused item on Poster ScrollContainer
117 FocusAnimation(_postersContainer[_currentPostersContainerID], FocusEffectDirection.BottomToTop);
120 else if (e.Direction == View.FocusDirection.Down)
122 // Show Bottom Container (Menu ScrollContainer) and move the Focus to it
123 if (!_menuContainer.IsFocused)
125 ShowBottomContainer();
126 actor = _menuContainer.GetCurrentFocusedActor();
127 _postersContainer[_currentPostersContainerID].SetFocused(false);
128 _menuContainer.SetFocused(true);
130 // Also apply Focus animation on Focused item on Menu ScrollContainer
131 FocusAnimation(_menuContainer, FocusEffectDirection.TopToBottom);
136 actor = e.ProposedView;
139 if (e.Direction == View.FocusDirection.Left)
141 if (_menuContainer.IsFocused)
143 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
144 if (id != _currentPostersContainerID)
146 Hide(_postersContainer[_currentPostersContainerID]);
147 _currentPostersContainerID = id;
149 Show(_postersContainer[_currentPostersContainerID]);
153 else if (e.Direction == View.FocusDirection.Right)
155 if (_menuContainer.IsFocused)
157 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
158 if (id != _currentPostersContainerID)
160 Hide(_postersContainer[_currentPostersContainerID]);
161 _currentPostersContainerID = id;
162 Show(_postersContainer[_currentPostersContainerID]);
170 // Perform Focus animation Effect on the current Focused Item on ScrollContainer.
171 private void FocusAnimation(ScrollContainer scrollContainer, FocusEffectDirection direction)
173 _focusEffect.FocusAnimation(scrollContainer.GetCurrentFocusedActor(), scrollContainer.ItemSize, 1000, direction);
176 // Perform Show animation on ScrollContainer (used only for Poster Container)
177 private void Show(ScrollContainer scrollContainer)
179 scrollContainer.Add(scrollContainer.Container);
181 _hideScrollContainer = null;
183 // This animation will move Poster scrollContainer from bottom to top and make it non-transparent.
184 _showAnimation = new Animation(350);
185 _showAnimation.AnimateTo(scrollContainer.Container, "ColorAlpha", 1.0f);
187 scrollContainer.Container.PositionY = scrollContainer.Container.Position.Y + 200.0f;
188 float targetPositionY = scrollContainer.Container.Position.Y - 200.0f;
190 _showAnimation.AnimateTo(scrollContainer.Container, "PositionY", targetPositionY, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
192 _showAnimation.Play();
195 // Perform Hide animation on ScrollContainer (used only for Poster Container)
196 private void Hide(ScrollContainer scrollContainer)
200 _hideAnimation.Clear();
201 _hideAnimation.Reset();
205 _hideAnimation = new Animation(duration);
206 _hideAnimation.Duration = duration;
207 _hideAnimation.AnimateTo(scrollContainer.Container, "ColorAlpha", 0.0f, 0, (int)((float)duration * 0.75f), new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
208 _hideAnimation.Finished += OnHideAnimationFinished;
209 _hideScrollContainer = scrollContainer;
210 _hideAnimation.Play();
213 // This removes all the items from the specified unused Poster ScrollContainer (hence Stage) to improve performance.
214 private void OnHideAnimationFinished(object source, EventArgs e)
216 if (_hideScrollContainer)
218 _hideScrollContainer.Remove(_hideScrollContainer.Container);
222 // Hide Bottom Container (Menu ScrollContainer) when it is not focused
223 private void HideBottomContainer()
225 _topClipLayer.ClippingBox = new Rectangle(0,
226 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
227 Convert.ToInt32((_stageSize.Width)),
228 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerExpandHeightFactor))); // X, Y, Width, Height
231 _hideBottomContainerAnimation.AnimateTo(_bottomContainer, "Position", new Position(0.0f, _stageSize.Height * Constants.BottomContainerHidePositionFactor, 0.0f),
232 new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
234 _hideBottomContainerAnimation.Play();
237 // Show (unhide) Bottom Container (Menu ScrollContainer) when it is focused
238 private void ShowBottomContainer()
240 _topClipLayer.ClippingBox = new Rectangle(0,
241 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
242 Convert.ToInt32((_stageSize.Width)),
243 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
245 _showBottomContainerAnimation.AnimateTo(_bottomContainer, "Position", new Position(0.0f, _stageSize.Height * Constants.BottomContainerShowPositionFactor, 0.0f),
246 new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
247 _showBottomContainerAnimation.Play();
250 // First screen demo Application initialisation
251 private void OnInitialize()
253 Tizen.Log.Debug("NUI", "OnInitialize() is called!");
254 _hideScrollContainer = null;
255 _stage = Stage.Instance;
256 _stageSize = _stage.Size;
257 _totalPostersContainers = Constants.TotalPostersContainers;
258 _imagePath = Constants.ImageResourcePath;
260 _postersContainer = new List<ScrollContainer>();
261 _menuContainer = new ScrollContainer();
263 _hideBottomContainerAnimation = new Animation(250);
264 _showBottomContainerAnimation = new Animation(250);
266 // Create a Top Container for poster items
267 _topContainer = new View();
268 _topContainer.Size = new Size(_stageSize.Width, _stageSize.Height * Constants.TopContainerHeightFactor, 0);
269 _topContainer.Position = new Position(0.0f, _stageSize.Height * Constants.TopContainerPositionFactor, 0.0f);
270 _topContainer.ParentOrigin = ParentOrigin.TopLeft;
272 // Add a background to Top container
273 PropertyMap visual = new PropertyMap();
274 visual.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
275 visual.Insert(ImageVisualProperty.URL, new PropertyValue(_imagePath + "/focuseffect/background.png"));
276 _topContainer.Background = visual;
277 _topContainer.Name = "TopControl";
279 // Create a Bottom Container
280 _bottomContainer = new View();
281 _bottomContainer.Size = new Size(_stageSize.Width, _stageSize.Height * Constants.BottomContainerHeightFactor, 0);
282 _bottomContainer.Position = new Position(0.0f, _stageSize.Height * Constants.BottomContainerHidePositionFactor, 0.0f);
283 _bottomContainer.ParentOrigin = ParentOrigin.TopLeft;
285 // Add a background to Bottom Container
286 visual = new PropertyMap();
287 visual.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
288 visual.Insert(ImageVisualProperty.URL, new PropertyValue(_imagePath + "/focuseffect/background.png"));
289 _bottomContainer.Background = visual;
290 _bottomContainer.Name = "BottomControl";
292 // Add both Top and Bottom Containers to Stage
293 _stage.GetDefaultLayer().Add(_topContainer);
294 _stage.GetDefaultLayer().Add(_bottomContainer);
296 // Add a clip layer to Top Container
297 _topClipLayer = new Layer();
298 _topClipLayer.ParentOrigin = ParentOrigin.BottomCenter;
299 _topClipLayer.ClippingEnable = true;
300 _topClipLayer.ClippingBox = new Rectangle(0,
301 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
302 Convert.ToInt32((_stageSize.Width)),
303 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
304 _topContainer.Add(_topClipLayer);
306 // Create a SpotLight for items / images of both Poster and Menu ScrollContainers
307 ImageView spotLight = new ImageView(_imagePath + "/focuseffect/highlight_spot.png");
308 spotLight.WidthResizePolicy = ResizePolicyType.UseNaturalSize;
309 spotLight.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
310 spotLight.ParentOrigin = ParentOrigin.Center;
311 spotLight.PivotPoint = PivotPoint.Center;
312 spotLight.PositionUsesPivotPoint = true;
313 spotLight.Name = "spotLight";
315 // Create a shadowBorder for items / images of Poster ScrollContainers
316 ImageView shadowBorder = new ImageView(_imagePath + "/focuseffect/thumbnail_shadow.9.png");
317 shadowBorder.ParentOrigin = ParentOrigin.Center;
318 shadowBorder.PivotPoint = PivotPoint.Center;
319 shadowBorder.PositionUsesPivotPoint = true;
320 shadowBorder.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
321 shadowBorder.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
322 shadowBorder.SizeModeFactor = (new Vector3(32.0f, 41.0f, 0.0f));
323 shadowBorder.Name = "poster shadowBorder";
325 // Create Poster Containers and add them to Top Clip layer
326 for (int i = 0; i < _totalPostersContainers; i++)
328 _postersContainer.Add(new ScrollContainer());
329 _postersContainer[i].Container.Name = "poster" + i;
332 _postersContainer[i].ItemSize = new Size((_stageSize.Width * Constants.Poster0ItemWidthFactor) - Constants.PostersContainerPadding,
333 _stageSize.Height * Constants.PostersItemHeightFactor, 0.0f);
337 _postersContainer[i].ItemSize = new Size((_stageSize.Width * Constants.Poster1ItemWidthFactor) - Constants.PostersContainerPadding,
338 _stageSize.Height * Constants.PostersItemHeightFactor, 0.0f);
341 _postersContainer[i].Gap = Constants.PostersContainerPadding;
342 _postersContainer[i].MarginX = Constants.PostersContainerMargin;
343 _postersContainer[i].OffsetYFator = Constants.PostersContainerOffsetYFactor;
344 _postersContainer[i].Width = _stageSize.Width;
345 _postersContainer[i].Height = _stageSize.Height * Constants.PostersContainerHeightFactor;
346 _postersContainer[i].ShadowBorder = shadowBorder;
347 _postersContainer[i].ShadowBorder.Position = new Position(0.0f, 4.0f, 0.0f);
348 _postersContainer[i].SpotLight = spotLight;
349 _topClipLayer.Add(_postersContainer[i]);
352 // Add a clip layer to Bottom Container
353 _bottomClipLayer = new Layer();
354 _bottomClipLayer.PivotPoint = PivotPoint.BottomCenter;
355 _bottomClipLayer.PositionUsesPivotPoint = true;
356 _bottomClipLayer.ParentOrigin = ParentOrigin.BottomCenter;
357 _bottomClipLayer.ClippingEnable = true;
358 _bottomClipLayer.ClippingBox = new Rectangle(Convert.ToInt32(Constants.LauncherWidth),
359 Convert.ToInt32(_stageSize.Height * Constants.BottomContainerShowPositionFactor),
360 Convert.ToInt32((_stageSize.Width)),
361 Convert.ToInt32((_stageSize.Height - (_stageSize.Height * Constants.BottomClipLayerHeightFactor)))); // X, Y, Width, Height
362 _bottomContainer.Add(_bottomClipLayer);
364 // Add Launcher items to Bottom Container. Launcher is used to display three images on left of Menu ScrollContainer
365 launcherIcon = new ImageView[Convert.ToInt32(Constants.LauncherItemsCount)];
366 for (int launcherIndex = 0; launcherIndex < Constants.LauncherItemsCount; launcherIndex++)
368 launcherIcon[launcherIndex] = new ImageView(_imagePath + "/focuseffect/" + launcherIndex + "-normal.png");
369 launcherIcon[launcherIndex].Name = "launcherIcon" + launcherIndex;
370 launcherIcon[launcherIndex].WidthResizePolicy = ResizePolicyType.UseNaturalSize;
371 launcherIcon[launcherIndex].HeightResizePolicy = ResizePolicyType.UseNaturalSize;
372 launcherIcon[launcherIndex].ParentOrigin = ParentOrigin.CenterLeft;
373 launcherIcon[launcherIndex].PivotPoint = PivotPoint.CenterLeft;
374 launcherIcon[launcherIndex].PositionUsesPivotPoint = true;
375 launcherIcon[launcherIndex].Position = new Position(Constants.LauncherIconWidth * launcherIndex + Constants.LauncherLeftMargin, 0.0f, 0.0f);
376 _bottomContainer.Add(launcherIcon[launcherIndex]);
379 // Add a shadow seperator image between last Launcher icon and Menu ScrollContainer
380 _launcherSeparator = new ImageView(_imagePath + "/focuseffect/focus_launcher_shadow_n.png");
381 _launcherSeparator.Name = "launcherSeparator";
382 _launcherSeparator.WidthResizePolicy = ResizePolicyType.UseNaturalSize;
383 _launcherSeparator.HeightResizePolicy = ResizePolicyType.FillToParent;
384 _launcherSeparator.ParentOrigin = ParentOrigin.CenterLeft;
385 _launcherSeparator.PivotPoint = PivotPoint.CenterLeft;
386 _launcherSeparator.PositionUsesPivotPoint = true;
387 _launcherSeparator.Position = new Position(Constants.LauncherIconWidth * Constants.LauncherItemsCount + Constants.LauncherLeftMargin, 0.0f, 0.0f);
388 _bottomContainer.Add(_launcherSeparator);
390 // Create Menu Container and add it to Bottom Clip Layer
391 Size menuItemSize = new Size((_stageSize.Width * Constants.MenuItemWidthFactor) - Constants.MenuContainerPadding,
392 _stageSize.Height * Constants.MenuItemHeightFactor, 0.0f);
393 _menuContainer.Container.Name = "menu";
394 _menuContainer.ItemSize = menuItemSize;
395 _menuContainer.Gap = Constants.MenuContainerPadding;
396 _menuContainer.MarginX = Constants.MenuContainerMargin;
397 _menuContainer.OffsetYFator = Constants.MenuContainerOffsetYFactor;
398 _menuContainer.OffsetX = Constants.LauncherWidth;
399 _menuContainer.Width = _stageSize.Width - Constants.LauncherWidth;
400 _menuContainer.Height = _stageSize.Height * Constants.MenuContainerHeightFactor;
401 _menuContainer.ShadowBorder = new ImageView(_imagePath + "/focuseffect/focus_launcher_shadow.9.png");
402 _menuContainer.ShadowBorder.Name = "_menuContainer.ShadowBorder";
403 _menuContainer.ShadowBorder.Size = new Size(_menuContainer.ItemSize.Width + 40.0f, _menuContainer.ItemSize.Height + 50.0f, 0.0f);
404 _menuContainer.ShadowBorder.Position = new Position(0.0f, 5.0f, 0.0f);
405 _menuContainer.ShadowBorder.ParentOrigin = ParentOrigin.Center;
406 _menuContainer.ShadowBorder.PivotPoint = PivotPoint.Center;
407 _menuContainer.ShadowBorder.PositionUsesPivotPoint = true;
408 _menuContainer.SpotLight = spotLight;
409 _bottomClipLayer.Add(_menuContainer);
411 CreatePosters(); // Create Items for Poster ScrollContainer
412 CreateMenu(); // Create Items for Menu ScrollContainer
414 // Initialize PreFocusChange event of KeyboardFocusManager
415 _keyboardFocusManager = FocusManager.Instance;
416 _keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChangeSignal;
418 _keyboardFocusIndicator = new ImageView(_imagePath + "/focuseffect/highlight_stroke.9.png");
419 _keyboardFocusIndicator.ParentOrigin = ParentOrigin.Center;
420 _keyboardFocusIndicator.PivotPoint = PivotPoint.Center;
421 _keyboardFocusIndicator.PositionUsesPivotPoint = true;
422 _keyboardFocusIndicator.WidthResizePolicy = ResizePolicyType.FillToParent;
423 _keyboardFocusIndicator.HeightResizePolicy = ResizePolicyType.FillToParent;
425 _keyboardFocusManager.FocusIndicator = (_keyboardFocusIndicator);
427 _keyboardFocusManager.SetAsFocusGroup(_menuContainer, true);
428 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[0], true);
429 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[1], true);
430 _keyboardFocusManager.FocusGroupLoop = (true);
432 _focusEffect = new FocusEffect();
434 // Move Fcous to Bottom Container (Menu ScrollContainer)
435 ShowBottomContainer();
436 _menuContainer.SetFocused(true);
440 TextLabel _dateOfTest = new TextLabel();
441 _dateOfTest.WidthResizePolicy = ResizePolicyType.FillToParent;
442 _dateOfTest.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
443 _dateOfTest.PivotPoint = PivotPoint.TopCenter;
444 _dateOfTest.PositionUsesPivotPoint = true;
445 _dateOfTest.ParentOrigin = ParentOrigin.TopCenter;
446 _dateOfTest.SizeModeFactor = new Vector3(0.0f, 0.1f, 0.0f);
447 _dateOfTest.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
448 _dateOfTest.TextColor = Color.White;
449 _dateOfTest.Text = " Common Interface Define Verification Test of 2017-02-10 #1";
450 _dateOfTest.HorizontalAlignment = HorizontalAlignment.Begin;
451 _dateOfTest.VerticalAlignment = VerticalAlignment.Center;
452 _dateOfTest.PointSize = 12.0f;
453 _dateOfTest.UnderlineEnabled = true;
454 _stage.GetDefaultLayer().Add(_dateOfTest);
455 Tizen.Log.Debug("NUI", "### 1) ColorMode = " + _dateOfTest.ColorMode);
456 _dateOfTest.ColorMode = ColorMode.UseParentColor;
457 Tizen.Log.Debug("NUI", "### 2) ColorMode = " + _dateOfTest.ColorMode);
458 _dateOfTest.ColorMode = ColorMode.UseOwnMultiplyParentColor;
459 Tizen.Log.Debug("NUI", "### 3) ColorMode = " + _dateOfTest.ColorMode);
460 Tizen.Log.Debug("NUI", "### 1) DrawModeType = " + _dateOfTest.DrawMode);
461 _dateOfTest.DrawMode = DrawModeType.Overlay2D;
462 Tizen.Log.Debug("NUI", "### 2) DrawModeType = " + _dateOfTest.DrawMode);
469 static void _Main(string[] args)
471 Tizen.Log.Debug("NUI", "Main() is called! ");
473 FirstScreenApp app = new FirstScreenApp();