use of com.squareup.picasso.Callback in project glimmr by brk3.
the class PhotoViewerFragment method displayImage.
private void displayImage() {
if (BuildConfig.DEBUG)
Log.d(TAG, "displayImage()");
/* Fetch the main image */
if (mBasePhoto != null) {
String urlToFetch = getLargestUrlAvailable(mBasePhoto);
Picasso.with(mActivity).load(urlToFetch).into(mImageView, new Callback() {
@Override
public void onSuccess() {
mAttacher.update();
mProgress.setVisibility(View.INVISIBLE);
}
@Override
public void onError() {
Log.e(TAG, "displayImage -> Picasso -> onError");
}
});
/* Set the photo title and author text. If sw600dp then the parent
* activity will handle adding them to the actionbar instead */
if (!mActivity.getResources().getBoolean(R.bool.sw600dp)) {
String photoTitle = mBasePhoto.getTitle();
if (photoTitle == null || photoTitle.length() == 0) {
photoTitle = mActivity.getString(R.string.untitled);
}
String authorText = String.format("%s %s", mActivity.getString(R.string.by), mBasePhoto.getOwner().getUsername());
mTextViewTitle.setText(photoTitle);
mTextViewAuthor.setText(authorText);
}
} else {
Log.e(getLogTag(), "displayImage: mBasePhoto is null");
}
}
use of com.squareup.picasso.Callback in project Tusky by tuskyapp.
the class ViewMediaFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
photoView = rootView.findViewById(R.id.view_media_image);
final Bundle arguments = getArguments();
final String url = arguments.getString("url");
attacher = new PhotoViewAttacher(photoView);
// Clicking outside the photo closes the viewer.
attacher.setOnOutsidePhotoTapListener(new OnOutsidePhotoTapListener() {
@Override
public void onOutsidePhotoTap(ImageView imageView) {
photoActionsListener.onDismiss();
}
});
attacher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
photoActionsListener.onPhotoTap();
}
});
/* A vertical swipe motion also closes the viewer. This is especially useful when the photo
* mostly fills the screen so clicking outside is difficult. */
attacher.setOnSingleFlingListener(new OnSingleFlingListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (Math.abs(velocityY) > Math.abs(velocityX)) {
photoActionsListener.onDismiss();
return true;
}
return false;
}
});
ViewCompat.setTransitionName(photoView, url);
// If we are the view to be shown initially...
if (arguments.getBoolean(ARG_START_POSTPONED_TRANSITION)) {
// Try to load image from disk.
Picasso.with(getContext()).load(url).noFade().networkPolicy(NetworkPolicy.OFFLINE).into(photoView, new Callback() {
@Override
public void onSuccess() {
// if we loaded image from disk, we should check that view is attached.
if (ViewCompat.isAttachedToWindow(photoView)) {
finishLoadingSuccessfully();
} else {
// if view is not attached yet, wait for an attachment and
// start transition when it's finally ready.
photoView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
finishLoadingSuccessfully();
photoView.removeOnAttachStateChangeListener(this);
}
@Override
public void onViewDetachedFromWindow(View v) {
}
});
}
}
@Override
public void onError() {
// if there's no image in cache, load from network and start transition
// immediately.
photoActionsListener.onBringUp();
loadImageFromNetwork(url, photoView);
}
});
} else {
// if we're not initial page, don't bother.
loadImageFromNetwork(url, photoView);
}
return rootView;
}
use of com.squareup.picasso.Callback in project samourai-wallet-android by Samourai-Wallet.
the class PayNymDetailsActivity method setPayNym.
private void setPayNym() {
followMessage.setText(getResources().getString(R.string.follow).concat(" ").concat(BIP47Meta.getInstance().getDisplayLabel(pcode)).concat(" ").concat(getResources().getText(R.string.paynym_follow_message_2).toString()));
if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_NOT_SENT) {
showFollow();
} else {
showHistory();
}
if (BIP47Meta.getInstance().getIncomingIdx(pcode) == BIP47Meta.STATUS_NOT_SENT)
if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_SENT_NO_CFM) {
showWaitingForConfirm();
}
if (BIP47Meta.getInstance().getIncomingIdx(pcode) >= 0) {
historyLayout.setVisibility(View.VISIBLE);
}
// if(BIP47Meta.getInstance().getIncomingIdx(pcode)) ){
//
// }
// if (BIP47Meta.getInstance().incomingExists(pcode)) {
// followsYoutext.setVisibility(View.VISIBLE);
// } else {
// followsYoutext.setVisibility(View.GONE);
// }
// Log.i(TAG, "setPayNym: ".concat(String.valueOf(BIP47Meta.getInstance().getOutgoingStatus(pcode))));
paynymCode.setText(BIP47Meta.getInstance().getAbbreviatedPcode(pcode));
paynymLabel.setText(getLabel());
paynymAvatarPorgress.setVisibility(View.VISIBLE);
Picasso.with(getApplicationContext()).load(com.samourai.wallet.bip47.paynym.WebUtil.PAYNYM_API + pcode + "/avatar").into(userAvatar, new Callback() {
@Override
public void onSuccess() {
paynymAvatarPorgress.setVisibility(View.GONE);
}
@Override
public void onError() {
paynymAvatarPorgress.setVisibility(View.GONE);
Toast.makeText(PayNymDetailsActivity.this, "Unable to load avatar", Toast.LENGTH_SHORT).show();
}
});
if (menu != null) {
if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_SENT_NO_CFM) {
menu.findItem(R.id.retry_notiftx).setVisible(true);
} else {
menu.findItem(R.id.retry_notiftx).setVisible(false);
}
}
}
use of com.squareup.picasso.Callback in project iNaturalistAndroid by inaturalist.
the class ObservationCursorAdapter method loadObsImage.
/**
* Loads obs image either from local disk or triggers remote download with callback
*/
@UiThread
private void loadObsImage(final int position, final ImageView imageView, final String name, boolean isOnline, final boolean largeVersion) {
Logger.tag(TAG).debug("loadObsImage(pos:{}, iv:{}, name:{}, isOnline:{}, large:{})", position, imageView, name, isOnline, largeVersion);
String prevUrl = mImageViewToUrlExpected.get(imageView);
if ((prevUrl != null) && (prevUrl.equals(name)) && (!largeVersion)) {
imageView.setVisibility(View.VISIBLE);
return;
}
mImageViewToUrlExpected.put(imageView, name);
// noinspection ConstantConditions
if (mImageViewToUrlAfterLoading.containsKey(imageView) && mImageViewToUrlAfterLoading.get(imageView).equals(name)) {
imageView.setVisibility(View.VISIBLE);
return;
}
if (name == null) {
return;
}
String imageUrl = name;
if (!isOnline) {
Trace.beginSection("check_local");
File file = new File(name);
if (!file.exists()) {
// Local file - but it was deleted for some reason (probably user cleared cache)
// See if the obs has a remote URL
Cursor c = this.getCursor();
int oldPosition = c.getPosition();
c.moveToPosition(position);
Observation obs = new Observation(c);
c.moveToPosition(oldPosition);
String[] photoInfo = mPhotoInfo.get(obs.uuid);
if ((photoInfo == null) || (photoInfo[2] == null)) {
// No remote image
Logger.tag(TAG).debug("Local file deleted: " + position + ":" + name);
return;
} else {
// Try and load remote image instead
imageUrl = photoInfo[2];
Logger.tag(TAG).debug("Local file deleted - using remote URL: " + position + ":" + imageUrl);
isOnline = true;
}
}
Trace.endSection();
}
if (isOnline) {
Trace.beginSection("online");
// Online image
// Use the small image instead of a large image (default) - to load images quickly
String extension = imageUrl.substring(imageUrl.lastIndexOf(".") + 1);
final String newImageUrl = largeVersion ? imageUrl : imageUrl.substring(0, imageUrl.lastIndexOf('/') + 1) + "square." + extension;
RequestCreator request = Picasso.with(mContext).load(newImageUrl).fit().centerCrop();
if (largeVersion) {
request = request.placeholder(imageView.getDrawable());
}
request.into(imageView, new Callback() {
@Override
public void onSuccess() {
if (mImageViewToUrlExpected.containsKey(imageView)) {
String expectedUrl = mImageViewToUrlExpected.get(imageView);
if ((expectedUrl == null) || (!expectedUrl.equals(name))) {
// This ImageView has already been re-used for another URL (happens when scrolling fast)
return;
}
}
imageView.setVisibility(View.VISIBLE);
mImageViewToUrlAfterLoading.put(imageView, newImageUrl);
// we delay calling it until/unless we absolutely have to do so
if (!largeVersion && !mApp.isLowMemory()) {
loadObsImage(position, imageView, name, true, true);
}
}
@Override
public void onError() {
Logger.tag(TAG).warn("Picasso error for {}", newImageUrl);
}
});
} else {
// Offline image
Trace.beginSection("offline");
BitmapWorkerTask task = new BitmapWorkerTask(imageView);
task.execute(name);
}
Trace.endSection();
}
use of com.squareup.picasso.Callback in project iNaturalistAndroid by inaturalist.
the class UserObservationAdapter method getView.
@SuppressLint("NewApi")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(mViewType == VIEW_TYPE_GRID ? R.layout.user_profile_observation_item : R.layout.mission_grid_item, parent, false);
JSONObject item = mItems.get(position);
TextView idName = (TextView) view.findViewById(R.id.species_guess);
boolean hasSounds = (item.has("sounds")) && (!item.isNull("sounds")) && (item.optJSONArray("sounds").length() > 0);
if (mApp.getShowScientificNameFirst()) {
// Show scientific name first, before common name
if (!item.isNull("taxon")) {
TaxonUtils.setTaxonScientificName(mApp, idName, item.optJSONObject("taxon"));
} else {
idName.setText(item.isNull("species_guess") ? mContext.getResources().getString(R.string.unknown) : item.optString("species_guess", mContext.getResources().getString(R.string.unknown)));
}
} else {
if (!item.isNull("taxon")) {
try {
idName.setText(TaxonUtils.getTaxonName(mContext, item.getJSONObject("taxon")));
} catch (JSONException e) {
Logger.tag(TAG).error(e);
}
} else {
idName.setText(item.isNull("species_guess") ? mContext.getResources().getString(R.string.unknown) : item.optString("species_guess", mContext.getResources().getString(R.string.unknown)));
}
}
if (mViewType == VIEW_TYPE_GRID) {
TextView placeGuess = (TextView) view.findViewById(R.id.place_guess);
if (item.isNull("place_guess") || (item.optString("place_guess").length() == 0)) {
if (!item.isNull("latitude") && !item.isNull("longitude")) {
// Show coordinates instead
placeGuess.setText(String.format(mContext.getString(R.string.location_coords_no_acc), String.format("%.4f...", Double.valueOf(item.optString("latitude"))), String.format("%.4f...", Double.valueOf(item.optString("longitude")))));
} else {
// No place at all
placeGuess.setText(R.string.no_location);
}
} else {
placeGuess.setText(item.optString("place_guess"));
}
}
ImageView observationPic = (ImageView) view.findViewById(R.id.observation_pic);
ImageView obsIconicImage = (ImageView) view.findViewById(R.id.observation_iconic_pic);
obsIconicImage.setVisibility(View.VISIBLE);
obsIconicImage.setImageResource(TaxonUtils.observationIcon(item));
JSONArray observationPhotos;
try {
observationPhotos = item.has("observation_photos") ? item.getJSONArray("observation_photos") : item.getJSONArray("photos");
} catch (JSONException e1) {
Logger.tag(TAG).error(e1);
observationPhotos = new JSONArray();
}
if (observationPhotos.length() > 0) {
observationPic.setVisibility(View.VISIBLE);
JSONObject observationPhoto;
try {
String url;
observationPhoto = observationPhotos.getJSONObject(0);
if (observationPhoto.has("photo")) {
url = (observationPhoto.optJSONObject("photo").isNull("small_url") ? observationPhoto.optJSONObject("photo").optString("original_url") : observationPhoto.optJSONObject("photo").optString("small_url"));
if ((url == null) || (url.length() == 0)) {
url = observationPhoto.optJSONObject("photo").optString("url");
}
} else {
url = (observationPhoto.isNull("small_url") ? observationPhoto.optString("original_url") : observationPhoto.optString("small_url"));
if ((url == null) || (url.length() == 0)) {
url = observationPhoto.optString("url");
}
}
Picasso.with(mContext).load(url).fit().centerCrop().into(observationPic, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
}
});
} catch (JSONException e) {
Logger.tag(TAG).error(e);
} catch (Exception e) {
// Could happen if user scrolls really fast and there a LOT of thumbnails being downloaded at once (too many threads at once)
Logger.tag(TAG).error(e);
}
} else {
observationPic.setVisibility(View.INVISIBLE);
if (hasSounds) {
obsIconicImage.setImageResource(R.drawable.sound);
}
}
if (mViewType == VIEW_TYPE_GRID) {
TextView date = (TextView) view.findViewById(R.id.date);
BetterJSONObject json = new BetterJSONObject(item);
Timestamp dateTimestamp = json.getTimestamp("observed_on");
if (dateTimestamp == null) {
date.setVisibility(View.INVISIBLE);
} else {
date.setText(CommentsIdsAdapter.formatIdDate(mContext, dateTimestamp));
date.setVisibility(View.VISIBLE);
}
TextView commentCountText = (TextView) view.findViewById(R.id.comment_count);
ImageView commentCountIcon = (ImageView) view.findViewById(R.id.comment_pic);
int commentCount = item.optInt("comments_count");
if (commentCount > 0) {
commentCountIcon.setVisibility(View.VISIBLE);
commentCountText.setVisibility(View.VISIBLE);
commentCountText.setText(String.valueOf(commentCount));
} else {
commentCountIcon.setVisibility(View.GONE);
commentCountText.setVisibility(View.GONE);
}
TextView idCountText = (TextView) view.findViewById(R.id.id_count);
ImageView idCountIcon = (ImageView) view.findViewById(R.id.id_pic);
int idCount = item.optInt("identifications_count");
if (idCount > 0) {
idCountIcon.setVisibility(View.VISIBLE);
idCountText.setVisibility(View.VISIBLE);
idCountText.setText(String.valueOf(idCount));
} else {
idCountIcon.setVisibility(View.GONE);
idCountText.setVisibility(View.GONE);
}
}
view.setTag(item);
return view;
}
Aggregations