Android 圖片選擇對話框,通過本地相冊或照相機獲得圖片,可單選或多選,單選可設置是否裁剪

AndroidPickPhotoDialog

Android 圖片選擇對話框,通過本地相冊或照相機獲得圖片,可單選或多選,單選可設置是否裁剪Android 圖片選擇對話框,通過本地相冊或照相機獲得圖片,可單選或多選,單選可設置是否裁剪。

模擬器動態圖

image

1 張圖片

image

2 張圖片

image

3 張圖片

image

4 張圖片

image

調用方法:

    private PickPhotoDialog pickPhotoDialog;

    //點擊事件裡面添加
    pickPhotoDialog = new PickPhotoDialog(MainActivity.this, MainActivity.this);
    Window window = pickPhotoDialog.getWindow();
    window.setGravity(Gravity.BOTTOM);
    window.setWindowAnimations(R.style.DialogEnter);
    pickPhotoDialog.setCutImg(true, 5);
    pickPhotoDialog.setOnPhotoResultListener(new PickPhotoDialog.OnPhotoResultListener() {
        @Override
        public void onCameraResult(String path) {//相機拍照圖片路徑
            List imgBeens = new ArrayList();
            ImgBean imgBean = new ImgBean();
            imgBean.setPath(path);
            imgBeens.add(imgBean);
            adViewpagerUtil = new AdViewpagerUtil(MainActivity.this, viewpager, lydots, 8, 4, imgBeens);
            adViewpagerUtil.initVps();
        }

        @Override
        public void onCutPhotoResult(Bitmap bitmap) {
            //圖片(相機和相冊)裁剪後返回的 bitmap
        }

        @Override
        public void onPhotoResult(List selectedImgs) {//相冊多圖選擇返回圖片路徑結果集
            if(selectedImgs != null && selectedImgs.size() > 0) {
                adViewpagerUtil = new AdViewpagerUtil(MainActivity.this, viewpager, lydots, 8, 4, selectedImgs);
                adViewpagerUtil.initVps();
            }
            else
            {
                if(adViewpagerUtil != null) {
                    adViewpagerUtil.startLoopViewPager();
                }
            }
        }
    });

    //權限申請
    @TargetApi(23)
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (pickPhotoDialog != null)
        {
            pickPhotoDialog.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if(pickPhotoDialog != null)
        {
            pickPhotoDialog.onActivityResult(requestCode, resultCode, data);
        }
    }

You May Also Like