LayoutLib: return ViewInfo for all merged items + Build init.
android.os.Build is now initialized from the build properties parsed from the SDK build.prop file. Change-Id: If16953215ca90fb0beacb51bf405b89a5c8a34fa
This commit is contained in:
@ -446,6 +446,15 @@ public class Region_Delegate {
|
||||
return region1.mArea.equals(region2.mArea);
|
||||
}
|
||||
|
||||
/*package*/ static String nativeToString(int native_region) {
|
||||
Region_Delegate region = sManager.getDelegate(native_region);
|
||||
if (region == null) {
|
||||
return "not found";
|
||||
}
|
||||
|
||||
return region.mArea.toString();
|
||||
}
|
||||
|
||||
// ---- Private delegate/helper methods ----
|
||||
|
||||
}
|
||||
|
46
tools/layoutlib/bridge/src/android/os/Build_Delegate.java
Normal file
46
tools/layoutlib/bridge/src/android/os/Build_Delegate.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed 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 android.os;
|
||||
|
||||
import com.android.layoutlib.bridge.Bridge;
|
||||
import com.android.layoutlib.bridge.impl.DelegateManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Delegate implementing the native methods of android.os.Build
|
||||
*
|
||||
* Through the layoutlib_create tool, the original native methods of Build have been replaced
|
||||
* by calls to methods of the same name in this delegate class.
|
||||
*
|
||||
* Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
|
||||
* around to map int to instance of the delegate.
|
||||
*
|
||||
*/
|
||||
public class Build_Delegate {
|
||||
|
||||
/*package*/ static String getString(String property) {
|
||||
Map<String, String> properties = Bridge.getPlatformProperties();
|
||||
String value = properties.get(property);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return Build.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
@ -93,6 +93,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
||||
new HashMap<String, SoftReference<NinePatchChunk>>();
|
||||
|
||||
private static Map<String, Map<String, Integer>> sEnumValueMap;
|
||||
private static Map<String, String> sPlatformProperties;
|
||||
|
||||
/**
|
||||
* int[] wrapper to use as keys in maps.
|
||||
@ -157,10 +158,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
||||
*/
|
||||
private static LayoutLog sCurrentLog = sDefaultLog;
|
||||
|
||||
|
||||
private EnumSet<Capability> mCapabilities;
|
||||
|
||||
|
||||
@Override
|
||||
public int getApiLevel() {
|
||||
return com.android.ide.common.rendering.api.Bridge.API_CURRENT;
|
||||
@ -172,8 +171,11 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap,
|
||||
public boolean init(Map<String,String> platformProperties,
|
||||
File fontLocation,
|
||||
Map<String, Map<String, Integer>> enumValueMap,
|
||||
LayoutLog log) {
|
||||
sPlatformProperties = platformProperties;
|
||||
sEnumValueMap = enumValueMap;
|
||||
|
||||
// don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
|
||||
@ -428,6 +430,13 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the platform build properties.
|
||||
*/
|
||||
public static Map<String, String> getPlatformProperties() {
|
||||
return sPlatformProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bitmap for a specific path, from a specific project cache, or from the
|
||||
* framework cache.
|
||||
|
@ -30,6 +30,7 @@ import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -55,8 +56,8 @@ public class BridgeRenderSession extends RenderSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewInfo getRootView() {
|
||||
return mSession.getViewInfo();
|
||||
public List<ViewInfo> getRootViews() {
|
||||
return mSession.getViewInfos();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,7 +116,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
|
||||
// information being returned through the API
|
||||
private BufferedImage mImage;
|
||||
private ViewInfo mViewInfo;
|
||||
private List<ViewInfo> mViewInfoList;
|
||||
|
||||
private static final class PostInflateException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -478,7 +478,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
|
||||
mViewRoot.draw(mCanvas);
|
||||
|
||||
mViewInfo = visit(((ViewGroup)mViewRoot).getChildAt(0), mContext);
|
||||
mViewInfoList = visitAllChildren((ViewGroup)mViewRoot, mContext);
|
||||
|
||||
// success!
|
||||
return SUCCESS.createResult();
|
||||
@ -1101,16 +1101,25 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
|
||||
if (view instanceof ViewGroup) {
|
||||
ViewGroup group = ((ViewGroup) view);
|
||||
List<ViewInfo> children = new ArrayList<ViewInfo>();
|
||||
for (int i = 0; i < group.getChildCount(); i++) {
|
||||
children.add(visit(group.getChildAt(i), context));
|
||||
}
|
||||
result.setChildren(children);
|
||||
result.setChildren(visitAllChildren(group, context));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, BridgeContext context) {
|
||||
if (viewGroup == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ViewInfo> children = new ArrayList<ViewInfo>();
|
||||
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
||||
children.add(visit(viewGroup.getChildAt(i), context));
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
private void invalidateRenderingSize() {
|
||||
mMeasuredScreenWidth = mMeasuredScreenHeight = -1;
|
||||
}
|
||||
@ -1119,8 +1128,8 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
return mImage;
|
||||
}
|
||||
|
||||
public ViewInfo getViewInfo() {
|
||||
return mViewInfo;
|
||||
public List<ViewInfo> getViewInfos() {
|
||||
return mViewInfoList;
|
||||
}
|
||||
|
||||
public Map<String, String> getDefaultProperties(Object viewObject) {
|
||||
|
@ -96,6 +96,7 @@ public final class CreateInfo implements ICreateInfo {
|
||||
private final static String[] DELEGATE_METHODS = new String[] {
|
||||
"android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
|
||||
"android.os.Handler#sendMessageAtTime",
|
||||
"android.os.Build#getString",
|
||||
"android.view.LayoutInflater#rInflate",
|
||||
"android.view.View#isInEditMode",
|
||||
"com.android.internal.util.XmlUtils#convertValueToInt",
|
||||
|
Reference in New Issue
Block a user