File tree Expand file tree Collapse file tree 3 files changed +47
-4
lines changed
library/src/main/java/com/bumptech/glide Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 1+ package com .bumptech .glide ;
2+
3+ import android .view .ViewTreeObserver .OnPreDrawListener ;
4+ import java .util .function .Function ;
5+
6+ /**
7+ * A class for holding static methods that are used to globally modify the behavior of Glide. This
8+ * class is used to allow apps to globally modify the behavior of Glide.
9+ */
10+ public final class GlidePlugins {
11+
12+ private static Function <OnPreDrawListener , OnPreDrawListener > onPreDrawListenerDecorator = null ;
13+
14+ /**
15+ * Sets a decorator to be applied to all {@link OnPreDrawListener}s created by Glide.
16+ *
17+ * <p>This is intended to be used by apps that want to globally modify all {@link
18+ * OnPreDrawListener}s created by Glide.
19+ *
20+ * <p>This is an experimental method that may be removed without warning in a future version.
21+ */
22+ public static void experimentalSetOnPreDrawListenerDecorator (
23+ Function <OnPreDrawListener , OnPreDrawListener > decorator ) {
24+ onPreDrawListenerDecorator = decorator ;
25+ }
26+
27+ /**
28+ * Returns the {@link OnPreDrawListener} provided, possibly after being decorated by {@link
29+ * #experimentalSetOnPreDrawListenerDecorator(Function)}.
30+ */
31+ public static OnPreDrawListener decorateOnPreDrawListener (OnPreDrawListener listener ) {
32+ if (onPreDrawListenerDecorator == null ) {
33+ return listener ;
34+ }
35+ return onPreDrawListenerDecorator .apply (listener );
36+ }
37+
38+ private GlidePlugins () {}
39+ }
Original file line number Diff line number Diff line change 1414import androidx .annotation .NonNull ;
1515import androidx .annotation .Nullable ;
1616import androidx .annotation .VisibleForTesting ;
17+ import com .bumptech .glide .GlidePlugins ;
1718import com .bumptech .glide .R ;
1819import com .bumptech .glide .request .Request ;
1920import com .bumptech .glide .request .transition .Transition ;
@@ -299,7 +300,7 @@ static final class SizeDeterminer {
299300 private final List <SizeReadyCallback > cbs = new ArrayList <>();
300301 @ Synthetic boolean waitForLayout ;
301302
302- @ Nullable private SizeDeterminerLayoutListener layoutListener ;
303+ @ Nullable private ViewTreeObserver . OnPreDrawListener layoutListener ;
303304
304305 SizeDeterminer (@ NonNull View view ) {
305306 this .view = view ;
@@ -359,7 +360,8 @@ void getSize(@NonNull SizeReadyCallback cb) {
359360 }
360361 if (layoutListener == null ) {
361362 ViewTreeObserver observer = view .getViewTreeObserver ();
362- layoutListener = new SizeDeterminerLayoutListener (this );
363+ layoutListener =
364+ GlidePlugins .decorateOnPreDrawListener (new SizeDeterminerLayoutListener (this ));
363365 observer .addOnPreDrawListener (layoutListener );
364366 }
365367 }
Original file line number Diff line number Diff line change 1414import androidx .annotation .NonNull ;
1515import androidx .annotation .Nullable ;
1616import androidx .annotation .VisibleForTesting ;
17+ import com .bumptech .glide .GlidePlugins ;
1718import com .bumptech .glide .R ;
1819import com .bumptech .glide .request .Request ;
1920import com .bumptech .glide .util .Preconditions ;
@@ -324,7 +325,7 @@ static final class SizeDeterminer {
324325 private final List <SizeReadyCallback > cbs = new ArrayList <>();
325326 @ Synthetic boolean waitForLayout ;
326327
327- @ Nullable private SizeDeterminerLayoutListener layoutListener ;
328+ @ Nullable private ViewTreeObserver . OnPreDrawListener layoutListener ;
328329
329330 SizeDeterminer (@ NonNull View view ) {
330331 this .view = view ;
@@ -384,7 +385,8 @@ void getSize(@NonNull SizeReadyCallback cb) {
384385 }
385386 if (layoutListener == null ) {
386387 ViewTreeObserver observer = view .getViewTreeObserver ();
387- layoutListener = new SizeDeterminerLayoutListener (this );
388+ layoutListener =
389+ GlidePlugins .decorateOnPreDrawListener (new SizeDeterminerLayoutListener (this ));
388390 observer .addOnPreDrawListener (layoutListener );
389391 }
390392 }
You can’t perform that action at this time.
0 commit comments