1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.common.layout;
import com.android.annotations.NonNull;
import com.android.ide.common.api.DrawingStyle;
import com.android.ide.common.api.IColor;
import com.android.ide.common.api.IGraphics;
import com.android.ide.common.api.Point;
import com.android.ide.common.api.Rect;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
// TODO: Create box of ascii art
public class TestGraphics implements IGraphics {
/** List of things we have drawn */
private List<String> mDrawn = new ArrayList<String>();
private IColor mBackground = new TestColor(0x000000);
private IColor mForeground = new TestColor(0xFFFFFF);
private int mAlpha = 128;
/** Return log of graphics calls */
public List<String> getDrawn() {
return Collections.unmodifiableList(mDrawn);
}
/** Wipe out log of graphics calls */
public void clear() {
mDrawn.clear();
}
// ==== IGraphics ====
@Override
public void drawBoxedStrings(int x, int y, @NonNull List<?> strings) {
mDrawn.add("drawBoxedStrings(" + x + "," + y + "," + strings + ")");
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
mDrawn.add("drawLine(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
}
@Override
public void drawLine(@NonNull Point p1, @NonNull Point p2) {
mDrawn.add("drawLine(" + p1 + "," + p2 + ")");
}
@Override
public void drawRect(int x1, int y1, int x2, int y2) {
mDrawn.add("drawRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
}
@Override
public void drawRect(@NonNull Point p1, @NonNull Point p2) {
mDrawn.add("drawRect(" + p1 + "," + p2 + ")");
}
@Override
public void drawRect(@NonNull Rect r) {
mDrawn.add("drawRect(" + rectToString(r) + ")");
}
@Override
public void drawString(@NonNull String string, int x, int y) {
mDrawn.add("drawString(" + x + "," + y + "," + string + ")");
}
@Override
public void drawString(@NonNull String string, @NonNull Point topLeft) {
mDrawn.add("drawString(" + string + "," + topLeft + ")");
}
@Override
public void fillRect(int x1, int y1, int x2, int y2) {
mDrawn.add("fillRect(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
}
@Override
public void fillRect(@NonNull Point p1, @NonNull Point p2) {
mDrawn.add("fillRect(" + p1 + "," + p2 + ")");
}
@Override
public void fillRect(@NonNull Rect r) {
mDrawn.add("fillRect(" + rectToString(r) + ")");
}
@Override
public int getAlpha() {
return mAlpha;
}
@Override
public @NonNull IColor getBackground() {
return mBackground;
}
@Override
public int getFontHeight() {
return 12;
}
@Override
public @NonNull IColor getForeground() {
return mForeground;
}
@Override
public @NonNull IColor registerColor(int rgb) {
mDrawn.add("registerColor(" + Integer.toHexString(rgb) + ")");
return new TestColor(rgb);
}
@Override
public void setAlpha(int alpha) {
mAlpha = alpha;
mDrawn.add("setAlpha(" + alpha + ")");
}
@Override
public void setBackground(@NonNull IColor color) {
mDrawn.add("setBackground(" + color + ")");
mBackground = color;
}
@Override
public void setForeground(@NonNull IColor color) {
mDrawn.add("setForeground(" + color + ")");
mForeground = color;
}
@Override
public void setLineStyle(@NonNull LineStyle style) {
mDrawn.add("setLineStyle(" + style + ")");
}
@Override
public void setLineWidth(int width) {
mDrawn.add("setLineWidth(" + width + ")");
}
@Override
public void useStyle(@NonNull DrawingStyle style) {
mDrawn.add("useStyle(" + style + ")");
}
@Override
public void drawArrow(int x1, int y1, int x2, int y2, int size) {
mDrawn.add("drawArrow(" + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
}
@Override
public void drawPoint(int x, int y) {
mDrawn.add("drawPoint(" + x + "," + y + ")");
}
private static String rectToString(Rect rect) {
return "Rect[" + rect.x + "," + rect.y + "," + rect.w + "," + rect.h + "]";
}
}
|