Skip to content

Commit

Permalink
Moved custom decoder color XML example to the Showcase app and delete…
Browse files Browse the repository at this point in the history
…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
oprisnik authored and facebook-github-bot committed Jan 9, 2017
1 parent 4d3bb42 commit a4bec85
Show file tree
Hide file tree
Showing 25 changed files with 184 additions and 252 deletions.
1 change: 0 additions & 1 deletion samples/decoders/.gitignore

This file was deleted.

46 changes: 0 additions & 46 deletions samples/decoders/build.gradle

This file was deleted.

20 changes: 0 additions & 20 deletions samples/decoders/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 0 additions & 41 deletions samples/decoders/src/main/res/layout/activity_main.xml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions samples/decoders/src/main/res/values-w820dp/dimens.xml

This file was deleted.

6 changes: 0 additions & 6 deletions samples/decoders/src/main/res/values/colors.xml

This file was deleted.

6 changes: 0 additions & 6 deletions samples/decoders/src/main/res/values/dimens.xml

This file was deleted.

4 changes: 0 additions & 4 deletions samples/decoders/src/main/res/values/strings.xml

This file was deleted.

11 changes: 0 additions & 11 deletions samples/decoders/src/main/res/values/styles.xml

This file was deleted.

Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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());
}
Expand All @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -46,24 +45,29 @@ public class ColorImageExample {
/**
* 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}.
Expand All @@ -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;
}
Expand Down

0 comments on commit a4bec85

Please sign in to comment.