Search in sources :

Example 1 with ImageRecyclerAdapter

use of com.lzy.imagepicker.adapter.ImageRecyclerAdapter 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)

Aggregations

Intent (android.content.Intent)1 ImageDataSource (com.lzy.imagepicker.ImageDataSource)1 ImageFolderAdapter (com.lzy.imagepicker.adapter.ImageFolderAdapter)1 ImageRecyclerAdapter (com.lzy.imagepicker.adapter.ImageRecyclerAdapter)1 ImageItem (com.lzy.imagepicker.bean.ImageItem)1 ArrayList (java.util.ArrayList)1