HTML Image SRC Android AsyncTask

0

Good afternoon, I'm developing an Android application that needs to consume Web Service, but the detail is that the content of one of the data comes in a hypertext format, therefore I have to convert it to Android, sometimes it comes with images src and I also have to show, I have the following code with AsyncTask:

 class ConvertirDatos extends AsyncTask<Html.ImageGetter, String, Html.ImageGetter> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog.setTitle("Obteniendo detalles");
        progressDialog.setCancelable(false);
        progressDialog.setIcon(R.drawable.logo);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

        progressDialog.show();

    }

    @Override
    **protected Html.ImageGetter doInBackground(Html.ImageGetter... imageGetters) {
        Html.ImageGetter imageHTML = new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(String s) {
                try {
                    Drawable d = Drawable.createFromStream(new URL(s).openStream(), "srcName");
                    d.setBounds(0, 0, d.getMinimumWidth(), d.getMinimumHeight());
                    return d;
                } catch (IOException e) {
                    Log.v("IOException", e.getMessage());
                    e.printStackTrace();
                    return null;
                }
            }
        };
        return imageHTML;**

    }
    @Override
    protected void onPostExecute(Html.ImageGetter imageGetter) {
        super.onPostExecute(imageGetter);
        Bundle bundle = getIntent().getExtras();
        String contenido = (String) bundle.get("contenido");


        if (contenido.equals("") && contenido !=null){
            tvContenido.setText("Para más información descarga los archivos asociados");
        }else {
            **Spanned s = Html.fromHtml(contenido, doInBackground(), null);
            tvContenido.setAutoLinkMask(Linkify.WEB_URLS);
            tvContenido.setLinksClickable(true);
            tvContenido.setText(s);**
        }


        progressDialog.dismiss();
    }

The detail is in when I load heavy images, it is loaded in the main thread, it does not show me the progressDialog, and the screen remains in black, I do not know if I am implementing the AsyncTask badly.

Thanks for the help. Happy year

    
asked by Enrique 09.01.2018 в 23:45
source

0 answers