From 831b817ade8cde921bc0a4dd408f746206c0f6e7 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Thu, 13 Dec 2012 09:16:19 +0000 Subject: [PATCH] --- src/com/upc/pbe/upcnews/Descarrega.java | 40 +++++++++++++++++++++++++++------------- src/com/upc/pbe/upcnews/MainActivity.java | 1 + 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/com/upc/pbe/upcnews/Descarrega.java b/src/com/upc/pbe/upcnews/Descarrega.java index 999eab7..0a9e540 100644 --- a/src/com/upc/pbe/upcnews/Descarrega.java +++ b/src/com/upc/pbe/upcnews/Descarrega.java @@ -22,20 +22,29 @@ public class Descarrega extends AsyncTask } @Override - protected String doInBackground(URL... urls) - { + protected void onPreExecute() { + //Codi previ a l'execució de la tasca en background + //pDialog.setMax(100); + //pDialog.setProgress(0); + } + + @Override + protected String doInBackground(URL... urls){ + //Codi de la tasca en background String html = ""; - // Iniciem la connexi� i creem els Streams - try - { + // Iniciem la connexió i creem els Streams + try { URLConnection conn = urls[0].openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); - // Iniciem la descarrega i anem guardant al String - Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + conn.getContentLength() + " bytes"); + // Iniciem la descarrega, anem guardant al String i actualitzant la barra de progrés + int totalLength = conn.getContentLength(); + int downloaded=0; String inputLine; - while ((inputLine = in.readLine()) != null) - { + Log.d(TAG, "\nDescarregant: \n"); + Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + " bytes"); + while ((inputLine = in.readLine()) != null) { + downloaded = downloaded + Integer.parseInt(inputLine.getBytes().toString()); + publishProgress((downloaded/totalLength)*100); html += inputLine + "\n"; } in.close(); @@ -49,6 +58,11 @@ public class Descarrega extends AsyncTask } return html; } - -} - + + @Override + protected void onProgressUpdate(Integer... values) { + //Actualitza la barra de progrés de la descàrrega, respon a la crida de publishProgress + int progreso = values[0].intValue(); + //pDialog.setProgress(progreso); + } +} \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/MainActivity.java b/src/com/upc/pbe/upcnews/MainActivity.java index 9f65484..2eb2aff 100644 --- a/src/com/upc/pbe/upcnews/MainActivity.java +++ b/src/com/upc/pbe/upcnews/MainActivity.java @@ -50,6 +50,7 @@ public class MainActivity extends Activity implements OnClickListener { buttonDescarrega = (ImageButton) findViewById(R.id.button); buttonDescarrega.setOnClickListener(this); updateURL(); + //Si vitamio no està instal·lat, mostrem el missatge d'alerta PackageManager pm = getPackageManager(); List apps = pm.getInstalledPackages(0); for(int i = 0; i < apps.size(); i++) -- libgit2 0.22.2