Uri正确加载到onActivityResult中的ImageView中,但未正确添加到ArrayList中?

时间:2019-05-06 21:40:43

标签: android image android-activity firebase-storage crop

我目前正在使用Arthur图像裁剪库来裁剪图像并将生成的Uris添加到onActivityResult中的ArrayList中,以便以后可以使用它们上载到Firebase Storage,然后在各种ImageButton中设置uri。 Uris正在从图像裁剪活动中恢复并正确地在ImageButtons中进行了设置,但是随后图像不正确地上传到Firebase Storage。以前我没有进行任何裁剪活动就获得了Uris,它们可以正确上传,但是现在看来Uris arent已正确添加到我的ArrayList中。

我的ImageButton的onClickListners:

carImage1.setOnClickListener(v -> {

        Intent intent1 = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent1, 11);

    });

    carImage2.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST2);
    });

    carImage3.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST3);
    });

    carImage4.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST4);
    });

    carImage5.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST5);
    });

    carImage6.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST6);
    });

    carImage7.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST7);
    });

    carImage8.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST8);
    });

    carImage9.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST9);
    });

    carImage10.setOnClickListener(v -> {
        Intent intent = CropImage.activity()
                .setMaxCropResultSize(1100, 800)
                .setGuidelines(CropImageView.Guidelines.ON)
                .getIntent(this);
        startActivityForResult(intent, PICK_IMAGE_REQUEST10);
    });

我的onActivityResult方法:

@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


    if (resultCode == RESULT_OK && data != null) {

        switch (requestCode) {


            case PICK_IMAGE_REQUEST1:
                Uri uriIn = CropImage.getPickImageResultUri(this, intent1);
                Intent cropImage1 = CropImage.activity(uriIn)
                        .setMaxCropResultSize(1100, 800)
                        .setGuidelines(CropImageView.Guidelines.ON)
                        .getIntent(this);

                startActivityForResult(cropImage1, 11);
              break;

            case 11:
                CropImageView.CropResult result = CropImage.getActivityResult(data);
                Uri uri1 = CropImage.getActivityResult(data).getUri();
                uris.set(0, uri1);
                Log.i("Uri1: ", uri1.toString());
                carImage2.setVisibility(View.VISIBLE);
                Glide.with(this).load(uri1).into(carImage1);
                break;

            case PICK_IMAGE_REQUEST2:
                CropImage.ActivityResult result2 = CropImage.getActivityResult(data);
                Uri uri2 = CropImage.getActivityResult(data).getUri();
                uris.set(1, uri2);
                Log.i("Uri2: ", uri2.toString());
                Glide.with(this).load(uri2).into(carImage2);
                carImage3.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST3:
                CropImage.ActivityResult result3 = CropImage.getActivityResult(data);
                Uri uri3 = CropImage.getActivityResult(data).getUri();
                uris.set(2, uri3);
                Log.i("Uri3: ", uri3.toString());
                Glide.with(this).load(uri3).into(carImage3);
                carImage4.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST4:
                CropImage.ActivityResult result4 = CropImage.getActivityResult(data);
                Uri uri4 = CropImage.getActivityResult(data).getUri();
                uris.set(3, uri4);
                Log.i("Uri4: ", uri4.toString());
                Glide.with(this).load(uri4).into(carImage4);
                carImage5.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST5:
                CropImage.ActivityResult result5 = CropImage.getActivityResult(data);
                Uri uri5 = CropImage.getActivityResult(data).getUri();
                uris.set(4, uri5);
                Log.i("Uri5: ", uri5.toString());
                Glide.with(this).load(uri5).into(carImage5);
                carImage6.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST6:
                CropImage.ActivityResult result6 = CropImage.getActivityResult(data);
                Uri uri6 = CropImage.getActivityResult(data).getUri();
                uris.set(5, uri6);
                Glide.with(this).load(uri6).into(carImage6);
                carImage7.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST7:
                CropImage.ActivityResult result7 = CropImage.getActivityResult(data);
                Uri uri7 = CropImage.getActivityResult(data).getUri();
                uris.set(6, uri7);
                Glide.with(this).load(uri7).into(carImage7);
                carImage8.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST8:
                CropImage.ActivityResult result8 = CropImage.getActivityResult(data);
                Uri uri8 = CropImage.getActivityResult(data).getUri();
                uris.set(7, uri8);
                Glide.with(this).load(uri8).into(carImage8);
                carImage9.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST9:
                CropImage.ActivityResult result9 = CropImage.getActivityResult(data);
                Uri uri9 = result9.getUri();
                uris.set(8, uri9);
                Glide.with(this).load(uri9).into(carImage9);
                carImage10.setVisibility(View.VISIBLE);
                break;

            case PICK_IMAGE_REQUEST10:
                CropImage.ActivityResult result10 = CropImage.getActivityResult(data);
                Uri uri10 = result10.getUri();
                uris.set(9, uri10);
                Glide.with(this).load(uri10).into(carImage10);
                break;
        }
    }

}

0 个答案:

没有答案