Permalink
Browse files

Moved custom decoder color XML example to the Showcase app and delete…

…d decoder sample app

Summary:
The decoder sample app only had a single color XML sample decoders since we added the others to the Showcase sample.
I moved the color XML sample to the Showcase app and adapted it accordingly and also removed the old sample app since it's no longer needed.

Reviewed By: massimocarli

Differential Revision: D4375212

fbshipit-source-id: cefe4b09c2377f165a9f89799ca93f32b0083671
  • Loading branch information...
1 parent 4d3bb42 commit a4bec859446c74281c1b6a26029ee3fd17dc285d @oprisnik oprisnik committed with facebook-github-bot Jan 9, 2017
Showing with 184 additions and 252 deletions.
  1. +0 −1 samples/decoders/.gitignore
  2. +0 −46 samples/decoders/build.gradle
  3. +0 −20 samples/decoders/src/main/AndroidManifest.xml
  4. +0 −62 samples/decoders/src/main/java/com/facebook/samples/decoders/CustomDecoderApplication.java
  5. +0 −40 samples/decoders/src/main/java/com/facebook/samples/decoders/MainActivity.java
  6. +0 −41 samples/decoders/src/main/res/layout/activity_main.xml
  7. BIN samples/decoders/src/main/res/mipmap-hdpi/ic_launcher.png
  8. BIN samples/decoders/src/main/res/mipmap-mdpi/ic_launcher.png
  9. BIN samples/decoders/src/main/res/mipmap-xhdpi/ic_launcher.png
  10. BIN samples/decoders/src/main/res/mipmap-xxhdpi/ic_launcher.png
  11. +0 −6 samples/decoders/src/main/res/values-w820dp/dimens.xml
  12. +0 −6 samples/decoders/src/main/res/values/colors.xml
  13. +0 −6 samples/decoders/src/main/res/values/dimens.xml
  14. +0 −4 samples/decoders/src/main/res/values/strings.xml
  15. +0 −11 samples/decoders/src/main/res/values/styles.xml
  16. +19 −0 ...es/showcase/src/main/java/com/facebook/fresco/samples/showcase/CustomImageFormatConfigurator.java
  17. +4 −0 samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/MainActivity.java
  18. +12 −8 ...case/src/main/java/com/facebook/fresco/samples/showcase/imageformat}/color/ColorImageExample.java
  19. +84 −0 ...rc/main/java/com/facebook/fresco/samples/showcase/imageformat/color/ImageFormatColorFragment.java
  20. +57 −0 samples/showcase/src/main/res/layout/fragment_format_color.xml
  21. +4 −0 samples/showcase/src/main/res/menu/activity_main_drawer.xml
  22. 0 samples/{decoders → showcase}/src/main/res/raw/custom_color1.color
  23. 0 samples/{decoders → showcase}/src/main/res/raw/custom_color2.color
  24. +4 −0 samples/showcase/src/main/res/values/strings.xml
  25. +0 −1 settings.gradle
