Display Custom ProgressDialog while bitmap is saving in Gallery

I'm trying to display a custom dialog while bitmap saving in Gallery, I tried to use Asynthask and display the custom dialog in onPreExecute method and dismiss it in onPostExecute method.

@SuppressLint("StaticFieldLeak")
    public class saveWithStickersFile extends AsyncTask<File, File, File> {
        Context mContext;
        TextView view;

        saveWithStickersFile(Context context) {
            mContext = context;
        }

        @SuppressLint("SetTextI18n")
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            content.setVisibility(View.GONE);
            dialogLoading = new Dialog(BaseActivity.this);
            dialogLoading.requestWindowFeature(Window.FEATURE_NO_TITLE);
            assert dialogLoading.getWindow() != null;dialogLoading.getWindow().setBackgroundDrawableResource(R.color.transparent);
            dialogLoading.setCancelable(true);
            dialogLoading.setContentView(R.layout.bottomdialog);
            GifImageView gifImageView = dialogLoading.findViewById(R.id.progress);
            gifImageView.setVisibility(View.VISIBLE);
            LinearLayout buttons = dialogLoading.findViewById(R.id.buttons);
            buttons.setVisibility(View.GONE);
            view = dialogLoading.findViewById(R.id.text);
            view.setText("Saving ...");
            fullImageView.setVisibility(View.VISIBLE);
            dialogLoading.show();
        }

        @Override
        protected File doInBackground(File... files) {
            File fileSaved = files[1];
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    stickerView.save(files[0], true);
                }
            });
            return fileSaved;
        }


        @Override
        protected void onPostExecute(File file) {
            super.onPostExecute(file);
            if (file.exists()) {
                dialogLoading.dismiss();
                Toast.makeText(BaseActivity.this, "Done !", Toast.LENGTH_SHORT).show();
            }
        }
    }

My Issue:

When I run the app, Bitmap saved in the gallery but I can't see the custom dialog, and nothing appears, for some reason, runOnUiThread prevents the onPreExecute method. can anyone help me to get resolve this issue?

Upvotes: 0

Views: 92

Answers (0)

Related Questions