Skip to content
This repository
Browse code

added support for rim:orientation

  • Loading branch information...
commit 0529f6dbc49d9fb2c013db23fb3b3ec2ff4449b3 1 parent b49033a
Tim Neil tneil authored qingbiao committed
12 framework/src/blackberry/web/widget/Widget.java
@@ -53,6 +53,18 @@ public Widget( WidgetConfig wConfig, String locationURI ) {
53 53 initialize();
54 54 _locationURI = locationURI;
55 55
  56 + // Set our orientation
  57 + WidgetConfigImpl configImpl = (WidgetConfigImpl) _wConfig;
  58 + if (configImpl.isOrientationDefined()) {
  59 + int direction;
  60 + if (configImpl.getOrientation() == 0) {
  61 + direction = net.rim.device.api.system.Display.DIRECTION_PORTRAIT;
  62 + } else {
  63 + direction = net.rim.device.api.system.Display.DIRECTION_LANDSCAPE;
  64 + }
  65 + net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(direction);
  66 + }
  67 +
56 68 // Create PageManager
57 69 PageManager pageManager = new PageManager( this, (WidgetConfigImpl) _wConfig );
58 70
17 framework/src/blackberry/web/widget/impl/WidgetConfigImpl.java
@@ -92,6 +92,10 @@
92 92 protected int _transitionType;
93 93 protected int _transitionDuration;
94 94 protected int _transitionDirection;
  95 +
  96 + // orientation configuration
  97 + protected int _orientation;
  98 + protected boolean _orientationDefined;
95 99
96 100 // caches configuration
97 101 protected boolean _cacheEnabled;
@@ -137,6 +141,10 @@ protected WidgetConfigImpl() {
137 141 _transitionType = TransitionConstants.TRANSITION_NONE;
138 142 _transitionDuration = TransitionConstants.DEFAULT_DURATION;
139 143 _transitionDirection = TransitionConstants.DIRECTION_LEFT;
  144 +
  145 + // Set default orientation values
  146 + _orientationDefined = false;
  147 + _orientation = -1;
140 148
141 149 // Set default value of cache configuration
142 150 _cacheEnabled = true;
@@ -282,6 +290,15 @@ public int getTransitionDuration() {
282 290 public int getTransitionDirection() {
283 291 return _transitionDirection;
284 292 }
  293 +
  294 + // Getters of orientation
  295 + public boolean isOrientationDefined() {
  296 + return _orientationDefined;
  297 + }
  298 +
  299 + public int getOrientation() {
  300 + return _orientation;
  301 + }
285 302
286 303 // Getters of cache configuration
287 304 public boolean isCacheEnabled() {
19 packager/src/net/rim/tumbler/config/WidgetConfig.java
@@ -35,6 +35,9 @@
35 35 private String _name;
36 36 private String _version;
37 37
  38 + protected int _orientation; // Portrait 0, Landscape 1
  39 + protected boolean _orientationDefined;
  40 +
38 41 private String _loadingScreenColour;
39 42 private String _backgroundImage;
40 43 private String _foregroundImage;
@@ -106,6 +109,9 @@ public WidgetConfig() {
106 109 _aggressiveCacheAge= null;
107 110 _maxCacheable = null;
108 111 _maxCacheSize = null;
  112 +
  113 + _orientationDefined = false;
  114 + _orientation = -1;
109 115
110 116 _runOnStartup=false;
111 117 _allowInvokeParams=false;
@@ -151,6 +157,14 @@ public String getDescription() {
151 157 return _description;
152 158 }
153 159
  160 + public int getOrientation() {
  161 + return _orientation;
  162 + }
  163 +
  164 + public boolean getOrientationDefined() {
  165 + return _orientationDefined;
  166 + }
  167 +
154 168 public Vector<String> getHoverIconSrc() {
155 169 return _hoverIconSrc;
156 170 }
@@ -162,6 +176,11 @@ public String getDescription() {
162 176 public void setContent(String content) {
163 177 _content = content;
164 178 }
  179 +
  180 + public void setOrientation(int value) {
  181 + _orientation = value;
  182 + _orientationDefined = true;
  183 + }
165 184
166 185 public void setAuthor(String author) {
167 186 _author = author;
6 packager/src/net/rim/tumbler/serialize/WidgetConfig_v1Serializer.java
@@ -135,6 +135,12 @@ public WidgetConfig_v1Serializer(WidgetConfig widgetConfig) {
135 135 if (_widgetConfig.getNavigationMode()) {
136 136 buffer.append("_widgetNavigationMode = true;").append(NL_LVL_0);
137 137 }
  138 +
  139 + // Set orientation
  140 + if (_widgetConfig.getOrientationDefined()) {
  141 + buffer.append("_orientationDefined = true;").append(NL_LVL_0);
  142 + buffer.append("_orientation = " + Integer.toString(_widgetConfig.getOrientation()) + ";").append(NL_LVL_0);
  143 + }
138 144
139 145 // Add LoadingScreen configuration
140 146 if (_widgetConfig.getFirstPageLoad()) {
28 packager/src/net/rim/tumbler/xml/ConfigXMLParser.java
@@ -102,6 +102,8 @@ private WidgetConfig parseDocument(Document dom, WidgetArchive archive) throws E
102 102 processNavigationNode(node);
103 103 } else if (node.getNodeName().equals("rim:cache")) {
104 104 processCacheNode(node);
  105 + } else if (node.getNodeName().equals("rim:orientation")) {
  106 + processOrientationNode(node);
105 107 } else if (node.getNodeName().equals("name")) {
106 108 _widgetConfig.setName(getTextValue(node));
107 109 } else if (node.getNodeName().equals("description")) {
@@ -601,6 +603,32 @@ private void processConnectionNode(Node connectionNode) throws Exception {
601 603 _widgetConfig.setTransportOrder(transportArray);
602 604 }
603 605 }
  606 +
  607 +
  608 + // Processing for the <rim:orientation> node
  609 + private void processOrientationNode(Node orientationNode) throws Exception {
  610 +
  611 + // get mode
  612 + NamedNodeMap attrs = orientationNode.getAttributes();
  613 + Node modeAttrNode = attrs.getNamedItem("mode");
  614 + if (modeAttrNode != null) {
  615 + try{
  616 + int orientation = -1;
  617 + if (modeAttrNode.getNodeValue().equalsIgnoreCase("portrait")) {
  618 + orientation = 0;
  619 + } else if (modeAttrNode.getNodeValue().equalsIgnoreCase("landscape")) {
  620 + orientation = 1;
  621 + }
  622 + // Only set the orientation if it was properly specified
  623 + if (orientation != -1) {
  624 + _widgetConfig.setOrientation(orientation);
  625 + }
  626 + }catch(Exception e){
  627 + // Default values are used if an error happens
  628 + }
  629 + }
  630 + }
  631 +
604 632 // Processing for the <rim:cache> node
605 633 private void processCacheNode(Node cacheNode) throws Exception {
606 634

0 comments on commit 0529f6d

Please sign in to comment.
Something went wrong with that request. Please try again.