Search in sources :

Example 11 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class ImageVideoPickActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imagepick);
    themeId = R.style.picture_default_style;
    minus = (ImageView) findViewById(R.id.minus);
    plus = (ImageView) findViewById(R.id.plus);
    tv_select_num = (TextView) findViewById(R.id.tv_select_num);
    rgb_style = (RadioGroup) findViewById(R.id.rgb_style);
    rgb_photo_mode = (RadioGroup) findViewById(R.id.rgb_photo_mode);
    rgb_compress = (RadioGroup) findViewById(R.id.rgb_compress);
    cb_voice = (CheckBox) findViewById(R.id.cb_voice);
    cb_choose_mode = (CheckBox) findViewById(R.id.cb_choose_mode);
    cb_isCamera = (CheckBox) findViewById(R.id.cb_isCamera);
    cb_isGif = (CheckBox) findViewById(R.id.cb_isGif);
    cb_preview_img = (CheckBox) findViewById(R.id.cb_preview_img);
    cb_preview_video = (CheckBox) findViewById(R.id.cb_preview_video);
    cb_compress = (CheckBox) findViewById(R.id.cb_compress);
    cb_mode = (CheckBox) findViewById(R.id.cb_mode);
    rgb_compress.setOnCheckedChangeListener(this);
    rgb_style.setOnCheckedChangeListener(this);
    rgb_photo_mode.setOnCheckedChangeListener(this);
    recyclerView = (RecyclerView) findViewById(R.id.recycler);
    left_back = (ImageView) findViewById(R.id.left_back);
    left_back.setOnClickListener(this);
    minus.setOnClickListener(this);
    plus.setOnClickListener(this);
    cb_compress.setOnCheckedChangeListener(this);
    FullyGridLayoutManager manager = new FullyGridLayoutManager(ImageVideoPickActivity.this, 4, GridLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(manager);
    adapter = new GridImageAdapter(ImageVideoPickActivity.this, onAddPicClickListener);
    adapter.setList(selectList);
    adapter.setSelectMax(maxSelectNum);
    recyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener(new GridImageAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View v) {
            if (selectList.size() > 0) {
                LocalMedia media = selectList.get(position);
                String pictureType = media.getPictureType();
                int mediaType = PictureMimeType.pictureToVideo(pictureType);
                switch(mediaType) {
                    case 1:
                        // 预览图片 可自定长按保存路径
                        // PictureSelector.create(ImageVideoPickActivity.this).externalPicturePreview(position, "/custom_file", selectList);
                        PictureSelector.create(ImageVideoPickActivity.this).externalPicturePreview(position, selectList);
                        break;
                    case 2:
                        // 预览视频
                        PictureSelector.create(ImageVideoPickActivity.this).externalPictureVideo(media.getPath());
                        break;
                }
            }
        }
    });
    // 清空图片缓存,包括裁剪、压缩后的图片 注意:必须要在上传完成后调用 必须要获取权限
    RxPermissions permissions = new RxPermissions(this);
    permissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Observer<Boolean>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Boolean aBoolean) {
            if (aBoolean) {
                PictureFileUtils.deleteCacheDirFile(ImageVideoPickActivity.this);
            } else {
                Toast.makeText(ImageVideoPickActivity.this, getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RxPermissions(com.ningcui.mylibrary.viewLib.Imagepicker.permissions.RxPermissions) GridImageAdapter(com.litingzhe.justandroid.someOther.imagePicker.adapter.GridImageAdapter) FullyGridLayoutManager(com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Example 12 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureSelectorActivity method startPreview.

/**
 * preview image and video
 *
 * @param previewImages
 * @param position
 */
public void startPreview(List<LocalMedia> previewImages, int position) {
    LocalMedia media = previewImages.get(position);
    String pictureType = media.getPictureType();
    Bundle bundle = new Bundle();
    List<LocalMedia> result;
    int mediaType = PictureMimeType.isPictureType(pictureType);
    DebugUtil.i(TAG, "mediaType:" + mediaType);
    switch(mediaType) {
        case PictureConfig.TYPE_IMAGE:
            // image
            if (selectionMode == PictureConfig.SINGLE) {
                result = new ArrayList<>();
                result.add(media);
                handlerResult(result);
            } else {
                List<LocalMedia> selectedImages = adapter.getSelectedImages();
                ImagesObservable.getInstance().saveLocalMedia(previewImages);
                bundle.putSerializable(PictureConfig.EXTRA_SELECT_LIST, (Serializable) selectedImages);
                bundle.putInt(PictureConfig.EXTRA_POSITION, position);
                startActivity(PicturePreviewActivity.class, bundle);
                overridePendingTransition(R.anim.a5, 0);
            }
            break;
        case PictureConfig.TYPE_VIDEO:
            // video
            if (selectionMode == PictureConfig.SINGLE) {
                result = new ArrayList<>();
                result.add(media);
                onResult(result);
            } else {
                bundle.putString("video_path", media.getPath());
                startActivity(PictureVideoPlayActivity.class, bundle);
            }
            break;
    }
}
Also used : Bundle(android.os.Bundle) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Example 13 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureSelectorActivity method onClick.

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.picture_left_back || id == R.id.picture_right) {
        if (folderWindow.isShowing()) {
            folderWindow.dismiss();
        } else {
            closeActivity();
        }
    }
    if (id == R.id.picture_title) {
        if (folderWindow.isShowing()) {
            folderWindow.dismiss();
        } else {
            if (images != null && images.size() > 0) {
                folderWindow.showAsDropDown(rl_picture_title);
                List<LocalMedia> selectedImages = adapter.getSelectedImages();
                folderWindow.notifyDataCheckedStatus(selectedImages);
            }
        }
    }
    if (id == R.id.picture_id_preview) {
        List<LocalMedia> selectedImages = adapter.getSelectedImages();
        List<LocalMedia> medias = new ArrayList<>();
        for (LocalMedia media : selectedImages) {
            medias.add(media);
        }
        Bundle bundle = new Bundle();
        bundle.putSerializable(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (Serializable) medias);
        bundle.putSerializable(PictureConfig.EXTRA_SELECT_LIST, (Serializable) selectedImages);
        bundle.putBoolean(PictureConfig.EXTRA_BOTTOM_PREVIEW, true);
        startActivity(PicturePreviewActivity.class, bundle);
        overridePendingTransition(R.anim.a5, 0);
    }
    if (id == R.id.id_ll_ok) {
        List<LocalMedia> images = adapter.getSelectedImages();
        String pictureType = images.size() > 0 ? images.get(0).getPictureType() : "";
        // 如果设置了图片最小选择数量,则判断是否满足条件
        int size = images.size();
        if (minSelectNum > 0 && selectionMode == PictureConfig.MULTIPLE) {
            if (size < minSelectNum) {
                boolean eqImg = pictureType.startsWith("image");
                String str = eqImg ? getString(R.string.picture_min_img_num, minSelectNum) : getString(R.string.picture_min_video_num, minSelectNum);
                showToast(str);
                return;
            }
        }
        boolean eqImg = pictureType.startsWith("image");
        if (isCompress && eqImg) {
            // 图片才压缩,视频不管
            compressImage(images);
        } else {
            onResult(images);
        }
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Example 14 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImageGridAdapter method changeCheckboxState.

/**
 * 改变图片选中状态
 *
 * @param contentHolder
 * @param image
 */
private void changeCheckboxState(ViewHolder contentHolder, LocalMedia image) {
    boolean isChecked = contentHolder.check.isSelected();
    String pictureType = selectImages.size() > 0 ? selectImages.get(0).getPictureType() : "";
    if (!TextUtils.isEmpty(pictureType)) {
        boolean toEqual = PictureMimeType.mimeToEqual(pictureType, image.getPictureType());
        if (!toEqual) {
            Toast.makeText(context, context.getString(R.string.picture_rule), Toast.LENGTH_LONG).show();
            return;
        }
    }
    if (selectImages.size() >= maxSelectNum && !isChecked) {
        boolean eqImg = pictureType.startsWith(PictureConfig.IMAGE);
        String str = eqImg ? context.getString(R.string.picture_message_max_num, maxSelectNum) : context.getString(R.string.picture_message_video_max_num, maxSelectNum);
        Toast.makeText(context, str, Toast.LENGTH_LONG).show();
        return;
    }
    if (isChecked) {
        for (LocalMedia media : selectImages) {
            if (media.getPath().equals(image.getPath())) {
                selectImages.remove(media);
                DebugUtil.i("selectImages remove::", config.selectionMedias.size() + "");
                subSelectPosition();
                break;
            }
        }
    } else {
        selectImages.add(image);
        DebugUtil.i("selectImages add::", config.selectionMedias.size() + "");
        image.setNum(selectImages.size());
        VoiceUtils.playVoice(context, enableVoice);
    }
    // 通知点击项发生了改变
    notifyItemChanged(contentHolder.getAdapterPosition());
    selectImage(contentHolder, !isChecked, true);
    if (imageSelectChangedListener != null) {
        imageSelectChangedListener.onChange(selectImages);
    }
}
Also used : LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Example 15 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImageGridAdapter method notifyCheckChanged.

/**
 * 选择按钮更新
 */
private void notifyCheckChanged(ViewHolder viewHolder, LocalMedia imageBean) {
    viewHolder.check.setText("");
    for (LocalMedia media : selectImages) {
        if (media.getPath().equals(imageBean.getPath())) {
            imageBean.setNum(media.getNum());
            media.setPosition(imageBean.getPosition());
            viewHolder.check.setText(String.valueOf(imageBean.getNum()));
        }
    }
}
Also used : LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Aggregations

LocalMedia (com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)18 View (android.view.View)4 RecyclerView (android.support.v7.widget.RecyclerView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 File (java.io.File)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 GridImageAdapter (com.litingzhe.justandroid.someOther.imagePicker.adapter.GridImageAdapter)1 FullyGridLayoutManager (com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager)1 LocalMediaFolder (com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMediaFolder)1 RxPermissions (com.ningcui.mylibrary.viewLib.Imagepicker.permissions.RxPermissions)1 Disposable (io.reactivex.disposables.Disposable)1 PhotoView (uk.co.senab.photoview.PhotoView)1 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)1