Skip to content

Commit

Permalink
added support for rim:orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Neil authored and qingbiao committed Nov 29, 2011
1 parent b49033a commit 0529f6d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
12 changes: 12 additions & 0 deletions framework/src/blackberry/web/widget/Widget.java
Expand Up @@ -53,6 +53,18 @@ public Widget( WidgetConfig wConfig, String locationURI ) {
initialize();
_locationURI = locationURI;

// Set our orientation
WidgetConfigImpl configImpl = (WidgetConfigImpl) _wConfig;
if (configImpl.isOrientationDefined()) {
int direction;
if (configImpl.getOrientation() == 0) {
direction = net.rim.device.api.system.Display.DIRECTION_PORTRAIT;
} else {
direction = net.rim.device.api.system.Display.DIRECTION_LANDSCAPE;
}
net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(direction);
}

// Create PageManager
PageManager pageManager = new PageManager( this, (WidgetConfigImpl) _wConfig );

Expand Down
17 changes: 17 additions & 0 deletions framework/src/blackberry/web/widget/impl/WidgetConfigImpl.java
Expand Up @@ -92,6 +92,10 @@ public abstract class WidgetConfigImpl implements WidgetConfig {
protected int _transitionType;
protected int _transitionDuration;
protected int _transitionDirection;

// orientation configuration
protected int _orientation;
protected boolean _orientationDefined;

// caches configuration
protected boolean _cacheEnabled;
Expand Down Expand Up @@ -137,6 +141,10 @@ protected WidgetConfigImpl() {
_transitionType = TransitionConstants.TRANSITION_NONE;
_transitionDuration = TransitionConstants.DEFAULT_DURATION;
_transitionDirection = TransitionConstants.DIRECTION_LEFT;

// Set default orientation values
_orientationDefined = false;
_orientation = -1;

// Set default value of cache configuration
_cacheEnabled = true;
Expand Down Expand Up @@ -282,6 +290,15 @@ public int getTransitionDuration() {
public int getTransitionDirection() {
return _transitionDirection;
}

// Getters of orientation
public boolean isOrientationDefined() {
return _orientationDefined;
}

public int getOrientation() {
return _orientation;
}

// Getters of cache configuration
public boolean isCacheEnabled() {
Expand Down
19 changes: 19 additions & 0 deletions packager/src/net/rim/tumbler/config/WidgetConfig.java
Expand Up @@ -35,6 +35,9 @@ public class WidgetConfig {
private String _name;
private String _version;

protected int _orientation; // Portrait 0, Landscape 1
protected boolean _orientationDefined;

private String _loadingScreenColour;
private String _backgroundImage;
private String _foregroundImage;
Expand Down Expand Up @@ -106,6 +109,9 @@ public WidgetConfig() {
_aggressiveCacheAge= null;
_maxCacheable = null;
_maxCacheSize = null;

_orientationDefined = false;
_orientation = -1;

_runOnStartup=false;
_allowInvokeParams=false;
Expand Down Expand Up @@ -151,6 +157,14 @@ public String getDescription() {
return _description;
}

public int getOrientation() {
return _orientation;
}

public boolean getOrientationDefined() {
return _orientationDefined;
}

public Vector<String> getHoverIconSrc() {
return _hoverIconSrc;
}
Expand All @@ -162,6 +176,11 @@ public Vector<String> getIconSrc() {
public void setContent(String content) {
_content = content;
}

public void setOrientation(int value) {
_orientation = value;
_orientationDefined = true;
}

public void setAuthor(String author) {
_author = author;
Expand Down
Expand Up @@ -135,6 +135,12 @@ public byte[] serialize() {
if (_widgetConfig.getNavigationMode()) {
buffer.append("_widgetNavigationMode = true;").append(NL_LVL_0);
}

// Set orientation
if (_widgetConfig.getOrientationDefined()) {
buffer.append("_orientationDefined = true;").append(NL_LVL_0);
buffer.append("_orientation = " + Integer.toString(_widgetConfig.getOrientation()) + ";").append(NL_LVL_0);
}

// Add LoadingScreen configuration
if (_widgetConfig.getFirstPageLoad()) {
Expand Down
28 changes: 28 additions & 0 deletions packager/src/net/rim/tumbler/xml/ConfigXMLParser.java
Expand Up @@ -102,6 +102,8 @@ private WidgetConfig parseDocument(Document dom, WidgetArchive archive) throws E
processNavigationNode(node);
} else if (node.getNodeName().equals("rim:cache")) {
processCacheNode(node);
} else if (node.getNodeName().equals("rim:orientation")) {
processOrientationNode(node);
} else if (node.getNodeName().equals("name")) {
_widgetConfig.setName(getTextValue(node));
} else if (node.getNodeName().equals("description")) {
Expand Down Expand Up @@ -601,6 +603,32 @@ private void processConnectionNode(Node connectionNode) throws Exception {
_widgetConfig.setTransportOrder(transportArray);
}
}


// Processing for the <rim:orientation> node
private void processOrientationNode(Node orientationNode) throws Exception {

// get mode
NamedNodeMap attrs = orientationNode.getAttributes();
Node modeAttrNode = attrs.getNamedItem("mode");
if (modeAttrNode != null) {
try{
int orientation = -1;
if (modeAttrNode.getNodeValue().equalsIgnoreCase("portrait")) {
orientation = 0;
} else if (modeAttrNode.getNodeValue().equalsIgnoreCase("landscape")) {
orientation = 1;
}
// Only set the orientation if it was properly specified
if (orientation != -1) {
_widgetConfig.setOrientation(orientation);
}
}catch(Exception e){
// Default values are used if an error happens
}
}
}

// Processing for the <rim:cache> node
private void processCacheNode(Node cacheNode) throws Exception {

Expand Down

0 comments on commit 0529f6d

Please sign in to comment.