com.zhihu.matisse.internal.entity.Item Java Examples
The following examples show how to use
com.zhihu.matisse.internal.entity.Item.
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 |
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: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 6 votes |
public void refreshSelection() { GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager(); int first = layoutManager.findFirstVisibleItemPosition(); int last = layoutManager.findLastVisibleItemPosition(); if (first == -1 || last == -1) { return; } Cursor cursor = getCursor(); for (int i = first; i <= last; i++) { RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first); if (holder instanceof MediaViewHolder) { if (cursor.moveToPosition(i)) { setCheckStatus(Item.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid); } } } }
Example #3
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 6 votes |
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 #4
Source File: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 6 votes |
private void updateSelectedItem(Item item, RecyclerView.ViewHolder holder) { if (mSelectionSpec.countable) { int checkedNum = mSelectedCollection.checkedNumOf(item); if (checkedNum == CheckView.UNCHECKED) { if (assertAddSelection(holder.itemView.getContext(), item)) { mSelectedCollection.add(item); notifyCheckStateChanged(); } } else { mSelectedCollection.remove(item); notifyCheckStateChanged(); } } else { if (mSelectedCollection.isSelected(item)) { mSelectedCollection.remove(item); notifyCheckStateChanged(); } else { if (assertAddSelection(holder.itemView.getContext(), item)) { mSelectedCollection.add(item); notifyCheckStateChanged(); } } } }
Example #5
Source File: AlbumPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override public void onAlbumMediaLoad(Cursor cursor) { List<Item> items = new ArrayList<>(); while (cursor.moveToNext()) { items.add(Item.valueOf(cursor)); } // cursor.close(); if (items.isEmpty()) { return; } PreviewPagerAdapter adapter = (PreviewPagerAdapter) mPager.getAdapter(); adapter.addAll(items); adapter.notifyDataSetChanged(); if (!mIsAlreadySetPosition) { //onAlbumMediaLoad is called many times.. mIsAlreadySetPosition = true; Item selected = getIntent().getParcelableExtra(EXTRA_ITEM); int selectedIndex = items.indexOf(selected); mPager.setCurrentItem(selectedIndex, false); mPreviousPos = selectedIndex; } }
Example #6
Source File: BasePreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override public void onClick(View v) { if (v.getId() == R.id.button_back) { onBackPressed(); } else if (v.getId() == R.id.button_apply) { Item item = mAdapter.getMediaItem(mPager.getCurrentItem()); if (mSpec.isCrop && mSpec.maxSelectable <= 1 && !item.mimeType.toLowerCase().contains("video")) { Intent intentCrop = new Intent(this, ImageCropActivity.class); intentCrop.putExtra(MatisseActivity.EXTRA_RESULT_SELECTION_PATH, PathUtils.getPath(this, item.getContentUri())); startActivityForResult(intentCrop, REQUEST_CODE_CROP); } else { sendBackResult(true); finish(); } } }
Example #7
Source File: AlbumPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!SelectionSpec.getInstance().hasInited) { setResult(RESULT_CANCELED); finish(); return; } mCollection.onCreate(this, this); Album album = getIntent().getParcelableExtra(EXTRA_ALBUM); mCollection.load(album); Item item = getIntent().getParcelableExtra(EXTRA_ITEM); if (mSpec.countable) { mCheckView.setCheckedNum(mSelectedCollection.checkedNumOf(item)); } else { mCheckView.setChecked(mSelectedCollection.isSelected(item)); } updateSize(item); }
Example #8
Source File: AlbumPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override public void onAlbumMediaLoad(Cursor cursor) { List<Item> items = new ArrayList<>(); while (cursor.moveToNext()) { items.add(Item.valueOf(cursor)); } PreviewPagerAdapter adapter = (PreviewPagerAdapter) mPager.getAdapter(); adapter.addAll(items); adapter.notifyDataSetChanged(); if (!mIsAlreadySetPosition) { //onAlbumMediaLoad is called many times.. mIsAlreadySetPosition = true; Item selected = getIntent().getParcelableExtra(EXTRA_ITEM); int selectedIndex = items.indexOf(selected); mPager.setCurrentItem(selectedIndex, false); mPreviousPos = selectedIndex; } }
Example #9
Source File: SelectedPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getBundleExtra(EXTRA_DEFAULT_BUNDLE); List<Item> selected = bundle.getParcelableArrayList(SelectedItemCollection.STATE_SELECTION); mAdapter.addAll(selected); mAdapter.notifyDataSetChanged(); if (mSpec.countable) { mCheckView.setCheckedNum(1); } else { mCheckView.setChecked(true); } mPreviousPos = 0; updateSize(selected.get(0)); }
Example #10
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 6 votes |
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 #11
Source File: AlbumPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCollection.onCreate(this, this); Album album = getIntent().getParcelableExtra(EXTRA_ALBUM); mCollection.load(album); Item item = getIntent().getParcelableExtra(EXTRA_ITEM); if (mSpec.countable) { mCheckView.setCheckedNum(mSelectedCollection.checkedNumOf(item)); } else { mCheckView.setChecked(mSelectedCollection.isSelected(item)); } updateSize(item); }
Example #12
Source File: SelectedPreviewActivity.java From Matisse with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!SelectionSpec.getInstance().hasInited) { setResult(RESULT_CANCELED); finish(); return; } Bundle bundle = getIntent().getBundleExtra(EXTRA_DEFAULT_BUNDLE); List<Item> selected = bundle.getParcelableArrayList(SelectedItemCollection.STATE_SELECTION); mAdapter.addAll(selected); mAdapter.notifyDataSetChanged(); if (mSpec.countable) { mCheckView.setCheckedNum(1); } else { mCheckView.setChecked(true); } mPreviousPos = 0; updateSize(selected.get(0)); }
Example #13
Source File: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 6 votes |
public void refreshSelection() { GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager(); int first = layoutManager.findFirstVisibleItemPosition(); int last = layoutManager.findLastVisibleItemPosition(); if (first == -1 || last == -1) { return; } Cursor cursor = getCursor(); for (int i = first; i <= last; i++) { RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first); if (holder instanceof MediaViewHolder) { if (cursor.moveToPosition(i)) { setCheckStatus(Item.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid); } } } }
Example #14
Source File: GifSizeFilter.java From Matisse with Apache License 2.0 | 5 votes |
@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 #15
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 5 votes |
public void overwrite(ArrayList<Item> items, int collectionType) { if (items.size() == 0) { mCollectionType = COLLECTION_UNDEFINED; } else { mCollectionType = collectionType; } mItems.clear(); mItems.addAll(items); }
Example #16
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 5 votes |
public List<Uri> asListOfUri() { List<Uri> uris = new ArrayList<>(); for (Item item : mItems) { uris.add(item.getContentUri()); } return uris; }
Example #17
Source File: MediaSelectionFragment.java From Matisse with Apache License 2.0 | 5 votes |
@Override public void onMediaClick(Album album, Item item, int adapterPosition) { if (mOnMediaClickListener != null) { mOnMediaClickListener.onMediaClick((Album) getArguments().getParcelable(EXTRA_ALBUM), item, adapterPosition); } }
Example #18
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 5 votes |
public boolean remove(Item item) { boolean removed = mItems.remove(item); if (removed) { if (mItems.size() == 0) { mCollectionType = COLLECTION_UNDEFINED; } else { if (mCollectionType == COLLECTION_MIXED) { refineCollectionType(); } } } return removed; }
Example #19
Source File: MediaGrid.java From Matisse with Apache License 2.0 | 5 votes |
public void bindMedia(Item item) { mMedia = item; setGifTag(); initCheckView(); setImage(); setVideoDuration(); }
Example #20
Source File: BasePreviewActivity.java From Matisse with Apache License 2.0 | 5 votes |
@Override public void onPageSelected(int position) { PreviewPagerAdapter adapter = (PreviewPagerAdapter) mPager.getAdapter(); if (mPreviousPos != -1 && mPreviousPos != position) { ((PreviewItemFragment) adapter.instantiateItem(mPager, mPreviousPos)).resetView(); Item item = adapter.getMediaItem(position); if (mSpec.countable) { int checkedNum = mSelectedCollection.checkedNumOf(item); mCheckView.setCheckedNum(checkedNum); if (checkedNum > 0) { mCheckView.setEnabled(true); } else { mCheckView.setEnabled(!mSelectedCollection.maxSelectableReached()); } } else { boolean checked = mSelectedCollection.isSelected(item); mCheckView.setChecked(checked); if (checked) { mCheckView.setEnabled(true); } else { mCheckView.setEnabled(!mSelectedCollection.maxSelectableReached()); } } updateSize(item); } mPreviousPos = position; }
Example #21
Source File: MatisseActivity.java From Matisse with Apache License 2.0 | 5 votes |
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 #22
Source File: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 5 votes |
@Override public void onCheckViewClicked(CheckView checkView, Item item, RecyclerView.ViewHolder holder) { if (mSelectionSpec.countable) { int checkedNum = mSelectedCollection.checkedNumOf(item); if (checkedNum == CheckView.UNCHECKED) { if (assertAddSelection(holder.itemView.getContext(), item)) { mSelectedCollection.add(item); notifyCheckStateChanged(); } } else { mSelectedCollection.remove(item); notifyCheckStateChanged(); } } else { if (mSelectedCollection.isSelected(item)) { mSelectedCollection.remove(item); notifyCheckStateChanged(); } else { if (mSelectionSpec.maxSelectable <= 1) { mSelectedCollection.removeAll(); mSelectedCollection.add(item); notifyCheckStateChanged(); } else if (assertAddSelection(holder.itemView.getContext(), item)) { mSelectedCollection.add(item); notifyCheckStateChanged(); } } } }
Example #23
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 5 votes |
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 #24
Source File: SelectedItemCollection.java From Matisse with Apache License 2.0 | 5 votes |
public void onCreate(Bundle bundle) { if (bundle == null) { mItems = new LinkedHashSet<>(); } else { List<Item> saved = bundle.getParcelableArrayList(STATE_SELECTION); mItems = new LinkedHashSet<>(saved); mCollectionType = bundle.getInt(STATE_COLLECTION_TYPE, COLLECTION_UNDEFINED); } }
Example #25
Source File: BasePreviewActivity.java From Matisse with Apache License 2.0 | 5 votes |
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 #26
Source File: MediaSelectionFragment.java From Matisse with Apache License 2.0 | 5 votes |
@Override public void onMediaClick(Album album, Item item, int adapterPosition) { if (mOnMediaClickListener != null) { mOnMediaClickListener.onMediaClick((Album) getArguments().getParcelable(EXTRA_ALBUM), item, adapterPosition); } }
Example #27
Source File: BasePreviewActivity.java From Matisse with Apache License 2.0 | 5 votes |
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 #28
Source File: MediaGrid.java From Matisse with Apache License 2.0 | 5 votes |
public void bindMedia(Item item) { mMedia = item; setGifTag(); initCheckView(); setImage(); setVideoDuration(); }
Example #29
Source File: GifSizeFilter.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
@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 #30
Source File: AlbumMediaAdapter.java From Matisse with Apache License 2.0 | 5 votes |
private void setCheckStatus(Item item, MediaGrid mediaGrid) { if (mSelectionSpec.countable) { int checkedNum = mSelectedCollection.checkedNumOf(item); if (checkedNum > 0) { mediaGrid.setCheckEnabled(true); mediaGrid.setCheckedNum(checkedNum); } else { if (mSelectedCollection.maxSelectableReached()) { mediaGrid.setCheckEnabled(false); mediaGrid.setCheckedNum(CheckView.UNCHECKED); } else { mediaGrid.setCheckEnabled(true); mediaGrid.setCheckedNum(checkedNum); } } } else { boolean selected = mSelectedCollection.isSelected(item); if (selected) { mediaGrid.setCheckEnabled(true); mediaGrid.setChecked(true); } else { if (mSelectedCollection.maxSelectableReached()) { mediaGrid.setCheckEnabled(false); mediaGrid.setChecked(false); } else { mediaGrid.setCheckEnabled(true); mediaGrid.setChecked(false); } } } }