forked from facebook/fresco
/
AbstractDraweeController.java
693 lines (633 loc) · 23.9 KB
/
AbstractDraweeController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.drawee.controller;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import com.facebook.common.internal.Objects;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.logging.FLog;
import com.facebook.datasource.BaseDataSubscriber;
import com.facebook.datasource.DataSource;
import com.facebook.datasource.DataSubscriber;
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.components.DraweeEventTracker;
import com.facebook.drawee.components.RetryManager;
import com.facebook.drawee.gestures.GestureDetector;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.interfaces.DraweeHierarchy;
import com.facebook.drawee.interfaces.SettableDraweeHierarchy;
import com.facebook.imagepipeline.systrace.FrescoSystrace;
import com.facebook.infer.annotation.ReturnsOwnership;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static com.facebook.drawee.components.DraweeEventTracker.Event;
/**
* Abstract Drawee controller that implements common functionality
* regardless of the backend used to fetch the image.
*
* All methods should be called on the main UI thread.
*
* @param <T> image type (e.g. Bitmap)
* @param <INFO> image info type (can be same as T)
*/
@NotThreadSafe
public abstract class AbstractDraweeController<T, INFO> implements
DraweeController,
DeferredReleaser.Releasable,
GestureDetector.ClickListener {
/**
* This class is used to allow an optimization of not creating a ForwardingControllerListener
* when there is only a single controller listener.
*/
private static class InternalForwardingListener<INFO> extends ForwardingControllerListener<INFO> {
public static <INFO> InternalForwardingListener<INFO> createInternal(
ControllerListener<? super INFO> listener1, ControllerListener<? super INFO> listener2) {
FrescoSystrace.beginSection("AbstractDraweeController#createInternal");
InternalForwardingListener<INFO> forwarder = new InternalForwardingListener<INFO>();
forwarder.addListener(listener1);
forwarder.addListener(listener2);
FrescoSystrace.endSection();
return forwarder;
}
}
private static final Class<?> TAG = AbstractDraweeController.class;
// Components
private final DraweeEventTracker mEventTracker = DraweeEventTracker.newInstance();
private final DeferredReleaser mDeferredReleaser;
private final Executor mUiThreadImmediateExecutor;
// Optional components
private @Nullable RetryManager mRetryManager;
private @Nullable GestureDetector mGestureDetector;
private @Nullable ControllerListener<INFO> mControllerListener;
private @Nullable ControllerViewportVisibilityListener mControllerViewportVisibilityListener;
// Hierarchy
private @Nullable SettableDraweeHierarchy mSettableDraweeHierarchy;
private @Nullable Drawable mControllerOverlay;
// Constant state (non-final because controllers can be reused)
private String mId;
private Object mCallerContext;
// Mutable state
private boolean mIsAttached;
private boolean mIsRequestSubmitted;
private boolean mIsVisibleInViewportHint;
private boolean mHasFetchFailed;
private boolean mRetainImageOnFailure;
private @Nullable String mContentDescription;
private @Nullable DataSource<T> mDataSource;
private @Nullable T mFetchedImage;
private @Nullable Drawable mDrawable;
private boolean mJustConstructed = true;
public AbstractDraweeController(
DeferredReleaser deferredReleaser,
Executor uiThreadImmediateExecutor,
String id,
Object callerContext) {
mDeferredReleaser = deferredReleaser;
mUiThreadImmediateExecutor = uiThreadImmediateExecutor;
init(id, callerContext);
}
/**
* Initializes this controller with the new id and caller context.
* This allows for reusing of the existing controller instead of instantiating a new one.
* This method should be called when the controller is in detached state.
* @param id unique id for this controller
* @param callerContext tag and context for this controller
*/
protected void initialize(String id, Object callerContext) {
init(id, callerContext);
mJustConstructed = false;
}
private synchronized void init(String id, Object callerContext) {
FrescoSystrace.beginSection("AbstractDraweeController#init");
mEventTracker.recordEvent(Event.ON_INIT_CONTROLLER);
// cancel deferred release
if (!mJustConstructed && mDeferredReleaser != null) {
mDeferredReleaser.cancelDeferredRelease(this);
}
// reinitialize mutable state (fetch state)
mIsAttached = false;
mIsVisibleInViewportHint = false;
releaseFetch();
mRetainImageOnFailure = false;
// reinitialize optional components
if (mRetryManager != null) {
mRetryManager.init();
}
if (mGestureDetector != null) {
mGestureDetector.init();
mGestureDetector.setClickListener(this);
}
if (mControllerListener instanceof InternalForwardingListener) {
((InternalForwardingListener) mControllerListener).clearListeners();
} else {
mControllerListener = null;
}
mControllerViewportVisibilityListener = null;
// clear hierarchy and controller overlay
if (mSettableDraweeHierarchy != null) {
mSettableDraweeHierarchy.reset();
mSettableDraweeHierarchy.setControllerOverlay(null);
mSettableDraweeHierarchy = null;
}
mControllerOverlay = null;
// reinitialize constant state
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "controller %x %s -> %s: initialize", System.identityHashCode(this), mId, id);
}
mId = id;
mCallerContext = callerContext;
FrescoSystrace.endSection();
}
@Override
public void release() {
mEventTracker.recordEvent(Event.ON_RELEASE_CONTROLLER);
if (mRetryManager != null) {
mRetryManager.reset();
}
if (mGestureDetector != null) {
mGestureDetector.reset();
}
if (mSettableDraweeHierarchy != null) {
mSettableDraweeHierarchy.reset();
}
releaseFetch();
}
private void releaseFetch() {
boolean wasRequestSubmitted = mIsRequestSubmitted;
mIsRequestSubmitted = false;
mHasFetchFailed = false;
if (mDataSource != null) {
mDataSource.close();
mDataSource = null;
}
if (mDrawable != null) {
releaseDrawable(mDrawable);
}
if (mContentDescription != null) {
mContentDescription = null;
}
mDrawable = null;
if (mFetchedImage != null) {
logMessageAndImage("release", mFetchedImage);
releaseImage(mFetchedImage);
mFetchedImage = null;
}
if (wasRequestSubmitted) {
getControllerListener().onRelease(mId);
}
}
/** Gets the controller id. */
public String getId() {
return mId;
}
/** Gets the analytic tag & caller context */
public Object getCallerContext() {
return mCallerContext;
}
/** Gets retry manager. */
@ReturnsOwnership protected RetryManager getRetryManager() {
if (mRetryManager == null) {
mRetryManager = new RetryManager();
}
return mRetryManager;
}
/** Gets gesture detector. */
protected @Nullable GestureDetector getGestureDetector() {
return mGestureDetector;
}
/** Sets gesture detector. */
protected void setGestureDetector(@Nullable GestureDetector gestureDetector) {
mGestureDetector = gestureDetector;
if (mGestureDetector != null) {
mGestureDetector.setClickListener(this);
}
}
/** Sets whether to display last available image in case of failure. */
protected void setRetainImageOnFailure(boolean enabled) {
mRetainImageOnFailure = enabled;
}
/** Gets accessibility content description. */
@Override
public @Nullable String getContentDescription() {
return mContentDescription;
}
/** Sets accessibility content description. */
@Override
public void setContentDescription(@Nullable String contentDescription) {
mContentDescription = contentDescription;
}
/** Adds controller listener. */
public void addControllerListener(ControllerListener<? super INFO> controllerListener) {
Preconditions.checkNotNull(controllerListener);
if (mControllerListener instanceof InternalForwardingListener) {
((InternalForwardingListener<INFO>) mControllerListener).addListener(controllerListener);
return;
}
if (mControllerListener != null) {
mControllerListener = InternalForwardingListener.createInternal(
mControllerListener,
controllerListener);
return;
}
// Listener only receives <INFO>, it never produces one.
// That means if it can accept <? super INFO>, it can very well accept <INFO>.
mControllerListener = (ControllerListener<INFO>) controllerListener;
}
/** Removes controller listener. */
public void removeControllerListener(ControllerListener<? super INFO> controllerListener) {
Preconditions.checkNotNull(controllerListener);
if (mControllerListener instanceof InternalForwardingListener) {
((InternalForwardingListener<INFO>) mControllerListener).removeListener(controllerListener);
return;
}
if (mControllerListener == controllerListener) {
mControllerListener = null;
}
}
/** Gets controller listener for internal use. */
protected ControllerListener<INFO> getControllerListener() {
if (mControllerListener == null) {
return BaseControllerListener.getNoOpListener();
}
return mControllerListener;
}
/** Sets the controller viewport visibility listener */
public void setControllerViewportVisibilityListener(
@Nullable ControllerViewportVisibilityListener controllerViewportVisibilityListener) {
mControllerViewportVisibilityListener = controllerViewportVisibilityListener;
}
/** Gets the hierarchy */
@Override
public @Nullable
DraweeHierarchy getHierarchy() {
return mSettableDraweeHierarchy;
}
/**
* Sets the hierarchy.
*
* <p>The controller should be detached when this method is called.
* @param hierarchy This must be an instance of {@link SettableDraweeHierarchy}
*/
@Override
public void setHierarchy(@Nullable DraweeHierarchy hierarchy) {
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(
TAG,
"controller %x %s: setHierarchy: %s",
System.identityHashCode(this),
mId,
hierarchy);
}
mEventTracker.recordEvent(
(hierarchy != null) ? Event.ON_SET_HIERARCHY : Event.ON_CLEAR_HIERARCHY);
// force release in case request was submitted
if (mIsRequestSubmitted) {
mDeferredReleaser.cancelDeferredRelease(this);
release();
}
// clear the existing hierarchy
if (mSettableDraweeHierarchy != null) {
mSettableDraweeHierarchy.setControllerOverlay(null);
mSettableDraweeHierarchy = null;
}
// set the new hierarchy
if (hierarchy != null) {
Preconditions.checkArgument(hierarchy instanceof SettableDraweeHierarchy);
mSettableDraweeHierarchy = (SettableDraweeHierarchy) hierarchy;
mSettableDraweeHierarchy.setControllerOverlay(mControllerOverlay);
}
}
/** Sets the controller overlay */
protected void setControllerOverlay(@Nullable Drawable controllerOverlay) {
mControllerOverlay = controllerOverlay;
if (mSettableDraweeHierarchy != null) {
mSettableDraweeHierarchy.setControllerOverlay(mControllerOverlay);
}
}
/** Gets the controller overlay */
protected @Nullable Drawable getControllerOverlay() {
return mControllerOverlay;
}
@Override
public void onAttach() {
FrescoSystrace.beginSection("AbstractDraweeController#onAttach");
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(
TAG,
"controller %x %s: onAttach: %s",
System.identityHashCode(this),
mId,
mIsRequestSubmitted ? "request already submitted" : "request needs submit");
}
mEventTracker.recordEvent(Event.ON_ATTACH_CONTROLLER);
Preconditions.checkNotNull(mSettableDraweeHierarchy);
mDeferredReleaser.cancelDeferredRelease(this);
mIsAttached = true;
if (!mIsRequestSubmitted) {
submitRequest();
}
FrescoSystrace.endSection();
}
@Override
public void onDetach() {
FrescoSystrace.beginSection("AbstractDraweeController#onDetach");
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "controller %x %s: onDetach", System.identityHashCode(this), mId);
}
mEventTracker.recordEvent(Event.ON_DETACH_CONTROLLER);
mIsAttached = false;
mDeferredReleaser.scheduleDeferredRelease(this);
FrescoSystrace.endSection();
}
@Override
public void onViewportVisibilityHint(boolean isVisibleInViewportHint) {
final ControllerViewportVisibilityListener listener = mControllerViewportVisibilityListener;
if (listener != null) {
if (isVisibleInViewportHint && !mIsVisibleInViewportHint) {
listener.onDraweeViewportEntry(mId);
} else if (!isVisibleInViewportHint && mIsVisibleInViewportHint) {
listener.onDraweeViewportExit(mId);
}
}
mIsVisibleInViewportHint = isVisibleInViewportHint;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "controller %x %s: onTouchEvent %s", System.identityHashCode(this), mId, event);
}
if (mGestureDetector == null) {
return false;
}
if (mGestureDetector.isCapturingGesture() || shouldHandleGesture()) {
mGestureDetector.onTouchEvent(event);
return true;
}
return false;
}
/** Returns whether the gesture should be handled by the controller */
protected boolean shouldHandleGesture() {
return shouldRetryOnTap();
}
private boolean shouldRetryOnTap() {
// We should only handle touch event if we are expecting some gesture.
// For example, we expect click when fetch fails and tap-to-retry is enabled.
return mHasFetchFailed && mRetryManager != null && mRetryManager.shouldRetryOnTap();
}
@Override
public boolean onClick() {
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "controller %x %s: onClick", System.identityHashCode(this), mId);
}
if (shouldRetryOnTap()) {
mRetryManager.notifyTapToRetry();
mSettableDraweeHierarchy.reset();
submitRequest();
return true;
}
return false;
}
protected void submitRequest() {
FrescoSystrace.beginSection("AbstractDraweeController#submitRequest");
final T closeableImage = getCachedImage();
if (closeableImage != null) {
mDataSource = null;
mIsRequestSubmitted = true;
mHasFetchFailed = false;
mEventTracker.recordEvent(Event.ON_SUBMIT_CACHE_HIT);
getControllerListener().onSubmit(mId, mCallerContext);
onImageLoadedFromCacheImmediately(mId, closeableImage);
onNewResultInternal(mId, mDataSource, closeableImage, 1.0f, true, true, true);
FrescoSystrace.endSection();
return;
}
mEventTracker.recordEvent(Event.ON_DATASOURCE_SUBMIT);
getControllerListener().onSubmit(mId, mCallerContext);
mSettableDraweeHierarchy.setProgress(0, true);
mIsRequestSubmitted = true;
mHasFetchFailed = false;
mDataSource = getDataSource();
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(
TAG,
"controller %x %s: submitRequest: dataSource: %x",
System.identityHashCode(this),
mId,
System.identityHashCode(mDataSource));
}
final String id = mId;
final boolean wasImmediate = mDataSource.hasResult();
final DataSubscriber<T> dataSubscriber =
new BaseDataSubscriber<T>() {
@Override
public void onNewResultImpl(DataSource<T> dataSource) {
// isFinished must be obtained before image, otherwise we might set intermediate result
// as final image.
boolean isFinished = dataSource.isFinished();
boolean isReadyToPlay = dataSource.isReadyToPlay();
float progress = dataSource.getProgress();
T image = dataSource.getResult();
if (image != null) {
onNewResultInternal(id, dataSource, image, progress, isFinished, wasImmediate, isReadyToPlay);
} else if (isFinished) {
onFailureInternal(id, dataSource, new NullPointerException(), /* isFinished */ true);
}
}
@Override
public void onFailureImpl(DataSource<T> dataSource) {
onFailureInternal(id, dataSource, dataSource.getFailureCause(), /* isFinished */ true);
}
@Override
public void onProgressUpdate(DataSource<T> dataSource) {
boolean isFinished = dataSource.isFinished();
float progress = dataSource.getProgress();
onProgressUpdateInternal(id, dataSource, progress, isFinished);
}
};
mDataSource.subscribe(dataSubscriber, mUiThreadImmediateExecutor);
FrescoSystrace.endSection();
}
private void onNewResultInternal(
String id,
DataSource<T> dataSource,
@Nullable T image,
float progress,
boolean isFinished,
boolean wasImmediate,
boolean isReadyToPlay) {
try {
FrescoSystrace.beginSection("AbstractDraweeController#onNewResultInternal");
// ignore late callbacks (data source that returned the new result is not the one we expected)
if (!isExpectedDataSource(id, dataSource)) {
logMessageAndImage("ignore_old_datasource @ onNewResult", image);
releaseImage(image);
dataSource.close();
return;
}
mEventTracker.recordEvent(
isFinished ? Event.ON_DATASOURCE_RESULT : Event.ON_DATASOURCE_RESULT_INT);
// create drawable
Drawable drawable;
try {
drawable = createDrawable(image);
} catch (Exception exception) {
logMessageAndImage("drawable_failed @ onNewResult", image);
releaseImage(image);
onFailureInternal(id, dataSource, exception, isFinished);
return;
}
T previousImage = mFetchedImage;
Drawable previousDrawable = mDrawable;
mFetchedImage = image;
mDrawable = drawable;
try {
// set the new image
if (isFinished) {
logMessageAndImage("set_final_result @ onNewResult", image);
mDataSource = null;
mSettableDraweeHierarchy.setImage(drawable, 1f, wasImmediate);
getControllerListener().onFinalImageSet(id, getImageInfo(image), getAnimatable());
} else if (isReadyToPlay) {
logMessageAndImage("set_temporary_result @ onNewResult", image);
mSettableDraweeHierarchy.setImage(drawable, 1f, wasImmediate);
getControllerListener().onFinalImageSet(id, getImageInfo(image), getAnimatable());
} else {
logMessageAndImage("set_intermediate_result @ onNewResult", image);
mSettableDraweeHierarchy.setImage(drawable, progress, wasImmediate);
getControllerListener().onIntermediateImageSet(id, getImageInfo(image));
// IMPORTANT: do not execute any instance-specific code after this point
}
} finally {
if (previousDrawable != null && previousDrawable != drawable) {
releaseDrawable(previousDrawable);
}
if (previousImage != null && previousImage != image) {
logMessageAndImage("release_previous_result @ onNewResult", previousImage);
releaseImage(previousImage);
}
}
} finally {
FrescoSystrace.endSection();
}
}
private void onFailureInternal(
String id,
DataSource<T> dataSource,
Throwable throwable,
boolean isFinished) {
FrescoSystrace.beginSection("AbstractDraweeController#onFailureInternal");
// ignore late callbacks (data source that failed is not the one we expected)
if (!isExpectedDataSource(id, dataSource)) {
logMessageAndFailure("ignore_old_datasource @ onFailure", throwable);
dataSource.close();
FrescoSystrace.endSection();
return;
}
mEventTracker.recordEvent(
isFinished ? Event.ON_DATASOURCE_FAILURE : Event.ON_DATASOURCE_FAILURE_INT);
// fail only if the data source is finished
if (isFinished) {
logMessageAndFailure("final_failed @ onFailure", throwable);
mDataSource = null;
mHasFetchFailed = true;
// Set the previously available image if available.
if (mRetainImageOnFailure && mDrawable != null) {
mSettableDraweeHierarchy.setImage(mDrawable, 1f, true);
} else if (shouldRetryOnTap()) {
mSettableDraweeHierarchy.setRetry(throwable);
} else {
mSettableDraweeHierarchy.setFailure(throwable);
}
getControllerListener().onFailure(mId, throwable);
// IMPORTANT: do not execute any instance-specific code after this point
} else {
logMessageAndFailure("intermediate_failed @ onFailure", throwable);
getControllerListener().onIntermediateImageFailed(mId, throwable);
// IMPORTANT: do not execute any instance-specific code after this point
}
FrescoSystrace.endSection();
}
private void onProgressUpdateInternal(
String id,
DataSource<T> dataSource,
float progress,
boolean isFinished) {
// ignore late callbacks (data source that failed is not the one we expected)
if (!isExpectedDataSource(id, dataSource)) {
logMessageAndFailure("ignore_old_datasource @ onProgress", null);
dataSource.close();
return;
}
if (!isFinished) {
mSettableDraweeHierarchy.setProgress(progress, false);
}
}
private boolean isExpectedDataSource(String id, DataSource<T> dataSource) {
if (dataSource == null && mDataSource == null) {
// DataSource is null when we use directly the Bitmap from the MemoryCache. In this case
// we don't have to close the DataSource.
return true;
}
// There are several situations in which an old data source might return a result that we are no
// longer interested in. To verify that the result is indeed expected, we check several things:
return id.equals(mId) && dataSource == mDataSource && mIsRequestSubmitted;
}
private void logMessageAndImage(String messageAndMethod, T image) {
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(
TAG,
"controller %x %s: %s: image: %s %x",
System.identityHashCode(this),
mId,
messageAndMethod,
getImageClass(image),
getImageHash(image));
}
}
private void logMessageAndFailure(String messageAndMethod, Throwable throwable) {
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(
TAG,
"controller %x %s: %s: failure: %s",
System.identityHashCode(this),
mId,
messageAndMethod,
throwable);
}
}
@Override
public @Nullable Animatable getAnimatable() {
return (mDrawable instanceof Animatable) ? (Animatable) mDrawable : null;
}
protected abstract DataSource<T> getDataSource();
protected abstract Drawable createDrawable(T image);
protected abstract @Nullable INFO getImageInfo(T image);
protected String getImageClass(@Nullable T image) {
return (image != null) ? image.getClass().getSimpleName() : "<null>";
}
protected int getImageHash(@Nullable T image) {
return System.identityHashCode(image);
}
protected abstract void releaseImage(@Nullable T image);
protected abstract void releaseDrawable(@Nullable Drawable drawable);
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("isAttached", mIsAttached)
.add("isRequestSubmitted", mIsRequestSubmitted)
.add("hasFetchFailed", mHasFetchFailed)
.add("fetchedImage", getImageHash(mFetchedImage))
.add("events", mEventTracker.toString())
.toString();
}
protected T getCachedImage() {
return null;
}
protected void onImageLoadedFromCacheImmediately(String id, T cachedImage) {}
}