Search in sources :

Example 1 with Photo

use of io.github.wangeason.multiphotopicker.entity.Photo in project MultiPhotoPicker by wangeason.

the class PhotoPickerActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ImageCaptureManager.REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
        captureManager.galleryAddPic(null);
        //            MediaStoreHelper.setIsBlock(true);
        if (multiGridAdapter.getPhotoDirectories().size() > 0) {
            String path = captureManager.getCurrentPhotoPath();
            PhotoDirectory directory = multiGridAdapter.getPhotoDirectories().get(INDEX_ALL_PHOTOS);
            Photo newPhoto = new Photo(path.hashCode(), path);
            directory.getPhotos().add(INDEX_ALL_PHOTOS, newPhoto);
            directory.setCoverPath(path);
            for (PhotoDirectory item : multiGridAdapter.getPhotoDirectories()) {
                if (item.getName().equals(Environment.DIRECTORY_PICTURES)) {
                    item.getPhotos().add(INDEX_ALL_PHOTOS, newPhoto);
                    item.setCoverPath(path);
                    break;
                }
            }
            if (multiChoose) {
                if (multiGridAdapter.getSelectedItemCount() >= maxCount) {
                    Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                } else {
                    multiGridAdapter.add(newPhoto);
                }
            } else {
                if (maxCount <= 1) {
                    multiGridAdapter.clearSelection();
                    multiGridAdapter.add(newPhoto);
                } else {
                    if (multiGridAdapter.getSelectedItemCount() >= maxCount) {
                        Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                    } else {
                        multiGridAdapter.add(newPhoto);
                    }
                }
            }
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
            multiGridAdapter.notifyDataSetChanged();
            pickerFragment.getListAdapter().notifyDataSetChanged();
        }
    }
}
Also used : PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) Photo(io.github.wangeason.multiphotopicker.entity.Photo) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto)

Example 2 with Photo

use of io.github.wangeason.multiphotopicker.entity.Photo in project MultiPhotoPicker by wangeason.

the class PhotoPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
    multiChoose = getIntent().getBooleanExtra(EXTRA_MULTI_CHOOSE, false);
    setShowGif(showGif);
    setContentView(R.layout.activity_photo_picker);
    captureManager = new ImageCaptureManager(getActivity());
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.images);
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        actionBar.setElevation(25);
    }
    maxCount = getIntent().getIntExtra(EXTRA_MAX_COUNT, DEFAULT_MAX_COUNT);
    minCount = getIntent().getIntExtra(EXTRA_MIN_COUNT, DEFAULT_MIN_COUNT);
    btnDoneItem = (Button) findViewById(R.id.done);
    btnDoneItem.setText(getString(R.string.done_with_count, 0, maxCount));
    btnDoneItem.setEnabled(false);
    btnDoneItem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            ArrayList<String> selectedPhotos = pickerFragment.getPhotoGridAdapter().getSelectedPhotoPaths();
            if (selectedPhotos.size() >= minCount) {
                intent.putStringArrayListExtra(KEY_SELECTED_PHOTOS, selectedPhotos);
                setResult(RESULT_OK, intent);
                finish();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(PhotoPickerActivity.this);
                builder.setTitle(R.string.choose_more).setCancelable(true).setMessage(getString(R.string.min_count_tips, minCount)).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
            }
        }
    });
    final Button btSwitchDirectory = (Button) findViewById(R.id.button);
    pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentById(R.id.photoPickerFragment);
    final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setAnchorView(findViewById(R.id.ll_control));
    listPopupWindow.setAdapter(pickerFragment.getListAdapter());
    listPopupWindow.setModal(true);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    listPopupWindow.setAnimationStyle(R.style.Animation_AppCompat_DropDownUp);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            PhotoDirectory directory = pickerFragment.getDirectories().get(position);
            btSwitchDirectory.setText(directory.getName());
            pickerFragment.getPhotoGridAdapter().setCurrentDirectoryIndex(position);
            pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
        }
    });
    btSwitchDirectory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listPopupWindow.isShowing()) {
                listPopupWindow.dismiss();
            } else if (!getActivity().isFinishing()) {
                listPopupWindow.setHeight(Math.round(pickerFragment.getView().getHeight() * 0.8f));
                listPopupWindow.show();
            }
        }
    });
    multiGridAdapter = pickerFragment.getPhotoGridAdapter();
    multiGridAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, Photo photo, int selectedItemCount, int selectTimes) {
            if (multiChoose) {
                if (photo.getSelectedTimes() > 0) {
                    if (selectedItemCount >= maxCount) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                } else {
                    if (selectedItemCount >= maxCount) {
                        Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                }
            } else {
                if (maxCount <= 1) {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(0);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.clearSelection();
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        if (selectedItemCount >= maxCount) {
                            Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                        } else {
                            multiGridAdapter.add(photo);
                            multiGridAdapter.notifyItemChanged(position);
                        }
                    }
                }
            }
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
    selectedPhotoAdapter = new PhotoSelectedAdapter(getActivity(), multiGridAdapter.getSelectedPhotos());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.selected_photos);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(selectedPhotoAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    selectedPhotoAdapter.setOnSelectedItemClickListener(new OnSelectedItemClickListener() {

        @Override
        public void onClick(View v, int position) {
            if (selectedPagerFragment != null && selectedPagerFragment.isVisible()) {
                selectedPagerFragment.getViewPager().setCurrentItem(position);
            } else {
                List<String> photos = multiGridAdapter.getSelectedPhotoPaths();
                int[] screenLocation = new int[2];
                v.getLocationOnScreen(screenLocation);
                ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, position, screenLocation, v.getWidth(), v.getHeight());
                addImagePagerFragment(imagePagerFragment, true);
            }
        }
    });
    selectedPhotoAdapter.setOnSelectedItemDelListener(new OnSelectedItemDelListener() {

        @Override
        public void onClick(int position, MultiSelectedPhoto path) {
            multiGridAdapter.getSelectedPhotos().get(position).getPhoto().del();
            multiGridAdapter.getSelectedPhotos().remove(position);
            multiGridAdapter.notifyDataSetChanged();
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ImagePagerFragment(io.github.wangeason.multiphotopicker.fragment.ImagePagerFragment) Photo(io.github.wangeason.multiphotopicker.entity.Photo) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) PhotoSelectedAdapter(io.github.wangeason.multiphotopicker.adapter.PhotoSelectedAdapter) OnSelectedItemClickListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemClickListener) ArrayList(java.util.ArrayList) List(java.util.List) ImageCaptureManager(io.github.wangeason.multiphotopicker.utils.ImageCaptureManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) OnItemClickListener(io.github.wangeason.multiphotopicker.event.OnItemClickListener) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnSelectedItemDelListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemDelListener) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with Photo

