@@ -77,7 +77,7 @@ static byte[] create(Context context, Map<Integer, Integer> colorMapping) throws
77
77
colorResource =
78
78
new ColorResource (
79
79
entry .getKey (),
80
- context .getResources ().getResourceName (entry .getKey ()),
80
+ context .getResources ().getResourceEntryName (entry .getKey ()),
81
81
entry .getValue ());
82
82
if (!context
83
83
.getResources ()
@@ -338,16 +338,37 @@ private static class PackageChunk {
338
338
PackageChunk (PackageInfo packageInfo , List <ColorResource > colorResources ) {
339
339
this .packageInfo = packageInfo ;
340
340
341
- // Placeholder String type, since only XML color resources will be replaced at runtime.
342
- typeStrings = new StringPoolChunk (false , "?1" , "?2" , "?3" , "?4" , "?5" , "color" );
341
+ typeStrings = new StringPoolChunk (false , generateTypeStrings (colorResources ));
342
+ keyStrings = new StringPoolChunk (true , generateKeyStrings (colorResources ));
343
+ typeSpecChunk = new TypeSpecChunk (colorResources );
344
+
345
+ header = new ResChunkHeader (HEADER_TYPE_PACKAGE , HEADER_SIZE , getChunkSize ());
346
+ }
347
+
348
+ private String [] generateTypeStrings (List <ColorResource > colorResources ) {
349
+ if (!colorResources .isEmpty ()) {
350
+ byte colorTypeId = colorResources .get (0 ).typeId ;
351
+ String [] types = new String [colorTypeId ];
352
+
353
+ // Placeholder String type, since only XML color resources will be replaced at runtime.
354
+ for (int i = 0 ; i < colorTypeId - 1 ; i ++) {
355
+ types [i ] = "?" + (i + 1 );
356
+ }
357
+
358
+ types [colorTypeId - 1 ] = "color" ;
359
+
360
+ return types ;
361
+ } else {
362
+ return new String [0 ];
363
+ }
364
+ }
365
+
366
+ private String [] generateKeyStrings (List <ColorResource > colorResources ) {
343
367
String [] keys = new String [colorResources .size ()];
344
368
for (int i = 0 ; i < colorResources .size (); i ++) {
345
369
keys [i ] = colorResources .get (i ).name ;
346
370
}
347
- keyStrings = new StringPoolChunk (true , keys );
348
- typeSpecChunk = new TypeSpecChunk (colorResources );
349
-
350
- header = new ResChunkHeader (HEADER_TYPE_PACKAGE , HEADER_SIZE , getChunkSize ());
371
+ return keys ;
351
372
}
352
373
353
374
void writeTo (ByteArrayOutputStream outputStream ) throws IOException {
0 commit comments