当前位置: 首页>>代码示例>>Java>>正文


Java ResourceCallback类代码示例

本文整理汇总了Java中com.bumptech.glide.request.ResourceCallback的典型用法代码示例。如果您正苦于以下问题:Java ResourceCallback类的具体用法?Java ResourceCallback怎么用?Java ResourceCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceCallback类属于com.bumptech.glide.request包,在下文中一共展示了ResourceCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleExceptionOnMainThread

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Synthetic
void handleExceptionOnMainThread() {
  stateVerifier.throwIfRecycled();
  if (isCancelled) {
    release(false /*isRemovedFromQueue*/);
    return;
  } else if (cbs.isEmpty()) {
    throw new IllegalStateException("Received an exception without any callbacks to notify");
  } else if (hasLoadFailed) {
    throw new IllegalStateException("Already failed once");
  }
  hasLoadFailed = true;

  listener.onEngineJobComplete(key, null);

  for (ResourceCallback cb : cbs) {
    if (!isInIgnoredCallbacks(cb)) {
      cb.onLoadFailed(exception);
    }
  }

  release(false /*isRemovedFromQueue*/);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:EngineJob.java

示例2: testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady() {
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback existingCallback = mock(ResourceCallback.class);
  final ResourceCallback newCallback = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.addCallback(newCallback);
      return null;
    }
  }).when(existingCallback).onResourceReady(anyResource(), isADataSource());

  job.addCallback(existingCallback);
  job.start(harness.decodeJob);
  job.onResourceReady(harness.resource, harness.dataSource);

  verify(newCallback).onResourceReady(eq(harness.engineResource), eq(harness.dataSource));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:EngineJobTest.java

示例3: testNotifiesNewCallbackOfExceptionIfCallbackIsAddedDuringOnException

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testNotifiesNewCallbackOfExceptionIfCallbackIsAddedDuringOnException() {
  harness = new EngineJobHarness();
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback existingCallback = mock(ResourceCallback.class);
  final ResourceCallback newCallback = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.addCallback(newCallback);
      return null;
    }
  }).when(existingCallback).onLoadFailed(any(GlideException.class));

  GlideException exception = new GlideException("test");
  job.addCallback(existingCallback);
  job.start(harness.decodeJob);
  job.onLoadFailed(exception);

  verify(newCallback).onLoadFailed(eq(exception));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:EngineJobTest.java

示例4: testRemovingCallbackDuringOnResourceReadyIsIgnoredIfCallbackHasAlreadyBeenCalled

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testRemovingCallbackDuringOnResourceReadyIsIgnoredIfCallbackHasAlreadyBeenCalled() {
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback cb = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(cb);
      return null;
    }
  }).when(cb).onResourceReady(anyResource(), isADataSource());

  job.addCallback(cb);
  job.start(harness.decodeJob);
  job.onResourceReady(harness.resource, harness.dataSource);

  verify(cb, times(1)).onResourceReady(anyResource(), isADataSource());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:EngineJobTest.java

示例5: testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled() {
  harness = new EngineJobHarness();
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback cb = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(cb);
      return null;
    }
  }).when(cb).onLoadFailed(any(GlideException.class));

  GlideException exception = new GlideException("test");
  job.addCallback(cb);
  job.start(harness.decodeJob);
  job.onLoadFailed(exception);

  verify(cb, times(1)).onLoadFailed(eq(exception));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:EngineJobTest.java

示例6: testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void
testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled() {
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback notYetCalled = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(notYetCalled);
      return null;
    }
  }).when(harness.cb).onResourceReady(anyResource(), isADataSource());

  job.addCallback(notYetCalled);
  job.start(harness.decodeJob);
  job.onResourceReady(harness.resource, harness.dataSource);

  verify(notYetCalled, never()).onResourceReady(anyResource(), isADataSource());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:EngineJobTest.java

示例7: testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void
testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback() {
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback notYetCalled = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(notYetCalled);
      return null;
    }
  }).when(harness.cb).onResourceReady(anyResource(), isADataSource());

  job.addCallback(notYetCalled);
  job.start(harness.decodeJob);

  job.onResourceReady(harness.resource, harness.dataSource);

  // Once for notifying, once for called.
  verify(harness.engineResource, times(2)).acquire();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:EngineJobTest.java

