Search in sources :

Example 1 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.

the class ImageGridAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    int itemViewType = getItemViewType(position);
    if (itemViewType == ITEM_TYPE_CAMERA) {
        convertView = LayoutInflater.from(mActivity).inflate(R.layout.adapter_camera_item, parent, false);
        //让图片是个正方形
        convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mImageSize));
        convertView.setTag(null);
        convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (!((ImageBaseActivity) mActivity).checkPermission(Manifest.permission.CAMERA)) {
                    ActivityCompat.requestPermissions(mActivity, new String[] { Manifest.permission.CAMERA }, ImageGridActivity.REQUEST_PERMISSION_CAMERA);
                } else {
                    imagePicker.takePicture(mActivity, ImagePicker.REQUEST_CODE_TAKE);
                }
            }
        });
    } else {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mActivity).inflate(R.layout.adapter_image_list_item, parent, false);
            //让图片是个正方形
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mImageSize));
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final ImageItem imageItem = getItem(position);
        holder.ivThumb.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.onImageItemClick(holder.rootView, imageItem, position);
            }
        });
        holder.cbCheck.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int selectLimit = imagePicker.getSelectLimit();
                if (holder.cbCheck.isChecked() && mSelectedImages.size() >= selectLimit) {
                    Toast.makeText(mActivity.getApplicationContext(), mActivity.getString(R.string.select_limit, selectLimit), Toast.LENGTH_SHORT).show();
                    holder.cbCheck.setChecked(false);
                    holder.mask.setVisibility(View.GONE);
                } else {
                    imagePicker.addSelectedImageItem(position, imageItem, holder.cbCheck.isChecked());
                    holder.mask.setVisibility(View.VISIBLE);
                }
            }
        });
        //根据是否多选,显示或隐藏checkbox
        if (imagePicker.isMultiMode()) {
            holder.cbCheck.setVisibility(View.VISIBLE);
            boolean checked = mSelectedImages.contains(imageItem);
            if (checked) {
                holder.mask.setVisibility(View.VISIBLE);
                holder.cbCheck.setChecked(true);
            } else {
                holder.mask.setVisibility(View.GONE);
                holder.cbCheck.setChecked(false);
            }
        } else {
            holder.cbCheck.setVisibility(View.GONE);
        }
        //显示图片
        imagePicker.getImageLoader().displayImage(mActivity, imageItem.path, holder.ivThumb, mImageSize, mImageSize);
    }
    return convertView;
}
Also used : AbsListView(android.widget.AbsListView) ImageItem(com.lzy.imagepicker.bean.ImageItem) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) ImageBaseActivity(com.lzy.imagepicker.ui.ImageBaseActivity)

Example 2 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project WeexErosFramework by bmfe.

the class DefaultImageAdapter method UpMultipleImageData.

