Back to project page game_guess_lib.
The source code is released under:
MIT License
If you think the Android project game_guess_lib 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.wkmf.guess.lib.common.async; /* w w w.j a v a 2s. c om*/ import android.app.ProgressDialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.AsyncTask; import com.wkmf.guess.lib.R; import com.wkmf.guess.lib.impl.GuessGameImageDownload; import com.wkmf.lib.common.utils.E_CommonFunctions; /** * Created by ernestofndz on 22/02/14. */ public class DownloadTask extends AsyncTask<String, Void, Bitmap> { private GuessGameImageDownload callback; private Context context; private String imageUrl; protected ProgressDialog pd; // constructor public DownloadTask(GuessGameImageDownload callback, String imageURL, ProgressDialog pd) { this.callback = callback; this.context = (Context) callback; this.imageUrl = imageURL; this.pd = pd; } @Override protected void onPreExecute() { super.onPreExecute(); // inicializamos el progress dialog pd.setMessage(this.context.getString(R.string.downloading_question_label)); pd.setIndeterminate(true); pd.setCancelable(false); // comprobamos la conectividad ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { pd.show(); } else { E_CommonFunctions.showMessage(context, "No Internet"); } } @Override protected Bitmap doInBackground(String... strings) { // descargamos la imagen return E_CommonFunctions.getBitmapFromURL(this.imageUrl); } @Override protected void onPostExecute(Bitmap bitmap) { this.callback.imageDownloaded(bitmap); } }