Search in sources :

Example 1 with PreviewViewPager

use of com.luck.picture.lib.weiui.library.widget.PreviewViewPager in project weiui by kuaifan.

the class PicturePreviewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.picture_preview);
    if (!RxBus.getDefault().isRegistered(this)) {
        RxBus.getDefault().register(this);
    }
    mHandler = new Handler();
    screenWidth = ScreenUtils.getScreenWidth(this);
    int status_color = AttrsUtils.getTypeValueColor(this, R.attr.picture_status_color);
    ToolbarUtil.setColorNoTranslucent(this, status_color);
    LightStatusBarUtils.setLightStatusBar(this, previewStatusFont);
    animation = OptAnimationLoader.loadAnimation(this, R.anim.modal_in);
    animation.setAnimationListener(this);
    picture_left_back = (ImageView) findViewById(R.id.picture_left_back);
    viewPager = (PreviewViewPager) findViewById(R.id.preview_pager);
    ll_check = (LinearLayout) findViewById(R.id.ll_check);
    id_ll_ok = (LinearLayout) findViewById(R.id.id_ll_ok);
    check = (TextView) findViewById(R.id.check);
    picture_left_back.setOnClickListener(this);
    tv_ok = (TextView) findViewById(R.id.tv_ok);
    id_ll_ok.setOnClickListener(this);
    tv_img_num = (TextView) findViewById(R.id.tv_img_num);
    tv_title = (TextView) findViewById(R.id.picture_title);
    position = getIntent().getIntExtra(PictureConfig.EXTRA_POSITION, 0);
    tv_ok.setText(numComplete ? getString(R.string.picture_done_front_num, 0, config.selectionMode == PictureConfig.SINGLE ? 1 : config.maxSelectNum) : getString(R.string.picture_please_select));
    tv_img_num.setSelected(config.checkNumMode ? true : false);
    selectImages = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_SELECT_LIST);
    boolean is_bottom_preview = getIntent().getBooleanExtra(PictureConfig.EXTRA_BOTTOM_PREVIEW, false);
    if (is_bottom_preview) {
        // 底部预览按钮过来
        images = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST);
    } else {
        images = ImagesObservable.getInstance().readLocalMedias();
    }
    initViewPageAdapterData();
    ll_check.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (images != null && images.size() > 0) {
                LocalMedia image = images.get(viewPager.getCurrentItem());
                String pictureType = selectImages.size() > 0 ? selectImages.get(0).getPictureType() : "";
                if (!TextUtils.isEmpty(pictureType)) {
                    boolean toEqual = PictureMimeType.mimeToEqual(pictureType, image.getPictureType());
                    if (!toEqual) {
                        showToast(getString(R.string.picture_rule));
                        return;
                    }
                }
                // 刷新图片列表中图片状态
                boolean isChecked;
                if (!check.isSelected()) {
                    isChecked = true;
                    check.setSelected(true);
                    check.startAnimation(animation);
                } else {
                    isChecked = false;
                    check.setSelected(false);
                }
                if (selectImages.size() >= config.maxSelectNum && isChecked) {
                    showToast(getString(R.string.picture_message_max_num, config.maxSelectNum));
                    check.setSelected(false);
                    return;
                }
                if (isChecked) {
                    VoiceUtils.playVoice(mContext, config.openClickSound);
                    // 如果是单选,则清空已选中的并刷新列表(作单一选择)
                    if (config.selectionMode == PictureConfig.SINGLE) {
                        singleRadioMediaImage();
                    }
                    selectImages.add(image);
                    image.setNum(selectImages.size());
                    if (config.checkNumMode) {
                        check.setText(String.valueOf(image.getNum()));
                    }
                } else {
                    for (LocalMedia media : selectImages) {
                        if (media.getPath().equals(image.getPath())) {
                            selectImages.remove(media);
                            subSelectPosition();
                            notifyCheckChanged(media);
                            break;
                        }
                    }
                }
                onSelectNumChange(true);
            }
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            isPreviewEggs(config.previewEggs, position, positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int i) {
            position = i;
            tv_title.setText(position + 1 + "/" + images.size());
            LocalMedia media = images.get(position);
            index = media.getPosition();
            if (!config.previewEggs) {
                if (config.checkNumMode) {
                    check.setText(media.getNum() + "");
                    notifyCheckChanged(media);
                }
                onImageChecked(position);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : Handler(android.os.Handler) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) PreviewViewPager(com.luck.picture.lib.weiui.library.widget.PreviewViewPager)

Aggregations

Handler (android.os.Handler)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 LocalMedia (com.luck.picture.lib.weiui.library.entity.LocalMedia)1 PreviewViewPager (com.luck.picture.lib.weiui.library.widget.PreviewViewPager)1