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

Commit c6083f2c authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: misc fixes.

- implement some Paint methods that are needed for 2.x
- fix the phone system bar to display the icons on the right.

Change-Id: I3a938b14ec9a449dbc23a33303a3c8405a5369a8
parent cc4977d0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -9,5 +9,7 @@
			android:layout_width="wrap_content"/>
	<ImageView
			android:layout_height="wrap_content"
			android:layout_width="wrap_content"/>
			android:layout_width="wrap_content"
			android:layout_marginLeft="3dip"
			android:layout_marginRight="5dip"/>
</merge>
+1 −1
Original line number Diff line number Diff line
@@ -948,7 +948,7 @@ public final class Canvas_Delegate {
        draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                new GcSnapshot.Drawable() {
            public void draw(Graphics2D graphics, Paint_Delegate paint) {
                // WARNING: the logic in this method is similar to Paint.measureText.
                // WARNING: the logic in this method is similar to Paint_Delegate.measureText.
                // Any change to this method should be reflected in Paint.measureText
                // Paint.TextAlign indicates how the text is positioned relative to X.
                // LEFT is the default and there's nothing to do.
+101 −24
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -541,9 +542,6 @@ public class Paint_Delegate {
    @LayoutlibDelegate
    /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index,
            int count) {
        // WARNING: the logic in this method is similar to Canvas.drawText.
        // Any change to this method should be reflected in Canvas.drawText

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
@@ -566,19 +564,51 @@ public class Paint_Delegate {
    @LayoutlibDelegate
    /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count,
            float maxWidth, float[] measuredWidth) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.native_breakText is not supported.", null, null /*data*/);

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        int inc = count > 0 ? 1 : -1;

        int measureIndex = 0;
        float measureAcc = 0;
        for (int i = index; i != index + count; i += inc, measureIndex++) {
            int start, end;
            if (i < index) {
                start = i;
                end = index;
            } else {
                start = index;
                end = i;
            }

            // measure from start to end
            float res = delegate.measureText(text, start, end - start + 1);

            if (measuredWidth != null) {
                measuredWidth[measureIndex] = res;
            }

            measureAcc += res;
            if (res > maxWidth) {
                // we should not return this char index, but since it's 0-based
                // and we need to return a count, we simply return measureIndex;
                return measureIndex;
            }

        }

        return measureIndex;
    }

    @LayoutlibDelegate
    /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards,
            float maxWidth, float[] measuredWidth) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.native_breakText is not supported.", null, null /*data*/);
        return 0;
        return native_breakText(thisPaint, text.toCharArray(), 0, text.length(), maxWidth,
                measuredWidth);
    }

    @LayoutlibDelegate
@@ -864,19 +894,49 @@ public class Paint_Delegate {
    @LayoutlibDelegate
    /*package*/ static int native_getTextWidths(int native_object, char[] text, int index,
            int count, float[] widths) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextWidths is not supported.", null, null /*data*/);
        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        if (delegate.mFonts.size() > 0) {
            // FIXME: handle multi-char characters (see measureText)
            float totalAdvance = 0;
            for (int i = 0; i < count; i++) {
                char c = text[i + index];
                boolean found = false;
                for (FontInfo info : delegate.mFonts) {
                    if (info.mFont.canDisplay(c)) {
                        float adv = info.mMetrics.charWidth(c);
                        totalAdvance += adv;
                        if (widths != null) {
                            widths[i] = adv;
                        }

                        found = true;
                        break;
                    }
                }

                if (found == false) {
                    // no advance for this char.
                    if (widths != null) {
                        widths[i] = 0.f;
                    }
                }
            }

            return (int) totalAdvance;
        }

        return 0;
    }

    @LayoutlibDelegate
    /*package*/ static int native_getTextWidths(int native_object, String text, int start,
            int end, float[] widths) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextWidths is not supported.", null, null /*data*/);
        return 0;
        return native_getTextWidths(native_object, text.toCharArray(), start, end - start, widths);
    }

    @LayoutlibDelegate
@@ -973,17 +1033,28 @@ public class Paint_Delegate {
    @LayoutlibDelegate
    /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start,
            int end, Rect bounds) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getStringBounds is not supported.", null, null /*data*/);
        nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bounds);
    }

    @LayoutlibDelegate
    /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index,
            int count, Rect bounds) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getCharArrayBounds is not supported.", null, null /*data*/);

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(nativePaint);
        if (delegate == null) {
            return;
        }

        // FIXME should test if the main font can display all those characters.
        // See MeasureText
        if (delegate.mFonts.size() > 0) {
            FontInfo mainInfo = delegate.mFonts.get(0);

            Rectangle2D rect = mainInfo.mFont.getStringBounds(text, index, index + count,
                    delegate.mFontContext);
            bounds.set(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
        }
    }

    @LayoutlibDelegate
@@ -1075,6 +1146,10 @@ public class Paint_Delegate {
    }

    /*package*/ float measureText(char[] text, int index, int count) {

        // WARNING: the logic in this method is similar to Canvas_Delegate.native_drawText
        // Any change to this method should be reflected there as well

        if (mFonts.size() > 0) {
            FontInfo mainFont = mFonts.get(0);
            int i = index;
@@ -1122,6 +1197,8 @@ public class Paint_Delegate {
                    i += size;
                }
            }

            return total;
        }

        return 0;
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.widget.TextView;
public class PhoneSystemBar extends CustomBar {

    public PhoneSystemBar(Context context, Density density) throws XmlPullParserException {
        super(context, density, "/bars/tablet_system_bar.xml");
        super(context, density, "/bars/phone_system_bar.xml");

        setGravity(mGravity | Gravity.RIGHT);
        setBackgroundColor(0xFF000000);