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

Commit 9b137e27 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Change BridgeResources to Resources_Delegate [DO NOT MERGE]

Do not merge because the resource implementation has changed in N and
the change is no longer valid there.

This is a very hacky fix to make layoutlib work with the latest support
lib. Inject a couple of fields in android.content.res.Resources to
allow using most of the earlier code as is.

Bug: 27403642
Bug: http://b.android.com/201934
Change-Id: I186cad32b1b4de64164fbad937d989e0110c6976
parent b75a0426
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ import static com.android.ide.common.rendering.api.RenderResources.REFERENCE_UND
 */
public final class BridgeTypedArray extends TypedArray {

    private final BridgeResources mBridgeResources;
    private final Resources mBridgeResources;
    private final BridgeContext mContext;
    private final boolean mPlatformFile;

@@ -84,7 +84,7 @@ public final class BridgeTypedArray extends TypedArray {
    @Nullable
    private int[] mEmptyIds;

    public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
    public BridgeTypedArray(Resources resources, BridgeContext context, int len,
            boolean platformFile) {
        super(resources, null, null, 0);
        mBridgeResources = resources;
@@ -756,7 +756,8 @@ public final class BridgeTypedArray extends TypedArray {
        if (resVal instanceof ArrayResourceValue) {
            ArrayResourceValue array = (ArrayResourceValue) resVal;
            int count = array.getElementCount();
            return count >= 0 ? mBridgeResources.fillValues(array, new CharSequence[count]) : null;
            return count >= 0 ? Resources_Delegate.fillValues(mBridgeResources, array, new CharSequence[count]) :
                    null;
        }
        int id = getResourceId(index, 0);
        String resIdMessage = id > 0 ? " (resource id 0x" + Integer.toHexString(id) + ')' : "";
@@ -1004,7 +1005,6 @@ public final class BridgeTypedArray extends TypedArray {
    }

    static TypedArray obtain(Resources res, int len) {
        return res instanceof BridgeResources ?
                new BridgeTypedArray(((BridgeResources) res), null, len, true) : null;
        return new BridgeTypedArray(res, null, len, true);
    }
}
+234 −207

File changed and moved.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.android.resources.Density;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import android.annotation.Nullable;
import android.content.res.BridgeResources.NinePatchInputStream;
import com.android.layoutlib.bridge.util.NinePatchInputStream;
import android.graphics.BitmapFactory.Options;
import android.graphics.Bitmap_Delegate.BitmapCreateFlags;

+6 −6
Original line number Diff line number Diff line
@@ -52,11 +52,11 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.BridgeAssetManager;
import android.content.res.BridgeResources;
import android.content.res.BridgeTypedArray;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.Resources_Delegate;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
@@ -223,7 +223,7 @@ public final class BridgeContext extends Context {
    public void initResources() {
        AssetManager assetManager = AssetManager.getSystem();

        mSystemResources = BridgeResources.initSystem(
        mSystemResources = Resources_Delegate.initSystem(
                this,
                assetManager,
                mMetrics,
@@ -236,7 +236,7 @@ public final class BridgeContext extends Context {
     * Disposes the {@link Resources} singleton.
     */
    public void disposeResources() {
        BridgeResources.disposeSystem();
        Resources_Delegate.disposeSystem();
    }

    public void setBridgeInflater(BridgeInflater inflater) {
@@ -705,8 +705,8 @@ public final class BridgeContext extends Context {

        List<Pair<String, Boolean>> attributeList = searchAttrs(attrs);

        BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
                isPlatformFile);
        BridgeTypedArray ta =
                Resources_Delegate.newTypeArray(mSystemResources, attrs.length, isPlatformFile);

        // look for a custom style.
        String customStyle = null;
@@ -940,7 +940,7 @@ public final class BridgeContext extends Context {

        List<Pair<String, Boolean>> attributes = searchAttrs(attrs);

        BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
        BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length,
                false);

        // for each attribute, get its name so that we can search it in the style
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * Simpler wrapper around FileInputStream. This is used when the input stream represent
 * not a normal bitmap but a nine patch.
 * This is useful when the InputStream is created in a method but used in another that needs
 * to know whether this is 9-patch or not, such as BitmapFactory.
 */
public class NinePatchInputStream extends FileInputStream {
    private boolean mFakeMarkSupport = true;
    public NinePatchInputStream(File file) throws FileNotFoundException {
        super(file);
    }

    @Override
    public boolean markSupported() {
        if (mFakeMarkSupport) {
            // this is needed so that BitmapFactory doesn't wrap this in a BufferedInputStream.
            return true;
        }

        return super.markSupported();
    }

    public void disableFakeMarkSupport() {
        // disable fake mark support so that in case codec actually try to use them
        // we don't lie to them.
        mFakeMarkSupport = false;
    }
}
Loading