com.zhihu.matisse.internal.utils.PhotoMetadataUtils Java Examples

The following examples show how to use com.zhihu.matisse.internal.utils.PhotoMetadataUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 6 votes vote down vote up
public IncapableCause isAcceptable(Item item) {
    if (maxSelectableReached()) {
        int maxSelectable = currentMaxSelectable();
        String cause;

        try {
            cause = mContext.getString(
                    R.string.error_over_count,
                    maxSelectable
            );
        } catch (Resources.NotFoundException e) {
            cause = mContext.getString(
                    R.string.error_over_count,
                    maxSelectable
            );
        }

        return new IncapableCause(cause);
    } else if (typeConflict(item)) {
        return new IncapableCause(mContext.getString(R.string.error_type_conflict));
    }

    return PhotoMetadataUtils.isAcceptable(mContext, item);
}
 
Example #2
Source File: GifSizeFilter.java    From Matisse with Apache License 2.0 5 votes vote down vote up
@Override
public IncapableCause filter(Context context, Item item) {
    if (!needFiltering(context, item))
        return null;

    Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri());
    if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) {
        return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth,
                String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize))));
    }
    return null;
}
 
Example #3
Source File: MatisseActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private int countOverMaxSize() {
    int count = 0;
    int selectedCount = mSelectedCollection.count();
    for (int i = 0; i < selectedCount; i++) {
        Item item = mSelectedCollection.asList().get(i);

        if (item.isImage()) {
            float size = PhotoMetadataUtils.getSizeInMB(item.size);
            if (size > mSpec.originalMaxSize) {
                count++;
            }
        }
    }
    return count;
}
 
Example #4
Source File: BasePreviewActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private int countOverMaxSize() {
    int count = 0;
    int selectedCount = mSelectedCollection.count();
    for (int i = 0; i < selectedCount; i++) {
        Item item = mSelectedCollection.asList().get(i);
        if(item.isImage()){
            float size = PhotoMetadataUtils.getSizeInMB(item.size);
            if (size > mSpec.originalMaxSize) {
                count++;
            }
        }
    }
    return count;
}
 
Example #5
Source File: BasePreviewActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
protected void updateSize(Item item) {
    if (item.isGif()) {
        mSize.setVisibility(View.VISIBLE);
        mSize.setText(PhotoMetadataUtils.getSizeInMB(item.size) + "M");
    } else {
        mSize.setVisibility(View.GONE);
    }
}
 
Example #6
Source File: PreviewItemFragment.java    From Matisse with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Item item = getArguments().getParcelable(ARGS_ITEM);
    if (item == null) {
        return;
    }

    View videoPlayButton = view.findViewById(R.id.video_play_button);
    if (item.isVideo()) {
        videoPlayButton.setVisibility(View.VISIBLE);
        videoPlayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(item.uri, "video/*");
                try {
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(getContext(), R.string.error_no_video_activity, Toast.LENGTH_SHORT).show();
                }
            }
        });
    } else {
        videoPlayButton.setVisibility(View.GONE);
    }

    ImageViewTouch image = (ImageViewTouch) view.findViewById(R.id.image_view);
    image.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);

    Point size = PhotoMetadataUtils.getBitmapSize(item.getContentUri(), getActivity());
    if (item.isGif()) {
        SelectionSpec.getInstance().imageEngine.loadGifImage(getContext(), size.x, size.y, image,
                item.getContentUri());
    } else {
        SelectionSpec.getInstance().imageEngine.loadImage(getContext(), size.x, size.y, image,
                item.getContentUri());
    }
}
 
Example #7
Source File: GifSizeFilter.java    From Matisse with Apache License 2.0 5 votes vote down vote up
@Override
public IncapableCause filter(Context context, Item item) {
    if (!needFiltering(context, item))
        return null;

    Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri());
    if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) {
        return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth,
                String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize))));
    }
    return null;
}
 
Example #8
Source File: MatisseActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private int countOverMaxSize() {
    int count = 0;
    int selectedCount = mSelectedCollection.count();
    for (int i = 0; i < selectedCount; i++) {
        Item item = mSelectedCollection.asList().get(i);

        if (item.isImage()) {
            float size = PhotoMetadataUtils.getSizeInMB(item.size);
            if (size > mSpec.originalMaxSize) {
                count++;
            }
        }
    }
    return count;
}
 
Example #9
Source File: BasePreviewActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private int countOverMaxSize() {
    int count = 0;
    int selectedCount = mSelectedCollection.count();
    for (int i = 0; i < selectedCount; i++) {
        Item item = mSelectedCollection.asList().get(i);
        if (item.isImage()) {
            float size = PhotoMetadataUtils.getSizeInMB(item.size);
            if (size > mSpec.originalMaxSize) {
                count++;
            }
        }
    }
    return count;
}
 
Example #10
Source File: BasePreviewActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
protected void updateSize(Item item) {
    if (item.isGif()) {
        mSize.setVisibility(View.VISIBLE);
        mSize.setText(PhotoMetadataUtils.getSizeInMB(item.size) + "M");
    } else {
        mSize.setVisibility(View.GONE);
    }

    if (item.isVideo()) {
        mOriginalLayout.setVisibility(View.GONE);
    } else if (mSpec.originalable) {
        mOriginalLayout.setVisibility(View.VISIBLE);
    }
}
 
Example #11
Source File: GifSizeFilter.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public IncapableCause filter(Context context, Item item) {
    if (!needFiltering(context, item))
        return null;

    Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri());
    if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) {
        return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth,
                String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize))));
    }
    return null;
}
 
Example #12
Source File: PreviewItemFragment.java    From Matisse with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Item item = getArguments().getParcelable(ARGS_ITEM);
    if (item == null) {
        return;
    }

    View videoPlayButton = view.findViewById(R.id.video_play_button);
    if (item.isVideo()) {
        videoPlayButton.setVisibility(View.VISIBLE);
        videoPlayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(item.uri, "video/*");
                try {
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(getContext(), R.string.error_no_video_activity, Toast.LENGTH_SHORT).show();
                }
            }
        });
    } else {
        videoPlayButton.setVisibility(View.GONE);
    }

    ImageViewTouch image = (ImageViewTouch) view.findViewById(R.id.image_view);
    image.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);

    image.setSingleTapListener(new ImageViewTouch.OnImageViewTouchSingleTapListener() {
        @Override
        public void onSingleTapConfirmed() {
            if (mListener != null) {
                mListener.onClick();
            }
        }
    });

    Point size = PhotoMetadataUtils.getBitmapSize(item.getContentUri(), getActivity());
    if (item.isGif()) {
        SelectionSpec.getInstance().imageEngine.loadGifImage(getContext(), size.x, size.y, image,
                item.getContentUri());
    } else {
        SelectionSpec.getInstance().imageEngine.loadImage(getContext(), size.x, size.y, image,
                item.getContentUri());
    }
}