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

Commit 8757d482 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update to ToT RemoteCompose" into main

parents c3512eee 77433df7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class CoreDocument {

    // We also keep a more fine-grained BUILD number, exposed as
    // ID_API_LEVEL = DOCUMENT_API_LEVEL + BUILD
    static final float BUILD = 0.2f;
    static final float BUILD = 0.3f;

    @NonNull ArrayList<Operation> mOperations = new ArrayList<>();

+12 −0
Original line number Diff line number Diff line
@@ -88,6 +88,8 @@ import com.android.internal.widget.remotecompose.core.operations.layout.TouchUpM
import com.android.internal.widget.remotecompose.core.operations.layout.animation.AnimationSpec;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.BoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CanvasLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleRowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.ColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.RowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.StateLayout;
@@ -97,6 +99,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.modifier
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ClipRectModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ComponentVisibilityOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.GraphicsLayerModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HeightInModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HeightModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HostActionOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HostNamedActionOperation;
@@ -111,6 +114,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.modifier
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ValueIntegerChangeActionOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ValueIntegerExpressionChangeActionOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ValueStringChangeActionOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.WidthInModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.WidthModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ZIndexModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.utilities.IntMap;
@@ -208,7 +212,9 @@ public class Operations {
    public static final int LAYOUT_CONTENT = 201;
    public static final int LAYOUT_BOX = 202;
    public static final int LAYOUT_ROW = 203;
    public static final int LAYOUT_COLLAPSIBLE_ROW = 230;
    public static final int LAYOUT_COLUMN = 204;
    public static final int LAYOUT_COLLAPSIBLE_COLUMN = 233;
    public static final int LAYOUT_CANVAS = 205;
    public static final int LAYOUT_CANVAS_CONTENT = 207;
    public static final int LAYOUT_TEXT = 208;
@@ -218,6 +224,8 @@ public class Operations {

    public static final int MODIFIER_WIDTH = 16;
    public static final int MODIFIER_HEIGHT = 67;
    public static final int MODIFIER_WIDTH_IN = 231;
    public static final int MODIFIER_HEIGHT_IN = 232;
    public static final int MODIFIER_BACKGROUND = 55;
    public static final int MODIFIER_BORDER = 107;
    public static final int MODIFIER_PADDING = 58;
@@ -324,6 +332,8 @@ public class Operations {

        map.put(MODIFIER_WIDTH, WidthModifierOperation::read);
        map.put(MODIFIER_HEIGHT, HeightModifierOperation::read);
        map.put(MODIFIER_WIDTH_IN, WidthInModifierOperation::read);
        map.put(MODIFIER_HEIGHT_IN, HeightInModifierOperation::read);
        map.put(MODIFIER_PADDING, PaddingModifierOperation::read);
        map.put(MODIFIER_BACKGROUND, BackgroundModifierOperation::read);
        map.put(MODIFIER_BORDER, BorderModifierOperation::read);
@@ -359,7 +369,9 @@ public class Operations {
        map.put(LAYOUT_CONTENT, LayoutComponentContent::read);
        map.put(LAYOUT_BOX, BoxLayout::read);
        map.put(LAYOUT_COLUMN, ColumnLayout::read);
        map.put(LAYOUT_COLLAPSIBLE_COLUMN, CollapsibleColumnLayout::read);
        map.put(LAYOUT_ROW, RowLayout::read);
        map.put(LAYOUT_COLLAPSIBLE_ROW, CollapsibleRowLayout::read);
        map.put(LAYOUT_CANVAS, CanvasLayout::read);
        map.put(LAYOUT_CANVAS_CONTENT, CanvasContent::read);
        map.put(LAYOUT_TEXT, TextLayout::read);
+126 −18
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ import com.android.internal.widget.remotecompose.core.operations.layout.LoopOper
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.BoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CanvasLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleRowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.ColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.RowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.StateLayout;
@@ -691,6 +693,12 @@ public class RemoteComposeBuffer {
        return out;
    }

    /**
     * Append a path to an existing path
     *
     * @param id id of the path to append to
     * @param path the path to append
     */
    public void pathAppend(int id, float... path) {
        PathAppend.apply(mBuffer, id, path);
    }
@@ -772,8 +780,8 @@ public class RemoteComposeBuffer {
     * @param text The text to be drawn
     * @param start The index of the first character in text to draw
     * @param end (end - 1) is the index of the last character in text to draw
     * @param contextStart
     * @param contextEnd
     * @param contextStart the context start
     * @param contextEnd the context end
     * @param x The x-coordinate of the origin of the text being drawn
     * @param y The y-coordinate of the baseline of the text being drawn
     * @param rtl Draw RTTL
@@ -798,8 +806,8 @@ public class RemoteComposeBuffer {
     * @param textId The text to be drawn
     * @param start The index of the first character in text to draw
     * @param end (end - 1) is the index of the last character in text to draw
     * @param contextStart
     * @param contextEnd
     * @param contextStart the context start
     * @param contextEnd the context end
     * @param x The x-coordinate of the origin of the text being drawn
     * @param y The y-coordinate of the baseline of the text being drawn
     * @param rtl Draw RTTL
@@ -986,6 +994,11 @@ public class RemoteComposeBuffer {

    ///////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * inflate the buffer into a list of operations
     *
     * @param operations the operations list to add to
     */
    public void inflateFromBuffer(@NonNull ArrayList<Operation> operations) {
        mBuffer.setIndex(0);
        while (mBuffer.available()) {
@@ -1001,6 +1014,12 @@ public class RemoteComposeBuffer {
        }
    }

    /**
     * Read the next operation from the buffer
     *
     * @param buffer The buff to read
     * @param operations the operations list to add to
     */
    public static void readNextOperation(
            @NonNull WireBuffer buffer, @NonNull ArrayList<Operation> operations) {
        int opId = buffer.readByte();
@@ -1014,6 +1033,11 @@ public class RemoteComposeBuffer {
        operation.read(buffer, operations);
    }

    /**
     * copy the current buffer to a new one
     *
     * @return A new RemoteComposeBuffer
     */
    @NonNull
    RemoteComposeBuffer copy() {
        ArrayList<Operation> operations = new ArrayList<>();
@@ -1022,6 +1046,11 @@ public class RemoteComposeBuffer {
        return copyFromOperations(operations, buffer);
    }

    /**
     * add a set theme
     *
     * @param theme The theme to set
     */
    public void setTheme(int theme) {
        Theme.apply(mBuffer, theme);
    }
@@ -1040,6 +1069,14 @@ public class RemoteComposeBuffer {
        return buffer;
    }

    /**
     * Create a RemoteComposeBuffer from a file
     *
     * @param file A file
     * @param remoteComposeState The RemoteComposeState
     * @return A RemoteComposeBuffer
     * @throws IOException if the file cannot be read
     */
    @NonNull
    public RemoteComposeBuffer fromFile(
            @NonNull File file, @NonNull RemoteComposeState remoteComposeState) throws IOException {
@@ -1048,6 +1085,13 @@ public class RemoteComposeBuffer {
        return buffer;
    }

    /**
     * Create a RemoteComposeBuffer from an InputStream
     *
     * @param inputStream An InputStream
     * @param remoteComposeState The RemoteComposeState
     * @return A RemoteComposeBuffer
     */
    @NonNull
    public static RemoteComposeBuffer fromInputStream(
            @NonNull InputStream inputStream, @NonNull RemoteComposeState remoteComposeState) {
@@ -1056,6 +1100,13 @@ public class RemoteComposeBuffer {
        return buffer;
    }

    /**
     * Create a RemoteComposeBuffer from an array of operations
     *
     * @param operations An array of operations
     * @param buffer A RemoteComposeBuffer
     * @return A RemoteComposeBuffer
     */
    @NonNull
    RemoteComposeBuffer copyFromOperations(
            @NonNull ArrayList<Operation> operations, @NonNull RemoteComposeBuffer buffer) {
@@ -1834,12 +1885,12 @@ public class RemoteComposeBuffer {
    /**
     * Add a marquee modifier
     *
     * @param iterations
     * @param animationMode
     * @param repeatDelayMillis
     * @param initialDelayMillis
     * @param spacing
     * @param velocity
     * @param iterations number of iterations
     * @param animationMode animation mode
     * @param repeatDelayMillis repeat delay
     * @param initialDelayMillis initial delay
     * @param spacing spacing between items
     * @param velocity velocity of the marquee
     */
    public void addModifierMarquee(
            int iterations,
@@ -1861,14 +1912,21 @@ public class RemoteComposeBuffer {
    /**
     * Add a graphics layer
     *
     * @param scaleX
     * @param scaleY
     * @param rotationX
     * @param rotationY
     * @param rotationZ
     * @param shadowElevation
     * @param transformOriginX
     * @param transformOriginY
     * @param scaleX scale x
     * @param scaleY scale y
     * @param rotationX rotation in X
     * @param rotationY rotation in Y
     * @param rotationZ rotation in Z
     * @param shadowElevation shadow elevation
     * @param transformOriginX transform origin x
     * @param transformOriginY transform origin y
     * @param alpha alpha value
     * @param cameraDistance camera distance
     * @param blendMode blend mode
     * @param spotShadowColorId spot shadow color
     * @param ambientShadowColorId ambient shadow color
     * @param colorFilterId id of color filter
     * @param renderEffectId id of render effect
     */
    public void addModifierGraphicsLayer(
            float scaleX,
@@ -1923,14 +1981,32 @@ public class RemoteComposeBuffer {
        ClipRectModifierOperation.apply(mBuffer);
    }

    /**
     * add start of loop
     *
     * @param indexId id of the variable
     * @param from start value
     * @param step step value
     * @param until stop value
     */
    public void addLoopStart(int indexId, float from, float step, float until) {
        LoopOperation.apply(mBuffer, indexId, from, step, until);
    }

    /** Add a loop end */
    public void addLoopEnd() {
        ContainerEnd.apply(mBuffer);
    }

    /**
     * add a state layout
     *
     * @param componentId id of the state
     * @param animationId animation id
     * @param horizontal horizontal alignment
     * @param vertical vertical alignment
     * @param indexId index of the state
     */
    public void addStateLayout(
            int componentId, int animationId, int horizontal, int vertical, int indexId) {
        mLastComponentId = getComponentId(componentId);
@@ -1965,6 +2041,22 @@ public class RemoteComposeBuffer {
        RowLayout.apply(mBuffer, mLastComponentId, animationId, horizontal, vertical, spacedBy);
    }

    /**
     * Add a row start tag
     *
     * @param componentId component id
     * @param animationId animation id
     * @param horizontal horizontal alignment
     * @param vertical vertical alignment
     * @param spacedBy spacing between items
     */
    public void addCollapsibleRowStart(
            int componentId, int animationId, int horizontal, int vertical, float spacedBy) {
        mLastComponentId = getComponentId(componentId);
        CollapsibleRowLayout.apply(
                mBuffer, mLastComponentId, animationId, horizontal, vertical, spacedBy);
    }

    /**
     * Add a column start tag
     *
@@ -1980,6 +2072,22 @@ public class RemoteComposeBuffer {
        ColumnLayout.apply(mBuffer, mLastComponentId, animationId, horizontal, vertical, spacedBy);
    }

    /**
     * Add a column start tag
     *
     * @param componentId component id
     * @param animationId animation id
     * @param horizontal horizontal alignment
     * @param vertical vertical alignment
     * @param spacedBy spacing between items
     */
    public void addCollapsibleColumnStart(
            int componentId, int animationId, int horizontal, int vertical, float spacedBy) {
        mLastComponentId = getComponentId(componentId);
        CollapsibleColumnLayout.apply(
                mBuffer, mLastComponentId, animationId, horizontal, vertical, spacedBy);
    }

    /**
     * Add a canvas start tag
     *
+72 −24
Original line number Diff line number Diff line
@@ -67,8 +67,8 @@ public class RemoteComposeState implements CollectionsAccess {
     * Get Object based on id. The system will cache things like bitmaps Paths etc. They can be
     * accessed with this command
     *
     * @param id
     * @return
     * @param id the id of the object
     * @return the object
     */
    @Nullable
    public Object getFromId(int id) {
@@ -78,8 +78,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * true if the cache contain this id
     *
     * @param id
     * @return
     * @param id the id of the object
     * @return true if the cache contain this id
     */
    public boolean containsId(int id) {
        return mIntDataMap.get(id) != null;
@@ -138,8 +138,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Get the path asociated with the Data
     *
     * @param id
     * @return
     * @param id of path
     * @return path object
     */
    public Object getPath(int id) {
        return mPathMap.get(id);
@@ -180,7 +180,7 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Adds a data Override.
     *
     * @param id
     * @param id the id of the data
     * @param item the new value
     */
    public void overrideData(int id, @NonNull Object item) {
@@ -222,8 +222,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Adds a float Override.
     *
     * @param id
     * @param value the new value
     * @param id The id of the float
     * @param value the override value
     */
    public void overrideFloat(int id, float value) {
        float previous = mFloatMap.get(id);
@@ -235,7 +235,12 @@ public class RemoteComposeState implements CollectionsAccess {
        }
    }

    /** Insert an item in the cache */
    /**
     * Insert an item in the cache
     *
     * @param item integer item to cache
     * @return the id of the integer
     */
    public int cacheInteger(int item) {
        int id = nextId();
        mIntegerMap.put(id, item);
@@ -243,7 +248,12 @@ public class RemoteComposeState implements CollectionsAccess {
        return id;
    }

    /** Insert an integer item in the cache */
    /**
     * Insert an integer item in the cache
     *
     * @param id the id of the integer
     * @param value the value of the integer
     */
    public void updateInteger(int id, int value) {
        if (!mIntegerOverride[id]) {
            int previous = mIntegerMap.get(id);
@@ -292,10 +302,10 @@ public class RemoteComposeState implements CollectionsAccess {
    }

    /**
     * Get the float value
     * Get the color from the cache
     *
     * @param id
     * @return
     * @param id The id of the color
     * @return The color
     */
    public int getColor(int id) {
        return mColorMap.get(id);
@@ -377,6 +387,9 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Method to determine if a cached value has been written to the documents WireBuffer based on
     * its id.
     *
     * @param id id to check
     * @return true if the value has not been written to the WireBuffer
     */
    public boolean wasNotWritten(int id) {
        return !mIntWrittenMap.get(id);
@@ -406,7 +419,7 @@ public class RemoteComposeState implements CollectionsAccess {
     * Get the next available id 0 is normal (float,int,String,color) 1 is VARIABLES 2 is
     * collections
     *
     * @return
     * @return return a unique id in the set
     */
    public int nextId(int type) {
        if (0 == type) {
@@ -418,7 +431,7 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Set the next id
     *
     * @param id
     * @param id set the id to increment off of
     */
    public void setNextId(int id) {
        mNextId = id;
@@ -440,8 +453,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Commands that listen to variables add themselves.
     *
     * @param id
     * @param variableSupport
     * @param id id of variable to listen to
     * @param variableSupport command that listens to variable
     */
    public void listenToVar(int id, @NonNull VariableSupport variableSupport) {
        add(id, variableSupport);
@@ -450,8 +463,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Is any command listening to this variable
     *
     * @param id
     * @return
     * @param id The Variable id
     * @return true if any command is listening to this variable
     */
    public boolean hasListener(int id) {
        return mVarListeners.get(id) != null;
@@ -460,8 +473,8 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * List of Commands that need to be updated
     *
     * @param context
     * @return
     * @param context The context
     * @return The number of ops to update
     */
    public int getOpsToUpdate(@NonNull RemoteContext context) {
        if (mVarListeners.get(RemoteContext.ID_CONTINUOUS_SEC) != null) {
@@ -479,7 +492,7 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Set the width of the overall document on screen.
     *
     * @param width
     * @param width the width of the document in pixels
     */
    public void setWindowWidth(float width) {
        updateFloat(RemoteContext.ID_WINDOW_WIDTH, width);
@@ -488,12 +501,18 @@ public class RemoteComposeState implements CollectionsAccess {
    /**
     * Set the width of the overall document on screen.
     *
     * @param height
     * @param height the height of the document in pixels
     */
    public void setWindowHeight(float height) {
        updateFloat(RemoteContext.ID_WINDOW_HEIGHT, height);
    }

    /**
     * Add an array access
     *
     * @param id The id of the array Access
     * @param collection The array access
     */
    public void addCollection(int id, @NonNull ArrayAccess collection) {
        mCollectionMap.put(id & 0xFFFFF, collection);
    }
@@ -513,10 +532,22 @@ public class RemoteComposeState implements CollectionsAccess {
        return mCollectionMap.get(id & 0xFFFFF).getId(index);
    }

    /**
     * adds a DataMap to the cache
     *
     * @param id The id of the data map
     * @param map The data map
     */
    public void putDataMap(int id, @NonNull DataMap map) {
        mDataMapMap.put(id, map);
    }

    /**
     * Get the DataMap asociated with the id
     *
     * @param id the id of the DataMap
     * @return the DataMap
     */
    public @Nullable DataMap getDataMap(int id) {
        return mDataMapMap.get(id);
    }
@@ -526,15 +557,32 @@ public class RemoteComposeState implements CollectionsAccess {
        return mCollectionMap.get(id & 0xFFFFF).getLength();
    }

    /**
     * sets the RemoteContext
     *
     * @param context the context
     */
    public void setContext(@NonNull RemoteContext context) {
        mRemoteContext = context;
        mRemoteContext.clearLastOpCount();
    }

    /**
     * Add an object to the cache. Uses the id for the item and adds it to the cache based
     *
     * @param id the id of the object
     * @param value the object
     */
    public void updateObject(int id, @NonNull Object value) {
        mObjectMap.put(id, value);
    }

    /**
     * Get an object from the cache
     *
     * @param id The id of the object
     * @return The object
     */
    public @Nullable Object getObject(int id) {
        return mObjectMap.get(id);
    }
+64 −3
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public abstract class RemoteContext {
            new RemoteComposeState(); // todo, is this a valid use of RemoteComposeState -- bbade@

    @Nullable protected PaintContext mPaintContext = null;
    protected float mDensity = 2.75f;
    protected float mDensity = Float.NaN;

    @NonNull ContextMode mMode = ContextMode.UNSET;

@@ -77,7 +77,7 @@ public abstract class RemoteContext {
     * @param density
     */
    public void setDensity(float density) {
        if (density > 0) {
        if (!Float.isNaN(density) && density > 0) {
            mDensity = density;
        }
    }
@@ -234,23 +234,60 @@ public abstract class RemoteContext {
     */
    public abstract void addCollection(int id, @NonNull ArrayAccess collection);

    /**
     * put DataMap under an id
     *
     * @param id the id of the DataMap
     * @param map the DataMap
     */
    public abstract void putDataMap(int id, @NonNull DataMap map);

    /**
     * Get a DataMap given an id
     *
     * @param id the id of the DataMap
     * @return the DataMap
     */
    public abstract @Nullable DataMap getDataMap(int id);

    /**
     * Run an action
     *
     * @param id the id of the action
     * @param metadata the metadata of the action
     */
    public abstract void runAction(int id, @NonNull String metadata);

    // TODO: we might add an interface to group all valid parameter types

    /**
     * Run an action with a named parameter
     *
     * @param textId the text id of the action
     * @param value the value of the parameter
     */
    public abstract void runNamedAction(int textId, Object value);

    /**
     * Put an object under an id
     *
     * @param mId the id of the object
     * @param command the object
     */
    public abstract void putObject(int mId, @NonNull Object command);

    /**
     * Get an object given an id
     *
     * @param mId the id of the object
     * @return the object
     */
    public abstract @Nullable Object getObject(int mId);

    /**
     * Add a touch listener to the context
     *
     * @param touchExpression
     * @param touchExpression the touch expression
     */
    public void addTouchListener(TouchListener touchExpression) {}

@@ -668,11 +705,24 @@ public abstract class RemoteContext {
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Click handling
    ///////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Is this a time id float
     *
     * @param fl the floatId to test
     * @return true if it is a time id
     */
    public static boolean isTime(float fl) {
        int value = Utils.idFromNan(fl);
        return value >= ID_CONTINUOUS_SEC && value <= ID_DAY_OF_MONTH;
    }

    /**
     * get the time from a float id that indicates a type of time
     *
     * @param fl id of the type of time information requested
     * @return various time information such as seconds or min
     */
    public static float getTime(float fl) {
        LocalDateTime dateTime =
                LocalDateTime.now(ZoneId.systemDefault()); // TODO, pass in a timezone explicitly?
@@ -716,6 +766,17 @@ public abstract class RemoteContext {
        return fl;
    }

    /**
     * Add a click area to the doc
     *
     * @param id the id of the click area
     * @param contentDescription the content description of the click area
     * @param left the left bounds of the click area
     * @param top the top bounds of the click area
     * @param right the right bounds of the click area
     * @param bottom the
     * @param metadataId the id of the metadata string
     */
    public abstract void addClickArea(
            int id,
            int contentDescription,
Loading