Search in sources :

Example 1 with FullyGridLayoutManager

use of com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager in project JustAndroid by chinaltz.

the class ImageVideoPickActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imagepick);
    themeId = R.style.picture_default_style;
    minus = (ImageView) findViewById(R.id.minus);
    plus = (ImageView) findViewById(R.id.plus);
    tv_select_num = (TextView) findViewById(R.id.tv_select_num);
    rgb_style = (RadioGroup) findViewById(R.id.rgb_style);
    rgb_photo_mode = (RadioGroup) findViewById(R.id.rgb_photo_mode);
    rgb_compress = (RadioGroup) findViewById(R.id.rgb_compress);
    cb_voice = (CheckBox) findViewById(R.id.cb_voice);
    cb_choose_mode = (CheckBox) findViewById(R.id.cb_choose_mode);
    cb_isCamera = (CheckBox) findViewById(R.id.cb_isCamera);
    cb_isGif = (CheckBox) findViewById(R.id.cb_isGif);
    cb_preview_img = (CheckBox) findViewById(R.id.cb_preview_img);
    cb_preview_video = (CheckBox) findViewById(R.id.cb_preview_video);
    cb_compress = (CheckBox) findViewById(R.id.cb_compress);
    cb_mode = (CheckBox) findViewById(R.id.cb_mode);
    rgb_compress.setOnCheckedChangeListener(this);
    rgb_style.setOnCheckedChangeListener(this);
    rgb_photo_mode.setOnCheckedChangeListener(this);
    recyclerView = (RecyclerView) findViewById(R.id.recycler);
    left_back = (ImageView) findViewById(R.id.left_back);
    left_back.setOnClickListener(this);
    minus.setOnClickListener(this);
    plus.setOnClickListener(this);
    cb_compress.setOnCheckedChangeListener(this);
    FullyGridLayoutManager manager = new FullyGridLayoutManager(ImageVideoPickActivity.this, 4, GridLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(manager);
    adapter = new GridImageAdapter(ImageVideoPickActivity.this, onAddPicClickListener);
    adapter.setList(selectList);
    adapter.setSelectMax(maxSelectNum);
    recyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener(new GridImageAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View v) {
            if (selectList.size() > 0) {
                LocalMedia media = selectList.get(position);
                String pictureType = media.getPictureType();
                int mediaType = PictureMimeType.pictureToVideo(pictureType);
                switch(mediaType) {
                    case 1:
                        // 预览图片 可自定长按保存路径
                        // PictureSelector.create(ImageVideoPickActivity.this).externalPicturePreview(position, "/custom_file", selectList);
                        PictureSelector.create(ImageVideoPickActivity.this).externalPicturePreview(position, selectList);
                        break;
                    case 2:
                        // 预览视频
                        PictureSelector.create(ImageVideoPickActivity.this).externalPictureVideo(media.getPath());
                        break;
                }
            }
        }
    });
    // 清空图片缓存,包括裁剪、压缩后的图片 注意:必须要在上传完成后调用 必须要获取权限
    RxPermissions permissions = new RxPermissions(this);
    permissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Observer<Boolean>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Boolean aBoolean) {
            if (aBoolean) {
                PictureFileUtils.deleteCacheDirFile(ImageVideoPickActivity.this);
            } else {
                Toast.makeText(ImageVideoPickActivity.this, getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RxPermissions(com.ningcui.mylibrary.viewLib.Imagepicker.permissions.RxPermissions) GridImageAdapter(com.litingzhe.justandroid.someOther.imagePicker.adapter.GridImageAdapter) FullyGridLayoutManager(com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 GridImageAdapter (com.litingzhe.justandroid.someOther.imagePicker.adapter.GridImageAdapter)1 FullyGridLayoutManager (com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager)1 LocalMedia (com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)1 RxPermissions (com.ningcui.mylibrary.viewLib.Imagepicker.permissions.RxPermissions)1 Disposable (io.reactivex.disposables.Disposable)1