0

i have a recyclerview with a imageview and textview , and i would like populate using a download in bad quality to accelerate the download process.

the imageview has a onclick method which display a dialog with image downloaded like background, so, i want download image in bad quality and only when user clicked in image , then download the image in hight quality.

this is my code for download:

try {
     ruta = "http://192.168.1.67/apptequila/fotos/" + usuariojSON + "/" + fotojSON;

    URL url = new URL(ruta);
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setConnectTimeout(15000);
    connection.connect();
    InputStream input = connection.getInputStream();
    bitmap = BitmapFactory.decodeStream(input);


     }catch (SocketTimeoutException e){
    cancelarHilo(3);
    } catch (Exception e) {
    Log.i("SMS", "ERROR AL OBTENER FOTO: " + e.toString());
     bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sin_perfil);
     }
     data.add(new MiModel(nombrejSON, categoriajSON, likesjSON, lemajSON, bitmap, idsjSON,latitudjSON,longitudjSON,distanciajSON));

code of onclick imageview:

    public void Pressimage(final int position) {
        customDiag = new Dialog(MainActivity.this);
        customDiag.requestWindowFeature(Window.FEATURE_NO_TITLE);
        customDiag.setContentView(R.layout.dialog);




                RelativeLayout relativeLayout = (RelativeLayout)customDiag.findViewById(R.id.root);
                Drawable drawable = new BitmapDrawable(getApplicationContext().getResources(),
                        data.get(position).getImagen());
                if(Build.VERSION.SDK_INT > 16) {
                    relativeLayout.setBackground(drawable);
                }else{
                    relativeLayout.setBackgroundDrawable(drawable);
                }

                customDiag.show();
}
kcire_eae
  • 333
  • 1
  • 3
  • 10

1 Answers1

1

Why would you want to do that? Use Picasso or Volley as they will allow downloading/caching of images. They also display images in listviews extremely well. This will mitigate your issue of attempting to reduce the memory burden by making your images look "bad".

TheSunny
  • 371
  • 4
  • 14