@@ -1 +0,0 @@
-/build
@@ -1,46 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
- buildToolsVersion rootProject.ext.buildToolsVersion
- compileSdkVersion rootProject.ext.compileSdkVersion
-
- defaultConfig {
- applicationId "com.facebook.samples.decoders"
- minSdkVersion rootProject.ext.minSdkVersion
- targetSdkVersion rootProject.ext.targetSdkVersion
- versionCode 1
- versionName "${VERSION_NAME}"
-
- testApplicationId "com.facebook.samples.decoders.test"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), '../../proguard-rules.pro'
- }
- }
-
- splits {
- abi {
- enable true
- reset()
- include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
- universalApk false
- }
- }
-}
-
-dependencies {
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- testCompile 'junit:junit:4.12'
-
- provided "com.android.support:support-annotations:${SUPPORT_LIB_VERSION}"
- provided "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
- compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
-
- compile project(':drawee-backends:drawee-pipeline')
-}
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.facebook.samples.decoders">
-
- <application
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:name=".CustomDecoderApplication"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
-
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- </application>
-
-</manifest>
@@ -1,62 +0,0 @@
-/*
- * This file provided by Facebook is for non-commercial testing and evaluation
- * purposes only. Facebook reserves all rights not expressly granted.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package com.facebook.samples.decoders;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import android.app.Application;
-
-import com.facebook.common.logging.FLog;
-import com.facebook.drawee.backends.pipeline.DraweeConfig;
-import com.facebook.drawee.backends.pipeline.Fresco;
-import com.facebook.imagepipeline.core.ImagePipelineConfig;
-import com.facebook.imagepipeline.decoder.ImageDecoderConfig;
-import com.facebook.imagepipeline.listener.RequestListener;
-import com.facebook.imagepipeline.listener.RequestLoggingListener;
-import com.facebook.samples.decoders.color.ColorImageExample;
-
-/**
- * Demo Application implementation where we set up Fresco
- */
-public class CustomDecoderApplication extends Application {
-
- @Override
- public void onCreate() {
- super.onCreate();
- FLog.setMinimumLoggingLevel(FLog.VERBOSE);
- Set<RequestListener> listeners = new HashSet<>();
- listeners.add(new RequestLoggingListener());
-
- // Add custom decoding capabilities to the image decoder config
- ImageDecoderConfig imageDecoderConfig = ImageDecoderConfig.newBuilder()
- .addDecodingCapability(
- ColorImageExample.COLOR,
- ColorImageExample.getChecker(),
- ColorImageExample.getDecoder())
- .build();
-
- // Set the image decoder config to be used by the image pipeline
- ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
- .setRequestListeners(listeners)
- .setImageDecoderConfig(imageDecoderConfig)
- .build();
-
- // Add a Drawee config so that we're able to correctly render our custom images
- DraweeConfig draweeConfig = DraweeConfig.newBuilder()
- .addCustomDrawableFactory(new ColorImageExample.ColorDrawableFactory())
- .build();
-
- // Initialize Fresco with our configurations
- Fresco.initialize(this, config, draweeConfig);
- }
-}
@@ -1,40 +0,0 @@
-/*
- * This file provided by Facebook is for non-commercial testing and evaluation
- * purposes only. Facebook reserves all rights not expressly granted.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package com.facebook.samples.decoders;
-
-import android.support.v7.app.AppCompatActivity;
-import android.os.Bundle;
-
-import com.facebook.common.util.UriUtil;
-import com.facebook.drawee.backends.pipeline.Fresco;
-import com.facebook.drawee.view.SimpleDraweeView;
-import com.facebook.imagepipeline.request.ImageRequestBuilder;
-
-public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- // Get the Drawee view
- SimpleDraweeView drawee1 = (SimpleDraweeView) findViewById(R.id.drawee1);
-
- // Set a simple custom color resource as the image.
- // The format of custom_color1 is <color>#4CAF50</color>
- drawee1.setImageURI(UriUtil.getUriForResourceId(R.raw.custom_color1));
-
- // Get another Drawee view and set another custom image resource
- SimpleDraweeView drawee2 = (SimpleDraweeView) findViewById(R.id.drawee2);
- drawee2.setImageURI(UriUtil.getUriForResourceId(R.raw.custom_color2));
- }
-}
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/activity_main"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:orientation="vertical"
- tools:context="com.facebook.samples.decoders.MainActivity">
-
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/color_decoder"
- android:layout_marginBottom="@dimen/activity_vertical_margin"
- />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="120dp"
- android:orientation="horizontal"
- >
- <com.facebook.drawee.view.SimpleDraweeView
- android:id="@+id/drawee1"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:layout_marginRight="@dimen/grid_item_margin"
- android:layout_marginEnd="@dimen/grid_item_margin"
- />
- <com.facebook.drawee.view.SimpleDraweeView
- android:id="@+id/drawee2"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- />
- </LinearLayout>
-</LinearLayout>
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
@@ -1,6 +0,0 @@
-<resources>
- <!-- Example customization of dimensions originally defined in res/values/dimens.xml
- (such as screen margins) for screens with more than 820dp of available width. This
- would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
- <dimen name="activity_horizontal_margin">64dp</dimen>
-</resources>
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <color name="colorPrimary">#3F51B5</color>
- <color name="colorPrimaryDark">#303F9F</color>
- <color name="colorAccent">#FF4081</color>
-</resources>
@@ -1,6 +0,0 @@
-<resources>
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="grid_item_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
-</resources>
@@ -1,4 +0,0 @@
-<resources>
- <string name="app_name">Custom Decoders</string>
- <string name="color_decoder">Color Decoder</string>
-</resources>
@@ -1,11 +0,0 @@
-<resources>
-
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <!-- Customize your theme here. -->
- <item name="colorPrimary">@color/colorPrimary</item>
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
- <item name="colorAccent">@color/colorAccent</item>
- </style>
-
-</resources>
@@ -16,6 +16,7 @@
import android.support.annotation.Nullable;
import com.facebook.drawee.backends.pipeline.DraweeConfig;
+import com.facebook.fresco.samples.showcase.imageformat.color.ColorImageExample;
import com.facebook.fresco.samples.showcase.imageformat.keyframes.KeyframesDecoderExample;
import com.facebook.fresco.samples.showcase.imageformat.svg.SvgDecoderExample;
import com.facebook.imagepipeline.decoder.ImageDecoderConfig;
@@ -26,11 +27,18 @@
public class CustomImageFormatConfigurator {
private static final String IMAGE_FORMAT_PREFS = "fresco_image_format_prefs";
+ private static final String IMAGE_FORMAT_COLOR_KEY = "color";
private static final String IMAGE_FORMAT_SVG_KEY = "svg";
@Nullable
public static ImageDecoderConfig createImageDecoderConfig(Context context) {
ImageDecoderConfig.Builder config = ImageDecoderConfig.newBuilder();
+ if (isColorEnabled(context)) {
+ config.addDecodingCapability(
+ ColorImageExample.IMAGE_FORMAT_COLOR,
+ ColorImageExample.createFormatChecker(),
+ ColorImageExample.createDecoder());
+ }
if (isSvgEnabled(context)) {
config.addDecodingCapability(
SvgDecoderExample.SVG_FORMAT,
@@ -49,6 +57,9 @@ public static ImageDecoderConfig createImageDecoderConfig(Context context) {
public static void addCustomDrawableFactories(
Context context,
DraweeConfig.Builder draweeConfigBuilder) {
+ if (isColorEnabled(context)) {
+ draweeConfigBuilder.addCustomDrawableFactory(ColorImageExample.createDrawableFactory());
+ }
if (isSvgEnabled(context)) {
draweeConfigBuilder.addCustomDrawableFactory(new SvgDecoderExample.SvgDrawableFactory());
}
@@ -57,6 +68,14 @@ public static void addCustomDrawableFactories(
}
}
+ public static boolean isColorEnabled(Context context) {
+ return getBoolean(context, IMAGE_FORMAT_COLOR_KEY, false);
+ }
+
+ public static void setColorEnabled(Context context, boolean colorEnabled) {
+ setBoolean(context, IMAGE_FORMAT_COLOR_KEY, colorEnabled);
+ }
+
public static boolean isSvgEnabled(Context context) {
return getBoolean(context, IMAGE_FORMAT_SVG_KEY, false);
}
@@ -33,6 +33,7 @@
import com.facebook.fresco.samples.showcase.drawee.DraweeScaleTypeFragment;
import com.facebook.fresco.samples.showcase.drawee.DraweeSimpleFragment;
import com.facebook.fresco.samples.showcase.drawee.DraweeSpanSimpleTextFragment;
+import com.facebook.fresco.samples.showcase.imageformat.color.ImageFormatColorFragment;
import com.facebook.fresco.samples.showcase.imageformat.gif.ImageFormatGifFragment;
import com.facebook.fresco.samples.showcase.imageformat.keyframes.ImageFormatKeyframesFragment;
import com.facebook.fresco.samples.showcase.imageformat.svg.ImageFormatSvgFragment;
@@ -150,6 +151,9 @@ private void handleNavigationItemClick(int itemId) {
break;
// Image Formats
+ case R.id.nav_format_color:
+ fragment = new ImageFormatColorFragment();
+ break;
case R.id.nav_format_gif:
fragment = new ImageFormatGifFragment();
break;
@@ -9,7 +9,7 @@
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package com.facebook.samples.decoders.color;
+package com.facebook.fresco.samples.showcase.imageformat.color;
import javax.annotation.Nullable;
@@ -23,7 +23,6 @@
import com.facebook.common.internal.ByteStreams;
import com.facebook.drawee.backends.pipeline.DrawableFactory;
import com.facebook.imageformat.ImageFormat;
-import com.facebook.imageformat.ImageFormatChecker;
import com.facebook.imageformat.ImageFormatCheckerUtils;
import com.facebook.imagepipeline.common.ImageDecodeOptions;
import com.facebook.imagepipeline.decoder.ImageDecoder;
@@ -46,24 +45,29 @@
/**
* Custom {@link ImageFormat} for color images.
*/
- public static final ImageFormat COLOR = new ImageFormat("COLOR", "color");
+ public static final ImageFormat IMAGE_FORMAT_COLOR =
+ new ImageFormat("IMAGE_FORMAT_COLOR", "color");
/**
- * Create a new image format checker for {@link #COLOR}.
+ * Create a new image format checker for {@link #IMAGE_FORMAT_COLOR}.
* @return the image format checker
*/
- public static ImageFormat.FormatChecker getChecker() {
+ public static ImageFormat.FormatChecker createFormatChecker() {
return new ColorFormatChecker();
}
/**
- * Create a new decoder that can decode {@link #COLOR} images.
+ * Create a new decoder that can decode {@link #IMAGE_FORMAT_COLOR} images.
* @return the decoder
*/
- public static ImageDecoder getDecoder() {
+ public static ImageDecoder createDecoder() {
return new ColorDecoder();
}
+ public static ColorDrawableFactory createDrawableFactory() {
+ return new ColorDrawableFactory();
+ }
+
/**
* Custom color format checker that verifies that the header of the file
* corresponds to our {@link #COLOR_TAG}.
@@ -84,7 +88,7 @@ public ImageFormat determineFormat(byte[] headerBytes, int headerSize) {
return null;
}
if (ImageFormatCheckerUtils.startsWithPattern(headerBytes, HEADER)) {
- return COLOR;
+ return IMAGE_FORMAT_COLOR;
}
return null;
}
Oops, something went wrong.

0 comments on commit a4bec85

Please sign in to comment.