Search in sources :

Example 16 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) 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);
    marginView = findViewById(R.id.margin_bottom);
    mCbOrigin.setText(getString(R.string.ip_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.ip_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.ip_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, getString(R.string.ip_select_limit, selectLimit), Toast.LENGTH_SHORT).show();
                mCbCheck.setChecked(false);
            } else {
                imagePicker.addSelectedImageItem(mCurrentPosition, imageItem, mCbCheck.isChecked());
            }
        }
    });
    NavigationBarChangeListener.with(this).setListener(new NavigationBarChangeListener.OnSoftInputStateChangeListener() {

        @Override
        public void onNavigationBarShow(int orientation, int height) {
            marginView.setVisibility(View.VISIBLE);
            ViewGroup.LayoutParams layoutParams = marginView.getLayoutParams();
            if (layoutParams.height == 0) {
                layoutParams.height = Utils.getNavigationBarHeight(ImagePreviewActivity.this);
                marginView.requestLayout();
            }
        }

        @Override
        public void onNavigationBarHide(int orientation) {
            marginView.setVisibility(View.GONE);
        }
    });
    NavigationBarChangeListener.with(this, NavigationBarChangeListener.ORIENTATION_HORIZONTAL).setListener(new NavigationBarChangeListener.OnSoftInputStateChangeListener() {

        @Override
        public void onNavigationBarShow(int orientation, int height) {
            topBar.setPadding(0, 0, height, 0);
            bottomBar.setPadding(0, 0, height, 0);
        }

        @Override
        public void onNavigationBarHide(int orientation) {
            topBar.setPadding(0, 0, 0, 0);
            bottomBar.setPadding(0, 0, 0, 0);
        }
    });
}
Also used : NavigationBarChangeListener(com.lzy.imagepicker.util.NavigationBarChangeListener) ImageItem(com.lzy.imagepicker.bean.ImageItem) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Example 17 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.ip_select_complete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
    } else {
        mBtnOk.setText(getString(R.string.ip_complete));
    }
    if (mCbOrigin.isChecked()) {
        long size = 0;
        for (ImageItem imageItem : selectedImages) size += imageItem.size;
        String fileSize = Formatter.formatFileSize(this, size);
        mCbOrigin.setText(getString(R.string.ip_origin_size, fileSize));
    }
}
Also used : ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 18 with ImageItem

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

the class ImageGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_grid);
    imagePicker = ImagePicker.getInstance();
    imagePicker.clear();
    imagePicker.addOnImageSelectedListener(this);
    Intent data = getIntent();
    // 新增可直接拍照
    if (data != null && data.getExtras() != null) {
        // 默认不是直接打开相机
        directPhoto = data.getBooleanExtra(EXTRAS_TAKE_PICKERS, false);
        if (directPhoto) {
            if (!(checkPermission(Manifest.permission.CAMERA))) {
                ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, ImageGridActivity.REQUEST_PERMISSION_CAMERA);
            } else {
                imagePicker.takePicture(this, ImagePicker.REQUEST_CODE_TAKE);
            }
        }
        ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(EXTRAS_IMAGES);
        imagePicker.setSelectedImages(images);
    }
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler);
    findViewById(R.id.btn_back).setOnClickListener(this);
    mBtnOk = (Button) findViewById(R.id.btn_ok);
    mBtnOk.setOnClickListener(this);
    mBtnPre = (TextView) findViewById(R.id.btn_preview);
    mBtnPre.setOnClickListener(this);
    mFooterBar = findViewById(R.id.footer_bar);
    mllDir = findViewById(R.id.ll_dir);
    mllDir.setOnClickListener(this);
    mtvDir = (TextView) findViewById(R.id.tv_dir);
    if (imagePicker.isMultiMode()) {
        mBtnOk.setVisibility(View.VISIBLE);
        mBtnPre.setVisibility(View.VISIBLE);
    } else {
        mBtnOk.setVisibility(View.GONE);
        mBtnPre.setVisibility(View.GONE);
    }
    // mImageGridAdapter = new ImageGridAdapter(this, null);
    mImageFolderAdapter = new ImageFolderAdapter(this, null);
    mRecyclerAdapter = new ImageRecyclerAdapter(this, null);
    onImageSelected(0, null, false);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        if (checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            new ImageDataSource(this, null, this);
        } else {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSION_STORAGE);
        }
    } else {
        new ImageDataSource(this, null, this);
    }
}
Also used : ImageDataSource(com.lzy.imagepicker.ImageDataSource) ImageRecyclerAdapter(com.lzy.imagepicker.adapter.ImageRecyclerAdapter) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageItem(com.lzy.imagepicker.bean.ImageItem) ImageFolderAdapter(com.lzy.imagepicker.adapter.ImageFolderAdapter)

Example 19 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 && data.getExtras() != 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());
            /**
             * 2017-03-21 对机型做旋转处理
             */
            String path = imagePicker.getTakeImageFile().getAbsolutePath();
            // int degree = BitmapUtil.getBitmapDegree(path);
            // if (degree != 0){
            // Bitmap bitmap = BitmapUtil.rotateBitmapByDegree(path,degree);
            // if (bitmap != null){
            // File file = new File(path);
            // try {
            // FileOutputStream bos = new FileOutputStream(file);
            // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            // bos.flush();
            // bos.close();
            // } catch (IOException e) {
            // e.printStackTrace();
            // }
            // }
            // }
            ImageItem imageItem = new ImageItem();
            imageItem.path = path;
            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();
            }
        } else if (directPhoto) {
            finish();
        }
    }
}
Also used : Intent(android.content.Intent) ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 20 with ImageItem

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

the class ImagePickerAdapter method setImages.

public void setImages(List<ImageItem> data) {
    mData = new ArrayList<>(data);
    if (getItemCount() < maxImgCount) {
        mData.add(new ImageItem());
        isAdded = true;
    } else {
        isAdded = false;
    }
    notifyDataSetChanged();
}
Also used : ImageItem(com.lzy.imagepicker.bean.ImageItem)

Aggregations

ImageItem (com.lzy.imagepicker.bean.ImageItem)22 ArrayList (java.util.ArrayList)11 Intent (android.content.Intent)5 View (android.view.View)5 File (java.io.File)4 Bitmap (android.graphics.Bitmap)2 ParseManager (com.benmu.framework.manager.impl.ParseManager)2 ParseManager (com.eros.framework.manager.impl.ParseManager)2 IntentResult (com.google.zxing.integration.android.IntentResult)2 HashMap (java.util.HashMap)2 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