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

Commit f666c0e2 authored by Jerome Gaillard's avatar Jerome Gaillard
Browse files

Fix layoutlib to reflect recent changes in platform code

Test: Layoutlib tests
Change-Id: I81964233a9e580ccee9c9e9b0cf3525babf30bd4
parent d0835e45
Loading
Loading
Loading
Loading
+727 −0

File added.

Preview size limit exceeded, changes collapsed.

+29 −758

File changed.

Preview size limit exceeded, changes collapsed.

+2 −10
Original line number Diff line number Diff line
@@ -63,16 +63,8 @@ public class ComposeShader_Delegate extends Shader_Delegate {
    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static long nativeCreate1(long native_shaderA, long native_shaderB,
            long native_mode) {
        // FIXME not supported yet.
        ComposeShader_Delegate newDelegate = new ComposeShader_Delegate();
        return sManager.addNewDelegate(newDelegate);
    }

    @LayoutlibDelegate
    /*package*/ static long nativeCreate2(long native_shaderA, long native_shaderB,
            int porterDuffMode) {
    /*package*/ static long nativeCreate(long native_shaderA, long native_shaderB,
            int native_mode) {
        // FIXME not supported yet.
        ComposeShader_Delegate newDelegate = new ComposeShader_Delegate();
        return sManager.addNewDelegate(newDelegate);
+32 −17
Original line number Diff line number Diff line
@@ -90,10 +90,11 @@ public class Paint_Delegate {
    private int mHintingMode = Paint.HINTING_ON;
    private int mHyphenEdit;
    private float mLetterSpacing;  // not used in actual text rendering.
    private float mWordSpacing;  // not used in actual text rendering.
    // Variant of the font. A paint's variant can only be compact or elegant.
    private FontVariant mFontVariant = FontVariant.COMPACT;

    private Xfermode_Delegate mXfermode;
    private int mPorterDuffMode = Xfermode.DEFAULT;
    private ColorFilter_Delegate mColorFilter;
    private Shader_Delegate mShader;
    private PathEffect_Delegate mPathEffect;
@@ -206,12 +207,10 @@ public class Paint_Delegate {
    }

    /**
     * Returns the {@link Xfermode} delegate or null if none have been set
     *
     * @return the delegate or null.
     * Returns the {@link PorterDuff.Mode} as an int
     */
    public Xfermode_Delegate getXfermode() {
        return mXfermode;
    public int getPorterDuffMode() {
        return mPorterDuffMode;
    }

    /**
@@ -841,16 +840,12 @@ public class Paint_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static long nSetXfermode(long native_object, long xfermode) {
        // get the delegate from the native int.
    /*package*/ static void nSetXfermode(long native_object, int xfermode) {
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return xfermode;
            return;
        }

        delegate.mXfermode = Xfermode_Delegate.getDelegate(xfermode);

        return xfermode;
        delegate.mPorterDuffMode = xfermode;
    }

    @LayoutlibDelegate
@@ -998,7 +993,7 @@ public class Paint_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static int nGetTextRunCursor(long native_object, char[] text,
    /*package*/ static int nGetTextRunCursor(Paint paint, long native_object, char[] text,
            int contextStart, int contextLength, int flags, int offset, int cursorOpt) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1007,7 +1002,7 @@ public class Paint_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static int nGetTextRunCursor(long native_object, String text,
    /*package*/ static int nGetTextRunCursor(Paint paint, long native_object, String text,
            int contextStart, int contextEnd, int flags, int offset, int cursorOpt) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1085,6 +1080,26 @@ public class Paint_Delegate {
        delegate.mLetterSpacing = letterSpacing;
    }

    @LayoutlibDelegate
    /*package*/ static float nGetWordSpacing(long nativePaint) {
        Paint_Delegate delegate = sManager.getDelegate(nativePaint);
        if (delegate == null) {
            return 0;
        }
        return delegate.mWordSpacing;
    }

    @LayoutlibDelegate
    /*package*/ static void nSetWordSpacing(long nativePaint, float wordSpacing) {
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_TEXT_RENDERING,
                "Paint.setWordSpacing() not supported.", null, null);
        Paint_Delegate delegate = sManager.getDelegate(nativePaint);
        if (delegate == null) {
            return;
        }
        delegate.mWordSpacing = wordSpacing;
    }

    @LayoutlibDelegate
    /*package*/ static void nSetFontFeatureSettings(long nativePaint, String settings) {
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_TEXT_RENDERING,
@@ -1215,7 +1230,7 @@ public class Paint_Delegate {

        mStrokeWidth = paint.mStrokeWidth;
        mStrokeMiter = paint.mStrokeMiter;
        mXfermode = paint.mXfermode;
        mPorterDuffMode = paint.mPorterDuffMode;
        mColorFilter = paint.mColorFilter;
        mShader = paint.mShader;
        mPathEffect = paint.mPathEffect;
@@ -1242,7 +1257,7 @@ public class Paint_Delegate {
        mTextSize = 20.f;
        mTextScaleX = 1.f;
        mTextSkewX = 0.f;
        mXfermode = null;
        mPorterDuffMode = Xfermode.DEFAULT;
        mColorFilter = null;
        mShader = null;
        mPathEffect = null;
+0 −87
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 android.graphics;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.PorterDuffUtility;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import android.graphics.PorterDuff.Mode;

import java.awt.Composite;

import static com.android.layoutlib.bridge.impl.PorterDuffUtility.getPorterDuffMode;

/**
 * Delegate implementing the native methods of android.graphics.PorterDuffXfermode
 *
 * Through the layoutlib_create tool, the original native methods of PorterDuffXfermode have been
 * replaced by calls to methods of the same name in this delegate class.
 *
 * This class behaves like the original native implementation, but in Java, keeping previously
 * native data into its own objects and mapping them to int that are sent back and forth between
 * it and the original PorterDuffXfermode class.
 *
 * Because this extends {@link Xfermode_Delegate}, there's no need to use a
 * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
 * {@link Xfermode_Delegate}.
 *
 */
public class PorterDuffXfermode_Delegate extends Xfermode_Delegate {

    // ---- delegate data ----

    private final Mode mMode;

    // ---- Public Helper methods ----

    public Mode getMode() {
        return mMode;
    }

    @Override
    public Composite getComposite(int alpha) {
        return PorterDuffUtility.getComposite(mMode, alpha);
    }

    @Override
    public boolean isSupported() {
        return true;
    }

    @Override
    public String getSupportMessage() {
        // no message since isSupported returns true;
        return null;
    }


    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static long nativeCreateXfermode(int mode) {
        PorterDuffXfermode_Delegate newDelegate = new PorterDuffXfermode_Delegate(mode);
        return sManager.addNewDelegate(newDelegate);
    }

    // ---- Private delegate/helper methods ----

    private PorterDuffXfermode_Delegate(int mode) {
        mMode = getPorterDuffMode(mode);
    }

}
Loading