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

Commit 01811aa8 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: Create new layoutparams when moving a child

Change-Id: Ie2183490e8d26ef194030a9d87fe7745f24f1d83
parent 3c78f2de
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public final class Bridge extends LayoutBridge {
    public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) {
        sEnumValueMap = enumValueMap;

        // don't use EnumSet.allOf(), because the bridge doesn't come with it's specific version
        // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
        // of layoutlib_api. It is provided by the client which could have a more recent version
        // with newer, unsupported capabilities.
        mCapabilities = EnumSet.of(
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class BridgeLayoutScene extends LayoutScene {
            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.moveChild((ViewGroup) parentView, (View) childView, index,
                        listener);
                        layoutParams, listener);
            }
        } finally {
            mScene.release();
+16 −13
Original line number Diff line number Diff line
@@ -319,18 +319,14 @@ public final class BridgeContext extends Activity {
    public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs,
            int defStyleAttr, int defStyleRes) {

        Map<String, String> defaultPropMap = null;
        boolean isPlatformFile = true;

        // Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java
        BridgeXmlBlockParser parser = null;
        if (set instanceof BridgeXmlBlockParser) {
            BridgeXmlBlockParser parser = null;
            parser = (BridgeXmlBlockParser)set;
        } else if (set != null) { // null parser is ok
            // really this should not be happening since its instantiated in Bridge
            mLogger.error("Parser is not a BridgeXmlBlockParser!");
            return null;
        }

        Map<String, String> defaultPropMap = null;
        if (parser != null) {
            Object key = parser.getViewKey();
            if (key != null) {
                defaultPropMap = mDefaultPropMaps.get(key);
@@ -339,21 +335,28 @@ public final class BridgeContext extends Activity {
                    mDefaultPropMaps.put(key, defaultPropMap);
                }
            }

        } else if (set instanceof BridgeLayoutParamsMapAttributes) {
            // good, nothing to do.
        } else if (set != null) { // null parser is ok
            // really this should not be happening since its instantiated in Bridge
            mLogger.error("Parser is not a BridgeXmlBlockParser!");
            return null;
        }

        boolean[] frameworkAttributes = new boolean[1];
        TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes);

        BridgeTypedArray ta = ((BridgeResources) mResources).newTypeArray(attrs.length,
                parser != null ? parser.isPlatformFile() : true);
                isPlatformFile);

        // resolve the defStyleAttr value into a IStyleResourceValue
        IStyleResourceValue defStyleValues = null;

        // look for a custom style.
        String customStyle = null;
        if (parser != null) {
            customStyle = parser.getAttributeValue(null /* namespace*/, "style");
        if (set != null) {
            customStyle = set.getAttributeValue(null /* namespace*/, "style");
        }
        if (customStyle != null) {
            IResourceValue item = findResValue(customStyle, false /*forceFrameworkOnly*/);
@@ -406,8 +409,8 @@ public final class BridgeContext extends Activity {

                String name = styleAttribute.getValue();
                String value = null;
                if (parser != null) {
                    value = parser.getAttributeValue(namespace, name);
                if (set != null) {
                    value = set.getAttributeValue(namespace, name);
                }

                // if there's no direct value for this attribute in the XML, we look for default
+142 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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 com.android.layoutlib.bridge.android;

import com.android.layoutlib.bridge.BridgeConstants;

import android.util.AttributeSet;

import java.util.Map;

/**
 * An implementation of the {@link AttributeSet} interface on top of a map of attribute in the form
 * of (name, value).
 *
 * This is meant to be called only from {@link BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)}
 * in the case of LayoutParams and therefore isn't a full implementation.
 */
public class BridgeLayoutParamsMapAttributes implements AttributeSet {

    private final Map<String, String> mAttributes;

    public BridgeLayoutParamsMapAttributes(Map<String, String> attributes) {
        mAttributes = attributes;
    }

    public String getAttributeValue(String namespace, String name) {
        if (BridgeConstants.NS_RESOURCES.equals(namespace)) {
            return mAttributes.get(name);
        }

        return null;
    }

    // ---- the following methods are not called from
    // BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)
    // Should they ever be called, we'll just implement them on a need basis.

    public int getAttributeCount() {
        throw new UnsupportedOperationException();
    }

    public String getAttributeName(int index) {
        throw new UnsupportedOperationException();
    }

    public String getAttributeValue(int index) {
        throw new UnsupportedOperationException();
    }

    public String getPositionDescription() {
        throw new UnsupportedOperationException();
    }

    public int getAttributeNameResource(int index) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeListValue(String namespace, String attribute,
            String[] options, int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public boolean getAttributeBooleanValue(String namespace, String attribute,
            boolean defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeResourceValue(String namespace, String attribute,
            int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeIntValue(String namespace, String attribute,
            int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeUnsignedIntValue(String namespace, String attribute,
            int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public float getAttributeFloatValue(String namespace, String attribute,
            float defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeListValue(int index,
            String[] options, int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeResourceValue(int index, int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeIntValue(int index, int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getAttributeUnsignedIntValue(int index, int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public float getAttributeFloatValue(int index, float defaultValue) {
        throw new UnsupportedOperationException();
    }

    public String getIdAttribute() {
        throw new UnsupportedOperationException();
    }

    public String getClassAttribute() {
        throw new UnsupportedOperationException();
    }

    public int getIdAttributeResourceValue(int defaultValue) {
        throw new UnsupportedOperationException();
    }

    public int getStyleAttribute() {
        throw new UnsupportedOperationException();
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -36,13 +36,13 @@ import java.io.Reader;
 */
public class BridgeXmlBlockParser implements XmlResourceParser {

    private XmlPullParser mParser;
    private XmlPullAttributes mAttrib;
    private final XmlPullParser mParser;
    private final XmlPullAttributes mAttrib;
    private final BridgeContext mContext;
    private final boolean mPlatformFile;

    private boolean mStarted = false;
    private int mEventType = START_DOCUMENT;
    private final boolean mPlatformFile;
    private final BridgeContext mContext;

    /**
     * Builds a {@link BridgeXmlBlockParser}.
Loading