Search in sources :

Example 51 with Callback

use of com.squareup.picasso.Callback in project Hummingbird-for-Android by xiprox.

the class FavoriteAnimeAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rootView = inflater.inflate(R.layout.item_favorite_grid, null);
    FavoriteAnime fav = mItems.get(position);
    final ImageView mCover = (ImageView) rootView.findViewById(R.id.item_favorite_cover);
    final TextView mTitle = (TextView) rootView.findViewById(R.id.item_favorite_title);
    ViewFlipper mFlipper = (ViewFlipper) rootView.findViewById(R.id.item_favorite_flipper);
    Picasso.with(context).load(fav.getCoverImage()).into(mCover, new Callback() {

        @Override
        public void onSuccess() {
            int darkMutedColor;
            Bitmap bitmap = ((BitmapDrawable) mCover.getDrawable()).getBitmap();
            darkMutedColor = Palette.generate(bitmap).getDarkMutedSwatch().getRgb();
            mTitle.setBackgroundDrawable(new ColorDrawable(darkMutedColor));
        }

        @Override
        public void onError() {
        }
    });
    mTitle.setText(fav.getTitle());
    if (mFlipper.getDisplayedChild() == 0)
        mFlipper.showNext();
    return rootView;
}
Also used : ViewFlipper(android.widget.ViewFlipper) Bitmap(android.graphics.Bitmap) Callback(com.squareup.picasso.Callback) ColorDrawable(android.graphics.drawable.ColorDrawable) FavoriteAnime(tr.bcxip.hummingbird.api.objects.FavoriteAnime) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 52 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 53 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 54 with Callback

use of com.squareup.picasso.Callback in project OsmAnd by osmandapp.

the class SavedArticlesRvAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
    if (viewHolder instanceof HeaderVH) {
        final HeaderVH holder = (HeaderVH) viewHolder;
        holder.title.setText((String) getItem(position));
        holder.description.setText(String.valueOf(items.size() - 1));
    } else if (viewHolder instanceof ItemVH) {
        final ItemVH holder = (ItemVH) viewHolder;
        TravelArticle article = (TravelArticle) getItem(position);
        final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
        Boolean loaded = picasso.isURLLoaded(url);
        boolean lastItem = position == getItemCount() - 1;
        RequestCreator rc = Picasso.get().load(url);
        WikivoyageUtils.setupNetworkPolicy(settings, rc);
        rc.transform(new CropCircleTransformation()).into(holder.icon, new Callback() {

            @Override
            public void onSuccess() {
                holder.icon.setVisibility(View.VISIBLE);
                picasso.setResultLoaded(url, true);
            }

            @Override
            public void onError(Exception e) {
                holder.icon.setVisibility(View.GONE);
                picasso.setResultLoaded(url, false);
            }
        });
        holder.icon.setVisibility(loaded == null || loaded.booleanValue() ? View.VISIBLE : View.GONE);
        holder.title.setText(article.getTitle());
        holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent()));
        holder.partOf.setText(article.getGeoDescription());
        holder.leftButton.setText(app.getString(R.string.shared_string_read));
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        holder.rightButton.setText(app.getString(R.string.shared_string_remove));
        holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
        holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    } else if (viewHolder instanceof TravelGpxVH) {
        final TravelGpx article = (TravelGpx) getItem(position);
        final TravelGpxVH holder = (TravelGpxVH) viewHolder;
        holder.title.setText(article.getTitle());
        holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
        holder.user.setText(article.user);
        String activityTypeKey = article.activityType;
        if (!Algorithms.isEmpty(activityTypeKey)) {
            RouteActivityType activityType = RouteActivityType.getOrCreateTypeFromName(activityTypeKey);
            int activityTypeIcon = getActivityTypeIcon(activityType);
            holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityTypeIcon));
            holder.activityType.setText(getActivityTypeTitle(activityType));
            holder.activityTypeLabel.setVisibility(View.VISIBLE);
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
        holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
        holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
        holder.leftButton.setText(app.getString(R.string.shared_string_view));
        View.OnClickListener readClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.openArticle(article);
                }
            }
        };
        holder.leftButton.setOnClickListener(readClickListener);
        holder.itemView.setOnClickListener(readClickListener);
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        updateSaveButton(holder, article);
    }
}
Also used : TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RequestCreator(com.squareup.picasso.RequestCreator) TravelGpxVH(net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH) Callback(com.squareup.picasso.Callback) RouteActivityType(net.osmand.osm.RouteActivityType) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation)

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