3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
8 public class FirstScreenApp
10 private int _currentPostersContainerID;
11 private int _totalPostersContainers;
13 private Application _application;
15 private Vector2 _stageSize;
17 private List<ScrollContainer> _postersContainer;
19 private ScrollContainer _menuContainer;
20 private Vector3 _menuItemSize;
22 private Layer _bottomClipLayer;
23 private Layer _topClipLayer;
24 private View _topContainer;
25 private View _bottomContainer;
27 private FocusEffect _focusEffect;
28 private string _imagePath;
30 private ImageView _keyboardFocusIndicator;
31 private ImageView _launcherSeparator;
32 private ImageView[] launcherIcon;
33 private Animation _showBottomContainerAnimation;
34 private Animation _hideBottomContainerAnimation;
36 public FirstScreenApp(Application application)
38 _application = application;
39 _application.Initialized += OnInitialize;
42 public static void Run()
44 FirstScreenApp tVApp = new FirstScreenApp(Application.NewApplication());
48 public 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].AddItem(item);
69 View item = new ImageView(_imagePath + "/poster"+j+"/"+ (i % 6)+ ".jpg");
70 item.SetName ("poster-item-" + _postersContainer[j].ItemCount);
71 _postersContainer[j].AddItem(item);
77 _postersContainer[j].Show();
81 _postersContainer[j].Hide();
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.AddItem(menuItem);
104 private Actor OnKeyboardPreFocusChangeSignal(object source, KeyboardFocusManager.PreFocusChangeEventArgs e)
106 Actor actor = _menuContainer.ItemRoot;
108 if (e.Direction == View.KeyboardFocus.Direction.UP)
110 // Move the Focus to Poster ScrollContainer and hide Bottom Container (Menu ScrollContainer)
111 if (_menuContainer.IsFocused)
113 actor = _postersContainer[_currentPostersContainerID].GetCurrentFocusedActor();
114 _menuContainer.SetFocused(false);
115 _postersContainer[_currentPostersContainerID].SetFocused(true);
116 HideBottomContainer();
118 // Also apply Focus animation on Focused item on Poster ScrollContainer
119 _postersContainer[_currentPostersContainerID].FocusAnimation(_focusEffect, FocusEffectDirection.BottomToTop);
122 else if (e.Direction == View.KeyboardFocus.Direction.DOWN)
124 // Show Bottom Container (Menu ScrollContainer) and move the Focus to it
125 if (!_menuContainer.IsFocused)
127 ShowBottomContainer();
128 actor = _menuContainer.GetCurrentFocusedActor();
129 _postersContainer[_currentPostersContainerID].SetFocused(false);
130 _menuContainer.SetFocused(true);
132 // Also apply Focus animation on Focused item on Menu ScrollContainer
133 _menuContainer.FocusAnimation(_focusEffect, FocusEffectDirection.TopToBottom);
136 else if (e.Direction == View.KeyboardFocus.Direction.LEFT)
138 if (_menuContainer.IsFocused)
140 // Move the Focus to the left item/image of currently focused item on Menu ScrollContainer
141 actor = _menuContainer.FocusPrevious();
143 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
144 if (id != _currentPostersContainerID)
146 _postersContainer[_currentPostersContainerID].Hide();
147 _currentPostersContainerID = id;
149 _postersContainer[_currentPostersContainerID].Show();
154 // Move the Focus to the left item/image of currently focused item on Poster ScrollContainer
155 actor = _postersContainer[_currentPostersContainerID].FocusPrevious();
158 else if (e.Direction == View.KeyboardFocus.Direction.RIGHT)
160 if (_menuContainer.IsFocused)
162 // Move the Focus to the right item/image of currently focused item on Menu ScrollContainer
163 actor = _menuContainer.FocusNext();
165 int id = _menuContainer.FocusedItemID % _totalPostersContainers;
166 if (id != _currentPostersContainerID)
168 _postersContainer[_currentPostersContainerID].Hide();
169 _currentPostersContainerID = id;
170 _postersContainer[_currentPostersContainerID].Show();
175 // Move the Focus to the right item/image of currently focused item on Poster ScrollContainer
176 actor = _postersContainer[_currentPostersContainerID].FocusNext();
183 // Hide Bottom Container (Menu ScrollContainer) when it is not focused
184 private void HideBottomContainer()
186 _topClipLayer.ClippingBox = new RectInteger(0,
187 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
188 Convert.ToInt32((_stageSize.width)),
189 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerExpandHeightFactor))); // X, Y, Width, Height
191 _hideBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION),
192 new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f)),
193 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
194 _hideBottomContainerAnimation.Play();
197 // Show (unhide) Bottom Container (Menu ScrollContainer) when it is focused
198 private void ShowBottomContainer()
200 _topClipLayer.ClippingBox = new RectInteger(0,
201 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
202 Convert.ToInt32((_stageSize.width)),
203 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
205 _showBottomContainerAnimation.AnimateTo(new Property(_bottomContainer, Actor.Property.POSITION),
206 new Property.Value(new Vector3(0.0f, _stageSize.height * Constants.BottomContainerShowPositionFactor, 0.0f)),
207 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
208 _showBottomContainerAnimation.Play();
211 // First screen demo Application initialisation
212 private void OnInitialize(object source, AUIApplicationInitEventArgs e)
214 _stage = Stage.GetCurrent();
215 _stageSize = _stage.GetSize();
216 // _stage.SetBackgroundColor(NDalic.TRANSPARENT);
218 _totalPostersContainers = Constants.TotalPostersContainers;
219 _imagePath = "./images/"; // Desktop
220 // _imagePath = "/home/owner/apps_rw/org.tizen.firstscreen/res/images/"; // Target
222 _postersContainer = new List<ScrollContainer> ();
223 _menuContainer = new ScrollContainer ();
225 _hideBottomContainerAnimation = new Animation(0.25f);
226 _showBottomContainerAnimation = new Animation(0.25f);
228 // Create a Top Container for poster items
229 _topContainer = new View();
230 _topContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.TopContainerHeightFactor, 0.0f);
231 _topContainer.Position = new Vector3(0.0f, _stageSize.y * Constants.TopContainerPositionFactor, 0.0f);
232 _topContainer.ParentOrigin = NDalic.ParentOriginTopLeft;
233 _topContainer.AnchorPoint = NDalic.AnchorPointTopLeft;
235 // Add a background to Top container
236 Property.Map visual = new Property.Map();
237 visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE));
238 visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png"));
239 _topContainer.Background = visual;
240 _topContainer.Name = "TopControl";
242 // Create a Bottom Container
243 _bottomContainer = new View();
244 _bottomContainer.Size = new Vector3(_stageSize.width, _stageSize.height * Constants.BottomContainerHeightFactor, 0.0f);
245 _bottomContainer.Position = new Vector3(0.0f, _stageSize.height * Constants.BottomContainerHidePositionFactor, 0.0f);
246 _bottomContainer.ParentOrigin = NDalic.ParentOriginTopLeft;
247 _bottomContainer.AnchorPoint = NDalic.AnchorPointTopLeft;
249 // Add a background to Bottom Container
250 visual = new Property.Map();
251 visual.Insert(NDalic.VISUAL_PROPERTY_TYPE, new Property.Value((int)VisualType.IMAGE));
252 visual.Insert(NDalic.IMAGE_VISUAL_URL, new Property.Value(_imagePath + "/background.png"));
253 _bottomContainer.Background = visual;
254 _bottomContainer.Name = "BottomControl";
256 // Add both Top and Bottom Containers to Stage
257 _stage.Add(_topContainer);
258 _stage.Add(_bottomContainer);
260 // Add a clip layer to Top Container
261 _topClipLayer = new Layer();
262 _topClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter;
263 _topClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter;
264 _topClipLayer.ClippingEnable = true;
265 _topClipLayer.ClippingBox = new RectInteger(0,
266 Convert.ToInt32(_stageSize.height * Constants.TopContainerPositionFactor),
267 Convert.ToInt32((_stageSize.width)),
268 Convert.ToInt32((_stageSize.height * Constants.TopClipLayerHeightFactor))); // X, Y, Width, Height
269 _topContainer.Add(_topClipLayer);
271 // Create a SpotLight for items / images of both Poster and Menu ScrollContainers
272 ImageView spotLight = new ImageView(_imagePath + "/highlight_spot.png");
273 spotLight.WidthResizePolicy = "USE_NATURAL_SIZE";
274 spotLight.HeightResizePolicy = "USE_NATURAL_SIZE";
275 spotLight.ParentOrigin = NDalic.ParentOriginCenter;
276 spotLight.AnchorPoint = NDalic.AnchorPointCenter;
277 spotLight.Name = "spotLight";
279 // Create a shadowBorder for items / images of Poster ScrollContainers
280 ImageView shadowBorder = new ImageView(_imagePath + "/thumbnail_shadow.9.png");
281 shadowBorder.ParentOrigin = NDalic.ParentOriginCenter;
282 shadowBorder.AnchorPoint = NDalic.AnchorPointCenter;
283 shadowBorder.WidthResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT";
284 shadowBorder.HeightResizePolicy = "SIZE_FIXED_OFFSET_FROM_PARENT";
285 shadowBorder.SetSizeModeFactor(new Vector3(32.0f, 41.0f, 0.0f));
286 shadowBorder.Name = "poster shadowBorder";
288 // Create Poster Containers and add them to Top Clip layer
289 for (int i = 0; i < _totalPostersContainers; i++)
291 _postersContainer.Add(new ScrollContainer());
292 _postersContainer[i].Container.Name = "poster" + i;
295 _postersContainer[i].ItemSize = new Vector3((_stageSize.width * Constants.Poster0ItemWidthFactor) - Constants.PostersContainerPadding,
296 _stageSize.height * Constants.PostersItemHeightFactor, 0.0f);
300 _postersContainer[i].ItemSize = new Vector3(_stageSize.width * Constants.Poster1ItemWidthFactor,
301 _stageSize.height * Constants.PostersItemHeightFactor, 0.0f);
303 _postersContainer[i].Padding = Constants.PostersContainerPadding;
304 _postersContainer[i].MarginX = Constants.PostersContainerMargin;
305 _postersContainer[i].OffsetY = Constants.PostersContainerOffsetYFactor;
306 _postersContainer[i].Width = _stageSize.width;
307 _postersContainer[i].Height = _stageSize.height * Constants.PostersContainerHeightFactor;
308 _postersContainer[i].ShadowBorder = shadowBorder;
309 _postersContainer[i].ShadowBorder.Position = new Vector3(0.0f, 4.0f, 0.0f);
310 _postersContainer[i].SpotLight = spotLight;
311 _topClipLayer.Add(_postersContainer[i].Container);
314 // Add a clip layer to Bottom Container
315 _bottomClipLayer = new Layer();
316 _bottomClipLayer.AnchorPoint = NDalic.AnchorPointBottomCenter;
317 _bottomClipLayer.ParentOrigin = NDalic.ParentOriginBottomCenter;
318 _bottomClipLayer.ClippingEnable = true;
319 _bottomClipLayer.ClippingBox = new RectInteger(Convert.ToInt32(Constants.LauncherWidth),
320 Convert.ToInt32(_stageSize.height * Constants.BottomContainerShowPositionFactor),
321 Convert.ToInt32((_stageSize.width)),
322 Convert.ToInt32((_stageSize.height - (_stageSize.height * Constants.BottomClipLayerHeightFactor)))); // X, Y, Width, Height
323 _bottomContainer.Add(_bottomClipLayer);
325 // Add Launcher items to Bottom Container. Launcher is used to display three images on left of Menu ScrollContainer
326 launcherIcon = new ImageView[Convert.ToInt32(Constants.LauncherItemsCount)];
327 for (int launcherIndex = 0; launcherIndex < Constants.LauncherItemsCount; launcherIndex++)
329 launcherIcon[launcherIndex] = new ImageView(_imagePath + "/" + launcherIndex + "-normal.png");
330 launcherIcon[launcherIndex].Name = "launcherIcon" + launcherIndex;
331 launcherIcon[launcherIndex].WidthResizePolicy = "USE_NATURAL_SIZE";
332 launcherIcon[launcherIndex].HeightResizePolicy = "USE_NATURAL_SIZE";
333 launcherIcon[launcherIndex].ParentOrigin = NDalic.ParentOriginCenterLeft;
334 launcherIcon[launcherIndex].AnchorPoint = NDalic.AnchorPointCenterLeft;
335 launcherIcon[launcherIndex].Position = new Vector3(Constants.LauncherIconWidth * launcherIndex + Constants.LauncherLeftMargin, 0.0f, 0.0f);
336 _bottomContainer.Add(launcherIcon[launcherIndex]);
339 // Add a shadow seperator image between last Launcher icon and Menu ScrollContainer
340 _launcherSeparator = new ImageView(_imagePath + "/focus_launcher_shadow_n.png");
341 _launcherSeparator.Name = "launcherSeparator";
342 _launcherSeparator.WidthResizePolicy = "USE_NATURAL_SIZE";
343 _launcherSeparator.HeightResizePolicy = "FILL_TO_PARENT";
344 _launcherSeparator.ParentOrigin = NDalic.ParentOriginCenterLeft;
345 _launcherSeparator.AnchorPoint = NDalic.AnchorPointCenterLeft;
346 _launcherSeparator.Position = new Vector3(Constants.LauncherIconWidth * Constants.LauncherItemsCount + Constants.LauncherLeftMargin, 0.0f, 0.0f);
347 _bottomContainer.Add(_launcherSeparator);
349 // Create Menu Container and add it to Bottom Clip Layer
350 _menuItemSize = new Vector3((_stageSize.width * Constants.MenuItemWidthFactor) - Constants.MenuContainerPadding,
351 _stageSize.height * Constants.MenuItemHeightFactor, 0.0f);
352 _menuContainer.Container.Name = "menu";
353 _menuContainer.ItemSize = _menuItemSize;
354 _menuContainer.Padding = Constants.MenuContainerPadding;
355 _menuContainer.MarginX = Constants.MenuContainerMargin;
356 _menuContainer.OffsetY = Constants.MenuContainerOffsetYFactor;
357 _menuContainer.OffsetX = Constants.LauncherWidth;
358 _menuContainer.Width = _stageSize.width - Constants.LauncherWidth;
359 _menuContainer.Height = _stageSize.height * Constants.MenuContainerHeightFactor;
360 _menuContainer.ShadowBorder = new ImageView(_imagePath + "/focus_launcher_shadow.9.png");
361 _menuContainer.ShadowBorder.Name = "_menuContainer.ShadowBorder";
362 _menuContainer.ShadowBorder.Size = new Vector3(_menuContainer.ItemSize.width + 40.0f, _menuContainer.ItemSize.height + 50.0f, 0.0f);
363 _menuContainer.ShadowBorder.Position = new Vector3(0.0f, 5.0f, 0.0f);
364 _menuContainer.ShadowBorder.ParentOrigin = NDalic.ParentOriginCenter;
365 _menuContainer.ShadowBorder.AnchorPoint = NDalic.AnchorPointCenter;
366 _menuContainer.SpotLight = spotLight;
367 _bottomClipLayer.Add(_menuContainer.Container);
369 CreatePosters(); // Create Items for Poster ScrollContainer
370 CreateMenu(); // Create Items for Menu ScrollContainer
372 // Initialize PreFocusChange event of KeyboardFocusManager
373 KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.Get();
374 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChangeSignal;
376 _keyboardFocusIndicator = new ImageView(_imagePath + "/highlight_stroke.9.png");
377 _keyboardFocusIndicator.ParentOrigin = NDalic.ParentOriginCenter;
378 _keyboardFocusIndicator.AnchorPoint = NDalic.AnchorPointCenter;
379 _keyboardFocusIndicator.WidthResizePolicy = "FILL_TO_PARENT";
380 _keyboardFocusIndicator.HeightResizePolicy = "FILL_TO_PARENT";
382 keyboardFocusManager.SetFocusIndicatorActor(_keyboardFocusIndicator);
384 _focusEffect = new FocusEffect();
386 // Move Fcous to Bottom Container (Menu ScrollContainer)
387 ShowBottomContainer();
388 _menuContainer.SetFocused(true);