use of com.squareup.picasso.RequestCreator in project android-sdk-examples by IndoorAtlas.
the class OpenStreetMapOverlay method fetchFloorPlanBitmap.
/**
* Download floor plan using Picasso library.
*/
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {
final String url = floorPlan.getUrl();
if (mLoadTarget == null) {
mLoadTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x" + bitmap.getHeight());
setupGroundOverlay(floorPlan, bitmap);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// N/A
}
@Override
public void onBitmapFailed(Drawable placeHolderDraweble) {
Toast.makeText(OpenStreetMapOverlay.this, "Failed to load bitmap", Toast.LENGTH_SHORT).show();
mOverlayFloorPlan = null;
}
};
}
RequestCreator request = Picasso.with(this).load(url);
final int bitmapWidth = floorPlan.getBitmapWidth();
final int bitmapHeight = floorPlan.getBitmapHeight();
if (bitmapHeight > MAX_DIMENSION) {
request.resize(0, MAX_DIMENSION);
} else if (bitmapWidth > MAX_DIMENSION) {
request.resize(MAX_DIMENSION, 0);
}
request.into(mLoadTarget);
}
use of com.squareup.picasso.RequestCreator in project android-sdk-examples by IndoorAtlas.
the class WayfindingOverlayActivity method fetchFloorPlanBitmap.
/**
* Download floor plan using Picasso library.
*/
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {
final String url = floorPlan.getUrl();
if (mLoadTarget == null) {
mLoadTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x" + bitmap.getHeight());
setupGroundOverlay(floorPlan, bitmap);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// N/A
}
@Override
public void onBitmapFailed(Drawable placeHolderDraweble) {
showInfo("Failed to load bitmap");
mOverlayFloorPlan = null;
}
};
}
RequestCreator request = Picasso.with(this).load(url);
final int bitmapWidth = floorPlan.getBitmapWidth();
final int bitmapHeight = floorPlan.getBitmapHeight();
if (bitmapHeight > MAX_DIMENSION) {
request.resize(0, MAX_DIMENSION);
} else if (bitmapWidth > MAX_DIMENSION) {
request.resize(MAX_DIMENSION, 0);
}
request.into(mLoadTarget);
}
use of com.squareup.picasso.RequestCreator in project iNaturalistAndroid by inaturalist.
the class UserActivitiesAdapter method loadObsImage.
private void loadObsImage(int obsId, final View view, BetterJSONObject item, final int position) {
Log.e(TAG, obsId + ": loadObsImage " + position + ":" + view);
ImageView obsPic = (ImageView) view.findViewById(R.id.obs_pic);
ImageView userPic = (ImageView) view.findViewById(R.id.user_pic);
ProgressBar loadingObs = (ProgressBar) view.findViewById(R.id.loading);
final View loadingObsOverlay = view.findViewById(R.id.loading_overlay);
view.post(new Runnable() {
@Override
public void run() {
loadingObsOverlay.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, view.getHeight()));
}
});
Cursor c = mContext.getContentResolver().query(Observation.CONTENT_URI, Observation.PROJECTION, "id = ?", new String[] { String.valueOf(obsId) }, null);
if ((c.getCount() == 0) || (!blah.containsKey(obsId))) {
blah.put(obsId, true);
// Couldn't find observation (must be an old one that isn't saved locally) - download it
c.close();
// Show loading status
obsPic.setImageResource(R.drawable.iconic_taxon_unknown);
loadingObs.setVisibility(View.VISIBLE);
loadingObsOverlay.setVisibility(View.VISIBLE);
userPic.setVisibility(View.GONE);
view.setBackgroundResource(R.drawable.activity_item_background);
if (!mObsIdBeingDownloaded.containsKey(obsId) || !mObsIdBeingDownloaded.get(obsId)) {
Intent serviceIntent = new Intent(INaturalistService.ACTION_GET_AND_SAVE_OBSERVATION, null, mContext, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, obsId);
mContext.startService(serviceIntent);
Log.e(TAG, obsId + ": Start download: " + mObsIdBeingDownloaded.containsKey(obsId));
} else {
Log.e(TAG, obsId + ": Downloading");
}
mObsIdBeingDownloaded.put(obsId, true);
// So when we get the result - we'll know which obs pic to set
if (!mObsIdToView.containsKey(obsId)) {
mObsIdToView.put(obsId, new ArrayList<Pair<View, Integer>>());
}
List<Pair<View, Integer>> views = mObsIdToView.get(obsId);
views.add(new Pair<>(view, position));
return;
}
Log.d(TAG, obsId + ": Showing");
final Observation obs = new Observation(c);
c.close();
loadingObs.setVisibility(View.GONE);
loadingObsOverlay.setVisibility(View.GONE);
userPic.setVisibility(View.VISIBLE);
view.setBackgroundResource(item.getBoolean("viewed") ? R.drawable.activity_item_background : R.drawable.activity_unviewed_item_background);
// Get first image for the observation
Cursor opc = mContext.getContentResolver().query(ObservationPhoto.CONTENT_URI, ObservationPhoto.PROJECTION, "observation_id = ?", new String[] { String.valueOf(obsId) }, ObservationPhoto.DEFAULT_SORT_ORDER);
int iconicTaxonDrawable = ObservationCursorAdapter.getIconicTaxonDrawable(obs.iconic_taxon_name);
if (opc.getCount() == 0) {
// No photos for observation - just show iconic taxon image
obsPic.setImageResource(iconicTaxonDrawable);
} else {
// Show first photo
ObservationPhoto op = new ObservationPhoto(opc);
RequestCreator rc;
if (op.photo_url != null) {
// Online photo
rc = Picasso.with(mContext).load(op.photo_url);
} else {
// Offline photo
rc = Picasso.with(mContext).load(new File(op.photo_filename));
}
rc.placeholder(iconicTaxonDrawable).fit().centerCrop().into(obsPic);
}
opc.close();
View.OnClickListener showObs = new View.OnClickListener() {
@Override
public void onClick(View v) {
mOnUpdateViewed.onUpdateViewed(obs, position);
// Show observation details screen
Intent intent;
if ((obs.user_login != null) && (obs.user_login.equals(mApp.currentUserLogin()))) {
// It's our own observation - allow editing it
Uri uri = obs.getUri();
intent = new Intent(Intent.ACTION_VIEW, uri, mContext, ObservationViewerActivity.class);
} else {
// It's another user's observation - read only mode
intent = new Intent(mContext, ObservationViewerActivity.class);
intent.putExtra("observation", obs.toJSONObject().toString());
intent.putExtra("read_only", true);
intent.putExtra("reload", true);
}
intent.putExtra(ObservationViewerActivity.SHOW_COMMENTS, true);
intent.putExtra(ObservationViewerActivity.SCROLL_TO_COMMENTS_BOTTOM, true);
mContext.startActivity(intent);
try {
JSONObject eventParams = new JSONObject();
eventParams.put(AnalyticsClient.EVENT_PARAM_VIA, AnalyticsClient.EVENT_VALUE_UPDATES);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_NAVIGATE_OBS_DETAILS, eventParams);
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject item = mResultList.get(position);
item.put("viewed", true);
} catch (JSONException e) {
e.printStackTrace();
}
view.setBackgroundResource(R.drawable.activity_item_background);
// Mark observation update as viewed
Intent serviceIntent = new Intent(INaturalistService.ACTION_VIEWED_UPDATE, null, mContext, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, obs.id);
mContext.startService(serviceIntent);
}
};
view.setOnClickListener(showObs);
}
use of com.squareup.picasso.RequestCreator in project Virtualview-Android by alibaba.
the class LocalPreviewActivity method initForPreview.
private void initForPreview() {
if (mVafContext == null) {
mVafContext = new VafContext(this);
mVafContext.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(LocalPreviewActivity.this).load(uri);
Log.d("LocalPreviewActivity", "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(LocalPreviewActivity.this).load(uri);
Log.d("LocalPreviewActivity", "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);
}
});
mViewManager = mVafContext.getViewManager();
mViewManager.init(this.getApplicationContext());
mVafContext.getEventManager().register(EventManager.TYPE_Click, new ClickProcessorImpl());
mVafContext.getEventManager().register(EventManager.TYPE_Exposure, new ExposureProcessorImpl());
}
}
use of com.squareup.picasso.RequestCreator in project open-event-android by fossasia.
the class SpeakerViewHolder method bindSpeaker.
public void bindSpeaker(Speaker speaker) {
this.speaker = speaker;
String thumbnail = Utils.parseImageUri(this.speaker.getThumbnailImageUrl());
String name = Utils.checkStringEmpty(speaker.getName());
if (thumbnail == null)
thumbnail = Utils.parseImageUri(this.speaker.getPhotoUrl());
final Palette.PaletteAsyncListener paletteAsyncListener = palette -> {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (speakerTextualInfo != null) {
if (swatch != null) {
// bitmap has vibrant swatch profile
speakerTextualInfo.setBackgroundColor(swatch.getRgb());
} else {
Palette.Swatch swatch2 = palette.getDarkMutedSwatch();
if (swatch2 != null) {
// bitmap has dark muted swatch profile
speakerTextualInfo.setBackgroundColor(swatch2.getRgb());
} else {
speakerTextualInfo.setBackgroundColor(ContextCompat.getColor(context, R.color.color_primary_dark));
}
}
}
};
RequestCreator requestCreator = StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(thumbnail);
TextDrawable drawable;
if (isImageCircle) {
requestCreator.transform(new CircleTransform());
drawable = Views.getTextDrawableBuilder().round().build(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
} else {
drawable = Views.getTextDrawableBuilder().buildRect(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
}
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
speakerImage.setImageBitmap(bitmap);
if (speakerTextualInfo != null) {
Palette.from(bitmap).generate(paletteAsyncListener);
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
speakerImage.setImageDrawable(drawable);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
speakerImage.setImageDrawable(drawable);
}
};
requestCreator.into(target);
setStringField(speakerName, name);
setStringField(speakerDesignation, String.format("%s %s", speaker.getPosition(), speaker.getOrganisation()));
setStringField(speakerCountry, speaker.getCountry());
}
Aggregations