use of com.squareup.picasso.RequestCreator in project UltimateAndroid by cymcsg.
the class BaseSliderView method bindEventAndShow.
/**
* When you want to implement your own slider view, please call this method in the end in `getView()` method
* @param v the whole view
* @param targetImageView where to place image
*/
protected void bindEventAndShow(final View v, ImageView targetImageView) {
final BaseSliderView me = this;
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnSliderClickListener != null) {
mOnSliderClickListener.onSliderClick(me);
}
}
});
if (targetImageView == null)
return;
mLoadListener.onStart(me);
Picasso p = Picasso.with(mContext);
RequestCreator rq = null;
if (mUrl != null) {
rq = p.load(mUrl);
} else if (mFile != null) {
rq = p.load(mFile);
} else if (mRes != 0) {
rq = p.load(mRes);
} else {
return;
}
if (rq == null) {
return;
}
if (getEmpty() != 0) {
rq.placeholder(getEmpty());
}
if (getError() != 0) {
rq.error(getError());
}
switch(mScaleType) {
case Fit:
rq.fit();
break;
case CenterCrop:
rq.fit().centerCrop();
break;
case CenterInside:
rq.fit().centerInside();
break;
}
rq.into(targetImageView, new Callback() {
@Override
public void onSuccess() {
if (v.findViewById(R.id.loading_bar) != null) {
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
}
}
@Override
public void onError() {
if (mLoadListener != null) {
mLoadListener.onEnd(false, me);
}
}
});
}
use of com.squareup.picasso.RequestCreator in project Tangram-Android by alibaba.
the class TangramActivity method onCreate.
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
Picasso.setSingletonInstance(new Picasso.Builder(this).loggingEnabled(true).build());
} catch (Exception e) {
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
recyclerView = (RecyclerView) findViewById(R.id.main_view);
// Step 1: init tangram
TangramBuilder.init(this, new IInnerImageSetter() {
@Override
public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
Picasso.with(TangramActivity.this).load(url).into(view);
}
}, ImageView.class);
// Tangram.switchLog(true);
mMainHandler = new Handler(getMainLooper());
// Step 2: register build=in cells and cards
builder = TangramBuilder.newInnerBuilder(this);
// Step 3: register business cells and cards
builder.registerCell(1, TestView.class);
builder.registerCell(10, SimpleImgView.class);
builder.registerCell(2, SimpleImgView.class);
builder.registerCell(4, RatioTextView.class);
builder.registerCell(110, TestViewHolderCell.class, new ViewHolderCreator<>(R.layout.item_holder, TestViewHolder.class, TextView.class));
builder.registerCell(199, SingleImageView.class);
builder.registerVirtualView("vvtest");
// Step 4: new engine
engine = builder.build();
engine.setVirtualViewTemplate(VVTEST.BIN);
engine.getService(VafContext.class).setImageLoaderAdapter(new IImageLoaderAdapter() {
private List<ImageTarget> cache = new ArrayList<ImageTarget>();
@Override
public void bindImage(String uri, final ImageBase imageBase, int reqWidth, int reqHeight) {
RequestCreator requestCreator = Picasso.with(TangramActivity.this).load(uri);
Log.d("TangramActivity", "bindImage request width height " + reqHeight + " " + reqWidth);
if (reqHeight > 0 || reqWidth > 0) {
requestCreator.resize(reqWidth, reqHeight);
}
ImageTarget imageTarget = new ImageTarget(imageBase);
cache.add(imageTarget);
requestCreator.into(imageTarget);
}
@Override
public void getBitmap(String uri, int reqWidth, int reqHeight, final Listener lis) {
RequestCreator requestCreator = Picasso.with(TangramActivity.this).load(uri);
Log.d("TangramActivity", "getBitmap request width height " + reqHeight + " " + reqWidth);
if (reqHeight > 0 || reqWidth > 0) {
requestCreator.resize(reqWidth, reqHeight);
}
ImageTarget imageTarget = new ImageTarget(lis);
cache.add(imageTarget);
requestCreator.into(imageTarget);
}
});
Utils.setUedScreenWidth(720);
// Step 5: add card load support if you have card that loading cells async
engine.addCardLoadSupport(new CardLoadSupport(new AsyncLoader() {
@Override
public void loadData(Card card, @NonNull final LoadedCallback callback) {
Log.w("Load Card", card.load);
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
// do loading
JSONArray cells = new JSONArray();
for (int i = 0; i < 10; i++) {
try {
JSONObject obj = new JSONObject();
obj.put("type", 1);
obj.put("msg", "async loaded");
JSONObject style = new JSONObject();
style.put("bgColor", "#FF1111");
obj.put("style", style.toString());
cells.put(obj);
} catch (JSONException e) {
e.printStackTrace();
}
}
// callback.fail(false);
callback.finish(engine.parseComponent(cells));
}
}, 200);
}
}, new AsyncPageLoader() {
@Override
public void loadData(final int page, @NonNull final Card card, @NonNull final LoadedCallback callback) {
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
Log.w("Load page", card.load + " page " + page);
JSONArray cells = new JSONArray();
for (int i = 0; i < 9; i++) {
try {
JSONObject obj = new JSONObject();
obj.put("type", 1);
obj.put("msg", "async page loaded, params: " + card.getParams().toString());
cells.put(obj);
} catch (JSONException e) {
e.printStackTrace();
}
}
List<BaseCell> cs = engine.parseComponent(cells);
if (card.page == 1) {
GroupBasicAdapter<Card, ?> adapter = engine.getGroupBasicAdapter();
card.setCells(cs);
adapter.refreshWithoutNotify();
Range<Integer> range = adapter.getCardRange(card);
adapter.notifyItemRemoved(range.getLower());
adapter.notifyItemRangeInserted(range.getLower(), cs.size());
} else
card.addCells(cs);
// mock load 6 pages
callback.finish(card.page != 6);
card.notifyDataChange();
}
}, 400);
}
}));
engine.addSimpleClickSupport(new SampleClickSupport());
// Step 6: enable auto load more if your page's data is lazy loaded
engine.enableAutoLoadMore(true);
// Step 7: bind recyclerView to engine
engine.bindView(recyclerView);
// Step 8: listener recyclerView onScroll event to trigger auto load more
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
engine.onScrolled();
}
});
// Step 9: set an offset to fix card
engine.getLayoutManager().setFixOffset(0, 40, 0, 0);
// Step 10: get tangram data and pass it to engine
String json = new String(getAssertsFile(this, "data.json"));
JSONArray data = null;
try {
data = new JSONArray(json);
engine.setData(data);
} catch (JSONException e) {
e.printStackTrace();
}
findViewById(R.id.first).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
engine.refresh(true);
}
});
}
use of com.squareup.picasso.RequestCreator in project frostwire by frostwire.
the class ImageLoader method load.
private void load(int resourceId, Uri uri, ImageView target, Params p) {
if (shutdown) {
return;
}
if (target == null) {
throw new IllegalArgumentException("Target image view can't be null");
}
if (p == null) {
throw new IllegalArgumentException("Params to load image can't be null");
}
if (// don't ask this recursively
!(p.callback instanceof RetryCallback) && Debug.hasContext(p.callback)) {
throw new RuntimeException("Possible context leak");
}
if (Debug.hasContext(p.filter)) {
throw new RuntimeException("Possible context leak");
}
RequestCreator rc;
if (uri != null) {
rc = picasso.load(uri);
} else if (resourceId != -1) {
rc = picasso.load(resourceId);
} else {
throw new IllegalArgumentException("resourceId == -1 and uri == null, check your logic");
}
if (p.targetWidth != 0 || p.targetHeight != 0)
rc.resize(p.targetWidth, p.targetHeight);
if (p.placeholderResId != 0)
rc.placeholder(p.placeholderResId);
if (p.fit)
rc.fit();
if (p.centerInside)
rc.centerInside();
if (p.noFade)
rc.noFade();
if (p.noCache) {
rc.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
rc.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE);
}
if (p.filter != null) {
rc.transform(new FilterWrapper(p.filter));
}
if (p.callback != null) {
rc.into(target, new CallbackWrapper(p.callback));
} else {
rc.into(target);
}
}
use of com.squareup.picasso.RequestCreator in project open-event-android by fossasia.
the class AboutFragmentViewModel method getEventLogo.
public LiveData<Bitmap> getEventLogo(String url) {
if (eventLogo == null) {
eventLogo = new MutableLiveData<>();
RequestCreator requestCreator = StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(url);
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
eventLogo.setValue(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
// no implementation
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// no implementation
}
};
requestCreator.into(target);
}
return eventLogo;
}
use of com.squareup.picasso.RequestCreator in project Virtualview-Android by alibaba.
the class VirtualViewApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (sVafContext == null) {
// VVFeatureConfig.setSliderCompat(true);
Picasso.setSingletonInstance(new Picasso.Builder(this).loggingEnabled(true).build());
sVafContext = new VafContext(this.getApplicationContext());
sVafContext.setImageLoaderAdapter(new IImageLoaderAdapter() {
private List<ImageTarget> cache = new ArrayList<ImageTarget>();
@Override
public void bindImage(String uri, final ImageBase imageBase, int reqWidth, int reqHeight) {
RequestCreator requestCreator = Picasso.with(VirtualViewApplication.this).load(uri);
Log.d("VirtualViewApplication", "bindImage request width height " + reqHeight + " " + reqWidth);
if (reqHeight > 0 || reqWidth > 0) {
requestCreator.resize(reqWidth, reqHeight);
}
ImageTarget imageTarget = new ImageTarget(imageBase);
cache.add(imageTarget);
requestCreator.into(imageTarget);
}
@Override
public void getBitmap(String uri, int reqWidth, int reqHeight, final Listener lis) {
RequestCreator requestCreator = Picasso.with(VirtualViewApplication.this).load(uri);
Log.d("VirtualViewApplication", "getBitmap request width height " + reqHeight + " " + reqWidth);
if (reqHeight > 0 || reqWidth > 0) {
requestCreator.resize(reqWidth, reqHeight);
}
ImageTarget imageTarget = new ImageTarget(lis);
cache.add(imageTarget);
requestCreator.into(imageTarget);
}
});
sViewManager = sVafContext.getViewManager();
sViewManager.init(this.getApplicationContext());
sViewManager.loadBinBufferSync(NTEXT.BIN);
sViewManager.loadBinBufferSync(VTEXT.BIN);
sViewManager.loadBinBufferSync(NIMAGE.BIN);
sViewManager.loadBinBufferSync(VIMAGE.BIN);
sViewManager.loadBinBufferSync(VLINE.BIN);
sViewManager.loadBinBufferSync(NLINE.BIN);
sViewManager.loadBinBufferSync(PROGRESS.BIN);
sViewManager.loadBinBufferSync(VGRAPH.BIN);
sViewManager.loadBinBufferSync(PAGE.BIN);
sViewManager.loadBinBufferSync(PAGEITEM.BIN);
sViewManager.loadBinBufferSync(PAGESCROLLSCRIPT.BIN);
sViewManager.loadBinBufferSync(SLIDER.BIN);
sViewManager.loadBinBufferSync(SLIDERITEM.BIN);
sViewManager.loadBinBufferSync(FRAMELAYOUT.BIN);
sViewManager.loadBinBufferSync(RATIOLAYOUT.BIN);
sViewManager.loadBinBufferSync(GRIDLAYOUT.BIN);
sViewManager.loadBinBufferSync(GRID.BIN);
sViewManager.loadBinBufferSync(GRIDITEM.BIN);
sViewManager.loadBinBufferSync(VHLAYOUT.BIN);
sViewManager.loadBinBufferSync(VH2LAYOUT.BIN);
sViewManager.loadBinBufferSync(VH.BIN);
sViewManager.loadBinBufferSync(SCROLLERVL.BIN);
sViewManager.loadBinBufferSync(SCROLLERVS.BIN);
sViewManager.loadBinBufferSync(SCROLLERH.BIN);
sViewManager.loadBinBufferSync(TOTALCONTAINER.BIN);
sViewManager.loadBinBufferSync(NFRAMELAYOUT.BIN);
sViewManager.loadBinBufferSync(NGRIDLAYOUT.BIN);
sViewManager.loadBinBufferSync(NRATIOLAYOUT.BIN);
sViewManager.loadBinBufferSync(NVHLAYOUT.BIN);
sViewManager.loadBinBufferSync(NVH2LAYOUT.BIN);
sViewManager.loadBinBufferSync(CLICKSCRIPT.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT1.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT2.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT3.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT4.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT5.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT6.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT7.BIN);
sViewManager.loadBinBufferSync(TMALLCOMPONENT8.BIN);
sViewManager.loadBinBufferSync(PICASSO.BIN);
sViewManager.getViewFactory().registerBuilder(BizCommon.TM_TOTAL_CONTAINER, new TotalContainer.Builder());
sViewManager.getViewFactory().registerBuilder(1014, new PicassoImage.Builder());
sVafContext.getCompactNativeManager().register("TMTags", TMReminderTagsView.class);
sVafContext.getEventManager().register(EventManager.TYPE_Click, new ClickProcessorImpl());
sVafContext.getEventManager().register(EventManager.TYPE_Exposure, new ExposureProcessorImpl());
}
}
Aggregations