1
I’m having a problem with an app I’m creating. There is an application screen that takes data from parse.com, in this case an image, and wanted to pass it to another screen, but without losing quality. I even managed to move the image to another screen, but it comes with a very Ruin and blurred quality. Is there no other way to receive the image without it losing quality? My code is this
public class Eventos extends ActionBarActivity {
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewEventos adapter;
private List<GetEventos> eventos_lista = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventos);
new RemoteDataTask().execute();
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(Eventos.this);
// Set progressdialog title
mProgressDialog.setTitle("Carregando Dados...");
// Set progressdialog message
mProgressDialog.setMessage("Aguarde...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
eventos_lista = new ArrayList<GetEventos>();
try {
// Localizando a classe noticias no parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Eventos");
//colocando por ordem de data
query.orderByAscending("Number");
ob = query.find();
for (ParseObject titulo : ob) {
// Localizando as imagens na coluna foto do parse
ParseFile image = (ParseFile) titulo.get("Foto");
ParseFile img = (ParseFile) titulo.get("FotoEvento");
GetEventos eventos = new GetEventos();
eventos.setTitulo((String) titulo.get("Titulo"));
eventos.setDescricao((String) titulo.get("Descricao"));
eventos.setTextoEvento((String) titulo.get("TextoEvento"));
eventos.setFoto(image.getUrl());
eventos.setFotoEvento(img.getUrl()); //<<-Está é a imagem
eventos_lista.add(eventos);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listViewEventos);
// Pass the results into ListViewAdapter.java
adapter = new ListViewEventos(Eventos.this,
eventos_lista);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
The adapter of listview:
public class ListViewEventos extends BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
ImageLoader imageLoader = new ImageLoader(context);
private List<GetEventos> eventos_lista = null;
private ArrayList<GetEventos> arraylist;
public ListViewEventos(Context context,
List<GetEventos> eventos_lista) {
this.context = context;
this.eventos_lista = eventos_lista;
inflater = LayoutInflater.from(context);
this.arraylist = new ArrayList<GetEventos>();
this.arraylist.addAll(eventos_lista);
imageLoader = new ImageLoader(context);
}
public class ViewHolder {
TextView titulo;
TextView descricao;
ImageView foto;
}
@Override
public int getCount() {
return eventos_lista.size();
}
@Override
public Object getItem(int position) {
return eventos_lista.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.listview_eventos, null);
// Locate the TextViews in listview_eventos.xml
holder.titulo = (TextView) view.findViewById(R.id.TituloEvento);
holder.descricao = (TextView) view.findViewById(R.id.DescricaoEvento);
// Locate the ImageView in listview_noticias.xml.xml
holder.foto = (ImageView) view.findViewById(R.id.ImgEvento);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.titulo.setText(eventos_lista.get(position).getTitulo());
holder.descricao.setText(eventos_lista.get(position).getDescricao());
// Set the results into ImageView
imageLoader.DisplayImage(eventos_lista.get(position).getFoto(),
holder.foto);
// Listen for ListView Item Click
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Send single item click data to SingleItemView Class
Intent intent = new Intent(context, EventosAbrir.class);
// Pass all data rank
intent.putExtra("titulo",
(eventos_lista.get(position).getTitulo()));
intent.putExtra("descricao",
(eventos_lista.get(position).getDescricao()));
// Pass all data flag
intent.putExtra("textoevento",
(eventos_lista.get(position).getTextoEvento()));
intent.putExtra("fotoevento",
(eventos_lista.get(position).getFotoEvento()));
// PEGA O ARRAY DE IMAGENS E ENVIA PARA A OUTRA TELA
context.startActivity(intent);
}
});
return view;
}
The Activity that receives the data, including the image:
public class EventosAbrir extends ActionBarActivity {
String titulo;
String fotoevento;
String descricao;
String textoevento;
ImageLoader imageLoader = new ImageLoader(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventos_abrir);
Intent i = getIntent();
// Get the result of rank
titulo = i.getStringExtra("titulo");
textoevento = i.getStringExtra("textoevento");
// Get the result of country
descricao = i.getStringExtra("descricao");
//PEGA A FOTO QUE FOI PASSADA NA TELA ANTERIOR
fotoevento = i.getStringExtra("fotoevento");
TextView title = (TextView) findViewById(R.id.TituloAbrir);
TextView desc = (TextView) findViewById(R.id.DescricaoAbrir);
TextView txtevento = (TextView) findViewById(R.id.textoevento);
ImageView imgflag = (ImageView) findViewById(R.id.abrir_foto);
imgflag.setScaleType(ImageView.ScaleType.FIT_XY);
// Set results to the TextViews
title.setText(titulo);
desc.setText(descricao);
txtevento.setText(textoevento);
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
//EXIBE A IMAGEM PASSADA NA TELA ANTERIOR
imageLoader.DisplayImage(fotoevento, imgflag);
}
I note that getStringExtra takes the photoevent as String, does it have any influence?
EDITED
Problem solved. The Imageloader class carried the images in 150x150 and the images I put in the parse.com are 512x512 and when increasing the size of the imageview it lost quality. I changed the values in the Imageloader class and now the images come with perfect quality.