1 /*
2  * Copyright 2019 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 
17 package android.processor.view.inspector.cts;
18 
19 import android.graphics.Color;
20 import android.util.SparseArray;
21 import android.view.inspector.PropertyReader;
22 
23 import java.util.Objects;
24 import java.util.Set;
25 
26 
27 class TestPropertyReader implements PropertyReader {
28     private final TestPropertyMapper mPropertyMapper;
29     private final SparseArray<Object> mProperties = new SparseArray<>();
30 
TestPropertyReader(TestPropertyMapper propertyMapper)31     TestPropertyReader(TestPropertyMapper propertyMapper) {
32         mPropertyMapper = Objects.requireNonNull(propertyMapper);
33     }
34 
get(String name)35     Object get(String name) {
36         return mProperties.get(mPropertyMapper.getId(name));
37     }
38 
getIntEnum(String name)39     String getIntEnum(String name) {
40         return mPropertyMapper.getIntEnumMapping(name).apply((Integer) get(name));
41     }
42 
getIntFlag(String name)43     Set<String> getIntFlag(String name) {
44         return mPropertyMapper.getIntFlagMapping(name).apply((Integer) get(name));
45     }
46 
47     @Override
readBoolean(int id, boolean value)48     public void readBoolean(int id, boolean value) {
49         mProperties.put(id, value);
50     }
51 
52     @Override
readByte(int id, byte value)53     public void readByte(int id, byte value) {
54         mProperties.put(id, value);
55     }
56 
57     @Override
readChar(int id, char value)58     public void readChar(int id, char value) {
59         mProperties.put(id, value);
60     }
61 
62     @Override
readDouble(int id, double value)63     public void readDouble(int id, double value) {
64         mProperties.put(id, value);
65     }
66 
67     @Override
readFloat(int id, float value)68     public void readFloat(int id, float value) {
69         mProperties.put(id, value);
70     }
71 
72     @Override
readInt(int id, int value)73     public void readInt(int id, int value) {
74         mProperties.put(id, value);
75     }
76 
77     @Override
readLong(int id, long value)78     public void readLong(int id, long value) {
79         mProperties.put(id, value);
80     }
81 
82     @Override
readShort(int id, short value)83     public void readShort(int id, short value) {
84         mProperties.put(id, value);
85     }
86 
87     @Override
readObject(int id, Object value)88     public void readObject(int id, Object value) {
89         mProperties.put(id, value);
90     }
91 
92     @Override
readColor(int id, int value)93     public void readColor(int id, int value) {
94         mProperties.put(id, value);
95     }
96 
97     @Override
readColor(int id, long value)98     public void readColor(int id, long value) {
99         mProperties.put(id, value);
100     }
101 
102     @Override
readColor(int id, Color value)103     public void readColor(int id, Color value) {
104         mProperties.put(id, value);
105     }
106 
107     @Override
readGravity(int id, int value)108     public void readGravity(int id, int value) {
109         mProperties.put(id, value);
110     }
111 
112     @Override
readIntEnum(int id, int value)113     public void readIntEnum(int id, int value) {
114         mProperties.put(id, value);
115     }
116 
117     @Override
readIntFlag(int id, int value)118     public void readIntFlag(int id, int value) {
119         mProperties.put(id, value);
120     }
121 
122     @Override
readResourceId(int id, int value)123     public void readResourceId(int id, int value) {
124         mProperties.put(id, value);
125     }
126 }
127