Search in sources :

Example 1 with AnimationRect

use of org.qii.weiciyuan.support.lib.AnimationRect in project weiciyuan by qii.

the class ContainerFragment method displayPicture.

private void displayPicture(String path, boolean animateIn) {
    GalleryAnimationActivity activity = (GalleryAnimationActivity) getActivity();
    AnimationRect rect = getArguments().getParcelable("rect");
    boolean firstOpenPage = getArguments().getBoolean("firstOpenPage");
    if (firstOpenPage) {
        if (animateIn) {
            ObjectAnimator animator = activity.showBackgroundAnimate();
            animator.start();
        } else {
            activity.showBackgroundImmediately();
        }
        getArguments().putBoolean("firstOpenPage", false);
    }
    if (!ImageUtility.isThisBitmapTooLargeToRead(path)) {
        Fragment fragment = null;
        if (ImageUtility.isThisPictureGif(path)) {
            fragment = GifPictureFragment.newInstance(path, rect, animateIn);
        } else {
            fragment = GeneralPictureFragment.newInstance(path, rect, animateIn);
        }
        getChildFragmentManager().beginTransaction().replace(R.id.child, fragment).commitAllowingStateLoss();
    } else {
        LargePictureFragment fragment = LargePictureFragment.newInstance(path, animateIn);
        getChildFragmentManager().beginTransaction().replace(R.id.child, fragment).commitAllowingStateLoss();
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) Fragment(android.support.v4.app.Fragment)

Example 2 with AnimationRect

use of org.qii.weiciyuan.support.lib.AnimationRect in project weiciyuan by qii.

the class AbstractAppListAdapter method buildMultiPic.

protected void buildMultiPic(final MessageBean msg, final GridLayout gridLayout) {
    if (SettingUtility.isEnablePic()) {
        gridLayout.setVisibility(View.VISIBLE);
        final int count = msg.getPicCount();
        for (int i = 0; i < count; i++) {
            final IWeiciyuanDrawable pic = (IWeiciyuanDrawable) gridLayout.getChildAt(i);
            pic.setVisibility(View.VISIBLE);
            if (SettingUtility.getEnableBigPic()) {
                TimeLineBitmapDownloader.getInstance().displayMultiPicture(pic, msg.getHighPicUrls().get(i), FileLocationMethod.picture_large, (AbstractTimeLineFragment) fragment);
            } else {
                TimeLineBitmapDownloader.getInstance().displayMultiPicture(pic, msg.getThumbnailPicUrls().get(i), FileLocationMethod.picture_thumbnail, (AbstractTimeLineFragment) fragment);
            }
            final int finalI = i;
            pic.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ArrayList<AnimationRect> animationRectArrayList = new ArrayList<AnimationRect>();
                    for (int i = 0; i < count; i++) {
                        final IWeiciyuanDrawable pic = (IWeiciyuanDrawable) gridLayout.getChildAt(i);
                        ImageView imageView = (ImageView) pic;
                        if (imageView.getVisibility() == View.VISIBLE) {
                            AnimationRect rect = AnimationRect.buildFromImageView(imageView);
                            animationRectArrayList.add(rect);
                        }
                    }
                    Intent intent = GalleryAnimationActivity.newIntent(msg, animationRectArrayList, finalI);
                    getActivity().startActivity(intent);
                }
            });
        }
        if (count < 9) {
            ImageView pic;
            switch(count) {
                case 8:
                    pic = (ImageView) gridLayout.getChildAt(8);
                    pic.setVisibility(View.INVISIBLE);
                    break;
                case 7:
                    for (int i = 8; i > 6; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.INVISIBLE);
                    }
                    break;
                case 6:
                    for (int i = 8; i > 5; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.GONE);
                    }
                    break;
                case 5:
                    for (int i = 8; i > 5; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.GONE);
                    }
                    pic = (ImageView) gridLayout.getChildAt(5);
                    pic.setVisibility(View.INVISIBLE);
                    break;
                case 4:
                    for (int i = 8; i > 5; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.GONE);
                    }
                    pic = (ImageView) gridLayout.getChildAt(5);
                    pic.setVisibility(View.INVISIBLE);
                    pic = (ImageView) gridLayout.getChildAt(4);
                    pic.setVisibility(View.INVISIBLE);
                    break;
                case 3:
                    for (int i = 8; i > 2; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.GONE);
                    }
                    break;
                case 2:
                    for (int i = 8; i > 2; i--) {
                        pic = (ImageView) gridLayout.getChildAt(i);
                        pic.setVisibility(View.GONE);
                    }
                    pic = (ImageView) gridLayout.getChildAt(2);
                    pic.setVisibility(View.INVISIBLE);
                    break;
            }
        }
    } else {
        gridLayout.setVisibility(View.GONE);
    }
}
Also used : AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageView(android.widget.ImageView) TimeLineAvatarImageView(org.qii.weiciyuan.support.lib.TimeLineAvatarImageView) ImageView(android.widget.ImageView) View(android.view.View) ListViewMiddleMsgLoadingView(org.qii.weiciyuan.support.lib.ListViewMiddleMsgLoadingView) AbsListView(android.widget.AbsListView) TimeLineAvatarImageView(org.qii.weiciyuan.support.lib.TimeLineAvatarImageView) TextView(android.widget.TextView) TimeTextView(org.qii.weiciyuan.support.lib.TimeTextView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) IWeiciyuanDrawable(org.qii.weiciyuan.support.asyncdrawable.IWeiciyuanDrawable)

