From ce4be6d2191af1232dcd2fefad7026e658b139a5 Mon Sep 17 00:00:00 2001 From: Jared Burrows Date: Thu, 8 Feb 2018 09:44:26 -0800 Subject: [PATCH 1/2] deprecate fragments --- .../EmptyAppGlideModuleTest/GlideApp.java | 5 +++-- .../recyclerview/RecyclerViewPreloader.java | 11 ++++++----- .../src/main/java/com/bumptech/glide/Glide.java | 15 ++++++++------- .../glide/manager/RequestManagerFragment.java | 1 + .../glide/manager/RequestManagerRetriever.java | 6 ++++++ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideApp.java b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideApp.java index 4a1e8e1087..a6b2b8941c 100644 --- a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideApp.java +++ b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideApp.java @@ -2,11 +2,11 @@ import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Fragment; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.view.View; import com.bumptech.glide.Glide; @@ -115,8 +115,9 @@ public static GlideRequests with(@NonNull Fragment arg0) { /** * @see Glide#with(Fragment) */ + @Deprecated @NonNull - public static GlideRequests with(@NonNull android.support.v4.app.Fragment arg0) { + public static GlideRequests with(@NonNull android.app.Fragment arg0) { return (GlideRequests) Glide.with(arg0); } diff --git a/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java b/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java index fb22947804..0f193e0369 100644 --- a/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java +++ b/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java @@ -1,8 +1,8 @@ package com.bumptech.glide.integration.recyclerview; import android.app.Activity; -import android.app.Fragment; import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -52,9 +52,10 @@ public RecyclerViewPreloader(@NonNull FragmentActivity fragmentActivity, } /** - * Helper constructor that accepts an {@link Fragment}. + * Helper constructor that accepts an {@link android.app.Fragment}. */ - public RecyclerViewPreloader(@NonNull Fragment fragment, + @Deprecated + public RecyclerViewPreloader(@NonNull android.app.Fragment fragment, @NonNull PreloadModelProvider preloadModelProvider, @NonNull PreloadSizeProvider preloadDimensionProvider, int maxPreload) { @@ -62,9 +63,9 @@ public RecyclerViewPreloader(@NonNull Fragment fragment, } /** - * Helper constructor that accepts an {@link android.support.v4.app.Fragment}. + * Helper constructor that accepts an {@link Fragment}. */ - public RecyclerViewPreloader(@NonNull android.support.v4.app.Fragment fragment, + public RecyclerViewPreloader(@NonNull Fragment fragment, @NonNull PreloadModelProvider preloadModelProvider, @NonNull PreloadSizeProvider preloadDimensionProvider, int maxPreload) { diff --git a/library/src/main/java/com/bumptech/glide/Glide.java b/library/src/main/java/com/bumptech/glide/Glide.java index c7f7e45627..25935c2d49 100644 --- a/library/src/main/java/com/bumptech/glide/Glide.java +++ b/library/src/main/java/com/bumptech/glide/Glide.java @@ -724,27 +724,28 @@ public static RequestManager with(@NonNull FragmentActivity activity) { } /** - * Begin a load with Glide that will be tied to the given {@link android.app.Fragment}'s lifecycle - * and that uses the given {@link android.app.Fragment}'s default options. + * Begin a load with Glide that will be tied to the given + * {@link android.support.v4.app.Fragment}'s lifecycle and that uses the given + * {@link android.support.v4.app.Fragment}'s default options. * * @param fragment The fragment to use. * @return A RequestManager for the given Fragment that can be used to start a load. */ @NonNull - public static RequestManager with(@NonNull android.app.Fragment fragment) { + public static RequestManager with(@NonNull Fragment fragment) { return getRetriever(fragment.getActivity()).get(fragment); } /** - * Begin a load with Glide that will be tied to the given - * {@link android.support.v4.app.Fragment}'s lifecycle and that uses the given - * {@link android.support.v4.app.Fragment}'s default options. + * Begin a load with Glide that will be tied to the given {@link android.app.Fragment}'s lifecycle + * and that uses the given {@link android.app.Fragment}'s default options. * * @param fragment The fragment to use. * @return A RequestManager for the given Fragment that can be used to start a load. */ + @Deprecated @NonNull - public static RequestManager with(@NonNull Fragment fragment) { + public static RequestManager with(@NonNull android.app.Fragment fragment) { return getRetriever(fragment.getActivity()).get(fragment); } diff --git a/library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java b/library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java index 272064fa4f..97b2498082 100644 --- a/library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java +++ b/library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java @@ -25,6 +25,7 @@ * @see com.bumptech.glide.manager.RequestManagerRetriever * @see com.bumptech.glide.RequestManager */ +@Deprecated public class RequestManagerFragment extends Fragment { private static final String TAG = "RMFragment"; private final ActivityFragmentLifecycle lifecycle; diff --git a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java b/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java index 7d25d760bf..25356d138d 100644 --- a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java +++ b/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java @@ -229,6 +229,7 @@ private Fragment findSupportFragment(@NonNull View target, @NonNull FragmentActi return result; } + @Deprecated @Nullable private android.app.Fragment findFragment(@NonNull View target, @NonNull Activity activity) { tempViewToFragment.clear(); @@ -255,6 +256,7 @@ private android.app.Fragment findFragment(@NonNull View target, @NonNull Activit // TODO: Consider using an accessor class in the support library package to more directly retrieve // non-support Fragments. + @Deprecated @TargetApi(Build.VERSION_CODES.O) private void findAllFragmentsWithViews( @NonNull android.app.FragmentManager fragmentManager, @@ -271,6 +273,7 @@ private void findAllFragmentsWithViews( } } + @Deprecated private void findAllFragmentsWithViewsPreO( @NonNull android.app.FragmentManager fragmentManager, @NonNull ArrayMap result) { @@ -313,6 +316,7 @@ private static void assertNotDestroyed(@NonNull Activity activity) { } } + @Deprecated @NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public RequestManager get(@NonNull android.app.Fragment fragment) { @@ -328,6 +332,7 @@ public RequestManager get(@NonNull android.app.Fragment fragment) { } } + @Deprecated @NonNull RequestManagerFragment getRequestManagerFragment( @NonNull final android.app.FragmentManager fm, @Nullable android.app.Fragment parentHint) { @@ -345,6 +350,7 @@ RequestManagerFragment getRequestManagerFragment( return current; } + @Deprecated @NonNull private RequestManager fragmentGet(@NonNull Context context, @NonNull android.app.FragmentManager fm, From 1fd7c7cb05aa44a74b72aca1dd6d400faddedf30 Mon Sep 17 00:00:00 2001 From: Jared Burrows Date: Fri, 9 Feb 2018 08:33:14 -0800 Subject: [PATCH 2/2] add @deprecated to javadoc and suppress deprecations in code --- .../java/com/bumptech/glide/DataUriTest.java | 1 + .../recyclerview/RecyclerViewPreloader.java | 12 +++++++----- library/src/main/java/com/bumptech/glide/Glide.java | 1 + .../glide/manager/RequestManagerRetriever.java | 7 +++++++ .../glide/manager/RequestManagerFragmentTest.java | 1 + .../glide/manager/RequestManagerRetrieverTest.java | 5 +++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/instrumentation/src/androidTest/java/com/bumptech/glide/DataUriTest.java b/instrumentation/src/androidTest/java/com/bumptech/glide/DataUriTest.java index 0b46ad79df..bfd695f31b 100644 --- a/instrumentation/src/androidTest/java/com/bumptech/glide/DataUriTest.java +++ b/instrumentation/src/androidTest/java/com/bumptech/glide/DataUriTest.java @@ -94,6 +94,7 @@ private String getDataUriString(CompressFormat format) { return "data:" + mimeType + ";base64," + bytes; } + @SuppressWarnings("deprecation") private String getBase64BitmapBytes(CompressFormat format) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Drawable drawable = context.getResources().getDrawable(ResourceIds.raw.canonical); diff --git a/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java b/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java index 0f193e0369..988561eaca 100644 --- a/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java +++ b/integration/recyclerview/src/main/java/com/bumptech/glide/integration/recyclerview/RecyclerViewPreloader.java @@ -52,10 +52,9 @@ public RecyclerViewPreloader(@NonNull FragmentActivity fragmentActivity, } /** - * Helper constructor that accepts an {@link android.app.Fragment}. + * Helper constructor that accepts an {@link Fragment}. */ - @Deprecated - public RecyclerViewPreloader(@NonNull android.app.Fragment fragment, + public RecyclerViewPreloader(@NonNull Fragment fragment, @NonNull PreloadModelProvider preloadModelProvider, @NonNull PreloadSizeProvider preloadDimensionProvider, int maxPreload) { @@ -63,9 +62,12 @@ public RecyclerViewPreloader(@NonNull android.app.Fragment fragment, } /** - * Helper constructor that accepts an {@link Fragment}. + * Helper constructor that accepts an {@link android.app.Fragment}. + * @deprecated Use constructor RecyclerViewPreloader(Fragment, PreloadModelProvider, + * PreloadSizeProvider) instead. */ - public RecyclerViewPreloader(@NonNull Fragment fragment, + @Deprecated + public RecyclerViewPreloader(@NonNull android.app.Fragment fragment, @NonNull PreloadModelProvider preloadModelProvider, @NonNull PreloadSizeProvider preloadDimensionProvider, int maxPreload) { diff --git a/library/src/main/java/com/bumptech/glide/Glide.java b/library/src/main/java/com/bumptech/glide/Glide.java index 25935c2d49..c380bea66d 100644 --- a/library/src/main/java/com/bumptech/glide/Glide.java +++ b/library/src/main/java/com/bumptech/glide/Glide.java @@ -742,6 +742,7 @@ public static RequestManager with(@NonNull Fragment fragment) { * * @param fragment The fragment to use. * @return A RequestManager for the given Fragment that can be used to start a load. + * @deprecated Use method {@link #with(Fragment)} instead. */ @Deprecated @NonNull diff --git a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java b/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java index 25356d138d..ce6de69b5e 100644 --- a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java +++ b/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java @@ -53,6 +53,7 @@ public class RequestManagerRetriever implements Handler.Callback { /** * Pending adds for RequestManagerFragments. */ + @SuppressWarnings("deprecation") @VisibleForTesting final Map pendingRequestManagerFragments = new HashMap<>(); @@ -229,6 +230,7 @@ private Fragment findSupportFragment(@NonNull View target, @NonNull FragmentActi return result; } + @SuppressWarnings("deprecation") @Deprecated @Nullable private android.app.Fragment findFragment(@NonNull View target, @NonNull Activity activity) { @@ -256,6 +258,7 @@ private android.app.Fragment findFragment(@NonNull View target, @NonNull Activit // TODO: Consider using an accessor class in the support library package to more directly retrieve // non-support Fragments. + @SuppressWarnings("deprecation") @Deprecated @TargetApi(Build.VERSION_CODES.O) private void findAllFragmentsWithViews( @@ -273,6 +276,7 @@ private void findAllFragmentsWithViews( } } + @SuppressWarnings("deprecation") @Deprecated private void findAllFragmentsWithViewsPreO( @NonNull android.app.FragmentManager fragmentManager, @@ -316,6 +320,7 @@ private static void assertNotDestroyed(@NonNull Activity activity) { } } + @SuppressWarnings("deprecation") @Deprecated @NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @@ -332,6 +337,7 @@ public RequestManager get(@NonNull android.app.Fragment fragment) { } } + @SuppressWarnings("deprecation") @Deprecated @NonNull RequestManagerFragment getRequestManagerFragment( @@ -350,6 +356,7 @@ RequestManagerFragment getRequestManagerFragment( return current; } + @SuppressWarnings("deprecation") @Deprecated @NonNull private RequestManager fragmentGet(@NonNull Context context, diff --git a/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java b/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java index 65b63694ec..191f023097 100644 --- a/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java +++ b/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java @@ -148,6 +148,7 @@ private interface Harness { void onTrimMemory(@SuppressWarnings("SameParameterValue") int level); } + @SuppressWarnings("deprecation") private static class RequestManagerHarness implements Harness { private final ActivityController controller; private final RequestManagerFragment fragment; diff --git a/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java b/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java index 79c5bd9f84..dd07da8138 100644 --- a/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java +++ b/library/test/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java @@ -134,6 +134,7 @@ public void testSupportCanGetRequestManagerFromActivity() { assertEquals(manager, retriever.get(fragmentActivity)); } + @SuppressWarnings("deprecation") @Test public void testCanGetRequestManagerFromFragment() { Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get(); @@ -168,6 +169,7 @@ public void testCanGetRequestManagerFromDetachedFragment_PreJellyBeanMr1() { helpTestCanGetRequestManagerFromDetachedFragment(); } + @SuppressWarnings("deprecation") private void helpTestCanGetRequestManagerFromDetachedFragment() { Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get(); android.app.Fragment fragment = new android.app.Fragment(); @@ -202,6 +204,7 @@ private void helpTestSupportCanGetRequestManagerFromDetachedFragment() { retriever.get(fragment); } + @SuppressWarnings("deprecation") @Test(expected = IllegalArgumentException.class) public void testThrowsIfFragmentNotAttached() { android.app.Fragment fragment = new android.app.Fragment(); @@ -319,6 +322,7 @@ public void testDoesNotThrowIfAskedToGetManagerForActivityPreJellYBeanMr1() { assertNotNull(retriever.get(spyActivity)); } + @SuppressWarnings("deprecation") @Test @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public void testDoesNotThrowIfAskedToGetManagerForFragmentPreJellyBeanMr1() { @@ -376,6 +380,7 @@ public boolean hasFragmentWithTag(String tag) { .findFragmentByTag(RequestManagerRetriever.FRAGMENT_TAG); } + @SuppressWarnings("deprecation") @Override public void addFragmentWithTag(String tag, RequestManager requestManager) { RequestManagerFragment fragment = new RequestManagerFragment();