OSDN Git Service

Add orientation to configuration for layoutlib.
authorDeepanshu Gupta <deepanshu@google.com>
Fri, 12 Jul 2013 22:24:51 +0000 (15:24 -0700)
committerDeepanshu Gupta <deepanshu@google.com>
Fri, 12 Jul 2013 22:54:08 +0000 (15:54 -0700)
Update the configuration with the device orientation before rendering.

Change-Id: Icd40901204fd13f90b18353e53a15e25e5b2176c

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java

index cbefd3d..b909bec 100644 (file)
@@ -30,6 +30,7 @@ import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.android.BridgeContext;
 import com.android.resources.Density;
 import com.android.resources.ResourceType;
+import com.android.resources.ScreenOrientation;
 import com.android.resources.ScreenSize;
 
 import android.content.res.Configuration;
@@ -347,6 +348,23 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
         config.compatScreenWidthDp = config.screenWidthDp;
         config.compatScreenHeightDp = config.screenHeightDp;
 
+        ScreenOrientation orientation = hardwareConfig.getOrientation();
+        if (orientation != null) {
+            switch (orientation) {
+            case PORTRAIT:
+                config.orientation = Configuration.ORIENTATION_PORTRAIT;
+                break;
+            case LANDSCAPE:
+                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
+                break;
+            case SQUARE:
+                config.orientation = Configuration.ORIENTATION_SQUARE;
+                break;
+            }
+        } else {
+            config.orientation = Configuration.ORIENTATION_UNDEFINED;
+        }
+
         // TODO: fill in more config info.
 
         return config;