diff options
Diffstat (limited to 'src/eu/deki/paste/PasteTask.java')
| -rw-r--r-- | src/eu/deki/paste/PasteTask.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/eu/deki/paste/PasteTask.java b/src/eu/deki/paste/PasteTask.java new file mode 100644 index 0000000..29b5c32 --- /dev/null +++ b/src/eu/deki/paste/PasteTask.java @@ -0,0 +1,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; +} + |
