Search in sources :

Example 16 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 17 with Callback

use of com.squareup.picasso.Callback in project UltimateAndroid by cymcsg.

the class BaseSliderView method bindEventAndShow.

/**
     * When you want to implement your own slider view, please call this method in the end in `getView()` method
     * @param v the whole view
     * @param targetImageView where to place image
     */
protected void bindEventAndShow(final View v, ImageView targetImageView) {
    final BaseSliderView me = this;
    v.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mOnSliderClickListener != null) {
                mOnSliderClickListener.onSliderClick(me);
            }
        }
    });
    if (targetImageView == null)
        return;
    mLoadListener.onStart(me);
    Picasso p = Picasso.with(mContext);
    RequestCreator rq = null;
    if (mUrl != null) {
        rq = p.load(mUrl);
    } else if (mFile != null) {
        rq = p.load(mFile);
    } else if (mRes != 0) {
        rq = p.load(mRes);
    } else {
        return;
    }
    if (rq == null) {
        return;
    }
    if (getEmpty() != 0) {
        rq.placeholder(getEmpty());
    }
    if (getError() != 0) {
        rq.error(getError());
    }
    switch(mScaleType) {
        case Fit:
            rq.fit();
            break;
        case CenterCrop:
            rq.fit().centerCrop();
            break;
        case CenterInside:
            rq.fit().centerInside();
            break;
    }
    rq.into(targetImageView, new Callback() {

        @Override
        public void onSuccess() {
            if (v.findViewById(R.id.loading_bar) != null) {
                v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void onError() {
            if (mLoadListener != null) {
                mLoadListener.onEnd(false, me);
            }
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback) Picasso(com.squareup.picasso.Picasso) ImageView(android.widget.ImageView) View(android.view.View) RequestCreator(com.squareup.picasso.RequestCreator)

Example 18 with Callback

use of com.squareup.picasso.Callback in project boxing by Bilibili.

the class BoxingPicassoLoader method displayRaw.

@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, final IBoxingCallback callback) {
    String path = "file://" + absPath;
    Picasso.with(img.getContext()).load(path).transform(new BitmapTransform(1080, 720)).into(img, new Callback() {

        @Override
        public void onSuccess() {
            if (callback != null) {
                callback.onSuccess();
            }
        }

        @Override
        public void onError() {
            if (callback != null) {
                callback.onFail(null);
            }
        }
    });
}
Also used : Callback(com.squareup.picasso.Callback) IBoxingCallback(com.bilibili.boxing.loader.IBoxingCallback)

Example 19 with Callback

use of com.squareup.picasso.Callback in project Tusky by Vavassor.

the class ViewMediaFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
    ButterKnife.bind(this, rootView);
    Bundle arguments = getArguments();
    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) {
            dismiss();
        }
    });
    /* 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)) {
                dismiss();
                return true;
            }
            return false;
        }
    });
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    Picasso.with(getContext()).load(url).into(photoView, new Callback() {

        @Override
        public void onSuccess() {
            rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE);
            toolbar.setOnMenuItemClickListener(ViewMediaFragment.this);
            toolbar.inflateMenu(R.menu.view_media_tooblar);
            attacher.update();
        }

        @Override
        public void onError() {
        }
    });
    return rootView;
}
Also used : Callback(com.squareup.picasso.Callback) Bundle(android.os.Bundle) OnSingleFlingListener(com.github.chrisbanes.photoview.OnSingleFlingListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) PhotoView(com.github.chrisbanes.photoview.PhotoView) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) OnOutsidePhotoTapListener(com.github.chrisbanes.photoview.OnOutsidePhotoTapListener) MotionEvent(android.view.MotionEvent)

Example 20 with Callback

use of com.squareup.picasso.Callback in project wh-app-android by WhiteHouse.

the class GalleryPhotoFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mPhotoDescription.setText(Html.fromHtml(prepDescription(mFeedItem.description())));
    Picasso.with(view.getContext()).load(mFeedItem.getBestThumbnailUrl(1500)).into(mPhotoView, new Callback() {

        @Override
        public void onSuccess() {
            mPhotoViewAttacher = new PhotoViewAttacher(mPhotoView) {

                @Override
                public boolean onTouch(View v, MotionEvent ev) {
                    switch(ev.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            mTouching = true;
                            decideDescriptionVisibility(getScale());
                            break;
                        case MotionEvent.ACTION_CANCEL:
                        case MotionEvent.ACTION_UP:
                            mTouching = false;
                            decideDescriptionVisibility(getScale());
                            break;
                    }
                    return super.onTouch(v, ev);
                }
            };
            mPhotoViewAttacher.setOnMatrixChangeListener(rectF -> {
                decideDescriptionVisibility(mPhotoViewAttacher.getScale());
                if (mPhotoViewAttacher.getScale() > 1.1f) {
                    mPhotoViewAttacher.setAllowParentInterceptOnEdge(false);
                } else {
                    mPhotoViewAttacher.setAllowParentInterceptOnEdge(true);
                }
            });
        }

        @Override
        public void onError() {
        }
    });
}
Also used : Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) InjectView(butterknife.InjectView) GsonUtils(gov.whitehouse.util.GsonUtils) ViewGroup(android.view.ViewGroup) FeedItem(gov.whitehouse.data.model.FeedItem) Picasso(com.squareup.picasso.Picasso) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Html(android.text.Html) Menu(android.view.Menu) View(android.view.View) Callback(com.squareup.picasso.Callback) Nullable(android.support.annotation.Nullable) BaseFragment(gov.whitehouse.app.BaseFragment) R(gov.whitehouse.R) Callback(com.squareup.picasso.Callback) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

Callback (com.squareup.picasso.Callback)23 ImageView (android.widget.ImageView)7 View (android.view.View)6 Bitmap (android.graphics.Bitmap)4 TextView (android.widget.TextView)4 Context (android.content.Context)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 DisplayMetrics (android.util.DisplayMetrics)3 LayoutInflater (android.view.LayoutInflater)3 Bundle (android.os.Bundle)2 Palette (android.support.v7.graphics.Palette)2 MotionEvent (android.view.MotionEvent)2 ViewGroup (android.view.ViewGroup)2 Picasso (com.squareup.picasso.Picasso)2 RequestCreator (com.squareup.picasso.RequestCreator)2 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)2 AccountManagerCallback (android.accounts.AccountManagerCallback)1 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1