Skip to content

[Color] ColorResourcesTableCreator: Fix the placement of the type string "color" #4707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,38 @@ private static class PackageChunk {
PackageChunk(PackageInfo packageInfo, List<ColorResource> colorResources) {
this.packageInfo = packageInfo;

// Placeholder String type, since only XML color resources will be replaced at runtime.
typeStrings = new StringPoolChunk(false, "?1", "?2", "?3", "?4", "?5", "color");
typeStrings = new StringPoolChunk(false, generateTypeStrings(colorResources));
keyStrings = new StringPoolChunk(true, generateKeyStrings(colorResources));
typeSpecChunk = new TypeSpecChunk(colorResources);

header = new ResChunkHeader(HEADER_TYPE_PACKAGE, HEADER_SIZE, getChunkSize());
}

private String[] generateTypeStrings(List<ColorResource> colorResources) {
if (!colorResources.isEmpty()) {
byte colorTypeId = colorResources.get(0).typeId;
String[] types = new String[colorTypeId];

// Placeholder String type, since only XML color resources will be replaced at runtime.
for (int i = 0; i < colorTypeId - 1; i++) {
types[i] = "?" + (i + 1);
}

types[colorTypeId - 1] = "color";

return types;
} else {
return new String[0];
}
}

private String[] generateKeyStrings(List<ColorResource> colorResources) {
String[] keys = new String[colorResources.size()];
for (int i = 0; i < colorResources.size(); i++) {
keys[i] = colorResources.get(i).name;
}
keyStrings = new StringPoolChunk(true, keys);
typeSpecChunk = new TypeSpecChunk(colorResources);

header = new ResChunkHeader(HEADER_TYPE_PACKAGE, HEADER_SIZE, getChunkSize());
return keys;
}

void writeTo(ByteArrayOutputStream outputStream) throws IOException {
Expand Down