If you think the Android project frc-notebook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.plnyyanks.frcnotebook.background;
//www.java2s.comimport android.app.Activity;
import android.os.AsyncTask;
import android.widget.Toast;
import com.plnyyanks.frcnotebook.datafeed.USFIRSTParser;
/**
* File created by phil on 4/19/14.
* Copyright 2014, Phil Lopreiato
* This file is part of FRC Notebook.
* FRC Notebook 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.
* FRC Notebook 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 FRC Notebook. If not, see http://www.gnu.org/licenses/.
*/publicclass AddMatchesFromURL extends AsyncTask<String,String,String> {
private Activity activity;
public AddMatchesFromURL(Activity act){
activity = act;
}
@Override
protectedvoid onPreExecute() {
super.onPreExecute();
try{
Toast.makeText(activity,"Fetching matches...",Toast.LENGTH_SHORT).show();
}catch(RuntimeException e){
activity.runOnUiThread(new Runnable() {
@Override
publicvoid run() {
Toast.makeText(activity,"Fetching matches...",Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
protected String doInBackground(String... params) {
String url = params[0],eventKey = params[1];
String[] parts = url.split("\\.");
String extension = parts[parts.length-1];
if(extension.equals("html") || extension.equals("csv")){
return USFIRSTParser.fetchMatchesFromURL(url, eventKey);
}else{
return"Unsupported filetype. Use .html or .csv";
}
}
@Override
protectedvoid onPostExecute(final String s) {
super.onPostExecute(s);
try {
if (!s.isEmpty()) {
Toast.makeText(activity, s, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, "Matches added", Toast.LENGTH_SHORT).show();
}
}catch(RuntimeException e){
activity.runOnUiThread(new Runnable() {
@Override
publicvoid run() {
if (!s.isEmpty()) {
Toast.makeText(activity, s, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, "Matches added", Toast.LENGTH_SHORT).show();
}
}
});
}
}
}