2017-08-26 124 views
1

我试图在我的应用程序中实现一个加载循环,因为它从之前的活动转换为此活动。由于在此活动中有大量计算,因此计算完成后,它会变成黑屏,一旦计算完成,它将显示一幅图像,在onCreate中看到:resultImage.setImageBitmap(finalBitmap);Android:ProgressDialog Circle not showing

但是,圆圈不会出现,并且它仍然是图像转换的旧黑屏。

进口:

import android.app.ProgressDialog;

宣称:

private ProgressDialog progressDialog;

初始化:

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

制造之可见:

progressDialog.show();

改了消息的代码进展:

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

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

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

...等等等等

的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(); 
     } 

    } 

链接代码文件:

Google Drive

注:

  1. MainActivity.java有一个工作进程环
  2. TestAutoRun.java是我正在开发的一个工具。
+0

[也许是颜色问题,请参阅我的unswear这里。(https://stackoverflow.com/a/47533325/4148568) – Rammgarot

回答

0

显示ProgressDialog,开始新建AsyncTask并在背景中进行繁重的计算。在AsyncTask完成后,隐藏进度对话框并转到下一个活动。

如果你不知道如何使用AsyncTask,请参考here.