Android Open Source - Meteogram Meteogram Download Task






From Project

Back to project page Meteogram.

License

The source code is released under:

License Human-readable version (http://creativecommons.org/licenses/by-sa/3.0/deed.en_US) THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "...

If you think the Android project Meteogram 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 net.kamburov.meteogram;
//  w ww.  j a  v  a2 s  .  c  o m
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

public class MeteogramDownloadTask extends AsyncTask<String, Integer, Bitmap> {

    private ProgressDialog dialog;

    private Context context;

    private ImageView imageView;

    public MeteogramDownloadTask(Context context, ImageView imageView) {
        this.context = context;
        this.imageView = imageView;
    }

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(context, "", context.getString(R.string.loading), true, false);
    }

    protected Bitmap doInBackground(final String... args) {
        try {
            String url = String.format(context.getString(R.string.location_url), args[0]);
            URLConnection connection = new URL(url).openConnection();
            return BitmapFactory.decodeStream(connection.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        dialog.dismiss();

        if (bitmap != null) {
            imageView.setImageBitmap(bitmap);
        } else {
            imageView.setImageResource(R.drawable.ic_menu_close_clear_cancel);
        }

        super.onPostExecute(bitmap);
    }
}




Java Source Code List

net.kamburov.meteogram.LocationsObject.java
net.kamburov.meteogram.MeteogramDownloadTask.java
net.kamburov.meteogram.Meteogram.java
net.kamburov.meteogram.SelectLocation.java
net.kamburov.meteogram.provider.Favorites.java
net.kamburov.meteogram.provider.LocationSuggestions.java
net.kamburov.meteogram.provider.Locations.java