Commit adb2f8c87973b0a54655882e96029f04b04e6fb3
1 parent
ad1210f1
--no commit message
Showing
2 changed files
with
21 additions
and
26 deletions
src/com/upc/pbe/upcnews/Descarrega.java
@@ -14,25 +14,26 @@ import java.net.URLConnection; | @@ -14,25 +14,26 @@ import java.net.URLConnection; | ||
14 | import android.os.AsyncTask; | 14 | import android.os.AsyncTask; |
15 | import android.util.Log; | 15 | import android.util.Log; |
16 | 16 | ||
17 | - | ||
18 | -public class Descarrega extends AsyncTask<Object, Object, Object>{ | 17 | +public class Descarrega extends AsyncTask<Object, Object, Object> { |
19 | final static String TAG = "Descarrega"; | 18 | final static String TAG = "Descarrega"; |
20 | private String url; | 19 | private String url; |
21 | - private String nomarxiu; | ||
22 | private String carpeta; | 20 | private String carpeta; |
21 | + private String nomarxiu; | ||
23 | private String html; | 22 | private String html; |
24 | private File arxiu; | 23 | private File arxiu; |
25 | 24 | ||
26 | public Descarrega() { | 25 | public Descarrega() { |
26 | + nomarxiu = "ejemplo.xml"; | ||
27 | + carpeta = "Environment.getExternalStorageDirectory.getPath()"; | ||
27 | 28 | ||
28 | - | 29 | + this.carpeta = null; |
29 | this.html = null; | 30 | this.html = null; |
30 | this.arxiu = null; | 31 | this.arxiu = null; |
31 | } | 32 | } |
32 | 33 | ||
33 | - public void descarregarguardar(String u, String nomarxiu, String carpeta) { | ||
34 | - this.nomarxiu = nomarxiu; | ||
35 | - this.carpeta = carpeta; | 34 | + public void descarregarguardar(String u, String nom, String car) { |
35 | + this.nomarxiu = nom; | ||
36 | + this.carpeta = car; | ||
36 | this.url = u; | 37 | this.url = u; |
37 | // Creem el directori | 38 | // Creem el directori |
38 | File dir = new File(carpeta); | 39 | File dir = new File(carpeta); |
@@ -73,8 +74,6 @@ public class Descarrega extends AsyncTask<Object, Object, Object>{ | @@ -73,8 +74,6 @@ public class Descarrega extends AsyncTask<Object, Object, Object>{ | ||
73 | } | 74 | } |
74 | } | 75 | } |
75 | 76 | ||
76 | - | ||
77 | - | ||
78 | protected String doInBackground(String u) { | 77 | protected String doInBackground(String u) { |
79 | this.url = u; | 78 | this.url = u; |
80 | try { | 79 | try { |
@@ -82,30 +81,29 @@ public class Descarrega extends AsyncTask<Object, Object, Object>{ | @@ -82,30 +81,29 @@ public class Descarrega extends AsyncTask<Object, Object, Object>{ | ||
82 | BufferedReader in = new BufferedReader(new InputStreamReader( | 81 | BufferedReader in = new BufferedReader(new InputStreamReader( |
83 | conn.getInputStream())); | 82 | conn.getInputStream())); |
84 | Log.d(TAG, "\nDescarregant: \n"); | 83 | Log.d(TAG, "\nDescarregant: \n"); |
85 | - Log.d(TAG, ">> URL: " + url + " >> Tamany: " + conn.getContentLength() + " bytes"); | 84 | + Log.d(TAG, |
85 | + ">> URL: " + url + " >> Tamany: " + conn.getContentLength() | ||
86 | + + " bytes"); | ||
86 | String inputLine; | 87 | String inputLine; |
87 | while ((inputLine = in.readLine()) != null) { | 88 | while ((inputLine = in.readLine()) != null) { |
88 | html = html + "\n" + inputLine; | 89 | html = html + "\n" + inputLine; |
89 | } | 90 | } |
90 | Log.d(TAG, "Descarrega finalitzada"); | 91 | Log.d(TAG, "Descarrega finalitzada"); |
91 | - | 92 | + |
92 | in.close(); | 93 | in.close(); |
93 | } catch (MalformedURLException e) { | 94 | } catch (MalformedURLException e) { |
94 | Log.d(TAG, "excepcio 1, no sha trobat la URL"); | 95 | Log.d(TAG, "excepcio 1, no sha trobat la URL"); |
95 | } catch (IOException e) { | 96 | } catch (IOException e) { |
96 | Log.d(TAG, "excepcio 2"); | 97 | Log.d(TAG, "excepcio 2"); |
97 | } | 98 | } |
98 | - | 99 | + |
99 | return html; | 100 | return html; |
100 | - | ||
101 | - | 101 | + |
102 | } | 102 | } |
103 | - | ||
104 | - | ||
105 | 103 | ||
106 | @Override | 104 | @Override |
107 | protected Object doInBackground(Object... arg0) { | 105 | protected Object doInBackground(Object... arg0) { |
108 | - | 106 | + |
109 | return null; | 107 | return null; |
110 | } | 108 | } |
111 | } | 109 | } |
src/com/upc/pbe/upcnews/Directoris.java
@@ -19,8 +19,6 @@ public class Directoris extends Activity implements OnClickListener { | @@ -19,8 +19,6 @@ public class Directoris extends Activity implements OnClickListener { | ||
19 | String s; | 19 | String s; |
20 | Descarrega d; | 20 | Descarrega d; |
21 | String url; | 21 | String url; |
22 | - String file = "ejemplo.xml"; | ||
23 | - String folder = "Environment.getExternalStorageDirectory.getPath()"; | ||
24 | 22 | ||
25 | ArrayList<Button> buttons = new ArrayList<Button>(); | 23 | ArrayList<Button> buttons = new ArrayList<Button>(); |
26 | 24 | ||
@@ -31,9 +29,9 @@ public class Directoris extends Activity implements OnClickListener { | @@ -31,9 +29,9 @@ public class Directoris extends Activity implements OnClickListener { | ||
31 | super.onCreate(savedInstanceState); | 29 | super.onCreate(savedInstanceState); |
32 | setContentView(R.layout.dirs); | 30 | setContentView(R.layout.dirs); |
33 | 31 | ||
34 | - this.crearButtons(); | ||
35 | 32 | ||
36 | //Descarrega del HTML de l'index, busqueda de directoris i creacio dels botons | 33 | //Descarrega del HTML de l'index, busqueda de directoris i creacio dels botons |
34 | + this.crearButtons(); | ||
37 | s = ((UpcApp) getApplication()).getDesc(); | 35 | s = ((UpcApp) getApplication()).getDesc(); |
38 | 36 | ||
39 | HTMLParser pars = new HTMLParser(); | 37 | HTMLParser pars = new HTMLParser(); |
@@ -121,15 +119,14 @@ public class Directoris extends Activity implements OnClickListener { | @@ -121,15 +119,14 @@ public class Directoris extends Activity implements OnClickListener { | ||
121 | Parser p = new Parser(); | 119 | Parser p = new Parser(); |
122 | try { | 120 | try { |
123 | ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8); | 121 | ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8); |
124 | - /* | ||
125 | - * Imanol: Recorda'm que et comenti una cosa sobre les excepcions! | ||
126 | - */ | 122 | + |
123 | + | ||
127 | } catch (ErrorException e) { | 124 | } catch (ErrorException e) { |
128 | - e.printStackTrace(); | 125 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); |
129 | } catch (WarningException e) { | 126 | } catch (WarningException e) { |
130 | - e.printStackTrace(); | 127 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); |
131 | } catch (InfoException e) { | 128 | } catch (InfoException e) { |
132 | - e.printStackTrace(); | 129 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); |
133 | } | 130 | } |
134 | } | 131 | } |
135 | 132 |