• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.internal.widget.remotecompose.core.operations.layout.modifiers;
17 
18 import static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.FLOAT;
19 import static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.INT;
20 
21 import android.annotation.NonNull;
22 
23 import com.android.internal.widget.remotecompose.core.Operation;
24 import com.android.internal.widget.remotecompose.core.Operations;
25 import com.android.internal.widget.remotecompose.core.WireBuffer;
26 import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder;
27 import com.android.internal.widget.remotecompose.core.serialize.MapSerializer;
28 import com.android.internal.widget.remotecompose.core.serialize.SerializeTags;
29 
30 import java.util.List;
31 
32 /** Set the height dimension on a component */
33 public class HeightModifierOperation extends DimensionModifierOperation {
34     private static final int OP_CODE = Operations.MODIFIER_HEIGHT;
35     public static final String CLASS_NAME = "HeightModifierOperation";
36     private HeightInModifierOperation mHeightIn = null;
37 
38     /**
39      * The name of the class
40      *
41      * @return the name
42      */
43     @NonNull
name()44     public static String name() {
45         return CLASS_NAME;
46     }
47 
48     /**
49      * The OP_CODE for this command
50      *
51      * @return the opcode
52      */
id()53     public static int id() {
54         return OP_CODE;
55     }
56 
57     /**
58      * Write the operation to the buffer
59      *
60      * @param buffer a WireBuffer
61      * @param type the type of dimension rule (DimensionModifierOperation.Type)
62      * @param value the value of the dimension
63      */
apply(@onNull WireBuffer buffer, int type, float value)64     public static void apply(@NonNull WireBuffer buffer, int type, float value) {
65         buffer.start(OP_CODE);
66         buffer.writeInt(type);
67         buffer.writeFloat(value);
68     }
69 
70     /**
71      * Read this operation and add it to the list of operations
72      *
73      * @param buffer the buffer to read
74      * @param operations the list of operations that will be added to
75      */
read(@onNull WireBuffer buffer, @NonNull List<Operation> operations)76     public static void read(@NonNull WireBuffer buffer, @NonNull List<Operation> operations) {
77         Type type = Type.fromInt(buffer.readInt());
78         float value = buffer.readFloat();
79         Operation op = new HeightModifierOperation(type, value);
80         operations.add(op);
81     }
82 
83     @Override
write(@onNull WireBuffer buffer)84     public void write(@NonNull WireBuffer buffer) {
85         apply(buffer, mType.ordinal(), mValue);
86     }
87 
HeightModifierOperation(@onNull Type type, float value)88     public HeightModifierOperation(@NonNull Type type, float value) {
89         super(type, value);
90     }
91 
HeightModifierOperation(@onNull Type type)92     public HeightModifierOperation(@NonNull Type type) {
93         super(type);
94     }
95 
HeightModifierOperation(float value)96     public HeightModifierOperation(float value) {
97         super(value);
98     }
99 
100     @NonNull
101     @Override
toString()102     public String toString() {
103         return "Height(" + mType + ", " + mValue + ")";
104     }
105 
106     @NonNull
107     @Override
serializedName()108     public String serializedName() {
109         return "HEIGHT";
110     }
111 
112     /**
113      * Populate the documentation with a description of this operation
114      *
115      * @param doc to append the description to.
116      */
documentation(@onNull DocumentationBuilder doc)117     public static void documentation(@NonNull DocumentationBuilder doc) {
118         doc.operation("Modifier Operations", OP_CODE, CLASS_NAME)
119                 .description("define the animation")
120                 .field(INT, "type", "")
121                 .field(FLOAT, "value", "");
122     }
123 
124     /**
125      * Set height in constraints
126      *
127      * @param heightInConstraints height constraints
128      */
setHeightIn(HeightInModifierOperation heightInConstraints)129     public void setHeightIn(HeightInModifierOperation heightInConstraints) {
130         mHeightIn = heightInConstraints;
131     }
132 
133     /**
134      * Returns height in constraints
135      *
136      * @return height in constraints
137      */
getHeightIn()138     public HeightInModifierOperation getHeightIn() {
139         return mHeightIn;
140     }
141 
142     @Override
serialize(MapSerializer serializer)143     public void serialize(MapSerializer serializer) {
144         serializer
145                 .addTags(SerializeTags.MODIFIER)
146                 .addType("HeightModifierOperation")
147                 .add("height", mValue, mOutValue)
148                 .add("dimensionModifierType", mType);
149     }
150 }
151