Search in sources :

Example 1 with Photo

use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.

the class PhotoPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    boolean showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
    boolean previewEnabled = getIntent().getBooleanExtra(EXTRA_PREVIEW_ENABLED, true);
    setShowGif(showGif);
    setContentView(R.layout.__picker_activity_photo_picker);
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    setTitle(R.string.__picker_title);
    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);
    int columnNumber = getIntent().getIntExtra(EXTRA_GRID_COLUMN, DEFAULT_COLUMN_NUMBER);
    originalPhotos = getIntent().getStringArrayListExtra(EXTRA_ORIGINAL_PHOTOS);
    pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentByTag("tag");
    if (pickerFragment == null) {
        pickerFragment = PhotoPickerFragment.newInstance(showCamera, showGif, previewEnabled, columnNumber, maxCount, originalPhotos);
        getSupportFragmentManager().beginTransaction().replace(R.id.container, pickerFragment, "tag").commit();
        getSupportFragmentManager().executePendingTransactions();
    }
    pickerFragment.getPhotoGridAdapter().setOnItemCheckListener(new OnItemCheckListener() {

        @Override
        public boolean onItemCheck(int position, Photo photo, final int selectedItemCount) {
            menuDoneItem.setEnabled(selectedItemCount > 0);
            if (maxCount <= 1) {
                List<String> photos = pickerFragment.getPhotoGridAdapter().getSelectedPhotos();
                if (!photos.contains(photo.getPath())) {
                    photos.clear();
                    pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
                }
                return true;
            }
            if (selectedItemCount > maxCount) {
                Toast.makeText(getActivity(), getString(R.string.__picker_over_max_count_tips, maxCount), LENGTH_LONG).show();
                return false;
            }
            if (maxCount > 1) {
                menuDoneItem.setTitle(getString(R.string.__picker_done_with_count, selectedItemCount, maxCount));
            } else {
                menuDoneItem.setTitle(getString(R.string.__picker_done));
            }
            return true;
        }
    });
}
Also used : Photo(me.iwf.photopicker.entity.Photo) ArrayList(java.util.ArrayList) List(java.util.List) ActionBar(android.support.v7.app.ActionBar) OnItemCheckListener(me.iwf.photopicker.event.OnItemCheckListener) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with Photo

use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.

the class PhotoGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final PhotoViewHolder holder, int position) {
    if (getItemViewType(position) == ITEM_TYPE_PHOTO) {
        List<Photo> photos = getCurrentPhotos();
        final Photo photo;
        if (showCamera()) {
            photo = photos.get(position - 1);
        } else {
            photo = photos.get(position);
        }
        boolean canLoadImage = AndroidLifecycleUtils.canLoadImage(holder.ivPhoto.getContext());
        if (canLoadImage) {
            final RequestOptions options = new RequestOptions();
            options.centerCrop().dontAnimate().override(imageSize, imageSize).placeholder(R.drawable.__picker_ic_photo_black_48dp).error(R.drawable.__picker_ic_broken_image_black_48dp);
            glide.setDefaultRequestOptions(options).load(new File(photo.getPath())).thumbnail(0.5f).into(holder.ivPhoto);
        }
        final boolean isChecked = isSelected(photo);
        holder.vSelected.setSelected(isChecked);
        holder.ivPhoto.setSelected(isChecked);
        holder.ivPhoto.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (onPhotoClickListener != null) {
                    int pos = holder.getAdapterPosition();
                    if (previewEnable) {
                        onPhotoClickListener.onClick(view, pos, showCamera());
                    } else {
                        holder.vSelected.performClick();
                    }
                }
            }
        });
        holder.vSelected.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int pos = holder.getAdapterPosition();
                boolean isEnable = true;
                if (onItemCheckListener != null) {
                    isEnable = onItemCheckListener.onItemCheck(pos, photo, getSelectedPhotos().size() + (isSelected(photo) ? -1 : 1));
                }
                if (isEnable) {
                    toggleSelection(photo);
                    notifyItemChanged(pos);
                }
            }
        });
    } else {
        holder.ivPhoto.setImageResource(R.drawable.__picker_camera);
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Photo(me.iwf.photopicker.entity.Photo) File(java.io.File) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 3 with Photo

use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.

the class PhotoPickerFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ImageCaptureManager.REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
        if (captureManager == null) {
            FragmentActivity activity = getActivity();
            captureManager = new ImageCaptureManager(activity);
        }
        captureManager.galleryAddPic();
        if (directories.size() > 0) {
            String path = captureManager.getCurrentPhotoPath();
            PhotoDirectory directory = directories.get(INDEX_ALL_PHOTOS);
            directory.getPhotos().add(INDEX_ALL_PHOTOS, new Photo(path.hashCode(), path));
            directory.setCoverPath(path);
            photoGridAdapter.notifyDataSetChanged();
        }
    }
}
Also used : PhotoDirectory(me.iwf.photopicker.entity.PhotoDirectory) FragmentActivity(android.support.v4.app.FragmentActivity) Photo(me.iwf.photopicker.entity.Photo) ImageCaptureManager(me.iwf.photopicker.utils.ImageCaptureManager)

Aggregations

Photo (me.iwf.photopicker.entity.Photo)3 FragmentActivity (android.support.v4.app.FragmentActivity)1 ActionBar (android.support.v7.app.ActionBar)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PhotoDirectory (me.iwf.photopicker.entity.PhotoDirectory)1 OnItemCheckListener (me.iwf.photopicker.event.OnItemCheckListener)1 ImageCaptureManager (me.iwf.photopicker.utils.ImageCaptureManager)1