From c3dafde00a061bafcd43a739336ca3503af13a7d Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 5 Dec 2017 19:23:56 -0800 Subject: [PATCH] Add nullability annotations to okhttp3 module and its dependencies (#2685) * Add nullability annotations to okhttp3 module and its dependencies Signed-off-by: Alex Saveau --- .../okhttp3/OkHttpLibraryGlideModule.java | 4 +++- .../integration/okhttp3/OkHttpStreamFetcher.java | 2 +- .../glide/integration/okhttp3/OkHttpUrlLoader.java | 12 +++++++----- .../integration/volley/VolleyLibraryGlideModule.java | 4 +++- .../glide/integration/volley/VolleyUrlLoader.java | 7 ++++--- .../bumptech/glide/load/model/AssetUriLoader.java | 7 ++++--- .../bumptech/glide/load/model/ByteArrayLoader.java | 4 ++-- .../glide/load/model/ByteBufferFileLoader.java | 6 +++--- .../com/bumptech/glide/load/model/DataUrlLoader.java | 5 +++-- .../com/bumptech/glide/load/model/FileLoader.java | 6 +++--- .../glide/load/model/MediaStoreFileLoader.java | 7 ++++--- .../com/bumptech/glide/load/model/ModelLoader.java | 6 ++++-- .../bumptech/glide/load/model/MultiModelLoader.java | 6 +++--- .../glide/load/model/MultiModelLoaderFactory.java | 6 ++++-- .../bumptech/glide/load/model/ResourceLoader.java | 6 ++++-- .../com/bumptech/glide/load/model/StringLoader.java | 7 ++++--- .../bumptech/glide/load/model/UnitModelLoader.java | 6 +++--- .../com/bumptech/glide/load/model/UriLoader.java | 7 ++++--- .../com/bumptech/glide/load/model/UrlUriLoader.java | 6 ++++-- .../glide/load/model/stream/BaseGlideUrlLoader.java | 4 +++- .../glide/load/model/stream/HttpGlideUrlLoader.java | 7 ++++--- .../glide/load/model/stream/HttpUriLoader.java | 6 ++++-- .../model/stream/MediaStoreImageThumbLoader.java | 6 ++++-- .../model/stream/MediaStoreVideoThumbLoader.java | 6 ++++-- .../bumptech/glide/load/model/stream/UrlLoader.java | 6 ++++-- .../bumptech/glide/module/LibraryGlideModule.java | 4 +++- .../bumptech/glide/module/RegistersComponents.java | 4 +++- .../load/model/stream/BaseGlideUrlLoaderTest.java | 8 ++++---- .../glide/samples/flickr/FlickrGlideModule.java | 4 +++- .../glide/samples/flickr/FlickrModelLoader.java | 3 ++- .../glide/samples/giphy/GiphyGlideModule.java | 4 +++- .../glide/samples/giphy/GiphyModelLoader.java | 3 ++- .../com/bumptech/glide/samples/svg/SvgModule.java | 4 +++- 33 files changed, 113 insertions(+), 70 deletions(-) diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java index 74eace9eb4..b315acbd79 100644 --- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java +++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java @@ -1,6 +1,7 @@ package com.bumptech.glide.integration.okhttp3; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; import com.bumptech.glide.annotation.GlideModule; @@ -19,7 +20,8 @@ @GlideModule public final class OkHttpLibraryGlideModule extends LibraryGlideModule { @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); } } diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java index f795fa2a32..7ffd81db6c 100644 --- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java +++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java @@ -77,7 +77,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) { } @Override - public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + public void onResponse(@NonNull Call call, @NonNull Response response) { responseBody = response.body(); if (response.isSuccessful()) { long contentLength = Preconditions.checkNotNull(responseBody).contentLength(); diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java index de8e2752ff..8f8f9066c5 100644 --- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java +++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.integration.okhttp3; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.ModelLoader; @@ -18,18 +19,18 @@ public class OkHttpUrlLoader implements ModelLoader { // Public API. @SuppressWarnings("WeakerAccess") - public OkHttpUrlLoader(Call.Factory client) { + public OkHttpUrlLoader(@NonNull Call.Factory client) { this.client = client; } @Override - public boolean handles(GlideUrl url) { + public boolean handles(@NonNull GlideUrl url) { return true; } @Override - public LoadData buildLoadData(GlideUrl model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull GlideUrl model, int width, int height, + @NonNull Options options) { return new LoadData<>(model, new OkHttpStreamFetcher(client, model)); } @@ -65,10 +66,11 @@ public Factory() { * * @param client this is typically an instance of {@code OkHttpClient}. */ - public Factory(Call.Factory client) { + public Factory(@NonNull Call.Factory client) { this.client = client; } + @NonNull @Override public ModelLoader build(MultiModelLoaderFactory multiFactory) { return new OkHttpUrlLoader(client); diff --git a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java index 6fa56468cb..514c62008d 100644 --- a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java +++ b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java @@ -1,6 +1,7 @@ package com.bumptech.glide.integration.volley; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; import com.bumptech.glide.annotation.GlideModule; @@ -21,7 +22,8 @@ @GlideModule public class VolleyLibraryGlideModule extends LibraryGlideModule { @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context)); } } diff --git a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java index 700a8a7d45..d64a47d409 100644 --- a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java +++ b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java @@ -1,6 +1,7 @@ package com.bumptech.glide.integration.volley; import android.content.Context; +import android.support.annotation.NonNull; import com.android.volley.RequestQueue; import com.android.volley.toolbox.Volley; import com.bumptech.glide.load.Options; @@ -32,13 +33,13 @@ public VolleyUrlLoader(RequestQueue requestQueue, VolleyRequestFactory requestFa } @Override - public boolean handles(GlideUrl url) { + public boolean handles(@NonNull GlideUrl url) { return true; } @Override - public LoadData buildLoadData(GlideUrl url, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull GlideUrl url, int width, int height, + @NonNull Options options) { return new LoadData<>(url, new VolleyStreamFetcher(requestQueue, url, requestFactory)); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java index f60999c6ae..f8af6151b0 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java @@ -4,6 +4,7 @@ import android.content.res.AssetManager; import android.net.Uri; import android.os.ParcelFileDescriptor; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.data.FileDescriptorAssetPathFetcher; @@ -33,14 +34,14 @@ public AssetUriLoader(AssetManager assetManager, AssetFetcherFactory facto } @Override - public LoadData buildLoadData(Uri model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull Uri model, int width, int height, + @NonNull Options options) { String assetPath = model.toString().substring(ASSET_PREFIX_LENGTH); return new LoadData<>(new ObjectKey(model), factory.buildFetcher(assetManager, assetPath)); } @Override - public boolean handles(Uri model) { + public boolean handles(@NonNull Uri model) { return ContentResolver.SCHEME_FILE.equals(model.getScheme()) && !model.getPathSegments() .isEmpty() && ASSET_PATH_SEGMENT.equals(model.getPathSegments().get(0)); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java index c0264e40ba..54d80326ce 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java @@ -28,12 +28,12 @@ public ByteArrayLoader(Converter converter) { @Override public LoadData buildLoadData( - byte[] model, int width, int height, Options options) { + @NonNull byte[] model, int width, int height, @NonNull Options options) { return new LoadData<>(new ObjectKey(model), new Fetcher<>(model, converter)); } @Override - public boolean handles(byte[] model) { + public boolean handles(@NonNull byte[] model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java index db442bc83f..bc0ac5dc5d 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java @@ -20,13 +20,13 @@ public class ByteBufferFileLoader implements ModelLoader { private static final String TAG = "ByteBufferFileLoader"; @Override - public LoadData buildLoadData(File file, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull File file, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(file), new ByteBufferFetcher(file)); } @Override - public boolean handles(File file) { + public boolean handles(@NonNull File file) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java b/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java index 436f251e0c..8a47e2068e 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java @@ -35,12 +35,13 @@ public DataUrlLoader(DataDecoder dataDecoder) { } @Override - public LoadData buildLoadData(String model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull String model, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(model), new DataUriFetcher<>(model, dataDecoder)); } @Override - public boolean handles(String url) { + public boolean handles(@NonNull String url) { return url.startsWith(DATA_SCHEME_IMAGE); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java index 7d83eba058..0e1b732b2f 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java @@ -32,13 +32,13 @@ public FileLoader(FileOpener fileOpener) { } @Override - public LoadData buildLoadData(File model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull File model, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(model), new FileFetcher<>(model, fileOpener)); } @Override - public boolean handles(File model) { + public boolean handles(@NonNull File model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java index d4cd56d7f2..32867b9283 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java @@ -18,7 +18,7 @@ /** * Loads the file path for {@link MediaStore} owned {@link Uri uris}. */ -public final class MediaStoreFileLoader implements ModelLoader { +public final class MediaStoreFileLoader implements ModelLoader { private final Context context; @@ -29,12 +29,13 @@ public MediaStoreFileLoader(Context context) { } @Override - public LoadData buildLoadData(Uri uri, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Uri uri, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(uri), new FilePathFetcher(context, uri)); } @Override - public boolean handles(Uri uri) { + public boolean handles(@NonNull Uri uri) { return MediaStoreUtil.isMediaStoreUri(uri); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java index 230551c5df..30fde57fd8 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.model; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Options; @@ -77,7 +78,8 @@ public LoadData(Key sourceKey, List alternateKeys, DataFetcher fetche * the resource should be loaded at its original height. */ @Nullable - LoadData buildLoadData(Model model, int width, int height, Options options); + LoadData buildLoadData(@NonNull Model model, int width, int height, + @NonNull Options options); /** * Returns true if the given model is a of a recognized type that this loader can probably load. @@ -89,5 +91,5 @@ public LoadData(Key sourceKey, List alternateKeys, DataFetcher fetche * results are acceptable. {@link ModelLoader ModelLoaders} that return true from this method may * return {@code null} from {@link #buildLoadData(Object, int, int, Options)}

*/ - boolean handles(Model model); + boolean handles(@NonNull Model model); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java index 316ee755e1..d77abaa5ee 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java @@ -36,8 +36,8 @@ class MultiModelLoader implements ModelLoader { } @Override - public LoadData buildLoadData(Model model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull Model model, int width, int height, + @NonNull Options options) { Key sourceKey = null; int size = modelLoaders.size(); List> fetchers = new ArrayList<>(size); @@ -56,7 +56,7 @@ public LoadData buildLoadData(Model model, int width, int height, } @Override - public boolean handles(Model model) { + public boolean handles(@NonNull Model model) { for (ModelLoader modelLoader : modelLoaders) { if (modelLoader.handles(model)) { return true; diff --git a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java index c5ac002667..eb903fab35 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java +++ b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.model; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.v4.util.Pools.Pool; @@ -213,12 +214,13 @@ private static class EmptyModelLoader implements ModelLoader { @Nullable @Override - public LoadData buildLoadData(Object o, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Object o, int width, int height, + @NonNull Options options) { return null; } @Override - public boolean handles(Object o) { + public boolean handles(@NonNull Object o) { return false; } } diff --git a/library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java index ccaba04543..7d1e491537 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java @@ -4,6 +4,7 @@ import android.content.res.Resources; import android.net.Uri; import android.os.ParcelFileDescriptor; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; import com.bumptech.glide.load.Options; @@ -28,7 +29,8 @@ public ResourceLoader(Resources resources, ModelLoader uriLoader) { } @Override - public LoadData buildLoadData(Integer model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Integer model, int width, int height, + @NonNull Options options) { Uri uri = getResourceUri(model); return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options); } @@ -49,7 +51,7 @@ private Uri getResourceUri(Integer model) { } @Override - public boolean handles(Integer model) { + public boolean handles(@NonNull Integer model) { // TODO: check that this is in fact a resource id. return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java b/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java index 37586671a0..85425979c5 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java @@ -2,6 +2,7 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; import com.bumptech.glide.load.Options; @@ -24,14 +25,14 @@ public StringLoader(ModelLoader uriLoader) { } @Override - public LoadData buildLoadData(String model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull String model, int width, int height, + @NonNull Options options) { Uri uri = parseUri(model); return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options); } @Override - public boolean handles(String model) { + public boolean handles(@NonNull String model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java b/library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java index 795752ed60..c59f2dd0aa 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java @@ -31,13 +31,13 @@ public UnitModelLoader() { } @Override - public LoadData buildLoadData(Model model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull Model model, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(model), new UnitFetcher<>(model)); } @Override - public boolean handles(Model model) { + public boolean handles(@NonNull Model model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/UriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/UriLoader.java index 5ec0e0bc8d..51277b4414 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/UriLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/UriLoader.java @@ -3,6 +3,7 @@ import android.content.ContentResolver; import android.net.Uri; import android.os.ParcelFileDescriptor; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher; @@ -42,13 +43,13 @@ public UriLoader(LocalUriFetcherFactory factory) { } @Override - public LoadData buildLoadData(Uri model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull Uri model, int width, int height, + @NonNull Options options) { return new LoadData<>(new ObjectKey(model), factory.build(model)); } @Override - public boolean handles(Uri model) { + public boolean handles(@NonNull Uri model) { return SCHEMES.contains(model.getScheme()); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/UrlUriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/UrlUriLoader.java index 6a823f36da..931ac86494 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/UrlUriLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/UrlUriLoader.java @@ -1,6 +1,7 @@ package com.bumptech.glide.load.model; import android.net.Uri; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import java.io.InputStream; import java.util.Arrays; @@ -32,13 +33,14 @@ public UrlUriLoader(ModelLoader urlLoader) { } @Override - public LoadData buildLoadData(Uri uri, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Uri uri, int width, int height, + @NonNull Options options) { GlideUrl glideUrl = new GlideUrl(uri.toString()); return urlLoader.buildLoadData(glideUrl, width, height, options); } @Override - public boolean handles(Uri uri) { + public boolean handles(@NonNull Uri uri) { return SCHEMES.contains(uri.getScheme()); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoader.java index f4cf7cf114..68c606f00d 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.model.stream; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; import com.bumptech.glide.load.Key; @@ -35,7 +36,8 @@ protected BaseGlideUrlLoader(ModelLoader concreteLoader, @Override @Nullable - public LoadData buildLoadData(Model model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Model model, int width, int height, + @NonNull Options options) { GlideUrl result = null; if (modelCache != null) { result = modelCache.get(model, width, height); diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/HttpGlideUrlLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/HttpGlideUrlLoader.java index 88253cbf20..90bfbcc6fe 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/HttpGlideUrlLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/HttpGlideUrlLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.model.stream; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.load.Option; import com.bumptech.glide.load.Options; @@ -38,8 +39,8 @@ public HttpGlideUrlLoader(@Nullable ModelCache modelCache) { } @Override - public LoadData buildLoadData(GlideUrl model, int width, int height, - Options options) { + public LoadData buildLoadData(@NonNull GlideUrl model, int width, int height, + @NonNull Options options) { // GlideUrls memoize parsed URLs so caching them saves a few object instantiations and time // spent parsing urls. GlideUrl url = model; @@ -55,7 +56,7 @@ public LoadData buildLoadData(GlideUrl model, int width, int height } @Override - public boolean handles(GlideUrl model) { + public boolean handles(@NonNull GlideUrl model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/HttpUriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/HttpUriLoader.java index 25c1e8f9f7..0567509267 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/HttpUriLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/HttpUriLoader.java @@ -1,6 +1,7 @@ package com.bumptech.glide.load.model.stream; import android.net.Uri; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.ModelLoader; @@ -28,12 +29,13 @@ public HttpUriLoader(ModelLoader urlLoader) { } @Override - public LoadData buildLoadData(Uri model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Uri model, int width, int height, + @NonNull Options options) { return urlLoader.buildLoadData(new GlideUrl(model.toString()), width, height, options); } @Override - public boolean handles(Uri model) { + public boolean handles(@NonNull Uri model) { return SCHEMES.contains(model.getScheme()); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreImageThumbLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreImageThumbLoader.java index 14b51a940c..fdce945ade 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreImageThumbLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreImageThumbLoader.java @@ -2,6 +2,7 @@ import android.content.Context; import android.net.Uri; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.mediastore.MediaStoreUtil; import com.bumptech.glide.load.data.mediastore.ThumbFetcher; @@ -25,7 +26,8 @@ public MediaStoreImageThumbLoader(Context context) { } @Override - public LoadData buildLoadData(Uri model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Uri model, int width, int height, + @NonNull Options options) { if (MediaStoreUtil.isThumbnailSize(width, height)) { return new LoadData<>(new ObjectKey(model), ThumbFetcher.buildImageFetcher(context, model)); } else { @@ -34,7 +36,7 @@ public LoadData buildLoadData(Uri model, int width, int height, Opt } @Override - public boolean handles(Uri model) { + public boolean handles(@NonNull Uri model) { return MediaStoreUtil.isMediaStoreImageUri(model); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreVideoThumbLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreVideoThumbLoader.java index 24d846e5ab..a2862cf02c 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreVideoThumbLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/MediaStoreVideoThumbLoader.java @@ -2,6 +2,7 @@ import android.content.Context; import android.net.Uri; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.mediastore.MediaStoreUtil; @@ -33,7 +34,8 @@ public MediaStoreVideoThumbLoader(Context context) { @Override @Nullable - public LoadData buildLoadData(Uri model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull Uri model, int width, int height, + @NonNull Options options) { if (MediaStoreUtil.isThumbnailSize(width, height) && isRequestingDefaultFrame(options)) { return new LoadData<>(new ObjectKey(model), ThumbFetcher.buildVideoFetcher(context, model)); } else { @@ -47,7 +49,7 @@ private boolean isRequestingDefaultFrame(Options options) { } @Override - public boolean handles(Uri model) { + public boolean handles(@NonNull Uri model) { return MediaStoreUtil.isMediaStoreVideoUri(model); } diff --git a/library/src/main/java/com/bumptech/glide/load/model/stream/UrlLoader.java b/library/src/main/java/com/bumptech/glide/load/model/stream/UrlLoader.java index 8c8a440a6a..a2ae62eff4 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/stream/UrlLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/stream/UrlLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.model.stream; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.ModelLoader; @@ -24,12 +25,13 @@ public UrlLoader(ModelLoader glideUrlLoader) { } @Override - public LoadData buildLoadData(URL model, int width, int height, Options options) { + public LoadData buildLoadData(@NonNull URL model, int width, int height, + @NonNull Options options) { return glideUrlLoader.buildLoadData(new GlideUrl(model), width, height, options); } @Override - public boolean handles(URL model) { + public boolean handles(@NonNull URL model) { return true; } diff --git a/library/src/main/java/com/bumptech/glide/module/LibraryGlideModule.java b/library/src/main/java/com/bumptech/glide/module/LibraryGlideModule.java index ccf368671b..647945aec8 100644 --- a/library/src/main/java/com/bumptech/glide/module/LibraryGlideModule.java +++ b/library/src/main/java/com/bumptech/glide/module/LibraryGlideModule.java @@ -1,6 +1,7 @@ package com.bumptech.glide.module; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; @@ -17,7 +18,8 @@ */ public abstract class LibraryGlideModule implements RegistersComponents { @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { // Default empty impl. } } diff --git a/library/src/main/java/com/bumptech/glide/module/RegistersComponents.java b/library/src/main/java/com/bumptech/glide/module/RegistersComponents.java index 56d7df081c..46c9c1ce7a 100644 --- a/library/src/main/java/com/bumptech/glide/module/RegistersComponents.java +++ b/library/src/main/java/com/bumptech/glide/module/RegistersComponents.java @@ -1,6 +1,7 @@ package com.bumptech.glide.module; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; @@ -21,5 +22,6 @@ interface RegistersComponents { * @param glide The Glide singleton that is in the process of being initialized. * @param registry An {@link com.bumptech.glide.Registry} to use to register components. */ - void registerComponents(Context context, Glide glide, Registry registry); + void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry); } diff --git a/library/src/test/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoaderTest.java b/library/src/test/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoaderTest.java index f5d60a9113..84b1210033 100644 --- a/library/src/test/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoaderTest.java +++ b/library/src/test/java/com/bumptech/glide/load/model/stream/BaseGlideUrlLoaderTest.java @@ -9,6 +9,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.DataFetcher; @@ -83,8 +84,7 @@ public void testBuildsNewUrlIfNotPresentInCache() { when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options))) .thenAnswer(new Answer>() { @Override - public ModelLoader.LoadData answer(InvocationOnMock invocationOnMock) - throws Throwable { + public ModelLoader.LoadData answer(InvocationOnMock invocationOnMock) { GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0]; assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl()); return new ModelLoader.LoadData<>(mock(Key.class), fetcher); @@ -107,7 +107,7 @@ public void testAddsNewUrlToCacheIfNotPresentInCache() { doAnswer(new Answer() { @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + public Void answer(InvocationOnMock invocationOnMock) { GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[3]; assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl()); return null; @@ -150,7 +150,7 @@ protected String getUrl(Object model, int width, int height, Options options) { } @Override - public boolean handles(Object model) { + public boolean handles(@NonNull Object model) { return true; } } diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideModule.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideModule.java index 3563b78e4b..83f7cc59dd 100644 --- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideModule.java +++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideModule.java @@ -1,6 +1,7 @@ package com.bumptech.glide.samples.flickr; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.GlideBuilder; import com.bumptech.glide.Registry; @@ -24,7 +25,8 @@ public void applyOptions(Context context, GlideBuilder builder) { } @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory()); } diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrModelLoader.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrModelLoader.java index 09a33ed1f9..1d59551014 100644 --- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrModelLoader.java +++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrModelLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.samples.flickr; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.ModelCache; @@ -42,7 +43,7 @@ private FlickrModelLoader( } @Override - public boolean handles(Photo model) { + public boolean handles(@NonNull Photo model) { return true; } diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyGlideModule.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyGlideModule.java index 5381e1f226..6fbca38269 100644 --- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyGlideModule.java +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyGlideModule.java @@ -1,6 +1,7 @@ package com.bumptech.glide.samples.giphy; import android.content.Context; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; import com.bumptech.glide.annotation.GlideModule; @@ -13,7 +14,8 @@ @GlideModule public class GiphyGlideModule extends AppGlideModule { @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory()); } diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java index 3b22f559d5..5e4a00502e 100644 --- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java +++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/GiphyModelLoader.java @@ -1,5 +1,6 @@ package com.bumptech.glide.samples.giphy; +import android.support.annotation.NonNull; import android.text.TextUtils; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.model.GlideUrl; @@ -18,7 +19,7 @@ public final class GiphyModelLoader extends BaseGlideUrlLoader { @Override - public boolean handles(Api.GifResult model) { + public boolean handles(@NonNull Api.GifResult model) { return true; } diff --git a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgModule.java b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgModule.java index 798d0f07f0..fdd14df98a 100644 --- a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgModule.java +++ b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgModule.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.drawable.PictureDrawable; +import android.support.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.Registry; import com.bumptech.glide.annotation.GlideModule; @@ -15,7 +16,8 @@ @GlideModule public class SvgModule extends AppGlideModule { @Override - public void registerComponents(Context context, Glide glide, Registry registry) { + public void registerComponents(@NonNull Context context, @NonNull Glide glide, + @NonNull Registry registry) { registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()) .append(InputStream.class, SVG.class, new SvgDecoder()); }