2 using Tizen.NUI.UIComponents;
4 using System.Runtime.InteropServices;
5 using System.Collections.Generic;
6 using Tizen.NUI.Constants;
10 public class FirstScreenApp : NUIApplication
12 //private Application _application; // Reference to Dali Application.
13 private Stage _stage; // Reference to Dali stage.
14 private Size2D _stageSize; // Reference to Dali stage size.
16 private View _topContainer; // Top Container added to the Stage will contain Poster ScrollContainers.
17 private View _bottomContainer; // Bottom Container added to the Stage will contain Menu ScrollContainer.
18 private int _currentPostersContainerID; // Current Poster Container ID visible on the Top Container / Stage.
19 private int _totalPostersContainers; // Number of Poster ScrollContainers to be added on Top Container.
20 private List<ScrollContainer> _postersContainer; // List collection of Poster ScrollContainers used on the Top Container in this demo application.
21 private ScrollContainer _menuContainer; // Menu ScrollContainer used on the Bottom Container in this demo application.
22 private Layer _bottomClipLayer; // Clip layer (Dali Clip Layer instance) used for Bottom Container.
23 private Layer _topClipLayer; // Clip layer (Dali Clip Layer instance) used for Top Container.
25 private FocusEffect _focusEffect; // FocusEffect is used to apply Focus animation effect on any supplied item/image.
26 private string _imagePath; // Contains the physical location of all images used in the demo application.
28 private ImageView _keyboardFocusIndicator; // Reference to the ImageView (Keyboard Focus indicator) applied to the focused item on ScrollContainer.
29 private ImageView _launcherSeparator; // Reference to the ImageView used for launcher separation (Launcher consists of three image icons on left of Menu ScrollContainer).
30 private ImageView[] launcherIcon; // ImageViews used for launcher Icons.
31 private Animation _showBottomContainerAnimation; // Animation used to show/unhide Bottom Container (Menu ScrollContainer) when it is focused.
32 private Animation _hideBottomContainerAnimation; // Animation used to hide Bottom Container (Menu ScrollContainer) when it is focused.
33 private Animation _showAnimation; // Animation used to move Poster scrollContainer from bottom to top and make it non-transparent.
34 private Animation _hideAnimation; // Animation used to make the unused specified Poster scrollContainer transparent.
35 private ScrollContainer _hideScrollContainer; // The unused Poster scrollContainer which needs to be transparent.
36 FocusManager _keyboardFocusManager; // Reference to Dali KeyboardFocusManager.
38 protected override void OnCreate()
45 // Create Items for Poster ScrollContainer
46 private void CreatePosters()
48 for (int j = 0; j < _totalPostersContainers; j++)
50 View posterContainer = _postersContainer[j].Container;
51 for (int i = 0; i < Constants.PostersItemsCount; i++)
53 if (j % _totalPostersContainers == 0)
55 View item = new ImageView(_imagePath + "/poster" + j + "/" + (i % 14) + ".jpg");
56 item.Name = ("poster-item-" + _postersContainer[j].ItemCount);
57 _postersContainer[j].Add(item);
61 View item = new ImageView(_imagePath + "/poster" + j + "/" + (i % 6) + ".jpg");
62 item.Name = ("poster-item-" + _postersContainer[j].ItemCount);
63 _postersContainer[j].Add(item);
69 Show(_postersContainer[j]);
73 Hide(_postersContainer[j]);
76 _postersContainer[j].SetFocused(false);
79 _currentPostersContainerID = 0;
82 // Create Items for Menu ScrollContainer
83 private void CreateMenu()
85 View menuContainer = _menuContainer.Container;
86 menuContainer.Position = new Position(Constants.LauncherWidth, 0.0f, 0.0f);
88 for (int i = 0; i < Constants.MenuItemsCount; i++)
90 View menuItem = new ImageView(_imagePath + "/menu/" + i % 7 + ".png");
91 menuItem.Name = ("menu-item-" + _menuContainer.ItemCount);
92 _menuContainer.Add(menuItem);
96 private View OnKeyboardPreFocusChangeSignal(object source, FocusManager.PreFocusChangeEventArgs e)
98 if (!e.CurrentView && !e.ProposedView)
100 return _menuContainer;
103 Actor actor = _menuContainer.Container;
105 if (e.Direction == View.FocusDirection.Up)
107 // Move the Focus to Poster ScrollContainer and hide Bottom Container (Menu ScrollContainer)
108 if (_menuContainer.IsFocused)
110 actor = _postersContainer[_currentPostersContainerID].GetCurrentFocusedActor();
111 _menuContainer.SetFocused(false);
112 _postersContainer[_currentPostersContainerID].SetFocused(true);
113 HideBottomContainer();
115 // Also apply Focus animation on Focused item on Poster ScrollContainer
116 FocusAnimation(_postersContainer[_currentPostersContainerID], FocusEffectDirection.BottomToTop);
119 else if (e.Direction == View.FocusDirection.Down)
121 // Show Bottom Container (Menu ScrollContainer) and move the Focus to it
122 if (!_menuContainer.IsFocused)
124 ShowBottomContainer();
125 actor = _menuContainer.GetCurrentFocusedActor();
126 _postersContainer[_currentPostersContainerID].SetFocused(false);
127 _menuContainer.SetFocused(true);
129 // Also apply Focus animation on Focused item on Menu ScrollContainer
130 FocusAnimation(_menuContainer, FocusEffectDirection.TopToBottom);
135 actor = e.ProposedView;
138 if (e.Direction == View.FocusDirection.Left)
140 if (_menuContainer.IsFocused)
142 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
143 if (id != _currentPostersContainerID)
145 Hide(_postersContainer[_currentPostersContainerID]);
146 _currentPostersContainerID = id;
148 Show(_postersContainer[_currentPostersContainerID]);
152 else if (e.Direction == View.FocusDirection.Right)
154 if (_menuContainer.IsFocused)
156 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
157 if (id != _currentPostersContainerID)
159 Hide(_postersContainer[_currentPostersContainerID]);
160 _currentPostersContainerID = id;
161 Show(_postersContainer[_currentPostersContainerID]);
166 return (Tizen.NUI.View)actor;
169 // Perform Focus animation Effect on the current Focused Item on ScrollContainer.
170 private void FocusAnimation(ScrollContainer scrollContainer, FocusEffectDirection direction)
172 _focusEffect.FocusAnimation(scrollContainer.GetCurrentFocusedActor(), scrollContainer.ItemSize, 1000, direction);
175 // Perform Show animation on ScrollContainer (used only for Poster Container)
176 private void Show(ScrollContainer scrollContainer)
178 scrollContainer.Add(scrollContainer.Container);
180 _hideScrollContainer = null;
182 // This animation will move Poster scrollContainer from bottom to top and make it non-transparent.
183 _showAnimation = new Animation(350);
184 _showAnimation.AnimateTo(scrollContainer.Container, "ColorAlpha", 1.0f);
186 scrollContainer.Container.PositionY = scrollContainer.Container.Position.Y + 200.0f;
187 float targetPositionY = scrollContainer.Container.Position.Y - 200.0f;
189 _showAnimation.AnimateTo(scrollContainer.Container, "PositionY", targetPositionY, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
191 _showAnimation.Play();
194 // Perform Hide animation on ScrollContainer (used only for Poster Container)
195 private void Hide(ScrollContainer scrollContainer)
199 _hideAnimation.Clear();
200 _hideAnimation.Reset();
204 _hideAnimation = new Animation(duration);
205 _hideAnimation.Duration = duration;
206 _hideAnimation.AnimateTo(scrollContainer.Container, "ColorAlpha", 0.0f, 0, (int)((float)duration * 0.75f), new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
207 _hideAnimation.Finished += OnHideAnimationFinished;
208 _hideScrollContainer = scrollContainer;
209 _hideAnimation.Play();
212 // This removes all the items from the specified unused Poster ScrollContainer (hence Stage) to improve performance.
213 private void OnHideAnimationFinished(object source, EventArgs e)
215 if (_hideScrollContainer)
217 _hideScrollContainer.Remove(_hideScrollContainer.Container);
221 // Hide Bottom Container (Menu ScrollContainer) when it is not focused
222 private void HideBottomContainer()
224 _topClipLayer.ClippingBox = new Rectangle(0,
225 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
226 Convert.ToInt32((_stageSize.Width)),
227 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerExpandHeightFactor))); // X, Y, Width, Height
230 _hideBottomContainerAnimation.AnimateTo(_bottomContainer, "Position", new Position(0.0f, _stageSize.Height * Constants.BottomContainerHidePositionFactor, 0.0f),
231 new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
233 _hideBottomContainerAnimation.Play();
236 // Show (unhide) Bottom Container (Menu ScrollContainer) when it is focused
237 private void ShowBottomContainer()
239 _topClipLayer.ClippingBox = new Rectangle(0,
240 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
241 Convert.ToInt32((_stageSize.Width)),
242 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
244 _showBottomContainerAnimation.AnimateTo(_bottomContainer, "Position", new Position(0.0f, _stageSize.Height * Constants.BottomContainerShowPositionFactor, 0.0f),
245 new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
246 _showBottomContainerAnimation.Play();
249 // First screen demo Application initialisation
250 private void OnInitialize()
252 Tizen.Log.Debug("NUI", "OnInitialize() is called!");
253 _hideScrollContainer = null;
254 _stage = Stage.Instance;
255 _stageSize = _stage.Size;
256 _totalPostersContainers = Constants.TotalPostersContainers;
257 _imagePath = Constants.ImageResourcePath;
259 _postersContainer = new List<ScrollContainer>();
260 _menuContainer = new ScrollContainer();
262 _hideBottomContainerAnimation = new Animation(250);
263 _showBottomContainerAnimation = new Animation(250);
265 // Create a Top Container for poster items
266 _topContainer = new View();
267 _topContainer.Size = new Size(_stageSize.Width, _stageSize.Height * Constants.TopContainerHeightFactor, 0);
268 _topContainer.Position = new Position(0.0f, _stageSize.Height * Constants.TopContainerPositionFactor, 0.0f);
269 _topContainer.ParentOrigin = ParentOrigin.TopLeft;
270 _topContainer.AnchorPoint = AnchorPoint.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;
284 _bottomContainer.AnchorPoint = AnchorPoint.TopLeft;
286 // Add a background to Bottom Container
287 visual = new PropertyMap();
288 visual.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
289 visual.Insert(ImageVisualProperty.URL, new PropertyValue(_imagePath + "/focuseffect/background.png"));
290 _bottomContainer.Background = visual;
291 _bottomContainer.Name = "BottomControl";
293 // Add both Top and Bottom Containers to Stage
294 _stage.GetDefaultLayer().Add(_topContainer);
295 _stage.GetDefaultLayer().Add(_bottomContainer);
297 // Add a clip layer to Top Container
298 _topClipLayer = new Layer();
299 _topClipLayer.AnchorPoint = AnchorPoint.BottomCenter;
300 _topClipLayer.ParentOrigin = ParentOrigin.BottomCenter;
301 _topClipLayer.ClippingEnable = true;
302 _topClipLayer.ClippingBox = new Rectangle(0,
303 Convert.ToInt32(_stageSize.Height * Constants.TopContainerPositionFactor),
304 Convert.ToInt32((_stageSize.Width)),
305 Convert.ToInt32((_stageSize.Height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
306 _topContainer.Add(_topClipLayer);
308 // Create a SpotLight for items / images of both Poster and Menu ScrollContainers
309 ImageView spotLight = new ImageView(_imagePath + "/focuseffect/highlight_spot.png");
310 spotLight.WidthResizePolicy = ResizePolicyType.UseNaturalSize;
311 spotLight.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
312 spotLight.ParentOrigin = ParentOrigin.Center;
313 spotLight.AnchorPoint = AnchorPoint.Center;
314 spotLight.Name = "spotLight";
316 // Create a shadowBorder for items / images of Poster ScrollContainers
317 ImageView shadowBorder = new ImageView(_imagePath + "/focuseffect/thumbnail_shadow.9.png");
318 shadowBorder.ParentOrigin = ParentOrigin.Center;
319 shadowBorder.AnchorPoint = AnchorPoint.Center;
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.AnchorPoint = AnchorPoint.BottomCenter;
355 _bottomClipLayer.ParentOrigin = ParentOrigin.BottomCenter;
356 _bottomClipLayer.ClippingEnable = true;
357 _bottomClipLayer.ClippingBox = new Rectangle(Convert.ToInt32(Constants.LauncherWidth),
358 Convert.ToInt32(_stageSize.Height * Constants.BottomContainerShowPositionFactor),
359 Convert.ToInt32((_stageSize.Width)),
360 Convert.ToInt32((_stageSize.Height - (_stageSize.Height * Constants.BottomClipLayerHeightFactor)))); // X, Y, Width, Height
361 _bottomContainer.Add(_bottomClipLayer);
363 // Add Launcher items to Bottom Container. Launcher is used to display three images on left of Menu ScrollContainer
364 launcherIcon = new ImageView[Convert.ToInt32(Constants.LauncherItemsCount)];
365 for (int launcherIndex = 0; launcherIndex < Constants.LauncherItemsCount; launcherIndex++)
367 launcherIcon[launcherIndex] = new ImageView(_imagePath + "/focuseffect/" + launcherIndex + "-normal.png");
368 launcherIcon[launcherIndex].Name = "launcherIcon" + launcherIndex;
369 launcherIcon[launcherIndex].WidthResizePolicy = ResizePolicyType.UseNaturalSize;
370 launcherIcon[launcherIndex].HeightResizePolicy = ResizePolicyType.UseNaturalSize;
371 launcherIcon[launcherIndex].ParentOrigin = ParentOrigin.CenterLeft;
372 launcherIcon[launcherIndex].AnchorPoint = AnchorPoint.CenterLeft;
373 launcherIcon[launcherIndex].Position = new Position(Constants.LauncherIconWidth * launcherIndex + Constants.LauncherLeftMargin, 0.0f, 0.0f);
374 _bottomContainer.Add(launcherIcon[launcherIndex]);
377 // Add a shadow seperator image between last Launcher icon and Menu ScrollContainer
378 _launcherSeparator = new ImageView(_imagePath + "/focuseffect/focus_launcher_shadow_n.png");
379 _launcherSeparator.Name = "launcherSeparator";
380 _launcherSeparator.WidthResizePolicy = ResizePolicyType.UseNaturalSize;
381 _launcherSeparator.HeightResizePolicy = ResizePolicyType.FillToParent;
382 _launcherSeparator.ParentOrigin = ParentOrigin.CenterLeft;
383 _launcherSeparator.AnchorPoint = AnchorPoint.CenterLeft;
384 _launcherSeparator.Position = new Position(Constants.LauncherIconWidth * Constants.LauncherItemsCount + Constants.LauncherLeftMargin, 0.0f, 0.0f);
385 _bottomContainer.Add(_launcherSeparator);
387 // Create Menu Container and add it to Bottom Clip Layer
388 Size menuItemSize = new Size((_stageSize.Width * Constants.MenuItemWidthFactor) - Constants.MenuContainerPadding,
389 _stageSize.Height * Constants.MenuItemHeightFactor, 0.0f);
390 _menuContainer.Container.Name = "menu";
391 _menuContainer.ItemSize = menuItemSize;
392 _menuContainer.Gap = Constants.MenuContainerPadding;
393 _menuContainer.MarginX = Constants.MenuContainerMargin;
394 _menuContainer.OffsetYFator = Constants.MenuContainerOffsetYFactor;
395 _menuContainer.OffsetX = Constants.LauncherWidth;
396 _menuContainer.Width = _stageSize.Width - Constants.LauncherWidth;
397 _menuContainer.Height = _stageSize.Height * Constants.MenuContainerHeightFactor;
398 _menuContainer.ShadowBorder = new ImageView(_imagePath + "/focuseffect/focus_launcher_shadow.9.png");
399 _menuContainer.ShadowBorder.Name = "_menuContainer.ShadowBorder";
400 _menuContainer.ShadowBorder.Size = new Size(_menuContainer.ItemSize.Width + 40.0f, _menuContainer.ItemSize.Height + 50.0f, 0.0f);
401 _menuContainer.ShadowBorder.Position = new Position(0.0f, 5.0f, 0.0f);
402 _menuContainer.ShadowBorder.ParentOrigin = ParentOrigin.Center;
403 _menuContainer.ShadowBorder.AnchorPoint = AnchorPoint.Center;
404 //_menuContainer.ShadowBorder.MixColor = Color.Red;
405 _menuContainer.SpotLight = spotLight;
406 _bottomClipLayer.Add(_menuContainer);
408 CreatePosters(); // Create Items for Poster ScrollContainer
409 CreateMenu(); // Create Items for Menu ScrollContainer
411 // Initialize PreFocusChange event of KeyboardFocusManager
412 _keyboardFocusManager = FocusManager.Instance;
413 _keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChangeSignal;
415 _keyboardFocusIndicator = new ImageView(_imagePath + "/focuseffect/highlight_stroke.9.png");
416 _keyboardFocusIndicator.ParentOrigin = ParentOrigin.Center;
417 _keyboardFocusIndicator.AnchorPoint = AnchorPoint.Center;
418 _keyboardFocusIndicator.WidthResizePolicy = ResizePolicyType.FillToParent;
419 _keyboardFocusIndicator.HeightResizePolicy = ResizePolicyType.FillToParent;
421 _keyboardFocusManager.FocusIndicator = (_keyboardFocusIndicator);
423 _keyboardFocusManager.SetAsFocusGroup(_menuContainer, true);
424 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[0], true);
425 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[1], true);
426 _keyboardFocusManager.FocusGroupLoop = (true);
428 _focusEffect = new FocusEffect();
430 // Move Fcous to Bottom Container (Menu ScrollContainer)
431 ShowBottomContainer();
432 _menuContainer.SetFocused(true);
436 TextLabel _dateOfTest = new TextLabel();
437 _dateOfTest.WidthResizePolicy = ResizePolicyType.FillToParent;
438 _dateOfTest.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
439 _dateOfTest.AnchorPoint = AnchorPoint.TopCenter;
440 _dateOfTest.ParentOrigin = ParentOrigin.TopCenter;
441 _dateOfTest.SizeModeFactor = new Vector3(0.0f, 0.1f, 0.0f);
442 _dateOfTest.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
443 _dateOfTest.TextColor = Color.White;
444 _dateOfTest.Text = " Common Interface Define Verification Test of 2017-02-10 #1";
445 _dateOfTest.HorizontalAlignment = HorizontalAlignment.HorizontalAlignBegin;
446 _dateOfTest.VerticalAlignment = VerticalAlignment.VerticalAlignCenter;
447 _dateOfTest.PointSize = 12.0f;
448 _dateOfTest.UnderlineEnabled = true;
449 _stage.GetDefaultLayer().Add(_dateOfTest);
450 Tizen.Log.Debug("NUI", "### 1) ColorMode = " + _dateOfTest.ColorMode);
451 _dateOfTest.ColorMode = ColorMode.UseParentColor;
452 Tizen.Log.Debug("NUI", "### 2) ColorMode = " + _dateOfTest.ColorMode);
453 _dateOfTest.ColorMode = ColorMode.UseOwnMultiplyParentColor;
454 Tizen.Log.Debug("NUI", "### 3) ColorMode = " + _dateOfTest.ColorMode);
455 Tizen.Log.Debug("NUI", "### 1) DrawModeType = " + _dateOfTest.DrawMode);
456 _dateOfTest.DrawMode = DrawModeType.Overlay2D;
457 Tizen.Log.Debug("NUI", "### 2) DrawModeType = " + _dateOfTest.DrawMode);
464 static void _Main(string[] args)
466 Tizen.Log.Debug("NUI", "Main() is called! ");
468 FirstScreenApp app = new FirstScreenApp();