• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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;
17 
18 import android.annotation.NonNull;
19 
20 import com.android.internal.widget.remotecompose.core.serialize.Serializable;
21 
22 /**
23  * PaintOperation interface, used for operations aimed at painting (while any operation _can_ paint,
24  * this make it a little more explicit)
25  */
26 public abstract class PaintOperation extends Operation implements Serializable {
27 
28     @Override
apply(@onNull RemoteContext context)29     public void apply(@NonNull RemoteContext context) {
30         if (context.getMode() == RemoteContext.ContextMode.PAINT) {
31             PaintContext paintContext = context.getPaintContext();
32             if (paintContext != null) {
33                 paint(paintContext);
34             }
35         }
36     }
37 
38     @NonNull
39     @Override
deepToString(@onNull String indent)40     public String deepToString(@NonNull String indent) {
41         return indent + toString();
42     }
43 
44     /**
45      * Paint the operation in the context
46      *
47      * @param context painting context
48      */
paint(@onNull PaintContext context)49     public abstract void paint(@NonNull PaintContext context);
50 
51     /**
52      * Will return true if the operation is similar enough to the current one, in the context of an
53      * animated transition.
54      */
suitableForTransition(@onNull Operation op)55     public boolean suitableForTransition(@NonNull Operation op) {
56         // by default expects the op to not be suitable
57         return false;
58     }
59 }
60