@@ -77,7 +77,7 @@ static byte[] create(Context context, Map<Integer, Integer> colorMapping) throws
7777 colorResource =
7878 new ColorResource (
7979 entry .getKey (),
80- context .getResources ().getResourceName (entry .getKey ()),
80+ context .getResources ().getResourceEntryName (entry .getKey ()),
8181 entry .getValue ());
8282 if (!context
8383 .getResources ()
@@ -338,16 +338,37 @@ private static class PackageChunk {
338338 PackageChunk (PackageInfo packageInfo , List <ColorResource > colorResources ) {
339339 this .packageInfo = packageInfo ;
340340
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 ) {
343367 String [] keys = new String [colorResources .size ()];
344368 for (int i = 0 ; i < colorResources .size (); i ++) {
345369 keys [i ] = colorResources .get (i ).name ;
346370 }
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 ;
351372 }
352373
353374 void writeTo (ByteArrayOutputStream outputStream ) throws IOException {
0 commit comments