diff --git a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ExampleDatabase.kt b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ExampleDatabase.kt
index e79553c888..f827d13e74 100644
--- a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ExampleDatabase.kt
+++ b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ExampleDatabase.kt
@@ -17,6 +17,7 @@ import com.facebook.fresco.samples.showcase.imageformat.override.ImageFormatOver
import com.facebook.fresco.samples.showcase.imageformat.pjpeg.ImageFormatProgressiveJpegFragment
import com.facebook.fresco.samples.showcase.imageformat.svg.ImageFormatSvgFragment
import com.facebook.fresco.samples.showcase.imageformat.webp.ImageFormatWebpFragment
+import com.facebook.fresco.samples.showcase.imageformat.xml.ImageFormatXmlFragment
import com.facebook.fresco.samples.showcase.imagepipeline.*
import com.facebook.fresco.samples.showcase.misc.WelcomeFragment
import com.facebook.fresco.samples.showcase.settings.SettingsFragment
@@ -56,7 +57,9 @@ object ExampleDatabase {
},
ExampleItem("Partial Image Loading") { PartialRequestFragment() },
ExampleItem("Platform Bitmap Factory") { ImagePipelineBitmapFactoryFragment() },
- ExampleItem("Region Decoding") { ImagePipelineRegionDecodingFragment() })),
+ ExampleItem("Region Decoding") { ImagePipelineRegionDecodingFragment() },
+ ),
+ ),
ExampleCategory(
"Image Formats",
listOf(
@@ -67,7 +70,10 @@ object ExampleDatabase {
ExampleItem("SVG") { ImageFormatSvgFragment() },
ExampleItem("Keyframes") { ImageFormatKeyframesFragment() },
ExampleItem("Decoder Override") { ImageFormatOverrideExample() },
- ExampleItem("Data URI") { ImageFormatDataUriFragment() })),
+ ExampleItem("Data URI") { ImageFormatDataUriFragment() },
+ ExampleItem("XML") { ImageFormatXmlFragment() },
+ ),
+ ),
ExampleCategory(
"Fresco Vito",
listOf(
diff --git a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ShowcaseApplication.kt b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ShowcaseApplication.kt
index 750f4e44a6..c383cd58b5 100644
--- a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ShowcaseApplication.kt
+++ b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ShowcaseApplication.kt
@@ -88,6 +88,7 @@ class ShowcaseApplication : Application() {
imagePipelineConfigBuilder
.experiment()
+ .setBinaryXmlEnabled(true)
.setBitmapPrepareToDraw(true, 0, Integer.MAX_VALUE, true)
.setDownsampleIfLargeBitmap(true)
diff --git a/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/imageformat/xml/ImageFormatXmlFragment.java b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/imageformat/xml/ImageFormatXmlFragment.java
new file mode 100644
index 0000000000..09482bdcaf
--- /dev/null
+++ b/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/imageformat/xml/ImageFormatXmlFragment.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+package com.facebook.fresco.samples.showcase.imageformat.xml;
+
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.Spinner;
+import android.widget.TextView;
+import androidx.annotation.DrawableRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import com.facebook.common.util.UriUtil;
+import com.facebook.fresco.samples.showcase.BaseShowcaseFragment;
+import com.facebook.fresco.samples.showcase.R;
+import com.facebook.fresco.vito.options.ImageOptions;
+import com.facebook.fresco.vito.view.VitoView;
+
+/** This fragment displays different XML images. */
+public class ImageFormatXmlFragment extends BaseShowcaseFragment {
+
+ private static final String CALLER_CONTEXT = "ImageFormatXmlFragment";
+
+ private ImageView mImageView;
+
+ @Nullable
+ @Override
+ public View onCreateView(
+ LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_format_xml, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ mImageView = view.findViewById(R.id.image);
+
+ final Spinner spinner = view.findViewById(R.id.spinner);
+ final Entry[] entries =
+ new Entry[] {
+ new Entry("Vector", fromResourceId(R.drawable.xml_vector)),
+ new Entry("Nine patch", fromResourceId(R.drawable.xml_nine_patch)),
+ new Entry("Layer list", fromResourceId(R.drawable.xml_layer_list)),
+ new Entry("Level list", fromResourceId(R.drawable.xml_level_list)),
+ new Entry("State list", fromResourceId(R.drawable.xml_state_list)),
+ new Entry("Bitmap", fromResourceId(R.drawable.xml_bitmap)),
+ };
+ spinner.setAdapter(new SimpleUriListAdapter(entries));
+ spinner.setOnItemSelectedListener(
+ new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ final Entry spinnerEntry = entries[spinner.getSelectedItemPosition()];
+ setImageUri(spinnerEntry.uri);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {}
+ });
+ spinner.setSelection(0);
+ }
+
+ private void setImageUri(Uri uri) {
+ VitoView.show(uri, ImageOptions.create().build(), CALLER_CONTEXT, mImageView);
+ }
+
+ private Uri fromResourceId(@DrawableRes int resourceId) {
+ return UriUtil.getUriForResourceId(resourceId);
+ }
+
+ private class SimpleUriListAdapter extends BaseAdapter {
+ final Entry[] mEntries;
+
+ SimpleUriListAdapter(Entry[] entries) {
+ this.mEntries = entries;
+ }
+
+ @Override
+ public int getCount() {
+ return mEntries.length;
+ }
+
+ @Override
+ public Entry getItem(int position) {
+ return mEntries[position];
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final LayoutInflater layoutInflater = getLayoutInflater(null);
+ final View view =
+ convertView != null
+ ? convertView
+ : layoutInflater.inflate(
+ android.R.layout.simple_spinner_dropdown_item, parent, false);
+ final TextView textView = (TextView) view.findViewById(android.R.id.text1);
+ textView.setText(mEntries[position].label);
+ return view;
+ }
+ }
+
+ private static class Entry {
+ final @NonNull String label;
+ final Uri uri;
+
+ private Entry(@NonNull String label, Uri uri) {
+ this.label = label;
+ this.uri = uri;
+ }
+ }
+}
diff --git a/samples/showcase/src/main/res/drawable/xml_bitmap.xml b/samples/showcase/src/main/res/drawable/xml_bitmap.xml
new file mode 100644
index 0000000000..8eedab836b
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_bitmap.xml
@@ -0,0 +1,5 @@
+
+
diff --git a/samples/showcase/src/main/res/drawable/xml_layer_list.xml b/samples/showcase/src/main/res/drawable/xml_layer_list.xml
new file mode 100644
index 0000000000..3c6ad43d8a
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_layer_list.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
diff --git a/samples/showcase/src/main/res/drawable/xml_level_list.xml b/samples/showcase/src/main/res/drawable/xml_level_list.xml
new file mode 100644
index 0000000000..e9feec39de
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_level_list.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/samples/showcase/src/main/res/drawable/xml_nine_patch.xml b/samples/showcase/src/main/res/drawable/xml_nine_patch.xml
new file mode 100644
index 0000000000..f23e28df65
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_nine_patch.xml
@@ -0,0 +1,5 @@
+
+
diff --git a/samples/showcase/src/main/res/drawable/xml_state_list.xml b/samples/showcase/src/main/res/drawable/xml_state_list.xml
new file mode 100644
index 0000000000..0ca33c61b9
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_state_list.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/samples/showcase/src/main/res/drawable/xml_vector.xml b/samples/showcase/src/main/res/drawable/xml_vector.xml
new file mode 100644
index 0000000000..b84f8093b6
--- /dev/null
+++ b/samples/showcase/src/main/res/drawable/xml_vector.xml
@@ -0,0 +1,13 @@
+
+
+
+
diff --git a/samples/showcase/src/main/res/layout/fragment_format_xml.xml b/samples/showcase/src/main/res/layout/fragment_format_xml.xml
new file mode 100644
index 0000000000..0c83ddae32
--- /dev/null
+++ b/samples/showcase/src/main/res/layout/fragment_format_xml.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/showcase/src/main/res/values/strings.xml b/samples/showcase/src/main/res/values/strings.xml
index 1842431f68..2bb06c0c81 100644
--- a/samples/showcase/src/main/res/values/strings.xml
+++ b/samples/showcase/src/main/res/values/strings.xml
@@ -112,6 +112,8 @@
Images can also be provided by data URIs such as the one below:
+ This example showcases different binary XML file types. Select different binary XML types from the spinner.
+
Configure the image source to be displayed
Configure image options to change the image\'s appearance
Auto play animations