示例8: testRemovingCallbackDuringOnExceptionPreventsCallbackFromBeingCalledIfNotYetCalled

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testRemovingCallbackDuringOnExceptionPreventsCallbackFromBeingCalledIfNotYetCalled() {
  harness = new EngineJobHarness();
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback called = mock(ResourceCallback.class);
  final ResourceCallback notYetCalled = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(notYetCalled);
      return null;
    }
  }).when(called).onLoadFailed(any(GlideException.class));

  job.addCallback(called);
  job.addCallback(notYetCalled);
  job.start(harness.decodeJob);
  job.onLoadFailed(new GlideException("test"));

  verify(notYetCalled, never()).onResourceReady(anyResource(), isADataSource());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:EngineJobTest.java

示例9: MultiCbHarness

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
public MultiCbHarness() {
  when(factory.build(eq(resource), eq(isCacheable))).thenReturn(engineResource);
  job =
      new EngineJob<>(
          diskCacheService,
          sourceService,
          sourceUnlimitedService,
          animationService,
          listener,
          pool,
          factory).init(key, isCacheable, useUnlimitedSourceGeneratorPool, useAnimationPool);
  for (int i = 0; i < numCbs; i++) {
    cbs.add(mock(ResourceCallback.class));
  }
  for (ResourceCallback cb : cbs) {
    job.addCallback(cb);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:EngineJobTest.java

示例10: onException

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Override
public void onException(final Exception e) {
    mainHandler.post(new Runnable() {
        @Override
        public void run() {
            if (isCancelled) {
                return;
            }
            isComplete = true;

            listener.onEngineJobComplete(key);
            for (ResourceCallback cb : cbs) {
                cb.onException(e);
            }
        }
    });
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:18,代码来源:EngineJob.java

示例11: addCallback

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
public void addCallback(ResourceCallback cb) {
  Util.assertMainThread();
  stateVerifier.throwIfRecycled();
  if (hasResource) {
    cb.onResourceReady(engineResource, dataSource);
  } else if (hasLoadFailed) {
    cb.onLoadFailed(exception);
  } else {
    cbs.add(cb);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:EngineJob.java

示例12: removeCallback

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
public void removeCallback(ResourceCallback cb) {
  Util.assertMainThread();
  stateVerifier.throwIfRecycled();
  if (hasResource || hasLoadFailed) {
    addIgnoredCallback(cb);
  } else {
    cbs.remove(cb);
    if (cbs.isEmpty()) {
      cancel();
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:EngineJob.java

示例13: addIgnoredCallback

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
private void addIgnoredCallback(ResourceCallback cb) {
  if (ignoredCallbacks == null) {
    ignoredCallbacks = new ArrayList<>(2);
  }
  if (!ignoredCallbacks.contains(cb)) {
    ignoredCallbacks.add(cb);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:EngineJob.java

示例14: handleResultOnMainThread

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Synthetic
void handleResultOnMainThread() {
  stateVerifier.throwIfRecycled();
  if (isCancelled) {
    resource.recycle();
    release(false /*isRemovedFromQueue*/);
    return;
  } else if (cbs.isEmpty()) {
    throw new IllegalStateException("Received a resource without any callbacks to notify");
  } else if (hasResource) {
    throw new IllegalStateException("Already have resource");
  }
  engineResource = engineResourceFactory.build(resource, isCacheable);
  hasResource = true;

  // Hold on to resource for duration of request so we don't recycle it in the middle of
  // notifying if it synchronously released by one of the callbacks.
  engineResource.acquire();
  listener.onEngineJobComplete(key, engineResource);

  for (ResourceCallback cb : cbs) {
    if (!isInIgnoredCallbacks(cb)) {
      engineResource.acquire();
      cb.onResourceReady(engineResource, dataSource);
    }
  }
  // Our request is complete, so we can release the resource.
  engineResource.release();

  release(false /*isRemovedFromQueue*/);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:EngineJob.java

示例15: testCallbackIsAddedToExistingRunnerWithExistingLoad

import com.bumptech.glide.request.ResourceCallback; //导入依赖的package包/类
@Test
public void testCallbackIsAddedToExistingRunnerWithExistingLoad() {
  harness.doLoad();

  ResourceCallback newCallback = mock(ResourceCallback.class);
  harness.cb = newCallback;
  harness.doLoad();

  verify(harness.job).addCallback(eq(newCallback));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:EngineTest.java


注:本文中的com.bumptech.glide.request.ResourceCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。