forked from gsu/ETime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeCardAsyncTask.java
85 lines (70 loc) · 2.36 KB
/
TimeCardAsyncTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.etime;
/*
* This file is part of ETime.
*
* ETime is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ETime is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ETime. If not, see <http://www.gnu.org/licenses/>.
*/
import android.os.AsyncTask;
import android.widget.ProgressBar;
import org.apache.http.impl.client.DefaultHttpClient;
import java.util.List;
/**
* User: dpayne2
* Date: 1/5/12
* Time: 12:02 PM
*/
public class TimeCardAsyncTask extends AsyncTask<Void, Integer, Boolean> {
private ProgressBar progressBar;
private ETimeActivity activity;
private DefaultHttpClient httpClient;
private String TIMECARD_URL;
private static final String TAG = "TimeCard-4321";
int myProgress;
private List<Punch> punches;
private double totalHrs;
@Override
protected void onPostExecute(Boolean result) {
activity.setPunches(punches);
activity.setTotalHrs(totalHrs);
activity.onPostParsingTimeCard();
}
@Override
protected void onPreExecute() {
TIMECARD_URL = activity.getString(R.string.timecard_url);
myProgress = 0;
}
@Override
protected Boolean doInBackground(Void... params) {
String page = ETimeUtils.getHtmlPage(httpClient, TIMECARD_URL);
totalHrs = ETimeUtils.getTotalsHrs(page);
punches = ETimeUtils.getTodaysPunches(page);
boolean status = !punches.isEmpty();
myProgress = 100;
publishProgress(myProgress);
return status;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressBar.setProgress(values[0]);
}
public void setProgressBar(ProgressBar progressBar) {
this.progressBar = progressBar;
}
public void setActivity(ETimeActivity activity) {
this.activity = activity;
}
public void setHttpClient(DefaultHttpClient httpClient) {
this.httpClient = httpClient;
}
}