本文整理匯總了Java中com.bumptech.glide.request.target.Target類的典型用法代碼示例。如果您正苦於以下問題:Java Target類的具體用法?Java Target怎麽用?Java Target使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Target類屬於com.bumptech.glide.request.target包,在下文中一共展示了Target類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onLoadFailed
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<PictureDrawable> target,
boolean isFirstResource) {
ImageView view = ((ImageViewTarget<?>) target).getView();
view.setLayerType(ImageView.LAYER_TYPE_NONE, null);
return false;
}
示例2: setImageUrls
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
public void setImageUrls(Collection<String> imageUrls) {
// clean up outdated stuff
for (Target target : mTargets) {
Glide.clear(target); // clears mBitmaps[i] as well
}
if (imageUrls == null) imageUrls = Collections.emptyList();
int newSize = imageUrls.size();
mImageUrls = imageUrls.toArray(new String[newSize]);
mBitmaps = new Bitmap[newSize];
mDrawRects = new RectF[newSize];
mTargets = new Target[newSize];
if (!haveRule) {
mColumns = imageUrls.size() <= 4 ? 2 : 3;
}
for (int i = 0; i < imageUrls.size(); i++) {
mTargets[i] = new PositionTarget(i);
}
requestLayout();
}
示例3: saveToFile
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
private void saveToFile() {
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Toast.makeText(this, R.string.gallery_save_file_not_have_external_storage, Toast.LENGTH_SHORT).show();
return;
}
final Future<File> future = getImageLoader()
.load(mPath)
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
AppOperator.runOnThread(new Runnable() {
@Override
public void run() {
try {
File sourceFile = future.get();
if (sourceFile == null || !sourceFile.exists())
return;
String extension = BitmapUtil.getExtension(sourceFile.getAbsolutePath());
String extDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
.getAbsolutePath() + File.separator + "開源中國";
File extDirFile = new File(extDir);
if (!extDirFile.exists()) {
if (!extDirFile.mkdirs()) {
// If mk dir error
callSaveStatus(false, null);
return;
}
}
final File saveFile = new File(extDirFile, String.format("IMG_%s.%s", System.currentTimeMillis(), extension));
final boolean isSuccess = StreamUtil.copyFile(sourceFile, saveFile);
callSaveStatus(isSuccess, saveFile);
} catch (Exception e) {
e.printStackTrace();
callSaveStatus(false, null);
}
}
});
}
示例4: transform
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Override
public final Resource<Bitmap> transform(
Context context, Resource<Bitmap> resource, int outWidth, int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
示例5: into
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
/**
* Set the target the resource will be loaded into.
*
* @param target The target to load the resource into.
* @return The given target.
* @see RequestManager#clear(Target)
*/
public <Y extends Target<TranscodeType>> Y into(@NonNull Y target) {
Util.assertMainThread();
Preconditions.checkNotNull(target);
if (!isModelSet) {
throw new IllegalArgumentException("You must call #load() before calling #into()");
}
Request previous = target.getRequest();
if (previous != null) {
requestManager.clear(target);
}
requestOptions.lock();
Request request = buildRequest(target);
target.setRequest(request);
requestManager.track(target, request);
return target;
}
示例6: obtainRequest
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
private Request obtainRequest(Target<TranscodeType> target,
RequestOptions requestOptions, RequestCoordinator requestCoordinator,
TransitionOptions<?, ? super TranscodeType> transitionOptions, Priority priority,
int overrideWidth, int overrideHeight) {
requestOptions.lock();
return SingleRequest.obtain(
context,
model,
transcodeClass,
requestOptions,
overrideWidth,
overrideHeight,
priority,
target,
requestListener,
requestCoordinator,
context.getEngine(),
transitionOptions.getTransitionFactory());
}
示例7: setUp
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Glide.tearDown();
RobolectricPackageManager pm = RuntimeEnvironment.getRobolectricPackageManager();
ApplicationInfo info =
pm.getApplicationInfo(RuntimeEnvironment.application.getPackageName(), 0);
info.metaData = new Bundle();
info.metaData.putString(SetupModule.class.getName(), "GlideModule");
// Ensure that target's size ready callback will be called synchronously.
target = mock(Target.class);
imageView = new ImageView(RuntimeEnvironment.application);
imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
imageView.layout(0, 0, 100, 100);
doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class));
Handler bgHandler = mock(Handler.class);
when(bgHandler.post(isA(Runnable.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = (Runnable) invocation.getArguments()[0];
runnable.run();
return true;
}
});
Lifecycle lifecycle = mock(Lifecycle.class);
RequestManagerTreeNode treeNode = mock(RequestManagerTreeNode.class);
requestManager = new RequestManager(Glide.get(getContext()), lifecycle, treeNode);
requestManager.resumeRequests();
}
示例8: testClone
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Test
public void testClone() throws IOException {
Target<Drawable> firstTarget = mock(Target.class);
doAnswer(new CallSizeReady(100, 100)).when(firstTarget).getSize(isA(SizeReadyCallback.class));
Target<Drawable> secondTarget = mock(Target.class);
doAnswer(new CallSizeReady(100, 100)).when(secondTarget).getSize(isA(SizeReadyCallback.class));
RequestBuilder<Drawable> firstRequest = requestManager
.load(mockUri("content://first"));
firstRequest.into(firstTarget);
firstRequest.clone()
.apply(placeholderOf(new ColorDrawable(Color.RED)))
.into(secondTarget);
verify(firstTarget).onResourceReady(isA(Drawable.class), isA(Transition.class));
verify(secondTarget).onResourceReady(notNull(Drawable.class), isA(Transition.class));
}
示例9: onResourceReady
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Override
public boolean onResourceReady(PictureDrawable resource, Object model,
Target<PictureDrawable> target, DataSource dataSource, boolean isFirstResource) {
ImageView view = ((ImageViewTarget<?>) target).getView();
view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);
return false;
}
示例10: showContact
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
private void showContact(long id) {
GlideRequests glideRequests = GlideApp.with(this);
RequestOptions originalSize = new RequestOptions().override(Target.SIZE_ORIGINAL);
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
glideRequests.load(contactUri).apply(originalSize).into(imageViewContact);
Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri);
glideRequests.load(lookupUri).apply(originalSize).into(imageViewLookup);
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
glideRequests.load(photoUri).apply(originalSize).into(imageViewPhoto);
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto);
}
}
示例11: saveImageToLocal
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
/**
* 保存圖片到本地
*
* @param fileName 文件名
*/
private void saveImageToLocal(final String fileName) {
Observable.create(new ObservableOnSubscribe<File>() {
@Override
public void subscribe(ObservableEmitter<File> e) throws Exception {
e.onNext(Glide.with(ImageBrowseActivity.this)
.load(mImageUrl)
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get());
e.onComplete();
}
}).compose(RxHelper.<File>rxSchedulerHelper()).subscribe(new Consumer<File>() {
@Override
public void accept(File file) throws Exception {
saveImage(fileName, file);
}
});
}
示例12: clear
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
/**
* Cancel any pending loads Glide may have for the target and free any resources (such as
* {@link Bitmap}s) that may have been loaded for the target so they may be reused.
*
* @param target The Target to cancel loads for.
*/
public void clear(@Nullable final Target<?> target) {
if (target == null) {
return;
}
if (Util.isOnMainThread()) {
untrackOrDelegate(target);
} else {
mainHandler.post(new Runnable() {
@Override
public void run() {
clear(target);
}
});
}
}
示例13: untrackOrDelegate
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
private void untrackOrDelegate(Target<?> target) {
boolean isOwnedByUs = untrack(target);
// We'll end up here if the Target was cleared after the RequestManager that started the request
// is destroyed. That can happen for at least two reasons:
// 1. We call clear() on a background thread using something other than Application Context
// RequestManager.
// 2. The caller retains a reference to the RequestManager after the corresponding Activity or
// Fragment is destroyed, starts a load with it, and then clears that load with a different
// RequestManager. Callers seem especially likely to do this in retained Fragments (#2262).
//
// #1 is always an error. At best the caller is leaking memory briefly in something like an
// AsyncTask. At worst the caller is leaking an Activity or Fragment for a sustained period of
// time if they do something like reference the Activity RequestManager in a long lived
// background thread or task.
//
// #2 is always an error. Callers shouldn't be starting new loads using RequestManagers after
// the corresponding Activity or Fragment is destroyed because retaining any reference to the
// RequestManager leaks memory. It's possible that there's some brief period of time during or
// immediately after onDestroy where this is reasonable, but I can't think of why.
if (!isOwnedByUs && !glide.removeFromManagers(target) && target.getRequest() != null) {
Request request = target.getRequest();
target.setRequest(null);
request.clear();
}
}
示例14: onResourceReady
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
@Override
public boolean onResourceReady(
GlideDrawable resource,
GlideUrl uri,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource
) {
if (!(target instanceof ImageViewTarget)) {
return false;
}
ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView();
ThemedReactContext context = (ThemedReactContext) view.getContext();
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = view.getId();
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_EVENT, new WritableNativeMap());
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap());
return false;
}
示例15: obtainRequest
import com.bumptech.glide.request.target.Target; //導入依賴的package包/類
private Request obtainRequest(
Target<TranscodeType> target,
RequestListener<TranscodeType> targetListener,
RequestOptions requestOptions,
RequestCoordinator requestCoordinator,
TransitionOptions<?, ? super TranscodeType> transitionOptions,
Priority priority,
int overrideWidth,
int overrideHeight) {
return SingleRequest.obtain(
context,
glideContext,
model,
transcodeClass,
requestOptions,
overrideWidth,
overrideHeight,
priority,
target,
targetListener,
requestListener,
requestCoordinator,
glideContext.getEngine(),
transitionOptions.getTransitionFactory());
}