use of io.github.wangeason.multiphotopicker.entity.Photo in project MultiPhotoPicker by wangeason.

the class PhotoDirectoryAsyncTask method onPostExecute.

@Override
protected void onPostExecute(Cursor data) {
    super.onPostExecute(data);
    if (data == null) {
        return;
    }
    List<PhotoDirectory> directories = new ArrayList<>();
    PhotoDirectory photoDirectoryAll = new PhotoDirectory();
    photoDirectoryAll.setName(mContext.getString(R.string.all_image));
    photoDirectoryAll.setId("ALL");
    while (data.moveToNext()) {
        int imageId = data.getInt(data.getColumnIndexOrThrow(_ID));
        String bucketId = data.getString(data.getColumnIndexOrThrow(BUCKET_ID));
        String name = data.getString(data.getColumnIndexOrThrow(BUCKET_DISPLAY_NAME));
        String path = data.getString(data.getColumnIndexOrThrow(DATA));
        PhotoDirectory photoDirectory = new PhotoDirectory();
        photoDirectory.setId(bucketId);
        photoDirectory.setName(name);
        Photo newPhoto = new Photo(imageId, path);
        if (!directories.contains(photoDirectory)) {
            photoDirectory.setCoverPath(path);
            photoDirectory.addPhoto(newPhoto);
            photoDirectory.setDateAdded(data.getLong(data.getColumnIndexOrThrow(DATE_ADDED)));
            directories.add(photoDirectory);
        } else {
            directories.get(directories.indexOf(photoDirectory)).addPhoto(newPhoto);
        }
        photoDirectoryAll.addPhoto(newPhoto);
    }
    if (photoDirectoryAll.getPhotoPaths().size() > 0) {
        photoDirectoryAll.setCoverPath(photoDirectoryAll.getPhotoPaths().get(0));
    }
    directories.add(PhotoPickerActivity.INDEX_ALL_PHOTOS, photoDirectoryAll);
    if (resultCallback != null) {
        resultCallback.onResultCallback(directories);
    }
}
Also used : PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) ArrayList(java.util.ArrayList) Photo(io.github.wangeason.multiphotopicker.entity.Photo)

Example 4 with Photo

use of io.github.wangeason.multiphotopicker.entity.Photo in project MultiPhotoPicker by wangeason.

the class PhotoMultiGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final PhotoViewHolder holder, final int position) {
    List<Photo> photos = getCurrentPhotos();
    final Photo photo = photos.get(position);
    Glide.with(mContext).load(new File(photo.getPath())).centerCrop().thumbnail(0.1f).placeholder(R.drawable.ic_photo_black_48dp).error(R.drawable.ic_broken_image_black_48dp).into(holder.ivPhoto);
    final int selectedTimes = photo.getSelectedTimes();
    Drawable mDrawable = mContext.getResources().getDrawable(R.drawable.photo_bg);
    if (selectedTimes > 0) {
        mDrawable.setColorFilter(new PorterDuffColorFilter(fetchAccentColor(), PorterDuff.Mode.MULTIPLY));
    }
    holder.ivPhoto.setBackgroundDrawable(mDrawable);
    holder.txtTimes.setVisibility(selectedTimes > 0 ? View.VISIBLE : View.INVISIBLE);
    holder.txtTimes.setBackgroundColor(fetchAccentColor());
    holder.txtTimes.setText("" + photo.getSelectedTimes());
    holder.ivPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(position, photo, getSelectedItemCount(), selectedTimes);
            }
        }
    });
    holder.vZoom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onZoomListener != null) {
                onZoomListener.onClick(view, position);
            }
        }
    });
}
Also used : Drawable(android.graphics.drawable.Drawable) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) Photo(io.github.wangeason.multiphotopicker.entity.Photo) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) File(java.io.File) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Photo (io.github.wangeason.multiphotopicker.entity.Photo)4 MultiSelectedPhoto (io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto)3 PhotoDirectory (io.github.wangeason.multiphotopicker.entity.PhotoDirectory)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ArrayList (java.util.ArrayList)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 Drawable (android.graphics.drawable.Drawable)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 Toolbar (android.support.v7.widget.Toolbar)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1