本文整理汇总了Java中com.facebook.datasource.DataSource.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java DataSource.subscribe方法的具体用法?Java DataSource.subscribe怎么用?Java DataSource.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.datasource.DataSource
的用法示例。
在下文中一共展示了DataSource.subscribe方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBitmapFromUrl
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void loadBitmapFromUrl(Context context, String url, String cookie, String referer, BaseBitmapDataSubscriber dataSubscriber) {
if (TextUtils.isEmpty(url))
return;
Uri uri = Uri.parse(url);
JsonObject header = new JsonObject();
header.addProperty("Cookie", cookie);
header.addProperty("Referer", referer);
if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
HProxy proxy = new HProxy(url);
header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
}
MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
ImageRequest request = builder.build();
DataSource<CloseableReference<CloseableImage>>
dataSource = imagePipeline.fetchDecodedImage(request, context);
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
示例2: loadResourceFromUrl
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void loadResourceFromUrl(Context context, Uri uri, String cookie, String referer, BaseDataSubscriber dataSubscriber) {
if (uri.getScheme().startsWith("http")) {
JsonObject header = new JsonObject();
header.addProperty("Cookie", cookie);
header.addProperty("Referer", referer);
if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
HProxy proxy = new HProxy(uri.toString());
header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
}
MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
}
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
ImageRequest request = builder.build();
DataSource<CloseableReference<PooledByteBuffer>>
dataSource = imagePipeline.fetchEncodedImage(request, context);
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
示例3: setSupplier
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public void setSupplier(@Nullable Supplier<DataSource<T>> supplier) {
// early return without calling {@code supplier.get()} in case we are closed
if (isClosed()) {
return;
}
DataSource<T> oldDataSource;
DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null;
synchronized (RetainingDataSource.this) {
if (isClosed()) {
oldDataSource = newDataSource;
newDataSource = null;
} else {
oldDataSource = mDataSource;
mDataSource = newDataSource;
}
}
if (newDataSource != null) {
newDataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance());
}
closeSafely(oldDataSource);
}
示例4: LoadImageFromURLAndCallBack
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds)
{
int w = destImageView.getWidth();
int h =destImageView.getHeight();
if(w<1){
w = destImageView.getLayoutParams().width;
}
if(h<1){
h =destImageView.getLayoutParams().height;
}
ImageRequest imageRequest =
ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
.setResizeOptions(new ResizeOptions(w,h))
.setProgressiveRenderingEnabled(true)
.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
.setImageRequest(imageRequest)
.setOldController(destImageView.getController())
.setAutoPlayAnimations(true)
.build();
destImageView.setController(draweeController);
}
示例5: LoadImageFromURIAndCallBack
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds)
{
int w = destImageView.getWidth();
int h =destImageView.getHeight();
if(w<1){
w = destImageView.getLayoutParams().width;
}
if(h<1){
h =destImageView.getLayoutParams().height;
}
ImageRequest imageRequest =
ImageRequestBuilder.newBuilderWithSource(uri)
.setResizeOptions(new ResizeOptions(w,h))
.setProgressiveRenderingEnabled(true)
.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
.setImageRequest(imageRequest)
.setOldController(destImageView.getController())
.setAutoPlayAnimations(true)
.build();
destImageView.setController(draweeController);
}
示例6: create
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static <T> ListDataSource<T> create(
DataSource<CloseableReference<T>>... dataSources) {
Preconditions.checkNotNull(dataSources);
Preconditions.checkState(dataSources.length > 0);
ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources);
for (DataSource<CloseableReference<T>> dataSource : dataSources) {
if (dataSource != null) {
dataSource.subscribe(
listDataSource.new InternalDataSubscriber(),
CallerThreadExecutor.getInstance());
}
}
return listDataSource;
}
示例7: save
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void save(Uri uri, String action) {
ImageRequest request = ImageRequest.fromUri(uri);
ImagePipeline pipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<PooledByteBuffer>> dataSource =
pipeline.fetchEncodedImage(request, null);
ImageSubscriber dataSubscriber = new ImageSubscriber(uri, action);
dataSource.subscribe(dataSubscriber,
ExpressApplication.getApplication().getImagePipelineConfig()
.getExecutorSupplier().forLocalStorageWrite());
}
示例8: loadImage
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
@Override
public void loadImage(int requestId, Uri uri, final Callback callback) {
ImageRequest request = ImageRequest.fromUri(uri);
File localCache = getCacheFile(request);
if (localCache.exists()) {
callback.onCacheHit(localCache);
callback.onSuccess(localCache);
} else {
callback.onStart(); // ensure `onStart` is called before `onProgress` and `onFinish`
callback.onProgress(0); // show 0 progress immediately
ImagePipeline pipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<PooledByteBuffer>> source
= pipeline.fetchEncodedImage(request, true);
source.subscribe(new ImageDownloadSubscriber(mAppContext) {
@Override
protected void onProgress(int progress) {
callback.onProgress(progress);
}
@Override
protected void onSuccess(final File image) {
callback.onFinish();
callback.onCacheMiss(image);
callback.onSuccess(image);
}
@Override
protected void onFail(final Throwable t) {
t.printStackTrace();
callback.onFail((Exception) t);
}
}, mExecutorSupplier.forBackgroundTasks());
closeSource(requestId);
saveSource(requestId, source);
}
}
示例9: getBitmapWithFresco
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public static void getBitmapWithFresco(Context context, String url, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(url))
.setProgressiveRenderingEnabled(true)
.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>>
dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
dataSource.subscribe(baseBitmapDataSubscriber,
CallerThreadExecutor.getInstance());
}
示例10: loadImage
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
@Override
public void loadImage(Uri uri, final Callback callback) {
ImageRequest request = ImageRequest.fromUri(uri);
File localCache = getCacheFile(request);
if (localCache.exists()) {
callback.onCacheHit(localCache);
} else {
callback.onStart(); // ensure `onStart` is called before `onProgress` and `onFinish`
callback.onProgress(0); // show 0 progress immediately
ImagePipeline pipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<PooledByteBuffer>> source
= pipeline.fetchEncodedImage(request, true);
source.subscribe(new ImageDownloadSubscriber(mAppContext) {
@Override
protected void onProgress(int progress) {
callback.onProgress(progress);
}
@Override
protected void onSuccess(File image) {
callback.onFinish();
callback.onCacheMiss(image);
}
@Override
protected void onFail(Throwable t) {
// TODO: 12/11/2016 fail
t.printStackTrace();
}
}, mExecutorSupplier.forBackgroundTasks());
}
}
示例11: instantiateItem
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
@Override
public View instantiateItem(ViewGroup container, int position) {
View view = LayoutInflater.from(ImageViewActivity.this).inflate(R.layout.item_imagepage, container, false);
final PhotoView photoView = (PhotoView) view.findViewById(R.id.photoview);
final View wheel = view.findViewById(R.id.wheel);
photoView.setOnPhotoTapListener((view1, v, v1) -> finish());
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(urls.get(position))
.setResizeOptions(new ResizeOptions(768, 768))
.build();
DataSource<CloseableReference<CloseableImage>>
dataSource = imagePipeline.fetchDecodedImage(request,this);
DataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(Bitmap bitmap) {
photoView.setImageBitmap(bitmap);
wheel.setVisibility(View.GONE);
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> closeableReferenceDataSource) {
}
};
dataSource.subscribe(dataSubscriber, new Executor() {
@Override
public void execute(Runnable command) {
handler.post(command);
}
});
container.addView(view);
return view;
}
示例12: get
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
public void get() {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl))
.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource
= imagePipeline.fetchDecodedImage(request, WikipediaApp.getInstance());
dataSource.subscribe(new BitmapDataSubscriber(), UiThreadImmediateExecutorService.getInstance());
}
示例13: setSubscribe
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
private static final void setSubscribe(Context context, ImageRequest request, BaseDataSubscriber subscriber) {
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource =
imagePipeline.fetchDecodedImage(request, context);
dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance());
}
示例14: loadImageInternal
import com.facebook.datasource.DataSource; //导入方法依赖的package包/类
/**
* Internal helper method for load Bitmap.
*
* @param maxSize 0 or less than 0 if want original bitmap.
*/
@Override
public void loadImageInternal(
final Uri uri,
final int maxSize,
final ImageLoaderUtils.ImageLoadListener listener) {
if (uri == null) {
listener.onFailed(-1);
return;
}
ImageRequestBuilder builder = ImageRequestBuilder
.newBuilderWithSource(uri)
.setAutoRotateEnabled(true);
if (maxSize > 0) {
builder.setResizeOptions(new ResizeOptions(maxSize, maxSize));
}
ImagePipeline pipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> data =
pipeline.fetchDecodedImage(builder.build(), null);
Executor executor = new Executor() {
@Override
public void execute(@NonNull Runnable command) {
ThreadManager.getInstance().postOnUIHandler(command);
}
};
data.subscribe(new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(Bitmap bitmap) {
if (bitmap == null) {
listener.onFailed(ImageLoaderUtils.ERROR_LOAD_EMPTY_IMAGE);
return;
}
final int width = bitmap.getWidth();
final int height = bitmap.getHeight();
try {
if (maxSize <= 0 || (width <= maxSize && height <= maxSize)) {
listener.onSuccess(uri, Bitmap.createBitmap(bitmap));
} else {
JungleSize size = ImageUtils.getMaxScaleSize(
bitmap.getWidth(), bitmap.getHeight(), maxSize);
listener.onSuccess(uri, Bitmap.createScaledBitmap(
bitmap, size.getWidth(), size.getHeight(), true));
}
} catch (Throwable e) {
e.printStackTrace();
listener.onSuccess(uri, bitmap);
}
}
@Override
protected void onFailureImpl(
DataSource<CloseableReference<CloseableImage>> dataSource) {
listener.onFailed(ImageLoaderUtils.ERROR_LOAD_FAILED);
}
}, executor);
}