Tecnologia do Blogger.
RSS

[androidbrasil-dev] Gallery com imagens da Web...

ola galera
tou fazendo uma gallery... mais essa galery vai usar imagens que estãso na web...
mais não consigo arrumar um erro protected String doInBackground quando retorna o endereço daqs imagens...
se alguem puder dar uma força;;;.. se aguem jah fez algo assimm...

valew

public class AdaptadordaImagem extends BaseAdapter {
    private Context cont;
    int GalItemBg;
    private String[] myRemoteImages = {
            "http://www.cuboweb.com.br/android/images/1.png",
            "http://www.cuboweb.com.br/android/images/2.png",
            "http://www.cuboweb.com.br/android/images/3.png",
            "http://www.cuboweb.com.br/android/images/4.png", };
    static Bitmap bm;
    BitmapFactory.Options bmOptions;

    public AdaptadordaImagem(Context c) {
        cont = c;
   }

    public int getCount() {
        return this.myRemoteImages.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(this.cont);
        try {
            /* Definindo a URL das imagens. */
            URL aURL = new URL(myRemoteImages[position]);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();// pegando a imagem
            /* Create Buffered is always good for a performance plus. */
            BufferedInputStream bis = new BufferedInputStream(is);
            /* Transformando a imagem em bitmap. */
            Bitmap bm = BitmapFactory.decodeStream(bis);
            /**/
            bis.close();
            is.close();
            /* Apply the Bitmap to the ImageView that will be returned. */
            i.setImageBitmap(bm);
        } catch (IOException e) {
            i.setImageResource(R.drawable.sem_conexao);
            Log.e("DEBUGTAG", "Remtoe Image Exception", e);
        }
        return i;
    }// aqui fecha o getView

    public Bitmap loadBitmap(String myRemoteImages,
            BitmapFactory.Options options) {
        InputStream in = null;
        try {
            in = OpenHttpConnection(myRemoteImages);
            bm = BitmapFactory.decodeStream(in, null, options);
            in.close();
        } catch (IOException e1) {
        }
        return bm;
    }// aqui fecha o load bitmap

    private InputStream OpenHttpConnection(String strURL) throws IOException {
        InputStream inputStream = null;
        URL url = new URL(strURL);
        URLConnection conn = url.openConnection();

        try {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setRequestMethod("GET");
            httpConn.connect();

            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                inputStream = httpConn.getInputStream();
            }
        } catch (Exception ex) {
        }
        return inputStream;
    }// aqui fecha o InputStream

    public class PegaImagens extends AsyncTask<String, Void, String> {
        private ProgressDialog progressgallery;

        protected void onPreExecute() {
            progressgallery = new ProgressDialog(cont, GalItemBg);
            progressgallery.setTitle("Aguarde...");
            progressgallery.setMessage("Carregando...");
            progressgallery.show();
        }

        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            bmOptions = new BitmapFactory.Options();
            bmOptions.inSampleSize = 1;
            loadBitmap(myRemoteImages, bmOptions); //error

            return myRemoteImages;  //error
        }

        // esse metodo vai ver se as imagens estão acessiveis na internet
        protected void onPostExecute(String myRemoteImages) {
            if (!myRemoteImages.equals("")) {
                // ok
            } else {
                // aqui devo fazer carregar a imagen do cache
                // error
            }
            progressgallery.dismiss();
        }
    }// end async task
}// end class

______________________________________




public class ExibeGallery extends SherlockActivity {
    private Gallery galleryView1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.exibegallery);

        galleryView1 = (Gallery) findViewById(R.id.GaleryView);
        galleryView1.setAdapter(new AdaptadordaImagem(this));

    }// end o oncreate

}

--
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário