Adding DeviceSizeBead to Mobile project.

Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/d03463c4
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/d03463c4
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/d03463c4

Branch: refs/heads/refactor-sprite
Commit: d03463c436b379d2f13f498bd80a1b63fe1222c1
Parents: ac43c3d
Author: Peter Ent <p...@apache.org>
Authored: Fri Oct 7 11:55:51 2016 -0400
Committer: Peter Ent <p...@apache.org>
Committed: Fri Oct 7 11:55:51 2016 -0400

----------------------------------------------------------------------
 .../apache/flex/mobile/beads/DeviceSizeBead.as  | 105 +++++++++++++++++++
 1 file changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d03463c4/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/DeviceSizeBead.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/DeviceSizeBead.as
 
b/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/DeviceSizeBead.as
new file mode 100644
index 0000000..eb004d0
--- /dev/null
+++ 
b/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/DeviceSizeBead.as
@@ -0,0 +1,105 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.mobile.beads
+{      
+       import org.apache.flex.core.Application;
+       import org.apache.flex.core.View;
+       import org.apache.flex.core.IStrand;
+       import org.apache.flex.core.IBead;
+       import org.apache.flex.core.IUIBase;
+       import org.apache.flex.core.UIBase;
+       import org.apache.flex.events.Event;
+       
+       COMPILE::SWF
+       {
+               import flash.events.Event;
+               import flash.external.ExternalInterface;
+               import flash.utils.getQualifiedClassName;        
+       }
+       
+       /**
+        * The DeviceSizeBead.
+        *  
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion FlexJS 0.0
+        */
+       public class DeviceSizeBead implements IBead
+       {
+               /**
+                * Constructor.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function DeviceSizeBead()
+               {
+                       super();
+               }
+               
+               private var _app:Application;
+               
+               /**
+                * @private
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _app = value as Application;
+                       
+                       COMPILE::SWF
+                       {
+                               _app.stage.addEventListener("resize", 
onResize);     
+                               onResize(null);
+                       }
+                       
+                       COMPILE::JS {
+                               window.addEventListener("resize", onResize, 
false);
+                               onResize();
+                       }
+               }
+               
+               COMPILE::JS
+               private function onResize():void
+               {
+                       var initialView:UIBase = _app.initialView as UIBase;
+                       var element:HTMLElement = _app.element;
+                       //if (!isNaN(initialView.percentWidth) || 
!isNaN(initialView.percentHeight)) {
+                               element.style.height = 
window.innerHeight.toString() + 'px';
+                               element.style.width = 
window.innerWidth.toString() + 'px';
+                               initialView.dispatchEvent('sizeChanged'); // 
kick off layout if % sizes
+                       //}
+                       //initialView.setWidthAndHeight(window.innerWidth, 
window.innerHeight);
+               }
+               
+               COMPILE::SWF
+               private function onResize(event:flash.events.Event):void
+               {
+                       var initialView:UIBase = _app.initialView as UIBase;
+                       if (!isNaN(initialView.percentWidth) && 
!isNaN(initialView.percentHeight))
+                               
initialView.setWidthAndHeight(_app.stage.stageWidth, _app.stage.stageHeight);
+                       else if (!isNaN(initialView.percentWidth))
+                               initialView.setWidth(_app.stage.stageWidth);
+                       else if (!isNaN(initialView.percentHeight))
+                               initialView.setHeight(_app.stage.stageHeight);
+               }
+       }
+}

Reply via email to