Search in sources :

Example 46 with Callback

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;
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) JSONException(org.json.JSONException) Callback(com.squareup.picasso.Callback) JSONObject(org.json.JSONObject) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with Callback

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);
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) PicassoUtils(net.osmand.plus.utils.PicassoUtils) RequestCreator(com.squareup.picasso.RequestCreator)

Example 48 with Callback

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);
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback) OsmandApplication(net.osmand.plus.OsmandApplication) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) PicassoUtils(net.osmand.plus.utils.PicassoUtils) RequestCreator(com.squareup.picasso.RequestCreator)

Example 49 with Callback

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;
}
Also used : Callback(com.squareup.picasso.Callback) ImageView(android.widget.ImageView)

Example 50 with Callback

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) {
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) ProgressDialog(android.app.ProgressDialog) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

Callback (com.squareup.picasso.Callback)54 ImageView (android.widget.ImageView)21 View (android.view.View)18 TextView (android.widget.TextView)14 RequestCreator (com.squareup.picasso.RequestCreator)12 LayoutInflater (android.view.LayoutInflater)7 Context (android.content.Context)6 DisplayMetrics (android.util.DisplayMetrics)6 Bitmap (android.graphics.Bitmap)5 Intent (android.content.Intent)4 ViewGroup (android.view.ViewGroup)4 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Resources (android.content.res.Resources)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Bundle (android.os.Bundle)3 MotionEvent (android.view.MotionEvent)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3