Update Piet Android code to use color style for image tints, instead of color_overlay

PiperOrigin-RevId: 246915045
Change-Id: Ie2dd94df04762927c928def68beb7b537a292302
diff --git a/src/main/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapter.java b/src/main/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapter.java
index 64a4892..2d96797 100644
--- a/src/main/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapter.java
+++ b/src/main/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapter.java
@@ -330,7 +330,7 @@
     }
 
     // Start asynchronously loading the real image.
-    Integer overlayColor = image.hasOverlayColor() ? image.getOverlayColor() : null;
+    Integer overlayColor = chunkStyle.hasColor() ? chunkStyle.getColor() : null;
     ImageSpanDrawableCallback imageSpanLoader =
         new ImageSpanDrawableCallback(wrapper, chunkStyle, overlayColor, textView);
     loadingImages.add(imageSpanLoader);
diff --git a/src/main/java/com/google/android/libraries/feed/piet/ImageElementAdapter.java b/src/main/java/com/google/android/libraries/feed/piet/ImageElementAdapter.java
index 315b4aa..af7d358 100644
--- a/src/main/java/com/google/android/libraries/feed/piet/ImageElementAdapter.java
+++ b/src/main/java/com/google/android/libraries/feed/piet/ImageElementAdapter.java
@@ -106,7 +106,7 @@
     getBaseView().setDefaultAspectRatio(getAspectRatio(image));
 
     checkState(currentlyLoadingImage == null, "An image loading callback exists; unbind first");
-    Integer overlayColor = image.hasOverlayColor() ? image.getOverlayColor() : null;
+    Integer overlayColor = getElementStyle().hasColor() ? getElementStyle().getColor() : null;
     LoadImageCallback loadImageCallback =
         createLoadImageCallback(getElementStyle().getScaleType(), overlayColor, frameContext);
     currentlyLoadingImage = loadImageCallback;
diff --git a/src/test/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapterTest.java b/src/test/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapterTest.java
index 1cf5a14..8a9e1ac 100644
--- a/src/test/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapterTest.java
+++ b/src/test/java/com/google/android/libraries/feed/piet/ChunkedTextElementAdapterTest.java
@@ -656,14 +656,22 @@
   }
 
   @Test
-  public void testAddImageChunk_overlayColor() {
+  public void testAddImageChunk_tintColor() {
     // Required to set up the local frameContext member var.
     adapter.createAdapter(asElement(TextElement.getDefaultInstance()), frameContext);
 
-    Image tintedImage = IMAGE_CHUNK_IMAGE.toBuilder().setOverlayColor(0xFEEDFACE).build();
+    StyleProvider tintStyleProvider =
+        new StyleProvider(
+            Style.newBuilder().setStyleId("tint").setColor(0xFEEDFACE).build(), mockAssetProvider);
+    StyleIdsStack tintStyle = StyleIdsStack.newBuilder().addStyleIds("tint").build();
+    when(frameContext.makeStyleFor(tintStyle)).thenReturn(tintStyleProvider);
+
     Chunk imageChunk =
         Chunk.newBuilder()
-            .setImageChunk(StyledImageChunk.newBuilder().setImage(tintedImage))
+            .setImageChunk(
+                StyledImageChunk.newBuilder()
+                    .setImage(IMAGE_CHUNK_IMAGE)
+                    .setStyleReferences(tintStyle))
             .build();
 
     adapter.addImageChunk(frameContext, textView, spannable, imageChunk);
@@ -674,7 +682,7 @@
     ArgumentCaptor<ImageSpanDrawableCallback> imageCallbackCaptor =
         ArgumentCaptor.forClass(ImageSpanDrawableCallback.class);
     verify(mockAssetProvider)
-        .getImage(eq(tintedImage), anyInt(), anyInt(), imageCallbackCaptor.capture());
+        .getImage(eq(IMAGE_CHUNK_IMAGE), anyInt(), anyInt(), imageCallbackCaptor.capture());
 
     // Activate the image loading callback
     imageCallbackCaptor.getValue().accept(drawable);
@@ -691,8 +699,7 @@
             .setChunkedText(
                 ChunkedText.newBuilder()
                     .addChunks(
-                        IMAGE_CHUNK
-                            .toBuilder()
+                        IMAGE_CHUNK.toBuilder()
                             .setActions(
                                 Actions.newBuilder()
                                     .setOnClickAction(Action.getDefaultInstance()))))
diff --git a/src/test/java/com/google/android/libraries/feed/piet/ImageElementAdapterTest.java b/src/test/java/com/google/android/libraries/feed/piet/ImageElementAdapterTest.java
index dd10a43..ace2207 100644
--- a/src/test/java/com/google/android/libraries/feed/piet/ImageElementAdapterTest.java
+++ b/src/test/java/com/google/android/libraries/feed/piet/ImageElementAdapterTest.java
@@ -58,6 +58,7 @@
 import com.google.search.now.ui.piet.RoundedCornersProto.RoundedCorners;
 import com.google.search.now.ui.piet.RoundedCornersProto.RoundedCorners.Corners;
 import com.google.search.now.ui.piet.StylesProto.EdgeWidths;
+import com.google.search.now.ui.piet.StylesProto.Style;
 import com.google.search.now.ui.piet.StylesProto.StyleIdsStack;
 import org.junit.Before;
 import org.junit.Test;
@@ -407,24 +408,26 @@
   }
 
   @Test
-  public void testBindModel_overlayColor() {
+  public void testBindModel_color() {
+    int red = 0xFFFF0000;
+    ImageElement defaultImageElement = ImageElement.newBuilder().setImage(DEFAULT_IMAGE).build();
+    StyleProvider redTintStyleProvider =
+        new StyleProvider(
+            Style.newBuilder().setStyleId("red").setColor(red).build(), assetProvider);
+    StyleIdsStack redTintStyle = StyleIdsStack.newBuilder().addStyleIds("red").build();
+    when(frameContext.makeStyleFor(redTintStyle)).thenReturn(redTintStyleProvider);
+
     Element modelWithOverlayColor =
         Element.newBuilder()
-            .setImageElement(
-                ImageElement.newBuilder()
-                    .setImage(DEFAULT_IMAGE.toBuilder().setOverlayColor(0x11223344)))
+            .setStyleReferences(redTintStyle)
+            .setImageElement(defaultImageElement)
             .build();
 
     // Bind and expect tint to be set
     adapter.createAdapter(modelWithOverlayColor, frameContext);
     adapter.bindModel(modelWithOverlayColor, frameContext);
-    assertThat(adapter.overlayColorForCallback).isEqualTo(0x11223344);
-
-    adapter.unbindModel();
-
-    // Bind again and expect tint to be reset
-    adapter.bindModel(DEFAULT_MODEL, frameContext);
-    assertThat(adapter.overlayColorForCallback).isNull();
+    verify(frameContext).makeStyleFor(redTintStyle);
+    assertThat(adapter.overlayColorForCallback).isEqualTo(red);
   }
 
   @Test