Commit 30f316ced7e327da3f32d12512e7d8b7931c246d

Authored by Imanol-Mikel Barba Sabariego
1 parent 2d7bbd5d

crash fixed

src/com/upc/pbe/upcnews/Descarrega.java
@@ -20,31 +20,21 @@ public class Descarrega extends AsyncTask<URL, Integer, String> @@ -20,31 +20,21 @@ public class Descarrega extends AsyncTask<URL, Integer, String>
20 { 20 {
21 ctx = c; 21 ctx = c;
22 } 22 }
23 -  
24 - @Override  
25 - protected void onPreExecute() {  
26 - //Codi previ a l'execució de la tasca en background  
27 - //pDialog.setMax(100);  
28 - //pDialog.setProgress(0);  
29 - }  
30 23
31 @Override 24 @Override
32 protected String doInBackground(URL... urls){ 25 protected String doInBackground(URL... urls){
33 //Codi de la tasca en background 26 //Codi de la tasca en background
34 String html = ""; 27 String html = "";
35 - // Iniciem la connexió i creem els Streams 28 + // Iniciem la connexi� i creem els Streams
36 try { 29 try {
37 URLConnection conn = urls[0].openConnection(); 30 URLConnection conn = urls[0].openConnection();
38 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 31 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
39 - // Iniciem la descarrega, anem guardant al String i actualitzant la barra de progrés 32 + // Iniciem la descarrega, anem guardant al String i actualitzant la barra de progr�s
40 int totalLength = conn.getContentLength(); 33 int totalLength = conn.getContentLength();
41 - int downloaded=0;  
42 String inputLine; 34 String inputLine;
43 Log.d(TAG, "\nDescarregant: \n"); 35 Log.d(TAG, "\nDescarregant: \n");
44 Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + " bytes"); 36 Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + " bytes");
45 while ((inputLine = in.readLine()) != null) { 37 while ((inputLine = in.readLine()) != null) {
46 - downloaded = downloaded + Integer.parseInt(inputLine.getBytes().toString());  
47 - publishProgress((downloaded/totalLength)*100);  
48 html += inputLine + "\n"; 38 html += inputLine + "\n";
49 } 39 }
50 in.close(); 40 in.close();
@@ -58,11 +48,4 @@ public class Descarrega extends AsyncTask<URL, Integer, String> @@ -58,11 +48,4 @@ public class Descarrega extends AsyncTask<URL, Integer, String>
58 } 48 }
59 return html; 49 return html;
60 } 50 }
61 -  
62 - @Override  
63 - protected void onProgressUpdate(Integer... values) {  
64 - //Actualitza la barra de progrés de la descàrrega, respon a la crida de publishProgress  
65 - int progreso = values[0].intValue();  
66 - //pDialog.setProgress(progreso);  
67 - }  
68 } 51 }
69 \ No newline at end of file 52 \ No newline at end of file
src/com/upc/pbe/upcnews/MainActivity.java
@@ -9,7 +9,6 @@ import java.util.concurrent.ExecutionException; @@ -9,7 +9,6 @@ import java.util.concurrent.ExecutionException;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.pm.PackageInfo; 11 import android.content.pm.PackageInfo;
12 -import android.content.pm.PackageManager;  
13 import android.os.Bundle; 12 import android.os.Bundle;
14 import android.util.Log; 13 import android.util.Log;
15 import android.view.Menu; 14 import android.view.Menu;
@@ -50,7 +49,7 @@ public class MainActivity extends Activity implements OnClickListener { @@ -50,7 +49,7 @@ public class MainActivity extends Activity implements OnClickListener {
50 buttonDescarrega = (ImageButton) findViewById(R.id.button); 49 buttonDescarrega = (ImageButton) findViewById(R.id.button);
51 buttonDescarrega.setOnClickListener(this); 50 buttonDescarrega.setOnClickListener(this);
52 updateURL(); 51 updateURL();
53 - //Si vitamio no està instal·lat, mostrem el missatge d'alerta 52 + //Si vitamio no est� instal�lat, mostrem el missatge d'alerta
54 List<PackageInfo> apps = getPackageManager().getInstalledPackages(0); 53 List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
55 for(int i = 0; i < apps.size(); i++) 54 for(int i = 0; i < apps.size(); i++)
56 { 55 {