本文整理了Java中com.bumptech.glide.request.target.ViewTarget
类的一些代码示例,展示了ViewTarget
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViewTarget
类的具体详情如下:
包路径:com.bumptech.glide.request.target.ViewTarget
类名称:ViewTarget
[英]A base Target for loading android.graphics.Bitmaps into Views that provides default implementations for most most methods and can determine the size of views using a android.view.ViewTreeObserver.OnDrawListener.
To detect View reuse in android.widget.ListView or any android.view.ViewGroup that reuses views, this class uses the View#setTag(Object) method to store some metadata so that if a view is reused, any previous loads or resources from previous loads can be cancelled or reused.
Any calls to View#setTag(Object)} on a View given to this class will result in excessive allocations and and/or IllegalArgumentExceptions. If you must call View#setTag(Object) on a view, use #setTagId(int) to specify a custom tag for Glide to use.
Subclasses must call super in #onLoadCleared(Drawable)
[中]加载android的基本目标。图样将位图映射到视图中,为大多数方法提供默认实现,并可以使用安卓系统确定视图的大小。看法ViewTreeObserver。我是你的听众。
检测android中的视图重用。小装置。ListView或任何安卓系统。看法ViewGroup重用视图,该类使用View#setTag(Object)方法存储一些元数据,以便在重用视图时,可以取消或重用以前加载的任何加载或资源。
在给定给该类的视图上调用View#setTag(Object)}将导致过度分配和/或IllegalArgumentException。如果必须在视图上调用View#setTag(Object),请使用#setTagId(int)指定Glide要使用的自定义标记。
子类必须在#onLoadCleared(Drawable)中调用super
代码示例来源:origin: bumptech/glide
/**
* Returns any stored request using {@link android.view.View#getTag()}.
*
* <p> For Glide to function correctly, Glide must be the only thing that calls {@link
* View#setTag(Object)}. If the tag is cleared or put to another object type, Glide will not be
* able to retrieve and cancel previous loads which will not only prevent Glide from reusing
* resource, but will also result in incorrect images being loaded and lots of flashing of images
* in lists. As a result, this will throw an {@link java.lang.IllegalArgumentException} if {@link
* android.view.View#getTag()}} returns a non null object that is not an {@link
* com.bumptech.glide.request.Request}. </p>
*/
@Override
@Nullable
public Request getRequest() {
Object tag = getTag();
Request request = null;
if (tag != null) {
if (tag instanceof Request) {
request = (Request) tag;
} else {
throw new IllegalArgumentException(
"You must not call setTag() on a view Glide is targeting");
}
}
return request;
}
代码示例来源:origin: bumptech/glide
/**
* Stores the request using {@link View#setTag(Object)}.
*
* @param request {@inheritDoc}
*/
@Override
public void setRequest(@Nullable Request request) {
setTag(request);
}
代码示例来源:origin: bumptech/glide
@Override
public void onBindViewHolder(GifViewHolder holder, int position) {
final Api.GifResult result = results[position];
holder.gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip =
ClipData.newPlainText("giphy_url", result.images.fixed_height.url);
Preconditions.checkNotNull(clipboard).setPrimaryClip(clip);
Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result);
activity.startActivity(fullscreenIntent);
}
});
// clearOnDetach let's us stop animating GifDrawables that RecyclerView hasn't yet recycled
// but that are currently off screen.
requestBuilder.load(result).into(holder.gifView).clearOnDetach();
preloadSizeProvider.setView(holder.gifView);
}
代码示例来源:origin: bumptech/glide
@Test
public void testCanSetAndRetrieveRequest() {
target.setRequest(request);
assertEquals(request, target.getRequest());
}
代码示例来源:origin: bumptech/glide
@Test
public void testDoesNotAddMultipleListenersIfMultipleCallbacksAreAdded() {
SizeReadyCallback cb1 = mock(SizeReadyCallback.class);
SizeReadyCallback cb2 = mock(SizeReadyCallback.class);
target.getSize(cb1);
target.getSize(cb2);
assertThat(shadowObserver.getPreDrawListeners()).hasSize(1);
}
代码示例来源:origin: waynell/VideoListPlayer
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
ViewTarget.setTagId(R.id.glide_loader);
builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
() {
@Override
public File getCacheDirectory() {
return context.getExternalCacheDir();
}
}, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
代码示例来源:origin: bumptech/glide
@SuppressWarnings("WeakerAccess")
@Synthetic void pauseMyRequest() {
Request request = getRequest();
// If the Request were cleared by the developer, it would be null here. The only way it's
// present is if the developer hasn't previously cleared this Target.
if (request != null) {
isClearedByUs = true;
request.clear();
isClearedByUs = false;
}
}
代码示例来源:origin: bumptech/glide
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param placeholder {@inheritDoc}
*/
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
setResourceInternal(null);
setDrawable(placeholder);
}
代码示例来源:origin: bumptech/glide
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param errorDrawable {@inheritDoc}
*/
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
setResourceInternal(null);
setDrawable(errorDrawable);
}
代码示例来源:origin: bumptech/glide
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param placeholder {@inheritDoc}
*/
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
super.onLoadCleared(placeholder);
if (animatable != null) {
animatable.stop();
}
setResourceInternal(null);
setDrawable(placeholder);
}
代码示例来源:origin: bumptech/glide
@Test
public void testDoesNotNotifyCallbackTwiceIfAddedTwice() {
target.getSize(cb);
target.getSize(cb);
view.setLayoutParams(new LayoutParams(100, 100));
shadowView.setIsLaidOut(true);
shadowObserver.fireOnPreDrawListeners();
verify(cb, times(1)).onSizeReady(anyInt(), anyInt());
}
代码示例来源:origin: w0080626/GankIO
@Override
public void applyOptions(Context context, GlideBuilder builder) {
ViewTarget.setTagId(R.id.image_tag);
}
代码示例来源:origin: bumptech/glide
@Test
public void testRetrievesRequestFromPreviousTargetForView() {
target.setRequest(request);
ViewTarget<View, Object> second = new TestViewTarget(view);
assertEquals(request, second.getRequest());
}
代码示例来源:origin: bumptech/glide
@Test(expected = IllegalArgumentException.class)
public void testThrowsIfViewTagIsNotRequestObject() {
view.setTag(new Object());
target.getRequest();
}
代码示例来源:origin: mozilla-tw/Rocket
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param placeholder {@inheritDoc}
*/
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
setResourceInternal(null);
setDrawable(placeholder);
}
代码示例来源:origin: mozilla-tw/Rocket
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param errorDrawable {@inheritDoc}
*/
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
setResourceInternal(null);
setDrawable(errorDrawable);
}
代码示例来源:origin: mozilla-tw/Rocket
/**
* Sets the given {@link android.graphics.drawable.Drawable} on the view using {@link
* android.widget.ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
*
* @param placeholder {@inheritDoc}
*/
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
super.onLoadCleared(placeholder);
setResourceInternal(null);
setDrawable(placeholder);
}
代码示例来源:origin: bumptech/glide
@Test
public void testSizeCallbackIsCalledSynchronouslyIfLayoutParamsConcreteSizeSet() {
int dimens = 444;
LayoutParams layoutParams = new LayoutParams(dimens, dimens);
view.setLayoutParams(layoutParams);
shadowView.setIsLaidOut(true);
target.getSize(cb);
verify(cb).onSizeReady(eq(dimens), eq(dimens));
}
代码示例来源:origin: mylhyl/Android-Zxing
@Override
public void onCreate() {
super.onCreate();
//因为Glide加载图片的源码中也使用了setTag和getTag模式而
//https://github.com/bumptech/glide/issues/370
ViewTarget.setTagId(R.string.app_name);
}
}
代码示例来源:origin: guolindev/giffun
/**
* Stores the request using {@link View#setTag(Object)}.
*
* @param request {@inheritDoc}
*/
@Override
public void setRequest(Request request) {
setTag(request);
}
内容来源于网络,如有侵权,请联系作者删除!