Back to project page WineDB.
The source code is released under:
MIT License
If you think the Android project WineDB listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.selesse.android.winedb.winescraper; //w ww. j a va 2s . com import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import com.selesse.android.winedb.R; import com.selesse.android.winedb.activity.WineDB; import com.selesse.android.winedb.database.Wine; import java.util.Collections; import java.util.List; public class WineScraperThread extends AsyncTask<String, Void, List<Wine>> { private ProgressDialog progress; private String barcode; private Activity activity; public WineScraperThread(Activity activity) { this.activity = activity; } @Override protected void onPreExecute() { super.onPreExecute(); progress = new ProgressDialog(activity); try { progress.setMessage(activity.getString(R.string.scraping)); progress.setIndeterminate(true); progress.show(); } catch (Exception e) { // The fetch may happen too fast, ignore any exceptions that may arise due to this } } @Override protected List<Wine> doInBackground(String... params) { barcode = params[0]; WineScrapers scrapers = new WineScrapers(barcode); return scrapers.scrape(); } @Override protected void onPostExecute(List<Wine> result) { super.onPostExecute(result); try { progress.dismiss(); progress = null; } catch (Exception e) { // do nothing } Wine wine; if (result.size() == 0) { wine = new Wine(); } else { wine = result.get(0); if (result.size() > 1) { Collections.sort(result, new WineScrapers.NumberOfFieldsComparator()); } } wine.setBarcode(barcode); ((WineDB) activity).startEditWineIntent(wine); } }