2017-08-26 163 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.