Search in sources :

Example 11 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

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.getApplicationContext(), 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.getApplicationContext(), str, Toast.LENGTH_LONG).show();
        return;
    }
    if (isChecked) {
        for (LocalMedia media : selectImages) {
            if (media.getPath().equals(image.getPath())) {
                selectImages.remove(media);
                subSelectPosition();
                disZoom(contentHolder.iv_picture);
                break;
            }
        }
    } else {
        // 如果是单选,则清空已选中的并刷新列表(作单一选择)
        if (selectMode == PictureConfig.SINGLE) {
            singleRadioMediaImage();
        }
        selectImages.add(image);
        image.setNum(selectImages.size());
        VoiceUtils.playVoice(context, enableVoice);
        zoom(contentHolder.iv_picture);
    }
    // 通知点击项发生了改变
    notifyItemChanged(contentHolder.getAdapterPosition());
    selectImage(contentHolder, !isChecked, true);
    if (imageSelectChangedListener != null) {
        imageSelectChangedListener.onChange(selectImages);
    }
}
Also used : LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 12 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class PictureImageGridAdapter method bindSelectImages.

public void bindSelectImages(List<LocalMedia> images) {
    // 这里重新构构造一个新集合,不然会产生已选集合一变,结果集合也会添加的问题
    List<LocalMedia> selection = new ArrayList<>();
    for (LocalMedia media : images) {
        selection.add(media);
    }
    this.selectImages = selection;
    subSelectPosition();
    if (imageSelectChangedListener != null) {
        imageSelectChangedListener.onChange(selectImages);
    }
}
Also used : ArrayList(java.util.ArrayList) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 13 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class PictureImageGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    if (getItemViewType(position) == PictureConfig.TYPE_CAMERA) {
        HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
        headerHolder.headerView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (imageSelectChangedListener != null) {
                    imageSelectChangedListener.onTakePhoto();
                }
            }
        });
    } else {
        final ViewHolder contentHolder = (ViewHolder) holder;
        final LocalMedia image = images.get(showCamera ? position - 1 : position);
        image.position = contentHolder.getAdapterPosition();
        final String path = image.getPath();
        final String pictureType = image.getPictureType();
        if (is_checked_num) {
            notifyCheckChanged(contentHolder, image);
        }
        selectImage(contentHolder, isSelected(image), false);
        final int mediaMimeType = PictureMimeType.isPictureType(pictureType);
        boolean gif = PictureMimeType.isGif(pictureType);
        contentHolder.tv_isGif.setVisibility(gif ? View.VISIBLE : View.GONE);
        if (mimeType == PictureMimeType.ofAudio()) {
            contentHolder.tv_duration.setVisibility(View.VISIBLE);
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.picture_audio);
            StringUtils.modifyTextViewDrawable(contentHolder.tv_duration, drawable, 0);
        } else {
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.video_icon);
            StringUtils.modifyTextViewDrawable(contentHolder.tv_duration, drawable, 0);
            contentHolder.tv_duration.setVisibility(mediaMimeType == PictureConfig.TYPE_VIDEO ? View.VISIBLE : View.GONE);
        }
        boolean eqLongImg = PictureMimeType.isLongImg(image);
        contentHolder.tv_long_chart.setVisibility(eqLongImg ? View.VISIBLE : View.GONE);
        long duration = image.getDuration();
        contentHolder.tv_duration.setText(DateUtils.timeParse(duration));
        if (mimeType == PictureMimeType.ofAudio()) {
            contentHolder.iv_picture.setImageResource(R.drawable.audio_placeholder);
        } else {
            RequestOptions options = new RequestOptions();
            if (overrideWidth <= 0 && overrideHeight <= 0) {
                options.sizeMultiplier(sizeMultiplier);
            } else {
                options.override(overrideWidth, overrideHeight);
            }
            options.diskCacheStrategy(DiskCacheStrategy.ALL);
            options.centerCrop();
            options.placeholder(R.drawable.image_placeholder);
            Glide.with(context).asBitmap().load(path).apply(options).into(contentHolder.iv_picture);
        }
        if (enablePreview || enablePreviewVideo || enablePreviewAudio) {
            contentHolder.ll_check.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // 如原图路径不存在或者路径存在但文件不存在
                    if (!new File(path).exists()) {
                        Toast.makeText(context.getApplicationContext(), context.getString(R.string.picture_error), Toast.LENGTH_LONG).show();
                        return;
                    }
                    changeCheckboxState(contentHolder, image);
                }
            });
        }
        contentHolder.contentView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // 如原图路径不存在或者路径存在但文件不存在
                if (!new File(path).exists()) {
                    Toast.makeText(context.getApplicationContext(), context.getString(R.string.picture_error), Toast.LENGTH_LONG).show();
                    return;
                }
                int index = showCamera ? position - 1 : position;
                boolean eqResult = mediaMimeType == PictureConfig.TYPE_IMAGE && enablePreview || mediaMimeType == PictureConfig.TYPE_VIDEO && (enablePreviewVideo || selectMode == PictureConfig.SINGLE) || mediaMimeType == PictureConfig.TYPE_AUDIO && (enablePreviewAudio || selectMode == PictureConfig.SINGLE);
                if (eqResult) {
                    imageSelectChangedListener.onPictureClick(image, index);
                } else {
                    changeCheckboxState(contentHolder, image);
                }
            }
        });
    }
}
Also used : RequestOptions(vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) File(java.io.File)

