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
|
package eu.deki.paste;
import java.io.IOException;
import android.os.AsyncTask;
import android.widget.Toast;
import android.content.Context;
import android.util.Log;
public abstract class PasteTask extends AsyncTask<String, Void, String>
{
private String errorMessage = null;
protected Context parentActivity = null;
public PasteTask(Context parent)
{
super();
parentActivity = parent;
}
@Override
protected String doInBackground(String... params)
{
String title, content, expiration, result;
if(params.length != 3)
return null;
title = params[0];
content = params[1];
expiration = params[2];
try
{
result = paste(title, content, expiration);
}
catch(IOException ex)
{
cancel(false);
errorMessage = ex.getLocalizedMessage();
result = errorMessage;
Log.e("PasteIt", "doInBackground", ex);
}
return result;
}
@Override
protected void onPostExecute(String result)
{
}
@Override
protected void onCancelled()
{
//Toast toast = Toast.makeText(parentActivity.getApplicationContext(), errorMessage, Toast.LENGTH_SHORT);
//toast.show();
}
protected abstract String paste(String title, String content, String delay) throws IOException;
}
|