1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2009 Adobe Systems Incorporated
5//  All Rights Reserved.
6//
7//  NOTICE: Adobe permits you to use, modify, and distribute this file
8//  in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11
12package spark.components
13{
14import flash.events.StageOrientationEvent;
15
16import mx.core.FlexGlobals;
17import mx.core.IDataRenderer;
18import mx.core.IVisualElement;
19import mx.core.mx_internal;
20import mx.events.FlexEvent;
21import mx.events.PropertyChangeEvent;
22import mx.events.ResizeEvent;
23
24import spark.core.ContainerDestructionPolicy;
25import spark.events.ViewNavigatorEvent;
26import spark.layouts.supportClasses.LayoutBase;
27
28use namespace mx_internal;
29
30[Exclude(name="height", kind="property")]
31[Exclude(name="minHeight", kind="property")]
32[Exclude(name="maxHeight", kind="property")]
33[Exclude(name="width", kind="property")]
34[Exclude(name="minWidth", kind="property")]
35[Exclude(name="maxWidth", kind="property")]
36[Exclude(name="scaleX", kind="property")]
37[Exclude(name="scaleY", kind="property")]
38[Exclude(name="scaleZ", kind="property")]
39[Exclude(name="z", kind="property")]
40
41//--------------------------------------
42//  Events
43//--------------------------------------
44
45/**
46 *  Dispatched when the back key is pressed when a view exists inside
47 *  a mobile application.
48 *
49 *  @langversion 3.0
50 *  @playerversion AIR 2.5
51 *  @productversion Flex 4.5
52 *
53 *  @eventType mx.events.FlexEvent.BACK_KEY_PRESSED
54 *
55 */
56[Event(name="backKeyPressed", type="mx.events.FlexEvent")]
57
58/**
59 *  Dispatched when the <code>data</code> property changes.
60 *
61 *  @langversion 3.0
62 *  @playerversion AIR 2.5
63 *  @productversion Flex 4.5
64 *
65 *  @eventType mx.events.FlexEvent.DATA_CHANGE
66 *
67 */
68[Event(name="dataChange", type="mx.events.FlexEvent")]
69
70/**
71 *  Dispatched when the menu key is pressed when a view exists inside
72 *  a mobile application.
73 *
74 *  @langversion 3.0
75 *  @playerversion AIR 2.5
76 *  @productversion Flex 4.5
77 *
78 *  @eventType mx.events.FlexEvent.MENU_KEY_PRESSED
79 *
80 */
81[Event(name="menuKeyPressed", type="mx.events.FlexEvent")]
82
83/**
84 *  Dispatched when the current view has been activated.
85 *
86 *  @eventType spark.events.ViewNavigatorEvent.VIEW_ACTIVATE
87 *
88 *  @langversion 3.0
89 *  @playerversion AIR 2.5
90 *  @productversion Flex 4.5
91 */
92[Event(name="viewActivate", type="spark.events.ViewNavigatorEvent")]
93
94/**
95 *  Dispatched when the current view has been deactivated.
96 *
97 *  @eventType spark.events.ViewNavigatorEvent.VIEW_DEACTIVATE
98 *
99 *  @langversion 3.0
100 *  @playerversion AIR 2.5
101 *  @productversion Flex 4.5
102 */
103[Event(name="viewDeactivate", type="spark.events.ViewNavigatorEvent")]
104
105/**
106 *  Dispatched when the screen is about to be removed in response
107 *  to a screen change.
108 *  Calling <code>preventDefault()</code>
109 *  while handling this event cancels the screen change.
110 *
111 *  @eventType spark.events.ViewNavigatorEvent.REMOVING
112 *
113 *  @langversion 3.0
114 *  @playerversion AIR 2.5
115 *  @productversion Flex 4.5
116 */
117[Event(name="removing", type="spark.events.ViewNavigatorEvent")]
118
119/**
120 *  The View class is the base container class for all views used by view
121 *  navigators.
122 *  The View container extends the Group container and adds
123 *  additional properties used to communicate with it's parent
124 *  navigator.
125 *
126 *  <p>In a mobile application, the content area of the application
127 *  displays the individual screens, or views, that make up the application.
128 *  Users navigate the views of the application by using the touch screen,
129 *  components built into the application, and the input controls of the mobile device.</p>
130 *
131 *  <p>The following image shows a View container with a List control:</p>
132 *
133 * <p>
134 *  <img src="../../images/vn_single_section_home_vn.png" alt="View container" />
135 * </p>
136 *
137 *  <p>Each view in an application corresponds to a View container defined
138 *  in an ActionScript or MXML file.
139 *  Each View contains a <code>data</code> property that specifies the data
140 *  associated with that view.
141 *  Views can use the <code>data</code> property to pass information to each
142 *  other as the user navigates the application.</p>
143 *
144 *  @mxml
145 *
146 *  <p>The <code>&lt;s:View&gt;</code> tag inherits all of the tag
147 *  attributes of its superclass and adds the following tag attributes:</p>
148 *
149 *  <pre>
150 *  &lt;s:View
151 *   <strong>Properties</strong>
152 *    actionBarVisible="true"
153 *    actionContent="null"
154 *    actionLayout="null"
155 *    data="null"
156 *    destructionPolicy="auto"
157 *    navigationContent="null"
158 *    navigationLayout="null"
159 *    overlayControls="false"
160 *    tabBarVisible="true"
161 *    title=""
162 *    titleContent="null"
163 *    titleLayout="null"
164 *    viewMenuItems="null"
165 *
166 *   <strong>Events</strong>
167 *    backKeyPressed="<i>No default</i>"
168 *    dataChange="<i>No default</i>"
169 *    menuKeyPressed="<i>No default</i>"
170 *    removing="<i>No default</i>"
171 *    viewActivate="<i>No default</i>"
172 *    viewDeactivate="<i>No default</i>"
173 *
174 *  &gt;
175 *  </pre>
176 *
177 *  @see ViewNavigator
178 *
179 *  @includeExample examples/ViewExample.mxml -noswf
180 *  @includeExample examples/ViewExampleHomeView.mxml -noswf
181 *
182 *  @langversion 3.0
183 *  @playerversion AIR 2.5
184 *  @productversion Flex 4.5
185 */
186public class View extends SkinnableContainer implements IDataRenderer
187{
188    //--------------------------------------------------------------------------
189    //
190    //  Constructor
191    //
192    //--------------------------------------------------------------------------
193
194    /**
195     *  Constructor.
196     *
197     *  @langversion 3.0
198     *  @playerversion AIR 2.5
199     *  @productversion Flex 4.5
200     */
201    public function View()
202    {
203        super();
204    }
205
206    //--------------------------------------------------------------------------
207    //
208    //  Properties
209    //
210    //--------------------------------------------------------------------------
211
212    //----------------------------------
213    //  active
214    //----------------------------------
215
216    private var _active:Boolean = false;
217
218    /**
219     *  Indicates whether the current view is active.
220     *  The view's navigator  automatically sets this flag to <code>true</code>
221     *  or <code>false</code> as its state changes.
222     *  Setting this property can dispatch the <code>viewActivate</code> or
223     *  <code>viewDeactivate</code> events.
224     *
225     *  @default false
226     *
227     *  @langversion 3.0
228     *  @playerversion AIR 2.5
229     *  @productversion Flex 4.5
230     */
231    public function get isActive():Boolean
232    {
233        return _active;
234    }
235
236    /**
237     * @private
238     */
239    mx_internal function setActive(value:Boolean):void
240    {
241        if (_active != value)
242        {
243            _active = value;
244
245            // Switch orientation states if needed
246            if (_active)
247                updateOrientationState();
248
249            var eventName:String = _active ?
250                ViewNavigatorEvent.VIEW_ACTIVATE :
251                ViewNavigatorEvent.VIEW_DEACTIVATE;
252
253            if (hasEventListener(eventName))
254                dispatchEvent(new ViewNavigatorEvent(eventName, false, false, navigator.lastAction));
255        }
256    }
257
258    //----------------------------------
259    //  canRemove
260    //----------------------------------
261
262    /**
263     *  @private
264     *  Determines if the current view can be removed by a navigator.  The default
265     *  implementation dispatches a <code>FlexEvent.REMOVING</code> event.  If
266     *  preventDefault() is called on the event, this property will return false.
267     *
268     *  @return Returns true if the view can be removed
269     *
270     *  @langversion 3.0
271     *  @playerversion AIR 2.5
272     *  @productversion Flex 4.5
273     */
274    mx_internal function canRemove():Boolean
275    {
276        if (hasEventListener(ViewNavigatorEvent.REMOVING))
277        {
278            var event:ViewNavigatorEvent =
279                new ViewNavigatorEvent(ViewNavigatorEvent.REMOVING,
280                                       false, true, navigator.lastAction);
281
282            return dispatchEvent(event);
283        }
284
285        return true;
286    }
287
288    /**
289     *  @private
290     */
291    mx_internal function backKeyHandledByView():Boolean
292    {
293        if (hasEventListener(FlexEvent.BACK_KEY_PRESSED))
294        {
295            var event:FlexEvent = new FlexEvent(FlexEvent.BACK_KEY_PRESSED, false, true);
296            var eventCanceled:Boolean = !dispatchEvent(event);
297
298            // If the event was canceled, that means the application
299            // is doing its own custom logic for the back key
300            return eventCanceled;
301        }
302
303        return false;
304    }
305
306    /**
307     *  @private
308     */
309    mx_internal function menuKeyHandledByView():Boolean
310    {
311        if (hasEventListener(FlexEvent.MENU_KEY_PRESSED))
312        {
313            var event:FlexEvent = new FlexEvent(FlexEvent.MENU_KEY_PRESSED, false, true);
314            var eventCanceled:Boolean = !dispatchEvent(event);
315
316            // If the event was canceled, that means the application
317            // is doing its own custom logic for the back key
318            return eventCanceled;
319        }
320
321        return false;
322    }
323
324    //----------------------------------
325    //  overlayControls
326    //----------------------------------
327
328    private var _overlayControls:Boolean = false;
329
330    [Inspectable(category="General", defaultValue="false")]
331    /**
332     *  By default, the TabBar and ActionBar controls of a
333     *  mobile application define an area that cannot be used
334     *  by the views of an application.
335     *  That means your content cannot use the full screen size
336     *  of the mobile device.
337     *  If you set this property to <code>true</code>, the content area
338     *  of the application spans the entire width and height of the screen.
339     *  The ActionBar and TabBar controls hover over the content area with
340     *  an <code>alpha</code> value of 0.5 so that they are partially transparent.
341     *
342     *  @default false
343     *
344     *  @langversion 3.0
345     *  @playerversion AIR 2.5
346     *  @productversion Flex 4.5
347     */
348    public function get overlayControls():Boolean
349    {
350        return _overlayControls;
351    }
352
353    /**
354     *  @private
355     */
356    public function set overlayControls(value:Boolean):void
357    {
358        if (_overlayControls != value)
359        {
360            var oldValue:Boolean = _overlayControls;
361            _overlayControls = value;
362
363            if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
364            {
365                var changeEvent:PropertyChangeEvent =
366                PropertyChangeEvent.createUpdateEvent(this, "overlayControls", oldValue, _overlayControls);
367
368                dispatchEvent(changeEvent);
369            }
370        }
371    }
372
373    //----------------------------------
374    //  destructionPolicy
375    //----------------------------------
376
377    private var _destructionPolicy:String = ContainerDestructionPolicy.AUTO;
378
379    [Inspectable(category="General", enumeration="auto,never", defaultValue="auto")]
380    /**
381     *  Defines the destruction policy the view's navigator should use
382     *  when this view is removed. If set to "auto", the navigator will
383     *  destroy the view when it isn't active.  If set to "never", the
384     *  view will be cached in memory.
385     *
386     *  @default auto
387     *
388     *  @langversion 3.0
389     *  @playerversion AIR 2.5
390     *  @productversion Flex 4.5
391     */
392    public function get destructionPolicy():String
393    {
394        return _destructionPolicy;
395    }
396
397    /**
398     *  @private
399     */
400    public function set destructionPolicy(value:String):void
401    {
402        _destructionPolicy = value;
403    }
404
405    //----------------------------------
406    //  navigator
407    //----------------------------------
408
409    private var _navigator:ViewNavigator = null;
410
411    /**
412     * The view navigator that this view resides in.
413     *
414     *  @langversion 3.0
415     *  @playerversion AIR 2.5
416     *  @productversion Flex 4.5
417     */
418
419    [Bindable("navigatorChanged")]
420    public function get navigator():ViewNavigator
421    {
422        return _navigator;
423    }
424
425    /**
426     *  @private
427     */
428    mx_internal function setNavigator(value:ViewNavigator):void
429    {
430        _navigator = value;
431
432        if (hasEventListener("navigatorChanged"))
433            dispatchEvent(new Event("navigatorChanged"));
434    }
435
436    //--------------------------------------------------------------------------
437    //
438    //  UI Template Properties
439    //
440    //--------------------------------------------------------------------------
441
442    //----------------------------------
443    //  actionBarVisible
444    //----------------------------------
445    private var _actionBarVisible:Boolean = true;
446
447    [Inspectable(category="General", defaultValue="true")]
448    /**
449     *  Specifies whether a view should show the action bar or not.
450     *  This property does not necessarily correlate to the
451     *  <code>visible</code> property of the view navigator's ActionBar control.
452     *
453     *  @default true
454     *
455     *  @langversion 3.0
456     *  @playerversion AIR 2.5
457     *  @productversion Flex 4.5
458     */
459    public function get actionBarVisible():Boolean
460    {
461        return _actionBarVisible;
462    }
463
464    /**
465     *  @private
466     */
467    public function set actionBarVisible(value:Boolean):void
468    {
469        _actionBarVisible = value;
470
471        // Immediately request actionBar's visibility be toggled
472        if (isActive && navigator)
473        {
474            if (_actionBarVisible)
475                navigator.showActionBar();
476            else
477                navigator.hideActionBar();
478        }
479    }
480
481    /**
482     *  @private
483     *  Method called by parent navigator to update the actionBarVisible
484     *  flag as a result of the showActionBar() or hideActionBar() methods.
485     */
486    mx_internal function setActionBarVisible(value:Boolean):void
487    {
488        _actionBarVisible = value;
489    }
490
491    //----------------------------------
492    //  actionContent
493    //----------------------------------
494
495    private var _actionContent:Array;
496
497    [ArrayElementType("mx.core.IVisualElement")]
498    /**
499     *  This property overrides the <code>actionContent</code>
500     *  property in the ActionBar, ViewNavigator, and
501     *  ViewNavigatorApplication components.
502     *
503     *  @copy ActionBar#actionContent
504     *
505     *  @default null
506     *
507     *  @see ActionBar#actionContent
508     *  @see spark.skins.mobile.ActionBarSkin
509     *
510     *  @langversion 3.0
511     *  @playerversion AIR 2.5
512     *  @productversion Flex 4.5
513     */
514    public function get actionContent():Array
515    {
516        return _actionContent;
517    }
518    /**
519     *  @private
520     */
521    public function set actionContent(value:Array):void
522    {
523        var oldValue:Array = _actionContent;
524        _actionContent = value;
525
526        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
527        {
528            var changeEvent:PropertyChangeEvent =
529                PropertyChangeEvent.createUpdateEvent(this, "actionContent", oldValue, _actionContent);
530
531            dispatchEvent(changeEvent);
532        }
533    }
534
535    //----------------------------------
536    //  actionLayout
537    //----------------------------------
538
539    private var _actionLayout:LayoutBase;
540
541    /**
542     *  @copy ActionBar#actionLayout
543     *
544     *  @default null
545     *
546     *  @langversion 3.0
547     *  @playerversion AIR 2.5
548     *  @productversion Flex 4.5
549     */
550    public function get actionLayout():LayoutBase
551    {
552        return _actionLayout;
553    }
554    /**
555     *  @private
556     */
557    public function set actionLayout(value:LayoutBase):void
558    {
559        var oldValue:LayoutBase = value;
560        _actionLayout = value;
561
562        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
563        {
564            var changeEvent:PropertyChangeEvent =
565                PropertyChangeEvent.createUpdateEvent(this, "actionLayout", oldValue, _actionLayout);
566
567            dispatchEvent(changeEvent);
568        }
569    }
570
571    //----------------------------------
572    //  viewMenuItems
573    //----------------------------------
574
575    private var _viewMenuItems:Vector.<ViewMenuItem>;
576
577    /**
578     *  The Vector of ViewMenuItem objects passed to the ViewMenu when
579     *  this View is the active view.
580     *
581     *  @see ViewMenu
582     *  @see ViewMenuItem
583     *
584     *  @langversion 3.0
585     *  @playerversion AIR 2.5
586     *  @productversion Flex 4.5
587     */
588    public function get viewMenuItems():Vector.<ViewMenuItem>
589    {
590        return _viewMenuItems;
591    }
592
593    public function set viewMenuItems(value:Vector.<ViewMenuItem>):void
594    {
595        _viewMenuItems = value;
596    }
597
598    //----------------------------------
599    //  navigationContent
600    //----------------------------------
601
602    private var _navigationContent:Array;
603
604    [ArrayElementType("mx.core.IVisualElement")]
605    /**
606     *  This property overrides the <code>navigationContent</code>
607     *  property in the ActionBar, ViewNavigator, and
608     *  ViewNavigatorApplication components.
609     *
610     *  @copy ActionBar#navigationContent
611     *
612     *  @default null
613     *
614     *  @see ActionBar#navigationContent
615     *  @see spark.skins.mobile.ActionBarSkin
616     *
617     *  @langversion 3.0
618     *  @playerversion AIR 2.5
619     *  @productversion Flex 4.5
620     */
621    public function get navigationContent():Array
622    {
623        return _navigationContent;
624    }
625    /**
626     *  @private
627     */
628    public function set navigationContent(value:Array):void
629    {
630        var oldValue:Array = _navigationContent;
631        _navigationContent = value;
632
633        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
634        {
635            var changeEvent:PropertyChangeEvent =
636                PropertyChangeEvent.createUpdateEvent(this, "navigationContent", oldValue, _navigationContent);
637
638            dispatchEvent(changeEvent);
639        }
640    }
641
642    //----------------------------------
643    //  navigationLayout
644    //----------------------------------
645
646    private var _navigationLayout:LayoutBase;
647
648    /**
649     *  @copy ActionBar#navigationLayout
650     *
651     *  @default null
652     *
653     *  @langversion 3.0
654     *  @playerversion AIR 2.5
655     *  @productversion Flex 4.5
656     */
657    public function get navigationLayout():LayoutBase
658    {
659        return _navigationLayout;
660    }
661    /**
662     *  @private
663     */
664    public function set navigationLayout(value:LayoutBase):void
665    {
666        var oldValue:LayoutBase = _navigationLayout;
667        _navigationLayout = value;
668
669        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
670        {
671            var changeEvent:PropertyChangeEvent =
672                PropertyChangeEvent.createUpdateEvent(this, "navigationLayout", _navigationLayout, value);
673
674            dispatchEvent(changeEvent);
675        }
676    }
677
678
679
680    //----------------------------------
681    //  tabBarVisible
682    //----------------------------------
683    private var _tabBarVisible:Boolean = true;
684
685    [Inspectable(category="General", defaultValue="true")]
686    /**
687     *  Specifies whether a view should show the tab bar or not.
688     *  This property does not necessarily correlate to the
689     *  <code>visible</code> property of the navigator's TabBar control.
690     *
691     *  @default true
692     *
693     *  @langversion 3.0
694     *  @playerversion AIR 2.5
695     *  @productversion Flex 4.5
696     */
697    public function get tabBarVisible():Boolean
698    {
699        return _tabBarVisible;
700    }
701
702    /**
703     *  @private
704     */
705    public function set tabBarVisible(value:Boolean):void
706    {
707        var oldValue:Boolean = _tabBarVisible;
708        _tabBarVisible = value;
709
710        // Immediately request actionBar's visibility be toggled
711        if (isActive && navigator)
712        {
713            if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
714            {
715                var changeEvent:PropertyChangeEvent =
716                    PropertyChangeEvent.createUpdateEvent(this, "tabBarVisible", oldValue, value);
717
718                dispatchEvent(changeEvent);
719            }
720        }
721    }
722
723    /**
724     *  @private
725     *  Method called by parent navigator to update the actionBarVisible
726     *  flag as a result of the showTabBar() or hideTabBar() methods.
727     */
728    mx_internal function setTabBarVisible(value:Boolean):void
729    {
730        _tabBarVisible = value;
731    }
732
733    //----------------------------------
734    //  title
735    //----------------------------------
736
737    private var _title:String;
738
739    [Bindable]
740    /**
741     *  This property overrides the <code>title</code>
742     *  property in the ActionBar, ViewNavigator, and
743     *  ViewNavigatorApplication components.
744     *
745     *  @copy ActionBar#title
746     *
747     *  @default ""
748     *
749     *  @langversion 3.0
750     *  @playerversion AIR 2.5
751     *  @productversion Flex 4.5
752     */
753    public function get title():String
754    {
755        return _title;
756    }
757    /**
758     *  @private
759     */
760    public function set title(value:String):void
761    {
762        if (_title != value)
763        {
764            var oldValue:String = _title;
765            _title = value;
766
767            if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
768            {
769                var changeEvent:PropertyChangeEvent =
770                    PropertyChangeEvent.createUpdateEvent(this, "title", oldValue, _title);
771
772                dispatchEvent(changeEvent);
773            }
774        }
775    }
776
777    //----------------------------------
778    //  titleContent
779    //----------------------------------
780
781    private var _titleContent:Array;
782
783    [ArrayElementType("mx.core.IVisualElement")]
784    /**
785     *  This property overrides the <code>titleContent</code>
786     *  property in the ActionBar, ViewNavigator, and
787     *  ViewNavigatorApplication components.
788     *
789     *  @copy ActionBar#titleContent
790     *
791     *  @default null
792     *
793     *  @see ActionBar#titleContent
794     *  @see spark.skins.mobile.ActionBarSkin
795     *
796     *  @langversion 3.0
797     *  @playerversion AIR 2.5
798     *  @productversion Flex 4.5
799     */
800    public function get titleContent():Array
801    {
802        return _titleContent;
803    }
804    /**
805     *  @private
806     */
807    public function set titleContent(value:Array):void
808    {
809        var oldValue:Array = _titleContent;
810        _titleContent = value;
811
812        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
813        {
814            var changeEvent:PropertyChangeEvent =
815                PropertyChangeEvent.createUpdateEvent(this, "titleContent", oldValue, _titleContent);
816
817            dispatchEvent(changeEvent);
818        }
819    }
820
821    //----------------------------------
822    //  titleLayout
823    //----------------------------------
824
825    private var _titleLayout:LayoutBase;
826
827    /**
828     *  @copy ActionBar#titleLayout
829     *
830     *  @default null
831     *
832     *  @langversion 3.0
833     *  @playerversion AIR 2.5
834     *  @productversion Flex 4.5
835     */
836    public function get titleLayout():LayoutBase
837    {
838        return _titleLayout;
839    }
840    /**
841     *  @private
842     */
843    public function set titleLayout(value:LayoutBase):void
844    {
845        var oldValue:LayoutBase = _titleLayout;
846        _titleLayout = value;
847
848        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
849        {
850            var changeEvent:PropertyChangeEvent =
851                PropertyChangeEvent.createUpdateEvent(this, "titleLayout", oldValue, _titleLayout);
852
853            dispatchEvent(changeEvent);
854        }
855    }
856
857    //--------------------------------------------------------------------------
858    //
859    //  IDataRenderer Properties
860    //
861    //--------------------------------------------------------------------------
862
863    //----------------------------------
864    //  data
865    //----------------------------------
866
867    private var _data:Object;
868
869    [Bindable("dataChange")]
870
871    /**
872     *  The data associated with the current view.
873     *  You use this property to pass infomration to the View when
874     *  it is pushed onto the navigator's stack.
875     *  You can set this property by passing a <code>data</code>
876     *  argument to the <code>pushView()</code> method.
877     *
878     *  @langversion 3.0
879     *  @playerversion AIR 2.5
880     *  @productversion Flex 4.5
881     */
882    public function get data():Object
883    {
884        return _data;
885    }
886
887    /**
888     *  @private
889     */
890    public function set data(value:Object):void
891    {
892        _data = value;
893
894        if (hasEventListener(FlexEvent.DATA_CHANGE))
895            dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
896    }
897
898    //--------------------------------------------------------------------------
899    //
900    //  Methods
901    //
902    //--------------------------------------------------------------------------
903
904    /**
905     *  Creates an object returned to the view navigator
906     *  when this view is popped off the navigator's stack.
907     *
908     *  <p>Override this method in a View to return data back the new
909     *  view when this view is popped off the stack.
910     *  The <code>createReturnObject()</code> method returns a single Object.
911     *  The Object returned by this method is written to the
912     *  <code>ViewNavigator.poppedViewReturnedObject</code> property. </p>
913     *
914     *  <p>The <code>ViewNavigator.poppedViewReturnedObject</code> property
915     *  is of type ViewReturnObject.
916     *  The <code>ViewReturnObject.object</code> property contains the
917     *  value returned by this method. </p>
918     *
919     *  <p>If the <code>poppedViewReturnedObject</code> property is null,
920     *  no data was returned.
921     *  The <code>poppedViewReturnedObject</code> property is guaranteed to be set
922     *  in the new view before the new view receives the <code>add</code> event.</p>
923     *
924     *  @return The value written to the <code>object</code> field of the
925     *  <code>ViewNavigator.poppedViewReturnedObject</code> property.
926     *
927     *  @see ViewNavigator#poppedViewReturnedObject
928     *  @see spark.components.supportClasses.ViewReturnObject
929     *
930     *  @langversion 3.0
931     *  @playerversion AIR 2.5
932     *  @productversion Flex 4.5
933     */
934    public function createReturnObject():Object
935    {
936        return null;
937    }
938
939    /**
940     *  Checks the aspect ratio of the stage and returns the proper state
941     *  that the View should change to.
942     *
943     *  @return A String specifying the name of the state to apply to the view.
944     *  The possible return values are <code>"portrait"</code>
945     *  or <code>"landscape"</code>.
946     *  The state is only changed if the desired state exists
947     *  on the View.
948     *  If it does not, this method returns the component's current state.
949     *
950     *  @langversion 3.0
951     *  @playerversion AIR 2.5
952     *  @productversion Flex 4.5
953     */
954    public function getCurrentViewState():String
955    {
956        var aspectRatio:String = FlexGlobals.topLevelApplication.aspectRatio;
957
958        if (hasState(aspectRatio))
959            return aspectRatio;
960
961        // If the appropriate state for the orientation of the device
962        // isn't defined, return the current state
963        return currentState;
964    }
965
966    //--------------------------------------------------------------------------
967    //
968    //  Private Methods
969    //
970    //--------------------------------------------------------------------------
971    /**
972     *  @private
973     */
974    private function application_resizeHandler(event:Event):void
975    {
976        if (isActive)
977            updateOrientationState();
978    }
979
980    /**
981     *  @private
982     */
983    mx_internal function updateOrientationState():void
984    {
985        setCurrentState(getCurrentViewState(), false);
986    }
987
988    //--------------------------------------------------------------------------
989    //
990    //  Overridden methods: UIComponent
991    //
992    //--------------------------------------------------------------------------
993
994    /**
995     *  @private
996     */
997    override public function initialize():void
998    {
999        super.initialize();
1000
1001        addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
1002    }
1003
1004    /**
1005     *  @private
1006     */
1007    private function creationCompleteHandler(event:FlexEvent):void
1008    {
1009        removeEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
1010
1011        // Create a weak listener so stage doesn't hold a reference to the view
1012        FlexGlobals.topLevelApplication.addEventListener(ResizeEvent.RESIZE,
1013            application_resizeHandler, false, 0, true);
1014
1015        updateOrientationState();
1016    }
1017
1018    //--------------------------------------------------------------------------
1019    //
1020    //  Persistence Methods
1021    //
1022    //--------------------------------------------------------------------------
1023
1024    /**
1025     *  Responsible for serializes the view's <code>data</code> property
1026     *  when the view is being persisted to disk.
1027     *  The returned object should be something that can
1028     *  be successfully written to a shared object.
1029     *  By default, this method returns the <code>data</code> property
1030     *  of the view.
1031     *
1032     *  @return The serialized data object.
1033     *
1034     *  @langversion 3.0
1035     *  @playerversion AIR 2.5
1036     *  @productversion Flex 4.5
1037     */
1038    public function serializeData():Object
1039    {
1040        return data;
1041    }
1042
1043    /**
1044     *  Deserializes a data object that was saved to disk by the view,
1045     *  typically by a call to the <code>serializeData()</code> method.
1046     *
1047     *  @param value The data object to deserialize.
1048     *
1049     *  @return The value assigned to the
1050     *  view's <code>data</code> property.
1051     *
1052     *
1053     *  @langversion 3.0
1054     *  @playerversion AIR 2.5
1055     *  @productversion Flex 4.5
1056     */
1057    public function deserializeData(value:Object):Object
1058    {
1059        return value;
1060    }
1061}
1062}