简体   繁体   中英

Android: ProgressDialog Circle not showing

I tried to implement a loading circle in my application as it transitioned from the previous activity to this activity. As there are a ton of calculations in this activity, it turns black screen as it's doing the calculations for a good 10 to 15 seconds, once the calculations are done it'd display an image, seen in onCreate: resultImage.setImageBitmap(finalBitmap);

However, the circle doesn't appear, and it's still the same old black screen to image transition.

Imported:

import android.app.ProgressDialog;

Declared:

private ProgressDialog progressDialog;

Initialized:

progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(null);
        progressDialog.setCancelable(false);

Made it visible:

progressDialog.show();

Changed its message as the code progressed:

progressDialog.setMessage("Finding Objects...");

progressDialog.setMessage("Calculating Areas...");

progressDialog.setMessage("Calculating Height...");

... etc etc

onCreate:

@Override
    public void onCreate(Bundle savedInstanceState) {

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(null);
        progressDialog.setCancelable(false);

        progressDialog.setMessage("Processing...");
        progressDialog.show();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auto_test);



        if (!OpenCVLoader.initDebug()) {
            Log.d("opencv", "OpenCVLoader.initDebug() - ERROR");
        } else {
            Log.d("opencv", "OpenCVLoader.initDebug() - OK");
        }


        String filePath = getIntent().getStringExtra(FILEPATH);
        ArrayList<String> f = new ArrayList<String>();

        File dir = new File(filePath);
        File[] listFile;

        listFile = dir.listFiles();

        for (File e : listFile) {
            f.add(e.getAbsolutePath());

        }


        paths = f;


        resetVariables();
        progressDialog.setMessage("Finding Objects...");
        for (int xx = 0; xx < paths.size(); xx++) {
            Bitmap areaBitmap = BitmapFactory.decodeFile(paths.get(xx));
            getArea(areaBitmap);

        }
        if (loopCounter > 0) {
            progressDialog.setMessage("Calculating Areas...");
            meanBlackArea = blackArea / loopCounter;

            Log.e("meanBlackArea", "30% of mean black " + String.valueOf(meanBlackArea * 0.3) + " 110% of mean black " + String.valueOf(meanBlackArea * 1.1));
            Log.e("Loopcounter", String.valueOf(loopCounter));
        }
        resetVariables();


        Log.e("~", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        Log.e("Lowest Green", String.valueOf(greenArea));
        Log.e("~", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        progressDialog.setMessage("Calculating Height...");

        int frameNumber = 0;
        for (int x = 0; x < paths.size(); x++) {

            Bitmap calculationsBitmap = BitmapFactory.decodeFile(paths.get(x));
            numRectBlack = 0;
            numRectGreen = 0;

            tempBitmap = findCombineBitmap(calculationsBitmap);
            if (check == true) {
                if (Double.isInfinite(tempLineHeightCm) == false) {
                    frameNumber = x;
                    finalBitmap = tempBitmap;
                }
            }

        }
        progressDialog.setMessage("Tidying Up...");
        TextView tvR = (TextView) findViewById(R.id.tvR);
        if(tempLineHeightCm==0) {
            tvR.setText("We could not detect a bounce!\nPlease do the following and try again:\n1. Remove all foreign objects from testing grounds.\n2.Make sure that there are ample lighting on the testing grounds.");
        }else{
            tvR.setText("Frame " + frameNumber + ", Bounce Height = " + tempLineHeightCm + "cm");

            ImageView resultImage = (ImageView) findViewById(R.id.resultImage);

            resultImage.setImageBitmap(finalBitmap);
            progressDialog.dismiss();
        }

    }

Link to code file:

Google Drive

Notes:

  1. MainActivity.java has a working progresscircle
  2. TestAutoRun.java is the one I'm working on.

Show ProgressDialog , start new AsyncTask and do your heavy calculations in background. After the AsyncTask completes, hide the progress dialog and go to next activity.

If you don't know how to use AsyncTask , check the reference here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM