Skip to content

Commit cfae30a

Browse files
SUPERCILEXsjudd
authored andcommitted
Add nullability annotations to gif encoder module (bumptech#2713)
Signed-off-by: Alex Saveau <[email protected]>
1 parent e923554 commit cfae30a

File tree

18 files changed

+66
-40
lines changed

18 files changed

+66
-40
lines changed

integration/gifencoder/src/main/java/com/bumptech/glide/integration/gifencoder/ReEncodingGifResourceEncoder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.graphics.Bitmap;
5+
import android.support.annotation.NonNull;
56
import android.support.annotation.VisibleForTesting;
67
import android.util.Log;
78
import com.bumptech.glide.gifdecoder.GifDecoder;
@@ -38,7 +39,7 @@ public class ReEncodingGifResourceEncoder implements ResourceEncoder<GifDrawable
3839

3940
private static final String KEY_ENCODE_TRANSFORMATION =
4041
"com.bumptech.glide.load.resource.gif.GifResourceEncoder.EncodeTransformation";
41-
/**
42+
/**
4243
* A boolean option that, if set to <code>true</code>, causes the fully transformed
4344
* GIF to be written to cache.
4445
*
@@ -47,7 +48,7 @@ public class ReEncodingGifResourceEncoder implements ResourceEncoder<GifDrawable
4748
*
4849
* <p>Defaults to <code>false</code>.
4950
*/
50-
// Public API.
51+
// Public API.
5152
@SuppressWarnings("WeakerAccess")
5253
public static final Option<Boolean> ENCODE_TRANSFORMATION =
5354
Option.disk(KEY_ENCODE_TRANSFORMATION, false, new Option.CacheKeyUpdater<Boolean>() {
@@ -68,7 +69,7 @@ public void update(byte[] keyBytes, Boolean value, MessageDigest messageDigest)
6869

6970
// Public API.
7071
@SuppressWarnings("unused")
71-
public ReEncodingGifResourceEncoder(Context context, BitmapPool bitmapPool) {
72+
public ReEncodingGifResourceEncoder(@NonNull Context context, @NonNull BitmapPool bitmapPool) {
7273
this(context, bitmapPool, FACTORY);
7374
}
7475

@@ -81,14 +82,15 @@ public ReEncodingGifResourceEncoder(Context context, BitmapPool bitmapPool) {
8182
}
8283

8384
@Override
84-
public EncodeStrategy getEncodeStrategy(Options options) {
85+
public EncodeStrategy getEncodeStrategy(@NonNull Options options) {
8586
Boolean encodeTransformation = options.get(ENCODE_TRANSFORMATION);
8687
return encodeTransformation != null && encodeTransformation
8788
? EncodeStrategy.TRANSFORMED : EncodeStrategy.SOURCE;
8889
}
8990

9091
@Override
91-
public boolean encode(Resource<GifDrawable> resource, File file, Options options) {
92+
public boolean encode(@NonNull Resource<GifDrawable> resource, @NonNull File file,
93+
@NonNull Options options) {
9294
GifDrawable drawable = resource.get();
9395
Transformation<Bitmap> transformation = drawable.getFrameTransformation();
9496
boolean isTransformed = !(transformation instanceof UnitTransformation);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load;
22

3+
import android.support.annotation.NonNull;
34
import java.io.File;
45

56
/**
@@ -8,7 +9,6 @@
89
* @param <T> The type of the data that will be written.
910
*/
1011
public interface Encoder<T> {
11-
1212
/**
1313
* Writes the given data to the given output stream and returns True if the write completed
1414
* successfully and should be committed.
@@ -17,5 +17,5 @@ public interface Encoder<T> {
1717
* @param file The File to write the data to.
1818
* @param options The put of options to apply when encoding.
1919
*/
20-
boolean encode(T data, File file, Options options);
20+
boolean encode(@NonNull T data, @NonNull File file, @NonNull Options options);
2121
}

library/src/main/java/com/bumptech/glide/load/MultiTransformation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.load;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.bumptech.glide.load.engine.Resource;
56
import java.security.MessageDigest;
67
import java.util.Arrays;
@@ -32,9 +33,10 @@ public MultiTransformation(Collection<? extends Transformation<T>> transformatio
3233
this.transformations = transformationList;
3334
}
3435

36+
@NonNull
3537
@Override
3638
public Resource<T> transform(
37-
Context context, Resource<T> resource, int outWidth, int outHeight) {
39+
@NonNull Context context, @NonNull Resource<T> resource, int outWidth, int outHeight) {
3840
Resource<T> previous = resource;
3941

4042
for (Transformation<T> transformation : transformations) {

library/src/main/java/com/bumptech/glide/load/ResourceEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load;
22

3+
import android.support.annotation.NonNull;
34
import com.bumptech.glide.load.engine.Resource;
45

56
/**
@@ -10,5 +11,5 @@
1011
*/
1112
public interface ResourceEncoder<T> extends Encoder<Resource<T>> {
1213
// specializing the generic arguments
13-
EncodeStrategy getEncodeStrategy(Options options);
14+
EncodeStrategy getEncodeStrategy(@NonNull Options options);
1415
}

library/src/main/java/com/bumptech/glide/load/Transformation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.load;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.bumptech.glide.load.engine.Resource;
56
import java.nio.charset.Charset;
67
import java.security.MessageDigest;
@@ -61,7 +62,9 @@ public interface Transformation<T> extends Key {
6162
* original resource height.
6263
* @return The transformed resource.
6364
*/
64-
Resource<T> transform(Context context, Resource<T> resource, int outWidth, int outHeight);
65+
@NonNull
66+
Resource<T> transform(@NonNull Context context, @NonNull Resource<T> resource,
67+
int outWidth, int outHeight);
6568

6669
/**
6770
* For caching to work correctly, implementations <em>must</em> implement this method and

library/src/main/java/com/bumptech/glide/load/engine/DataCacheWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.engine;
22

3+
import android.support.annotation.NonNull;
34
import com.bumptech.glide.load.Encoder;
45
import com.bumptech.glide.load.Options;
56
import com.bumptech.glide.load.engine.cache.DiskCache;
@@ -26,7 +27,7 @@ class DataCacheWriter<DataType> implements DiskCache.Writer {
2627
}
2728

2829
@Override
29-
public boolean write(File file) {
30+
public boolean write(@NonNull File file) {
3031
return encoder.encode(data, file, options);
3132
}
3233
}

library/src/main/java/com/bumptech/glide/load/engine/cache/DiskCache.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.engine.cache;
22

3+
import android.support.annotation.NonNull;
34
import android.support.annotation.Nullable;
45
import com.bumptech.glide.load.Key;
56
import java.io.File;
@@ -13,16 +14,13 @@ public interface DiskCache {
1314
* An interface for lazily creating a disk cache.
1415
*/
1516
interface Factory {
17+
/** 250 MB of cache. */
18+
int DEFAULT_DISK_CACHE_SIZE = 250 * 1024 * 1024;
19+
String DEFAULT_DISK_CACHE_DIR = "image_manager_disk_cache";
1620

17-
/** 250 MB of cache. */
18-
int DEFAULT_DISK_CACHE_SIZE = 250 * 1024 * 1024;
19-
String DEFAULT_DISK_CACHE_DIR = "image_manager_disk_cache";
20-
21-
/**
22-
* Returns a new disk cache, or {@code null} if no disk cache could be created.
23-
*/
24-
@Nullable
25-
DiskCache build();
21+
/** Returns a new disk cache, or {@code null} if no disk cache could be created. */
22+
@Nullable
23+
DiskCache build();
2624
}
2725

2826
/**
@@ -35,7 +33,7 @@ interface Writer {
3533
*
3634
* @param file The File the Writer should write to.
3735
*/
38-
boolean write(File file);
36+
boolean write(@NonNull File file);
3937
}
4038

4139
/**

library/src/main/java/com/bumptech/glide/load/model/ByteBufferEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.model;
22

3+
import android.support.annotation.NonNull;
34
import android.util.Log;
45
import com.bumptech.glide.load.Encoder;
56
import com.bumptech.glide.load.Options;
@@ -15,7 +16,7 @@ public class ByteBufferEncoder implements Encoder<ByteBuffer> {
1516
private static final String TAG = "ByteBufferEncoder";
1617

1718
@Override
18-
public boolean encode(ByteBuffer data, File file, Options options) {
19+
public boolean encode(@NonNull ByteBuffer data, @NonNull File file, @NonNull Options options) {
1920
boolean success = false;
2021
try {
2122
ByteBufferUtil.toFile(data, file);

library/src/main/java/com/bumptech/glide/load/model/StreamEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.model;
22

3+
import android.support.annotation.NonNull;
34
import android.util.Log;
45
import com.bumptech.glide.load.Encoder;
56
import com.bumptech.glide.load.Options;
@@ -23,7 +24,7 @@ public StreamEncoder(ArrayPool byteArrayPool) {
2324
}
2425

2526
@Override
26-
public boolean encode(InputStream data, File file, Options options) {
27+
public boolean encode(@NonNull InputStream data, @NonNull File file, @NonNull Options options) {
2728
byte[] buffer = byteArrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, byte[].class);
2829
boolean success = false;
2930
OutputStream os = null;

library/src/main/java/com/bumptech/glide/load/resource/UnitTransformation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.load.resource;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.bumptech.glide.load.Transformation;
56
import com.bumptech.glide.load.engine.Resource;
67
import java.security.MessageDigest;
@@ -27,8 +28,10 @@ private UnitTransformation() {
2728
// Only accessible as a singleton.
2829
}
2930

31+
@NonNull
3032
@Override
31-
public Resource<T> transform(Context context, Resource<T> resource, int outWidth, int outHeight) {
33+
public Resource<T> transform(@NonNull Context context, @NonNull Resource<T> resource,
34+
int outWidth, int outHeight) {
3235
return resource;
3336
}
3437

0 commit comments

Comments
 (0)