@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_photo_view, container, false);

    imageView = (PhotoView) view.findViewById(R.id.photoIm);
    progressBar = (CircularProgressBar) view.findViewById(R.id.progressBar);

    ImageLoader loader = ImageLoader.getInstance();
    ImageLoaderUtils.initImageLoader(getActivity());
    DisplayImageOptions options =
        new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();

    imageView.setOnViewTapListener(
        new PhotoViewAttacher.OnViewTapListener() {
          @Override
          public void onViewTap(View view, float x, float y) {
            getActivity().finish();
          }
        });

    loader.displayImage(
        url,
        imageView,
        options,
        new ImageLoadingListener() {
          @Override
          public void onLoadingStarted(String imageUri, View view) {}

          @Override
          public void onLoadingFailed(String imageUri, View view, FailReason failReason) {}

          @Override
          public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            if (imageUri.equals(url)) {
              progressBar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onLoadingCancelled(String imageUri, View view) {}
        },
        new ImageLoadingProgressListener() {
          @Override
          public void onProgressUpdate(String s, View view, int i, int i2) {
            progressBar.setProgressPecentage((float) i / i2);
          }
        });

    return view;
  }
예제 #2
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_gif, container, false);

    mGifView = (PhotoView) view.findViewById(R.id.iv_normal);
    mPhotoView = (ClipImageView) view.findViewById(R.id.cover);
    mScreenWidth = getResources().getDisplayMetrics().widthPixels;

    mGifView.setOnLongClickListener(this);

    File gifFile = new File(mPath);
    try {
      GifDrawable gifFromFile = new GifDrawable(gifFile);
      mGifView.setImageDrawable(gifFromFile);
    } catch (IOException e) {
      e.printStackTrace();
    }

    setBitmapToPhotoView();
    if (mAnimateIn) {
      mAnimateIn = false;
      runEnterAnimation();
    }

    if (SettingHelper.isClickToCloseGallery()) {
      mGifView.setOnViewTapListener(
          new PhotoViewAttacher.OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
              getActivity().onBackPressed();
            }
          });
    }
    return view;
  }
  @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);
        }
      }.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);

      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);
                  return true;
                }

                final Rect startBounds = new Rect(rect.scaledBitmapRect);
                final Rect finalBounds = AnimationUtility.getBitmapRectFromImageView(photoView);

                if (finalBounds == null) {
                  photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                  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;
  }