Java Code Examples for com.zhihu.matisse.internal.entity.Item#isVideo()

The following examples show how to use com.zhihu.matisse.internal.entity.Item#isVideo() . 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 boolean add(Item item) {
    if (typeConflict(item)) {
        throw new IllegalArgumentException("Can't select images and videos at the same time.");
    }
    boolean added = mItems.add(item);
    if (added) {
        if (mCollectionType == COLLECTION_UNDEFINED) {
            if (item.isImage()) {
                mCollectionType = COLLECTION_IMAGE;
            } else if (item.isVideo()) {
                mCollectionType = COLLECTION_VIDEO;
            }
        } else if (mCollectionType == COLLECTION_IMAGE) {
            if (item.isVideo()) {
                mCollectionType = COLLECTION_MIXED;
            }
        } else if (mCollectionType == COLLECTION_VIDEO) {
            if (item.isImage()) {
                mCollectionType = COLLECTION_MIXED;
            }
        }
    }
    return added;
}
 
Example 2
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 6 votes vote down vote up
public boolean add(Item item) {
    if (typeConflict(item)) {
        throw new IllegalArgumentException("Can't select images and videos at the same time.");
    }
    boolean added = mItems.add(item);
    if (added) {
        if (mCollectionType == COLLECTION_UNDEFINED) {
            if (item.isImage()) {
                mCollectionType = COLLECTION_IMAGE;
            } else if (item.isVideo()) {
                mCollectionType = COLLECTION_VIDEO;
            }
        } else if (mCollectionType == COLLECTION_IMAGE) {
            if (item.isVideo()) {
                mCollectionType = COLLECTION_MIXED;
            }
        } else if (mCollectionType == COLLECTION_VIDEO) {
            if (item.isImage()) {
                mCollectionType = COLLECTION_MIXED;
            }
        }
    }
    return added;
}
 
Example 3
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private void refineCollectionType() {
    boolean hasImage = false;
    boolean hasVideo = false;
    for (Item i : mItems) {
        if (i.isImage() && !hasImage) hasImage = true;
        if (i.isVideo() && !hasVideo) hasVideo = true;
    }
    if (hasImage && hasVideo) {
        mCollectionType = COLLECTION_MIXED;
    } else if (hasImage) {
        mCollectionType = COLLECTION_IMAGE;
    } else if (hasVideo) {
        mCollectionType = COLLECTION_VIDEO;
    }
}
 
Example 4
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 5
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private void refineCollectionType() {
    boolean hasImage = false;
    boolean hasVideo = false;
    for (Item i : mItems) {
        if (i.isImage() && !hasImage) hasImage = true;
        if (i.isVideo() && !hasVideo) hasVideo = true;
    }
    if (hasImage && hasVideo) {
        mCollectionType = COLLECTION_MIXED;
    } else if (hasImage) {
        mCollectionType = COLLECTION_IMAGE;
    } else if (hasVideo) {
        mCollectionType = COLLECTION_VIDEO;
    }
}
 
Example 6
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 7
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 4 votes vote down vote up
/**
 * Determine whether there will be conflict media types. A user can only select images and videos at the same time
 * while {@link SelectionSpec#mediaTypeExclusive} is set to false.
 */
public boolean typeConflict(Item item) {
    return SelectionSpec.getInstance().mediaTypeExclusive
            && ((item.isImage() && (mCollectionType == COLLECTION_VIDEO || mCollectionType == COLLECTION_MIXED))
            || (item.isVideo() && (mCollectionType == COLLECTION_IMAGE || mCollectionType == COLLECTION_MIXED)));
}
 
Example 8
Source File: SelectedItemCollection.java    From Matisse with Apache License 2.0 4 votes vote down vote up
/**
 * Determine whether there will be conflict media types. A user can only select images and videos at the same time
 * while {@link SelectionSpec#mediaTypeExclusive} is set to false.
 */
public boolean typeConflict(Item item) {
    return SelectionSpec.getInstance().mediaTypeExclusive
            && ((item.isImage() && (mCollectionType == COLLECTION_VIDEO || mCollectionType == COLLECTION_MIXED))
            || (item.isVideo() && (mCollectionType == COLLECTION_IMAGE || mCollectionType == COLLECTION_MIXED)));
}
 
Example 9
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());
    }
}