Example 3 with AnimationRect

use of org.qii.weiciyuan.support.lib.AnimationRect in project weiciyuan by qii.

the class BrowserWeiboMsgFragment method displayPictures.

private void displayPictures(final MessageBean msg, final GridLayout layout, WeiboDetailImageView view, boolean refreshPic) {
    if (!msg.isMultiPics()) {
        view.setVisibility(View.VISIBLE);
        if (Utility.isTaskStopped(picTask) && refreshPic) {
            picTask = new MsgDetailReadWorker(view, msg);
            picTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            picTask.setView(view);
        }
    } else {
        layout.setVisibility(View.VISIBLE);
        final int count = msg.getPicCount();
        for (int i = 0; i < count; i++) {
            final IWeiciyuanDrawable pic = (IWeiciyuanDrawable) layout.getChildAt(i);
            pic.setVisibility(View.VISIBLE);
            if (SettingUtility.getEnableBigPic()) {
                TimeLineBitmapDownloader.getInstance().displayMultiPicture(pic, msg.getHighPicUrls().get(i), FileLocationMethod.picture_large);
            } else {
                TimeLineBitmapDownloader.getInstance().displayMultiPicture(pic, msg.getMiddlePicUrls().get(i), FileLocationMethod.picture_bmiddle);
            }
            final int finalI = i;
            pic.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ArrayList<AnimationRect> animationRectArrayList = new ArrayList<AnimationRect>();
                    for (int i = 0; i < count; i++) {
                        final IWeiciyuanDrawable pic = (IWeiciyuanDrawable) layout.getChildAt(i);
                        ImageView imageView = (ImageView) pic;
                        if (imageView.getVisibility() == View.VISIBLE) {
                            AnimationRect rect = AnimationRect.buildFromImageView(imageView);
                            animationRectArrayList.add(rect);
                        }
                    }
                    Intent intent = GalleryAnimationActivity.newIntent(msg, animationRectArrayList, finalI);
                    getActivity().startActivity(intent);
                }
            });
        }
        if (count < 9) {
            for (int i = count; i < 9; i++) {
                ImageView pic = (ImageView) layout.getChildAt(i);
                pic.setVisibility(View.GONE);
            }
        }
    }
}
Also used : AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageView(android.widget.ImageView) WeiboDetailImageView(org.qii.weiciyuan.support.lib.WeiboDetailImageView) ProfileTopAvatarImageView(org.qii.weiciyuan.support.lib.ProfileTopAvatarImageView) MsgDetailReadWorker(org.qii.weiciyuan.support.asyncdrawable.MsgDetailReadWorker) ImageView(android.widget.ImageView) WeiboDetailImageView(org.qii.weiciyuan.support.lib.WeiboDetailImageView) View(android.view.View) AdapterView(android.widget.AdapterView) PullToRefreshListView(org.qii.weiciyuan.support.lib.pulltorefresh.PullToRefreshListView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ProfileTopAvatarImageView(org.qii.weiciyuan.support.lib.ProfileTopAvatarImageView) IWeiciyuanDrawable(org.qii.weiciyuan.support.asyncdrawable.IWeiciyuanDrawable)

Example 4 with AnimationRect

use of org.qii.weiciyuan.support.lib.AnimationRect in project weiciyuan by qii.

the class MsgDetailReadWorker method onPostExecute.

@Override
protected void onPostExecute(String path) {
    retry.setVisibility(View.INVISIBLE);
    pb.setIndeterminate(true);
    if (!TextUtils.isEmpty(path)) {
        if (!path.endsWith(".gif")) {
            readNormalPic(path);
        } else {
            view.setGif(path);
        }
        pb.setVisibility(View.INVISIBLE);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AnimationRect rect = AnimationRect.buildFromImageView(view.getImageView());
                ArrayList<AnimationRect> animationRectArrayList = new ArrayList<AnimationRect>();
                animationRectArrayList.add(rect);
                Intent intent = GalleryAnimationActivity.newIntent(msg, animationRectArrayList, 0);
                GlobalContext.getInstance().getActivity().startActivity(intent);
            }
        });
    } else {
        pb.setVisibility(View.INVISIBLE);
        view.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
        retry.setVisibility(View.VISIBLE);
        retry.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                MsgDetailReadWorker picTask = new MsgDetailReadWorker(view, msg);
                picTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            }
        });
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WeiboDetailImageView(org.qii.weiciyuan.support.lib.WeiboDetailImageView) View(android.view.View)

Example 5 with AnimationRect

use of org.qii.weiciyuan.support.lib.AnimationRect in project weiciyuan by qii.

the class GeneralPictureFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.gallery_general_layout, container, false);
    photoView = (PhotoView) view.findViewById(R.id.animation);
    if (SettingUtility.allowClickToCloseGallery()) {
        photoView.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {

            @Override
            public void onViewTap(View view, float x, float y) {
                getActivity().onBackPressed();
            }
        });
    }
    LongClickListener longClickListener = ((ContainerFragment) getParentFragment()).getLongClickListener();
    photoView.setOnLongClickListener(longClickListener);
    final String path = getArguments().getString("path");
    boolean animateIn = getArguments().getBoolean("animationIn");
    final AnimationRect rect = getArguments().getParcelable("rect");
    if (!animateIn) {
        new MyAsyncTask<Void, Bitmap, Bitmap>() {

            @Override
            protected Bitmap doInBackground(Void... params) {
                Bitmap bitmap = ImageUtility.decodeBitmapFromSDCard(path, IMAGEVIEW_SOFT_LAYER_MAX_WIDTH, IMAGEVIEW_SOFT_LAYER_MAX_HEIGHT);
                return bitmap;
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {
                super.onPostExecute(bitmap);
                photoView.setImageBitmap(bitmap);
            }
        }.executeOnIO();
        return view;
    }
    final Bitmap bitmap = ImageUtility.decodeBitmapFromSDCard(path, IMAGEVIEW_SOFT_LAYER_MAX_WIDTH, IMAGEVIEW_SOFT_LAYER_MAX_HEIGHT);
    photoView.setImageBitmap(bitmap);
    final Runnable endAction = new Runnable() {

        @Override
        public void run() {
            Bundle bundle = getArguments();
            bundle.putBoolean("animationIn", false);
        }
    };
    photoView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            if (rect == null) {
                photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                endAction.run();
                return true;
            }
            final Rect startBounds = new Rect(rect.scaledBitmapRect);
            final Rect finalBounds = AnimationUtility.getBitmapRectFromImageView(photoView);
            if (finalBounds == null) {
                photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                endAction.run();
                return true;
            }
            float startScale = (float) finalBounds.width() / startBounds.width();
            if (startScale * startBounds.height() > finalBounds.height()) {
                startScale = (float) finalBounds.height() / startBounds.height();
            }
            int deltaTop = startBounds.top - finalBounds.top;
            int deltaLeft = startBounds.left - finalBounds.left;
            photoView.setPivotY((photoView.getHeight() - finalBounds.height()) / 2);
            photoView.setPivotX((photoView.getWidth() - finalBounds.width()) / 2);
            photoView.setScaleX(1 / startScale);
            photoView.setScaleY(1 / startScale);
            photoView.setTranslationX(deltaLeft);
            photoView.setTranslationY(deltaTop);
            photoView.animate().translationY(0).translationX(0).scaleY(1).scaleX(1).setDuration(ANIMATION_DURATION).setInterpolator(new AccelerateDecelerateInterpolator()).withEndAction(endAction);
            AnimatorSet animationSet = new AnimatorSet();
            animationSet.setDuration(ANIMATION_DURATION);
            animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipBottom", AnimationRect.getClipBottom(rect, finalBounds), 0));
            animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipRight", AnimationRect.getClipRight(rect, finalBounds), 0));
            animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipTop", AnimationRect.getClipTop(rect, finalBounds), 0));
            animationSet.playTogether(ObjectAnimator.ofFloat(photoView, "clipLeft", AnimationRect.getClipLeft(rect, finalBounds), 0));
            animationSet.start();
            photoView.getViewTreeObserver().removeOnPreDrawListener(this);
            return true;
        }
    });
    return view;
}
Also used : Rect(android.graphics.Rect) AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) Bundle(android.os.Bundle) AnimationRect(org.qii.weiciyuan.support.lib.AnimationRect) AnimatorSet(android.animation.AnimatorSet) PhotoView(uk.co.senab.photoview.PhotoView) View(android.view.View) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) Bitmap(android.graphics.Bitmap) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

AnimationRect (org.qii.weiciyuan.support.lib.AnimationRect)8 View (android.view.View)5 AnimatorSet (android.animation.AnimatorSet)4 Rect (android.graphics.Rect)4 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)4 Intent (android.content.Intent)3 ArrayList (java.util.ArrayList)3 Bitmap (android.graphics.Bitmap)2 Bundle (android.os.Bundle)2 ViewTreeObserver (android.view.ViewTreeObserver)2 AbsListView (android.widget.AbsListView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 IWeiciyuanDrawable (org.qii.weiciyuan.support.asyncdrawable.IWeiciyuanDrawable)2 ClipImageView (org.qii.weiciyuan.support.lib.ClipImageView)2 WeiboDetailImageView (org.qii.weiciyuan.support.lib.WeiboDetailImageView)2 PhotoView (uk.co.senab.photoview.PhotoView)2 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)2 ObjectAnimator (android.animation.ObjectAnimator)1