-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: oprisnik Differential Revision: D64259734
- Loading branch information
1 parent
c0b3171
commit 7e1efeb
Showing
11 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...ain/java/com/facebook/fresco/samples/showcase/imageformat/xml/ImageFormatXmlFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:antialias="true" | ||
android:src="@drawable/logo" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:width="@dimen/drawee_height_medium" | ||
android:height="@dimen/drawee_height_medium" | ||
android:drawable="@drawable/ic_error_black_96dp" | ||
android:gravity="center" | ||
/> | ||
|
||
<item | ||
android:width="@dimen/drawee_height_medium" | ||
android:height="@dimen/drawee_height_medium" | ||
android:drawable="@drawable/xml_vector" | ||
android:gravity="center" | ||
/> | ||
|
||
<item | ||
android:width="@dimen/drawee_height_medium" | ||
android:height="@dimen/drawee_height_medium" | ||
android:drawable="@drawable/ic_edit" | ||
android:gravity="center" | ||
/> | ||
|
||
</layer-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<level-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:drawable="@drawable/ic_retry_black_48dp" | ||
android:minLevel="1" | ||
/> | ||
<item | ||
android:drawable="@drawable/xml_vector" | ||
android:maxLevel="1" | ||
android:minLevel="0" | ||
/> | ||
</level-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:dither="true" | ||
android:src="@drawable/ninepatch" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@drawable/ic_arrow_left" android:state_checked="false" android:state_pressed="false" /> | ||
<item android:drawable="@drawable/ic_arrow_right" android:state_checked="true" android:state_pressed="false" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#a4c639" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
> | ||
<path | ||
android:fillColor="#000" | ||
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z" | ||
/> | ||
</vector> |
39 changes: 39 additions & 0 deletions
39
samples/showcase/src/main/res/layout/fragment_format_xml.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".imageformat.xml.ImageFormatXmlFragment" | ||
> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
android:orientation="vertical" | ||
> | ||
|
||
<Spinner | ||
android:id="@+id/spinner" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/margin_medium" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:layout_width="@dimen/drawee_width_medium" | ||
android:layout_height="@dimen/drawee_height_medium" | ||
android:layout_marginTop="@dimen/margin_medium" | ||
android:importantForAccessibility="no" | ||
/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/margin_medium" | ||
android:text="@string/format_xml_help" | ||
android:textAppearance="?android:attr/textAppearanceSmall" | ||
/> | ||
</LinearLayout> | ||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters