Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart3.png 80% of files have more coverage
19   96   12   3,17
10   54   0,63   6
6     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  BackgroundTask       Line # 34 19 12 25,7% 0.25714287
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.util;
20   
21    import java.io.FileNotFoundException;
22    import java.io.IOException;
23   
24    import org.xmlpull.v1.XmlPullParserException;
25   
26    import android.app.Activity;
27    import android.os.Handler;
28    import android.util.Log;
29    import net.sourceforge.subsonic.androidapp.R;
30   
31    /**
32    * @author Sindre Mehus
33    */
 
34    public abstract class BackgroundTask<T> implements ProgressListener {
35   
36    private static final String TAG = BackgroundTask.class.getSimpleName();
37    private final Activity activity;
38    private final Handler handler;
39   
 
40  23 toggle public BackgroundTask(Activity activity) {
41  23 this.activity = activity;
42  23 handler = new Handler();
43    }
44   
 
45  2 toggle protected Activity getActivity() {
46  2 return activity;
47    }
48   
 
49  84 toggle protected Handler getHandler() {
50  84 return handler;
51    }
52   
53    public abstract void execute();
54   
55    protected abstract T doInBackground() throws Throwable;
56   
57    protected abstract void done(T result);
58   
 
59  0 toggle protected void error(Throwable error) {
60  0 Log.w(TAG, "Got exception: " + error, error);
61  0 new ErrorDialog(activity, getErrorMessage(error), true);
62    }
63   
 
64  0 toggle protected String getErrorMessage(Throwable error) {
65   
66  0 if (error instanceof IOException && !Util.isNetworkConnected(activity)) {
67  0 return activity.getResources().getString(R.string.background_task_no_network);
68    }
69   
70  0 if (error instanceof FileNotFoundException) {
71  0 return activity.getResources().getString(R.string.background_task_not_found);
72    }
73   
74  0 if (error instanceof IOException) {
75  0 return activity.getResources().getString(R.string.background_task_network_error);
76    }
77   
78  0 if (error instanceof XmlPullParserException) {
79  0 return activity.getResources().getString(R.string.background_task_parse_error);
80    }
81   
82  0 String message = error.getMessage();
83  0 if (message != null) {
84  0 return message;
85    }
86  0 return error.getClass().getSimpleName();
87    }
88   
89    @Override
90    public abstract void updateProgress(final String message);
91   
 
92  58 toggle @Override
93    public void updateProgress(int messageId) {
94  58 updateProgress(activity.getResources().getString(messageId));
95    }
96    }