3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
8 public class FirstScreenApp
10 private Application _application; // Reference to Dali Application.
11 private Stage _stage; // Reference to Dali stage.
12 private Vector2 _stageSize; // Reference to Dali stage size.
14 private View _topContainer; // Top Container added to the Stage will contain Poster ScrollContainers.
15 private View _bottomContainer; // Bottom Container added to the Stage will contain Menu ScrollContainer.
16 private int _currentPostersContainerID; // Current Poster Container ID visible on the Top Container / Stage.
17 private int _totalPostersContainers; // Number of Poster ScrollContainers to be added on Top Container.
18 private List<ScrollContainer> _postersContainer; // List collection of Poster ScrollContainers used on the Top Container in this demo application.
19 private ScrollContainer _menuContainer; // Menu ScrollContainer used on the Bottom Container in this demo application.
20 private Layer _bottomClipLayer; // Clip layer (Dali Clip Layer instance) used for Bottom Container.
21 private Layer _topClipLayer; // Clip layer (Dali Clip Layer instance) used for Top Container.
23 private FocusEffect _focusEffect; // FocusEffect is used to apply Focus animation effect on any supplied item/image.
24 private string _imagePath; // Contains the physical location of all images used in the demo application.
26 private ImageView _keyboardFocusIndicator; // Reference to the ImageView (Keyboard Focus indicator) applied to the focused item on ScrollContainer.
27 private ImageView _launcherSeparator; // Reference to the ImageView used for launcher separation (Launcher consists of three image icons on left of Menu ScrollContainer).
28 private ImageView[] launcherIcon; // ImageViews used for launcher Icons.
29 private Animation _showBottomContainerAnimation; // Animation used to show/unhide Bottom Container (Menu ScrollContainer) when it is focused.
30 private Animation _hideBottomContainerAnimation; // Animation used to hide Bottom Container (Menu ScrollContainer) when it is focused.
31 private Animation _showAnimation; // Animation used to move Poster scrollContainer from bottom to top and make it non-transparent.
32 private Animation _hideAnimation; // Animation used to make the unused specified Poster scrollContainer transparent.
33 private ScrollContainer _hideScrollContainer; // The unused Poster scrollContainer which needs to be transparent.
34 KeyboardFocusManager _keyboardFocusManager; // Reference to Dali KeyboardFocusManager.
36 private FirstScreenApp(Application application)
38 _application = application;
39 _application.Initialized += OnInitialize;
42 public static void Run()
44 FirstScreenApp tVApp = new FirstScreenApp(Application.NewApplication());
48 private void MainLoop()
50 _application.MainLoop();
53 // Create Items for Poster ScrollContainer
54 private void CreatePosters()
56 for (int j = 0; j < _totalPostersContainers; j++)
58 View posterContainer = _postersContainer[j].Container;
59 for (int i = 0; i < Constants.PostersItemsCount; i++)
61 if (j % _totalPostersContainers == 0)
63 View item = new ImageView(_imagePath + "/poster"+j+"/"+ (i % 6)+ ".jpg");
64 item.SetName ("poster-item-" + _postersContainer[j].ItemCount);
65 _postersContainer[j].Add(item);
69 View item = new ImageView(_imagePath + "/poster"+j+"/"+ (i % 6)+ ".jpg");
70 item.SetName ("poster-item-" + _postersContainer[j].ItemCount);
71 _postersContainer[j].Add(item);
77 Show(_postersContainer[j]);
81 Hide(_postersContainer[j]);
84 _postersContainer[j].SetFocused(false);
87 _currentPostersContainerID = 0;
90 // Create Items for Menu ScrollContainer
91 private void CreateMenu()
93 View menuContainer = _menuContainer.Container;
94 menuContainer.Position = new Vector3(Constants.LauncherWidth, 0.0f, 0.0f);
96 for(int i = 0; i < Constants.MenuItemsCount; i++)
98 View menuItem = new ImageView(_imagePath + "/menu/" + i % 7 + ".png");
99 menuItem.SetName("menu-item-" + _menuContainer.ItemCount);
100 _menuContainer.Add(menuItem);
104 private Actor OnKeyboardPreFocusChangeSignal(object source, KeyboardFocusManager.PreFocusChangeEventArgs e)
106 if (!e.Current && !e.Proposed)
108 return _menuContainer;
111 Actor actor = _menuContainer.Container;
113 if (e.Direction == View.KeyboardFocus.Direction.UP)
115 // Move the Focus to Poster ScrollContainer and hide Bottom Container (Menu ScrollContainer)
116 if (_menuContainer.IsFocused)
118 actor = _postersContainer[_currentPostersContainerID].GetCurrentFocusedActor();
119 _menuContainer.SetFocused(false);
120 _postersContainer[_currentPostersContainerID].SetFocused(true);
121 HideBottomContainer();
123 // Also apply Focus animation on Focused item on Poster ScrollContainer
124 FocusAnimation(_postersContainer[_currentPostersContainerID], FocusEffectDirection.BottomToTop);
127 else if (e.Direction == View.KeyboardFocus.Direction.DOWN)
129 // Show Bottom Container (Menu ScrollContainer) and move the Focus to it
130 if (!_menuContainer.IsFocused)
132 ShowBottomContainer();
133 actor = _menuContainer.GetCurrentFocusedActor();
134 _postersContainer[_currentPostersContainerID].SetFocused(false);
135 _menuContainer.SetFocused(true);
137 // Also apply Focus animation on Focused item on Menu ScrollContainer
138 FocusAnimation(_menuContainer, FocusEffectDirection.TopToBottom);
146 if (e.Direction == View.KeyboardFocus.Direction.LEFT)
148 if (_menuContainer.IsFocused)
150 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
151 if (id != _currentPostersContainerID)
153 Hide(_postersContainer[_currentPostersContainerID]);
154 _currentPostersContainerID = id;
156 Show(_postersContainer[_currentPostersContainerID]);
160 else if (e.Direction == View.KeyboardFocus.Direction.RIGHT)
162 if (_menuContainer.IsFocused)
164 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
165 if (id != _currentPostersContainerID)
167 Hide(_postersContainer[_currentPostersContainerID]);
168 _currentPostersContainerID = id;
169 Show(_postersContainer[_currentPostersContainerID]);
177 // Perform Focus animation Effect on the current Focused Item on ScrollContainer.
178 private void FocusAnimation(ScrollContainer scrollContainer, FocusEffectDirection direction)
180 _focusEffect.FocusAnimation(scrollContainer.GetCurrentFocusedActor(), scrollContainer.ItemSize, 1.0f, direction);
183 // Perform Show animation on ScrollContainer (used only for Poster Container)
184 private void Show(ScrollContainer scrollContainer)
186 scrollContainer.Add(scrollContainer.Container);
188 _hideScrollContainer = null;
189 _showAnimation = new Animation (0.35f);
191 // This animation will move Poster scrollContainer from bottom to top and make it non-transparent.
192 _showAnimation.AnimateTo(new Dali.Property(scrollContainer.Container, Actor.Property.COLOR_ALPHA), new Dali.Property.Value(1.0f));
194 scrollContainer.Container.PositionY = scrollContainer.Container.Position.y + 200.0f;
195 float targetPositionY = scrollContainer.Container.Position.y - 200.0f;
196 _showAnimation.AnimateTo(new Dali.Property(scrollContainer.Container, Actor.Property.POSITION_Y), new Dali.Property.Value(targetPositionY),
197 new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR));
199 _showAnimation.Play();
202 // Perform Hide animation on ScrollContainer (used only for Poster Container)
203 private void Hide(ScrollContainer scrollContainer)
207 _hideAnimation.Clear();
208 _hideAnimation.Reset();
211 float duration = 0.35f;
212 _hideAnimation = new Animation(duration);
214 _hideAnimation.AnimateTo(new Dali.Property(scrollContainer.Container, Actor.Property.COLOR_ALPHA), new Dali.Property.Value(0.0f),
215 new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, duration * 0.75f));
217 _hideAnimation.Finished += OnHideAnimationFinished;
219 _hideScrollContainer = scrollContainer;
220 _hideAnimation.Play();
223 // This removes all the items from the specified unused Poster ScrollContainer (hence Stage) to improve performance.
224 private void OnHideAnimationFinished(object source, Animation.FinishedEventArgs e)
226 if (_hideScrollContainer)
228 _hideScrollContainer.Remove(_hideScrollContainer.Container);
232 // Hide Bottom Container (Menu ScrollContainer) when it is not focused
233 private void HideBottomContainer()
235 _topClipLayer.ClippingBox = new RectInteger(0,
236 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
237 Convert.ToInt32((_stageSize.width)),
238 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerExpandHeightFactor))); // X, Y, Width, Height
240 _hideBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION),
241 new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f)),
242 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
243 _hideBottomContainerAnimation.Play();
246 // Show (unhide) Bottom Container (Menu ScrollContainer) when it is focused
247 private void ShowBottomContainer()
249 _topClipLayer.ClippingBox = new RectInteger(0,
250 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
251 Convert.ToInt32((_stageSize.width)),
252 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
254 _showBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION),
255 new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerShowPositionFactor, 0.0f)),
256 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
257 _showBottomContainerAnimation.Play();
260 // First screen demo Application initialisation
261 private void OnInitialize(object source, AUIApplicationInitEventArgs e)
263 _hideScrollContainer = null;
264 _stage = Stage.GetCurrent();
265 _stageSize = _stage.GetSize();
266 //_stage.SetBackgroundColor(NDalic.TRANSPARENT);
268 _totalPostersContainers = Constants.TotalPostersContainers;
269 _imagePath = "./images/"; // Desktop
270 //_imagePath = "/home/owner/apps_rw/org.tizen.firstscreen/res/images/"; // Target
272 _postersContainer = new List<ScrollContainer> ();
273 _menuContainer = new ScrollContainer ();
275 _hideBottomContainerAnimation = new Animation(0.25f);
276 _showBottomContainerAnimation = new Animation(0.25f);
278 // Create a Top Container for poster items
279 _topContainer = new View();
280 _topContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.TopContainerHeightFactor, 0.0f);
281 _topContainer.Position = new Vector3(0.0f, _stageSize.y * Constants.TopContainerPositionFactor, 0.0f);
282 _topContainer.ParentOrigin = NDalic.ParentOriginTopLeft;
283 _topContainer.AnchorPoint = NDalic.AnchorPointTopLeft;
285 // Add a background to Top container
286 Property.Map visual = new Property.Map();
287 visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE));
288 visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png"));
289 _topContainer.Background = visual;
290 _topContainer.Name = "TopControl";
292 // Create a Bottom Container
293 _bottomContainer = new View();
294 _bottomContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.BottomContainerHeightFactor, 0.0f);
295 _bottomContainer.Position = new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f);
296 _bottomContainer.ParentOrigin = NDalic.ParentOriginTopLeft;
297 _bottomContainer.AnchorPoint = NDalic.AnchorPointTopLeft;
299 // Add a background to Bottom Container
300 visual = new Property.Map();
301 visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE));
302 visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png"));
303 _bottomContainer.Background = visual;
304 _bottomContainer.Name = "BottomControl";
306 // Add both Top and Bottom Containers to Stage
307 _stage.Add(_topContainer);
308 _stage.Add(_bottomContainer);
310 // Add a clip layer to Top Container
311 _topClipLayer = new Layer();
312 _topClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter;
313 _topClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter;
314 _topClipLayer.ClippingEnable = true;
315 _topClipLayer.ClippingBox = new RectInteger(0,
316 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
317 Convert.ToInt32((_stageSize.width)),
318 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
319 _topContainer.Add(_topClipLayer);
321 // Create a SpotLight for items / images of both Poster and Menu ScrollContainers
322 ImageView spotLight = new ImageView(_imagePath + "/highlight_spot.png");
323 spotLight.WidthResizePolicy = "USE_NATURAL_SIZE";
324 spotLight.HeightResizePolicy = "USE_NATURAL_SIZE";
325 spotLight.ParentOrigin = NDalic.ParentOriginCenter;
326 spotLight.AnchorPoint = NDalic.AnchorPointCenter;
327 spotLight.Name = "spotLight";
329 // Create a shadowBorder for items / images of Poster ScrollContainers
330 ImageView shadowBorder = new ImageView(_imagePath + "/thumbnail_shadow.9.png");
331 shadowBorder.ParentOrigin = NDalic.ParentOriginCenter;
332 shadowBorder.AnchorPoint = NDalic.AnchorPointCenter;
333 shadowBorder.WidthResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT";
334 shadowBorder.HeightResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT";
335 shadowBorder.SetSizeModeFactor(new Vector3(32.0f, 41.0f, 0.0f));
336 shadowBorder.Name = "poster shadowBorder";
338 // Create Poster Containers and add them to Top Clip layer
339 for (int i = 0; i < _totalPostersContainers; i++)
341 _postersContainer.Add(new ScrollContainer());
342 _postersContainer[i].Container.Name = "poster" + i;
345 _postersContainer[i].ItemSize = new Vector3((_stageSize.width * Constants.Poster0ItemWidthFactor) - Constants.PostersContainerPadding,
346 _stageSize.height * Constants.PostersItemHeightFactor, 0.0f);
350 _postersContainer[i].ItemSize = new Vector3((_stageSize.width * Constants.Poster1ItemWidthFactor) - Constants.PostersContainerPadding,
351 _stageSize.height * Constants.PostersItemHeightFactor, 0.0f);
353 _postersContainer[i].Gap = Constants.PostersContainerPadding;
354 _postersContainer[i].MarginX = Constants.PostersContainerMargin;
355 _postersContainer[i].OffsetYFator = Constants.PostersContainerOffsetYFactor;
356 _postersContainer[i].Width = _stageSize.width;
357 _postersContainer[i].Height = _stageSize.height * Constants.PostersContainerHeightFactor;
358 _postersContainer[i].ShadowBorder = shadowBorder;
359 _postersContainer[i].ShadowBorder.Position = new Vector3(0.0f, 4.0f, 0.0f);
360 _postersContainer[i].SpotLight = spotLight;
361 _topClipLayer.Add(_postersContainer[i]);
364 // Add a clip layer to Bottom Container
365 _bottomClipLayer = new Layer();
366 _bottomClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter;
367 _bottomClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter;
368 _bottomClipLayer.ClippingEnable = true;
369 _bottomClipLayer.ClippingBox = new RectInteger(Convert.ToInt32(Constants.LauncherWidth),
370 Convert.ToInt32(_stageSize.height * Constants.BottomContainerShowPositionFactor),
371 Convert.ToInt32((_stageSize.width)),
372 Convert.ToInt32((_stageSize.height - (_stageSize.height * Constants.BottomClipLayerHeightFactor)))); // X, Y, Width, Height
373 _bottomContainer.Add(_bottomClipLayer);
375 // Add Launcher items to Bottom Container. Launcher is used to display three images on left of Menu ScrollContainer
376 launcherIcon = new ImageView[Convert.ToInt32(Constants.LauncherItemsCount)];
377 for (int launcherIndex = 0; launcherIndex < Constants.LauncherItemsCount; launcherIndex++)
379 launcherIcon[launcherIndex] = new ImageView(_imagePath + "/" + launcherIndex + "-normal.png");
380 launcherIcon[launcherIndex].Name = "launcherIcon" + launcherIndex;
381 launcherIcon[launcherIndex].WidthResizePolicy = "USE_NATURAL_SIZE";
382 launcherIcon[launcherIndex].HeightResizePolicy = "USE_NATURAL_SIZE";
383 launcherIcon[launcherIndex].ParentOrigin = NDalic.ParentOriginCenterLeft;
384 launcherIcon[launcherIndex].AnchorPoint = NDalic.AnchorPointCenterLeft;
385 launcherIcon[launcherIndex].Position = new Vector3(Constants.LauncherIconWidth * launcherIndex + Constants.LauncherLeftMargin, 0.0f, 0.0f);
386 _bottomContainer.Add(launcherIcon[launcherIndex]);
389 // Add a shadow seperator image between last Launcher icon and Menu ScrollContainer
390 _launcherSeparator = new ImageView(_imagePath + "/focus_launcher_shadow_n.png");
391 _launcherSeparator.Name = "launcherSeparator";
392 _launcherSeparator.WidthResizePolicy = "USE_NATURAL_SIZE";
393 _launcherSeparator.HeightResizePolicy = "FILL_TO_PARENT";
394 _launcherSeparator.ParentOrigin = NDalic.ParentOriginCenterLeft;
395 _launcherSeparator.AnchorPoint = NDalic.AnchorPointCenterLeft;
396 _launcherSeparator.Position = new Vector3(Constants.LauncherIconWidth * Constants.LauncherItemsCount + Constants.LauncherLeftMargin, 0.0f, 0.0f);
397 _bottomContainer.Add(_launcherSeparator);
399 // Create Menu Container and add it to Bottom Clip Layer
400 Vector3 menuItemSize = new Vector3((_stageSize.width * Constants.MenuItemWidthFactor) - Constants.MenuContainerPadding,
401 _stageSize.height * Constants.MenuItemHeightFactor, 0.0f);
402 _menuContainer.Container.Name = "menu";
403 _menuContainer.ItemSize = menuItemSize;
404 _menuContainer.Gap = Constants.MenuContainerPadding;
405 _menuContainer.MarginX = Constants.MenuContainerMargin;
406 _menuContainer.OffsetYFator = Constants.MenuContainerOffsetYFactor;
407 _menuContainer.OffsetX = Constants.LauncherWidth;
408 _menuContainer.Width = _stageSize.width - Constants.LauncherWidth;
409 _menuContainer.Height = _stageSize.height * Constants.MenuContainerHeightFactor;
410 _menuContainer.ShadowBorder = new ImageView(_imagePath + "/focus_launcher_shadow.9.png");
411 _menuContainer.ShadowBorder.Name = "_menuContainer.ShadowBorder";
412 _menuContainer.ShadowBorder.Size = new Vector3(_menuContainer.ItemSize.width + 40.0f, _menuContainer.ItemSize.height + 50.0f, 0.0f);
413 _menuContainer.ShadowBorder.Position = new Vector3(0.0f, 5.0f, 0.0f);
414 _menuContainer.ShadowBorder.ParentOrigin = NDalic.ParentOriginCenter;
415 _menuContainer.ShadowBorder.AnchorPoint = NDalic.AnchorPointCenter;
416 _menuContainer.SpotLight = spotLight;
417 _bottomClipLayer.Add(_menuContainer);
419 CreatePosters(); // Create Items for Poster ScrollContainer
420 CreateMenu(); // Create Items for Menu ScrollContainer
422 // Initialize PreFocusChange event of KeyboardFocusManager
423 _keyboardFocusManager = KeyboardFocusManager.Get();
424 _keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChangeSignal;
426 _keyboardFocusIndicator = new ImageView(_imagePath + "/highlight_stroke.9.png");
427 _keyboardFocusIndicator.ParentOrigin = NDalic.ParentOriginCenter;
428 _keyboardFocusIndicator.AnchorPoint = NDalic.AnchorPointCenter;
429 _keyboardFocusIndicator.WidthResizePolicy = "FILL_TO_PARENT";
430 _keyboardFocusIndicator.HeightResizePolicy = "FILL_TO_PARENT";
432 _keyboardFocusManager.SetFocusIndicatorActor(_keyboardFocusIndicator);
434 _keyboardFocusManager.SetAsFocusGroup(_menuContainer, true);
435 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[0], true);
436 _keyboardFocusManager.SetAsFocusGroup(_postersContainer[1], true);
437 _keyboardFocusManager.SetFocusGroupLoop(true);
439 _focusEffect = new FocusEffect();
441 // Move Fcous to Bottom Container (Menu ScrollContainer)
442 ShowBottomContainer();
443 _menuContainer.SetFocused(true);