use of com.squareup.picasso.Callback in project iNaturalistAndroid by inaturalist.
the class ObservationGridAdapter method getView.
@NotNull
@Override
public View getView(int position, View convertView, @NotNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.guide_taxon_item, parent, false);
boolean isLowMemory = mApp.isLowMemory();
JSONObject item = mItems.get(position);
TextView researchGrade = view.findViewById(R.id.is_research_grade);
researchGrade.setVisibility(item.optString("quality_grade", "none").equals("research") ? View.VISIBLE : View.GONE);
@SuppressWarnings("ConstantConditions") boolean hasSounds = (item.has("sounds")) && (!item.isNull("sounds")) && (item.optJSONArray("sounds").length() > 0);
ImageView hasSoundsImage = view.findViewById(R.id.has_sounds);
hasSoundsImage.setVisibility(hasSounds ? View.VISIBLE : View.INVISIBLE);
TextView idName = view.findViewById(R.id.id_name);
final JSONObject taxon = item.optJSONObject("taxon");
if (taxon != null) {
if (mApp.getShowScientificNameFirst()) {
// Show scientific name instead of common name
TaxonUtils.setTaxonScientificName(mApp, idName, taxon);
} else {
String idNameStr = TaxonUtils.getTaxonName(mContext, taxon);
idName.setText(idNameStr);
}
} else {
idName.setText(R.string.unknown_species);
}
final ImageView taxonPic = view.findViewById(R.id.taxon_photo);
final ImageView taxonIcon = view.findViewById(R.id.taxon_icon);
taxonPic.setLayoutParams(new RelativeLayout.LayoutParams(mDimension, mDimension));
taxonIcon.setLayoutParams(new RelativeLayout.LayoutParams(mDimension, mDimension));
int labelHeight = idName.getLayoutParams().height;
Resources r = mContext.getResources();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, labelHeight, r.getDisplayMetrics());
taxonIcon.setPadding(mDimension / 4, (mDimension - px) / 4, mDimension / 4, mDimension / 4);
taxonPic.setVisibility(View.INVISIBLE);
taxonIcon.setVisibility(View.VISIBLE);
taxonIcon.setImageResource(TaxonUtils.observationIcon(item));
JSONArray observationPhotos;
boolean isNewApi = !item.has("observation_photos");
try {
observationPhotos = item.getJSONArray(isNewApi ? "photos" : "observation_photos");
} catch (JSONException e1) {
Logger.tag(TAG).error(e1);
observationPhotos = new JSONArray();
}
if (observationPhotos.length() == 0) {
if (hasSounds) {
hasSoundsImage.setVisibility(View.INVISIBLE);
taxonIcon.setImageResource(R.drawable.sound);
}
} else {
JSONObject observationPhoto;
// noinspection TryWithIdenticalCatches
try {
String url = null;
observationPhoto = observationPhotos.getJSONObject(0);
if (isNewApi) {
url = observationPhoto.optString("url");
} else {
JSONObject innerPhoto = observationPhoto.optJSONObject("photo");
if (innerPhoto != null) {
url = (innerPhoto.isNull("small_url") ? innerPhoto.optString("original_url") : innerPhoto.optString("small_url"));
if (url.length() == 0)
url = innerPhoto.optString("url");
} else
Logger.tag(TAG).warn("photo field not present in json");
}
if ((url != null) && (url.length() > 0)) {
String extension = url.substring(url.lastIndexOf('.'));
// Deduce the original-sized URL
if (url.substring(0, url.lastIndexOf('/')).endsWith("assets")) {
// It's an assets default URL - e.g. https://www.inaturalist.org/assets/copyright-infringement-square.png
url = url.substring(0, url.lastIndexOf("-") + 1) + (isLowMemory ? "thumb" : "medium") + extension;
} else {
// "Regular" observation photo
url = url.substring(0, url.lastIndexOf("/") + 1) + (isLowMemory ? "thumb" : "medium") + extension;
}
}
if (url != null) {
Picasso.with(mContext).load(url).fit().centerCrop().into(taxonPic, new Callback() {
@Override
public void onSuccess() {
taxonPic.setLayoutParams(new RelativeLayout.LayoutParams(mDimension, mDimension));
taxonIcon.setVisibility(View.GONE);
taxonPic.setVisibility(View.VISIBLE);
}
@Override
public void onError() {
Logger.tag(TAG).warn("Picasso error downloading obs url");
}
});
} else {
Logger.tag(TAG).warn("Refusing to pass null URL to Picasso");
}
} 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);
}
}
view.setTag(item);
return view;
}
use of com.squareup.picasso.Callback in project Osmand by osmandapp.
the class DescriptionCard method setupImage.
private void setupImage(final String imageUrl) {
if (imageUrl == null) {
return;
}
final PicassoUtils picasso = PicassoUtils.getPicasso(app);
RequestCreator rc = Picasso.get().load(imageUrl);
final AppCompatImageView image = view.findViewById(R.id.main_image);
rc.into(image, new Callback() {
@Override
public void onSuccess() {
picasso.setResultLoaded(imageUrl, true);
AndroidUiHelper.updateVisibility(image, true);
}
@Override
public void onError(Exception e) {
picasso.setResultLoaded(imageUrl, false);
}
});
}
use of com.squareup.picasso.Callback in project Osmand by osmandapp.
the class GpxReadDescriptionDialogFragment method setupImage.
private void setupImage(View view) {
if (imageUrl == null) {
return;
}
final OsmandApplication app = getMyApplication();
final PicassoUtils picasso = PicassoUtils.getPicasso(app);
final AppCompatImageView image = view.findViewById(R.id.main_image);
RequestCreator rc = Picasso.get().load(imageUrl);
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.into(image, new Callback() {
@Override
public void onSuccess() {
picasso.setResultLoaded(imageUrl, true);
AndroidUiHelper.updateVisibility(image, true);
}
@Override
public void onError(Exception e) {
picasso.setResultLoaded(imageUrl, false);
}
});
}
use of com.squareup.picasso.Callback in project Osmand by osmandapp.
the class ImagesPagerAdapter method createImageView.
private View createImageView(int position) {
final ImageView imageView = new ImageView(app);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final String imageUrl = imageUrls.get(position);
if (!Algorithms.isEmpty(imageUrl)) {
Picasso.get().load(imageUrl).into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(imageUrl, true);
}
@Override
public void onError(Exception e) {
imageView.setVisibility(View.INVISIBLE);
picassoUtils.setResultLoaded(imageUrl, false);
}
});
} else {
imageView.setVisibility(View.INVISIBLE);
}
return imageView;
}
use of com.squareup.picasso.Callback in project Lets-Chat by kshitiz1007.
the class SettingActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
mCircleImageView = (CircleImageView) findViewById(R.id.displayimage);
mdisplayName = (TextView) findViewById(R.id.textViewDisplayname);
mstatus = (TextView) findViewById(R.id.textViewStatus);
mchangeImage = (Button) findViewById(R.id.buttonChangeImage);
mchangeStatus = (Button) findViewById(R.id.buttonChangeStatus);
mProgressDialog = new ProgressDialog(this);
mFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
uid = mFirebaseUser.getUid();
mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("users").child(uid);
mDatabaseReference.keepSynced(true);
mStorageReference = FirebaseStorage.getInstance().getReference();
// --------ADDING VIEW-------
mDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = (String) dataSnapshot.child("name").getValue();
status = (String) dataSnapshot.child("status").getValue();
final String image = (String) dataSnapshot.child("image").getValue();
String thumb = (String) dataSnapshot.child("thumb_image").getValue();
mdisplayName.setText(name);
mstatus.setText(status);
if (!image.equals("default"))
// Picasso.with(SettingActivity.this).load(image).placeholder(R.drawable.user_img).into(mCircleImageView);
// ----OFFLINE FEATURE-----
Picasso.with(SettingActivity.this).load(image).networkPolicy(NetworkPolicy.OFFLINE).placeholder(R.drawable.user_img).into(mCircleImageView, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(SettingActivity.this).load(image).placeholder(R.drawable.user_img).into(mCircleImageView);
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Aggregations