Search in sources :

Example 6 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 7 with ImageItem

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

the class ImageGridActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        if (resultCode == ImagePicker.RESULT_CODE_BACK) {
            isOrigin = data.getBooleanExtra(ImagePreviewActivity.ISORIGIN, false);
        } else {
            //点击 X , 没有选择照片
            if (data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS) == null) {
            //什么都不做 直接调起相机
            } else {
                //说明是从裁剪页面过来的数据,直接返回就可以
                setResult(ImagePicker.RESULT_CODE_ITEMS, data);
            }
            finish();
        }
    } else {
        //如果是裁剪,因为裁剪指定了存储的Uri,所以返回的data一定为null
        if (resultCode == RESULT_OK && requestCode == ImagePicker.REQUEST_CODE_TAKE) {
            //发送广播通知图片增加了
            ImagePicker.galleryAddPic(this, imagePicker.getTakeImageFile());
            ImageItem imageItem = new ImageItem();
            imageItem.path = imagePicker.getTakeImageFile().getAbsolutePath();
            imagePicker.clearSelectedImages();
            imagePicker.addSelectedImageItem(0, imageItem, true);
            if (imagePicker.isCrop()) {
                Intent intent = new Intent(ImageGridActivity.this, ImageCropActivity.class);
                //单选需要裁剪,进入裁剪界面
                startActivityForResult(intent, ImagePicker.REQUEST_CODE_CROP);
            } else {
                Intent intent = new Intent();
                intent.putExtra(ImagePicker.EXTRA_RESULT_ITEMS, imagePicker.getSelectedImages());
                //单选不需要裁剪,返回数据
                setResult(ImagePicker.RESULT_CODE_ITEMS, intent);
                finish();
            }
        }
        if (directPhoto) {
            finish();
        }
    }
}
Also used : Intent(android.content.Intent) ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 8 with ImageItem

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

the class ImagePreviewActivity method onImageSelected.

/**
     * 图片添加成功后,修改当前图片的选中数量
     * 当调用 addSelectedImageItem 或 deleteSelectedImageItem 都会触发当前回调
     */
@Override
public void onImageSelected(int position, ImageItem item, boolean isAdd) {
    if (imagePicker.getSelectImageCount() > 0) {
        mBtnOk.setText(getString(R.string.select_complete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
        mBtnOk.setEnabled(true);
    } else {
        mBtnOk.setText(getString(R.string.complete));
        mBtnOk.setEnabled(false);
    }
    if (mCbOrigin.isChecked()) {
        long size = 0;
        for (ImageItem imageItem : selectedImages) size += imageItem.size;
        String fileSize = Formatter.formatFileSize(this, size);
        mCbOrigin.setText(getString(R.string.origin_size, fileSize));
    }
}
Also used : ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 9 with ImageItem

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

the class ImagePreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isOrigin = getIntent().getBooleanExtra(ImagePreviewActivity.ISORIGIN, false);
    imagePicker.addOnImageSelectedListener(this);
    mBtnOk = (Button) topBar.findViewById(R.id.btn_ok);
    mBtnOk.setVisibility(View.VISIBLE);
    mBtnOk.setOnClickListener(this);
    bottomBar = findViewById(R.id.bottom_bar);
    bottomBar.setVisibility(View.VISIBLE);
    mCbCheck = (SuperCheckBox) findViewById(R.id.cb_check);
    mCbOrigin = (SuperCheckBox) findViewById(R.id.cb_origin);
    mCbOrigin.setText(getString(R.string.origin));
    mCbOrigin.setOnCheckedChangeListener(this);
    mCbOrigin.setChecked(isOrigin);
    //初始化当前页面的状态
    onImageSelected(0, null, false);
    ImageItem item = mImageItems.get(mCurrentPosition);
    boolean isSelected = imagePicker.isSelect(item);
    mTitleCount.setText(getString(R.string.preview_image_count, mCurrentPosition + 1, mImageItems.size()));
    mCbCheck.setChecked(isSelected);
    //滑动ViewPager的时候,根据外界的数据改变当前的选中状态和当前的图片的位置描述文本
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            mCurrentPosition = position;
            ImageItem item = mImageItems.get(mCurrentPosition);
            boolean isSelected = imagePicker.isSelect(item);
            mCbCheck.setChecked(isSelected);
            mTitleCount.setText(getString(R.string.preview_image_count, mCurrentPosition + 1, mImageItems.size()));
        }
    });
    //当点击当前选中按钮的时候,需要根据当前的选中状态添加和移除图片
    mCbCheck.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ImageItem imageItem = mImageItems.get(mCurrentPosition);
            int selectLimit = imagePicker.getSelectLimit();
            if (mCbCheck.isChecked() && selectedImages.size() >= selectLimit) {
                Toast.makeText(ImagePreviewActivity.this, ImagePreviewActivity.this.getString(R.string.select_limit, selectLimit), Toast.LENGTH_SHORT).show();
                mCbCheck.setChecked(false);
            } else {
                imagePicker.addSelectedImageItem(mCurrentPosition, imageItem, mCbCheck.isChecked());
            }
        }
    });
}
Also used : ImageItem(com.lzy.imagepicker.bean.ImageItem) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Example 10 with ImageItem

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

the class ImagePreviewActivity method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    int id = buttonView.getId();
    if (id == R.id.cb_origin) {
        if (isChecked) {
            long size = 0;
            for (ImageItem item : selectedImages) size += item.size;
            String fileSize = Formatter.formatFileSize(this, size);
            isOrigin = true;
            mCbOrigin.setText(getString(R.string.origin_size, fileSize));
        } else {
            isOrigin = false;
            mCbOrigin.setText(getString(R.string.origin));
        }
    }
}
Also used : ImageItem(com.lzy.imagepicker.bean.ImageItem)

Aggregations

ImageItem (com.lzy.imagepicker.bean.ImageItem)15 ArrayList (java.util.ArrayList)5 View (android.view.View)4 Intent (android.content.Intent)3 ParseManager (com.benmu.framework.manager.impl.ParseManager)2 File (java.io.File)2 Bitmap (android.graphics.Bitmap)1 ViewPager (android.support.v4.view.ViewPager)1 AbsListView (android.widget.AbsListView)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 ImagePageAdapter (com.lzy.imagepicker.adapter.ImagePageAdapter)1 ImageFolder (com.lzy.imagepicker.bean.ImageFolder)1 ImageBaseActivity (com.lzy.imagepicker.ui.ImageBaseActivity)1