diff --git a/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/SimpleProgressiveJpegConfig.java b/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/SimpleProgressiveJpegConfig.java
index bf0daf5b13..76461c5f12 100644
--- a/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/SimpleProgressiveJpegConfig.java
+++ b/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/SimpleProgressiveJpegConfig.java
@@ -9,9 +9,10 @@
package com.facebook.imagepipeline.decoder;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import com.facebook.common.internal.Preconditions;
import com.facebook.imagepipeline.image.ImmutableQualityInfo;
import com.facebook.imagepipeline.image.QualityInfo;
@@ -21,28 +22,43 @@
*
If no specific scans to decode are provided, every scan is allowed to be decoded.
*/
public class SimpleProgressiveJpegConfig implements ProgressiveJpegConfig {
- private final List mScansToDecode;
- private final int mGoodEnoughScanNumber;
+ public interface DynamicValueConfig {
+ List getScansToDecode();
+ int getGoodEnoughScanNumber();
+ }
+
+ private static class DefaultDynamicValueConfig implements DynamicValueConfig {
+ public List getScansToDecode() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public int getGoodEnoughScanNumber() {
+ return 0;
+ }
+ }
+
+ private final DynamicValueConfig mDynamicValueConfig;
public SimpleProgressiveJpegConfig() {
- this(new ArrayList(), 0);
+ this (new DefaultDynamicValueConfig());
}
- public SimpleProgressiveJpegConfig(
- List scansToDecode,
- int goodEnoughScanNumber) {
- mScansToDecode = scansToDecode;
- mGoodEnoughScanNumber = goodEnoughScanNumber;
+
+
+ public SimpleProgressiveJpegConfig(DynamicValueConfig dynamicValueConfig) {
+ mDynamicValueConfig = Preconditions.checkNotNull(dynamicValueConfig);
}
@Override
public int getNextScanNumberToDecode(int scanNumber) {
- if (mScansToDecode == null || mScansToDecode.isEmpty()) {
+ final List scansToDecode = mDynamicValueConfig.getScansToDecode();
+ if (scansToDecode == null || scansToDecode.isEmpty()) {
return scanNumber + 1;
}
- for (int i = 0; i < mScansToDecode.size(); i++) {
- if (mScansToDecode.get(i) > scanNumber) {
- return mScansToDecode.get(i);
+
+ for (int i = 0; i < scansToDecode.size(); i++) {
+ if (scansToDecode.get(i) > scanNumber) {
+ return scansToDecode.get(i);
}
}
return Integer.MAX_VALUE;
@@ -52,7 +68,7 @@ public int getNextScanNumberToDecode(int scanNumber) {
public QualityInfo getQualityInfo(int scanNumber) {
return ImmutableQualityInfo.of(
scanNumber,
- /* isOfGoodEnoughQuality */ scanNumber >= mGoodEnoughScanNumber,
+ /* isOfGoodEnoughQuality */ scanNumber >= mDynamicValueConfig.getGoodEnoughScanNumber(),
/* isOfFullQuality */ false);
}
}