Example 14 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class Luban method launch.

/**
 * start asynchronous compress thread
 */
@UiThread
private void launch(final Context context) {
    if (mPaths == null || mPaths.size() == 0 && mCompressListener != null) {
        mCompressListener.onError(new NullPointerException("image file cannot be null"));
    }
    Iterator<String> iterator = mPaths.iterator();
    // 当前压缩下标
    index = -1;
    while (iterator.hasNext()) {
        final String path = iterator.next();
        if (Checker.isImage(path)) {
            AsyncTask.SERIAL_EXECUTOR.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        index++;
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_START));
                        File result = Checker.isNeedCompress(mLeastCompressSize, path) ? new Engine(path, getImageCacheFile(context, Checker.checkSuffix(path))).compress() : new File(path);
                        if (medias != null && medias.size() > 0) {
                            LocalMedia media = medias.get(index);
                            String path = result.getAbsolutePath();
                            boolean eqHttp = PictureMimeType.isHttp(path);
                            media.setCompressed(eqHttp ? false : true);
                            media.setCompressPath(eqHttp ? "" : result.getAbsolutePath());
                            boolean isLast = index == medias.size() - 1;
                            if (isLast) {
                                mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_MULTIPLE_SUCCESS, medias));
                            }
                        } else {
                            mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, new IOException()));
                        }
                    } catch (IOException e) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, e));
                    }
                }
            });
        } else {
            mCompressListener.onError(new IllegalArgumentException("can not read the path : " + path));
        }
        iterator.remove();
    }
}
Also used : LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) IOException(java.io.IOException) File(java.io.File) UiThread(android.support.annotation.UiThread)

Example 15 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class weiuiPictureModule method picturePreview.

/**
 * 预览图片
 * @param position
 * @param array
 */
@JSMethod
public void picturePreview(int position, String array) {
    JSONArray lists = weiuiJson.parseArray(array);
    if (lists.size() == 0) {
        JSONObject tempJson = new JSONObject();
        tempJson.put("path", array);
        lists.add(tempJson);
    }
    // 
    List<LocalMedia> mediaLists = new ArrayList<>();
    for (int i = 0; i < lists.size(); i++) {
        JSONObject tempJson = weiuiJson.parseObject(lists.get(i));
        LocalMedia tempMedia = new LocalMedia();
        tempMedia.setPath(tempJson.getString("path"));
        mediaLists.add(tempMedia);
    }
    if (mediaLists.size() == 0) {
        return;
    }
    PictureSelector.create((Activity) mWXSDKInstance.getContext()).externalPicturePreview(position, mediaLists);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) PageActivity(vip.kuaifan.weiui.PageActivity) Activity(android.app.Activity) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) JSMethod(com.taobao.weex.annotation.JSMethod)

Aggregations

LocalMedia (com.luck.picture.lib.weiui.library.entity.LocalMedia)24 ArrayList (java.util.ArrayList)8 File (java.io.File)4 Bundle (android.os.Bundle)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 EventEntity (com.luck.picture.lib.weiui.library.entity.EventEntity)3 Intent (android.content.Intent)2 TextView (android.widget.TextView)2 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 JSMethod (com.taobao.weex.annotation.JSMethod)2 List (java.util.List)2 RequestOptions (vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 UiThread (android.support.annotation.UiThread)1