use of com.facebook.drawee.interfaces.SettableDraweeHierarchy in project fresco by facebook.
the class AbstractDraweeController method onFailureInternal.
private void onFailureInternal(String id, DataSource<T> dataSource, Throwable throwable, boolean isFinished) {
if (FrescoSystrace.isTracing()) {
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();
if (FrescoSystrace.isTracing()) {
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.
final SettableDraweeHierarchy hierarchy = mSettableDraweeHierarchy;
if (hierarchy != null) {
if (mRetainImageOnFailure && mDrawable != null) {
hierarchy.setImage(mDrawable, 1f, true);
} else if (shouldRetryOnTap()) {
hierarchy.setRetry(throwable);
} else {
hierarchy.setFailure(throwable);
}
}
reportFailure(throwable, dataSource);
// IMPORTANT: do not execute any instance-specific code after this point
} else {
logMessageAndFailure("intermediate_failed @ onFailure", throwable);
reportIntermediateFailure(throwable);
// IMPORTANT: do not execute any instance-specific code after this point
}
if (FrescoSystrace.isTracing()) {
FrescoSystrace.endSection();
}
}
use of com.facebook.drawee.interfaces.SettableDraweeHierarchy in project fresco by facebook.
the class AbstractDraweeController method obtainExtras.
private Extras obtainExtras(@Nullable Map<String, Object> datasourceExtras, @Nullable Map<String, Object> imageExtras, @Nullable Uri mainUri) {
String scaleType = null;
PointF focusPoint = null;
final SettableDraweeHierarchy hierarchy = mSettableDraweeHierarchy;
if (hierarchy instanceof GenericDraweeHierarchy) {
scaleType = String.valueOf(((GenericDraweeHierarchy) hierarchy).getActualImageScaleType());
focusPoint = ((GenericDraweeHierarchy) hierarchy).getActualImageFocusPoint();
}
return MiddlewareUtils.obtainExtras(COMPONENT_EXTRAS, SHORTCUT_EXTRAS, datasourceExtras, getDimensions(), scaleType, focusPoint, imageExtras, getCallerContext(), mainUri);
}
use of com.facebook.drawee.interfaces.SettableDraweeHierarchy in project fresco by facebook.
the class AbstractDraweeControllerTest method testSettingControllerOverlay.
@Test
public void testSettingControllerOverlay() {
Drawable controllerOverlay1 = mock(Drawable.class);
Drawable controllerOverlay2 = mock(Drawable.class);
SettableDraweeHierarchy draweeHierarchy1 = mock(SettableDraweeHierarchy.class);
SettableDraweeHierarchy draweeHierarchy2 = mock(SettableDraweeHierarchy.class);
InOrder inOrder = inOrder(draweeHierarchy1, draweeHierarchy2);
// initial state
assertNull(mController.getHierarchy());
// set controller overlay before hierarchy
mController.setControllerOverlay(controllerOverlay1);
// set drawee hierarchy
mController.setHierarchy(draweeHierarchy1);
assertSame(draweeHierarchy1, mController.getHierarchy());
inOrder.verify(draweeHierarchy1, times(1)).setControllerOverlay(controllerOverlay1);
inOrder.verify(draweeHierarchy1, times(0)).reset();
// change drawee hierarchy
mController.setHierarchy(draweeHierarchy2);
assertSame(draweeHierarchy2, mController.getHierarchy());
inOrder.verify(draweeHierarchy1, times(1)).setControllerOverlay(null);
inOrder.verify(draweeHierarchy1, times(0)).reset();
inOrder.verify(draweeHierarchy2, times(1)).setControllerOverlay(controllerOverlay1);
inOrder.verify(draweeHierarchy2, times(0)).reset();
// clear drawee hierarchy
mController.setHierarchy(null);
assertSame(null, mController.getHierarchy());
inOrder.verify(draweeHierarchy1, times(0)).setControllerOverlay(any(Drawable.class));
inOrder.verify(draweeHierarchy1, times(0)).reset();
inOrder.verify(draweeHierarchy2, times(1)).setControllerOverlay(null);
inOrder.verify(draweeHierarchy2, times(0)).reset();
// set drawee hierarchy
mController.setHierarchy(draweeHierarchy1);
assertSame(draweeHierarchy1, mController.getHierarchy());
inOrder.verify(draweeHierarchy1, times(1)).setControllerOverlay(controllerOverlay1);
inOrder.verify(draweeHierarchy1, times(0)).reset();
inOrder.verify(draweeHierarchy2, times(0)).setControllerOverlay(any(Drawable.class));
inOrder.verify(draweeHierarchy2, times(0)).reset();
// change controller overlay
mController.setControllerOverlay(controllerOverlay2);
inOrder.verify(draweeHierarchy1, times(1)).setControllerOverlay(controllerOverlay2);
inOrder.verify(draweeHierarchy1, times(0)).reset();
inOrder.verify(draweeHierarchy2, times(0)).setControllerOverlay(any(Drawable.class));
inOrder.verify(draweeHierarchy2, times(0)).reset();
// clear controller overlay
mController.setControllerOverlay(null);
inOrder.verify(draweeHierarchy1, times(1)).setControllerOverlay(null);
inOrder.verify(draweeHierarchy1, times(0)).reset();
inOrder.verify(draweeHierarchy2, times(0)).setControllerOverlay(any(Drawable.class));
inOrder.verify(draweeHierarchy2, times(0)).reset();
}
Aggregations