Clover Coverage Report - HeartsSkyThread Coverage Report
Coverage timestamp: gio dic 18 2014 15:52:24 EST
../../../../img/srcFileCovDistChart0.png 76% of files have more coverage
24   132   10   4
6   76   0,42   3
6     1,67  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  LoadingScreenActivity       Line # 10 5 3 0% 0.0
  LoadingScreenActivity.LoadViewTask       Line # 28 19 7 0% 0.0
 
No Tests
 
1    package game.shad.tempus.hearts;
2   
3    import android.app.Activity;
4    import android.os.AsyncTask;
5    import android.os.Bundle;
6    import android.widget.ProgressBar;
7    import android.widget.TextView;
8    import android.widget.ViewSwitcher;
9   
 
10    public class LoadingScreenActivity extends Activity
11    {
12   
13   
14    //creates a ViewSwitcher object, to switch between Views
15    private ViewSwitcher viewSwitcher;
16   
17    /** Called when the activity is first created. */
 
18  0 toggle @Override
19    public void onCreate(Bundle savedInstanceState)
20    {
21  0 super.onCreate(savedInstanceState);
22   
23    //Initialize a LoadViewTask object and call the execute() method
24  0 new LoadViewTask().execute();
25    }
26   
27    //To use the AsyncTask, it must be subclassed
 
28    private class LoadViewTask extends AsyncTask{
29    //A TextView object and a ProgressBar object
30    private TextView tv_progress;
31    private ProgressBar pb_progressBar;
32   
33    //Before running code in the separate thread
 
34  0 toggle @Override
35    protected void onPreExecute()
36    {
37    //Initialize the ViewSwitcher object
38  0 viewSwitcher = new ViewSwitcher(LoadingScreenActivity.this);
39    /* Initialize the loading screen with data from the 'loadingscreen.xml' layout xml file.
40    * Add the initialized View to the viewSwitcher./*/
41  0 viewSwitcher.addView(ViewSwitcher.inflate(LoadingScreenActivity.this, R.layout.startup, null));
42   
43    //Initialize the TextView and ProgressBar instances - IMPORTANT: call findViewById() from viewSwitcher.
44    //tv_progress = (TextView) viewSwitcher.findViewById(R.id.);
45  0 pb_progressBar = (ProgressBar) viewSwitcher.findViewById(R.id.progressBar);
46    //Sets the maximum value of the progress bar to 100
47  0 pb_progressBar.setMax(100);
48   
49    //Set ViewSwitcher instance as the current View.
50  0 setContentView(viewSwitcher);
51    }
52   
53    //The code to be executed in a background thread.
 
54  0 toggle @Override
55    protected Object doInBackground(Object... params) {
56   
57    /* This is just a code that delays the thread execution 4 times,
58    * during 850 milliseconds and updates the current progress. This
59    * is where the code that is going to be executed on a background
60    * thread must be placed.
61    */
62  0 try
63    {
64    //Get the current thread's token
65  0 synchronized (this)
66    {
67    //Initialize an integer (that will act as a counter) to zero
68  0 int counter = 0;
69    //While the counter is smaller than four
70  0 while(counter <= 20)
71    {
72    //Wait 850 milliseconds
73  0 this.wait(200);
74    //Increment the counter
75  0 counter++;
76    //Set the current progress.
77    //This value is going to be passed to the onProgressUpdate() method.
78  0 publishProgress(counter*5);
79    }
80    }
81    }
82    catch (InterruptedException e)
83    {
84  0 e.printStackTrace();
85    }
86  0 return null;
87    }
88   
89    //Update the TextView and the progress at progress bar
 
90  0 toggle @Override
91    protected void onProgressUpdate(Object... values) {
92    //Update the progress at the UI if progress value is smaller than 100
93  0 if((Integer)values[0] <= 100)
94    {
95  0 tv_progress.setText("Progress: " + Integer.toString((Integer)values[0]) + "%");
96  0 pb_progressBar.setProgress((Integer)values[0]);
97    }
98    }
99   
100    //After executing the code in the thread
 
101  0 toggle @Override
102    protected void onPostExecute(Object objects)
103    {
104    /* Initialize the application's main interface from the 'main.xml' layout xml file.
105    * Add the initialized View to the viewSwitcher.*
106    * */
107  0 viewSwitcher.addView(ViewSwitcher.inflate(LoadingScreenActivity.this, R.layout.main, null));
108    //Switch the Views
109  0 viewSwitcher.showNext();
110    }
111   
112    }
113   
114    //Override the default back key behavior
 
115  0 toggle @Override
116    public void onBackPressed()
117    {
118    //Emulate the progressDialog.setCancelable(false) behavior
119    //If the first view is being shown
120  0 if(viewSwitcher.getDisplayedChild() == 0)
121    {
122    //Do nothing
123  0 return;
124    }
125    else
126    {
127    //Finishes the current Activity
128  0 super.onBackPressed();
129    }
130    }
131   
132    }