Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94243b0e authored by Xavier Ducrohet's avatar Xavier Ducrohet Committed by Android Git Automerger
Browse files

am cf2b9ca1: Merge "LayoutLib: return ViewInfo for all merged items + Build init." into honeycomb

* commit 'cf2b9ca1':
  LayoutLib: return ViewInfo for all merged items + Build init.
parents 9392c41b cf2b9ca1
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
/*
 * 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;
    }

}
+12 −3
Original line number Diff line number Diff line
@@ -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.
+3 −2
Original line number Diff line number Diff line
@@ -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
+18 −9
Original line number Diff line number Diff line
@@ -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) {
Loading