public void UpMultipleImageData(Context context, ArrayList<ImageItem> items, UploadImageBean bean) {
    ModalManager.BmLoading.showLoading(context, null, false);
    ArrayList imagesFilrUrl = new ArrayList();
    if (items != null && items.size() > 0) {
        for (ImageItem item : items) {
            Bitmap bitmap = ImageUtil.getBitmap(item.path, context);
            // TODO 图片改为全路径
            String path = new File(FileManager.getTempFilePath(context), String.valueOf(SystemClock.currentThreadTimeMillis())).getAbsolutePath();
            String imageFileUrl = ImageUtil.zoomImage(context, bitmap, bean == null ? 0 : (int) bean.imageWidth, Constant.ImageConstants.BIGGESTWIDTH, path);
            imagesFilrUrl.add(imageFileUrl);
            bitmap.recycle();
        }
    }
    HashMap<String, String> uploadParams = null;
    HashMap<String, String> heads = null;
    if (bean != null) {
        String params = bean.params;
        ParseManager parseManager = ManagerFactory.getManagerService(ParseManager.class);
        uploadParams = parseManager.parseObject(params, HashMap.class);
        heads = parseManager.parseObject(bean.header, HashMap.class);
    }
    AxiosManager axiosManager = ManagerFactory.getManagerService(AxiosManager.class);
    String url = TextUtils.isEmpty(bean.url) ? Api.UPLOAD_URL : bean.url;
    axiosManager.upload(url, imagesFilrUrl, uploadParams, heads);
}
Also used : Bitmap(android.graphics.Bitmap) AxiosManager(com.benmu.framework.manager.impl.AxiosManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImageItem(com.lzy.imagepicker.bean.ImageItem) ParseManager(com.benmu.framework.manager.impl.ParseManager) File(java.io.File)

Example 3 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project WeexErosFramework by bmfe.

the class EventFetch method uploadImage.

public void uploadImage(String json, Context context, JSCallback jsCallback) {
    mUploadAvatar = jsCallback;
    mUploadContext = context;
    UploadImageBean bean = ManagerFactory.getManagerService(ParseManager.class).parseObject(json, UploadImageBean.class);
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().register(this);
    ImageManager imageManager = ManagerFactory.getManagerService(ImageManager.class);
    ArrayList<ImageItem> items = new ArrayList<>();
    if (bean.images == null || bean.images.size() == 0) {
        Toast.makeText(context, "没传递上传的图片~", Toast.LENGTH_SHORT).show();
        return;
    }
    for (String path : bean.images) {
        ImageItem item = new ImageItem();
        item.path = path;
        items.add(item);
    }
    imageManager.UpMultipleImageData(context, items, bean);
}
Also used : UploadImageBean(com.benmu.framework.model.UploadImageBean) ArrayList(java.util.ArrayList) ImageItem(com.lzy.imagepicker.bean.ImageItem) ParseManager(com.benmu.framework.manager.impl.ParseManager) ImageManager(com.benmu.framework.manager.impl.ImageManager)

Example 4 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project WeexErosFramework by bmfe.

the class AbstractWeexActivity method pickReturn.

/**
 * 选择图片结果返回。
 */
private void pickReturn(ArrayList<ImageItem> items) {
    UploadResultBean bean = new UploadResultBean();
    List<String> data = new ArrayList<>();
    for (ImageItem path : items) {
        data.add(path.path);
    }
    bean.data = data;
    ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(bean);
}
Also used : ArrayList(java.util.ArrayList) UploadResultBean(com.benmu.framework.model.UploadResultBean) ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 5 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project okhttp-OkGo by jeasonlzy.

the class UploadAdapter method updateData.

public List<UploadTask<?>> updateData(List<ImageItem> images) {
    this.type = -1;
    this.images = images;
    values = new ArrayList<>();
    if (images != null) {
        Random random = new Random();
        for (int i = 0; i < images.size(); i++) {
            ImageItem imageItem = images.get(i);
            // 这里是演示可以传递任何数据
            PostRequest<String> postRequest = // 
            OkGo.<String>post(Urls.URL_FORM_UPLOAD).headers("aaa", // 
            "111").params("bbb", // 
            "222").params("fileKey" + i, // 
            new File(imageItem.path)).converter(new StringConvert());
            UploadTask<String> task = // 
            OkUpload.request(imageItem.path, postRequest).priority(// 
            random.nextInt(100)).extra1(// 
            imageItem).save();
            values.add(task);
        }
    }
    notifyDataSetChanged();
    return values;
}
Also used : StringConvert(com.lzy.okgo.convert.StringConvert) Random(java.util.Random) ImageItem(com.lzy.imagepicker.bean.ImageItem) File(java.io.File)

Aggregations

ImageItem (com.lzy.imagepicker.bean.ImageItem)18 ArrayList (java.util.ArrayList)7 Intent (android.content.Intent)5 View (android.view.View)5 File (java.io.File)3 ParseManager (com.benmu.framework.manager.impl.ParseManager)2 Bitmap (android.graphics.Bitmap)1 ViewPager (android.support.v4.view.ViewPager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 AxiosManager (com.benmu.framework.manager.impl.AxiosManager)1 ImageManager (com.benmu.framework.manager.impl.ImageManager)1 UploadImageBean (com.benmu.framework.model.UploadImageBean)1 UploadResultBean (com.benmu.framework.model.UploadResultBean)1 IntentResult (com.google.zxing.integration.android.IntentResult)1 ImageDataSource (com.lzy.imagepicker.ImageDataSource)1