From 8885baa7a96c65ae0cc92b8460a89e3406081982 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Fri, 7 Dec 2012 22:31:58 +0000 Subject: [PATCH] Navegador HTTP funcional 100% :DDDDD --- src/com/upc/pbe/upcnews/Directoris.java | 88 +++++++++++++++++++++++++++++----------------------------------------------------------- src/com/upc/pbe/upcnews/HTMLParser.java | 24 +++++++++--------------- 2 files changed, 38 insertions(+), 74 deletions(-) diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index 8223850..9ea3a10 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -15,6 +15,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.Toast; public class Directoris extends Activity implements OnItemClickListener { @@ -77,60 +78,17 @@ public class Directoris extends Activity implements OnItemClickListener public void onItemClick(AdapterView parent, View view, int position, long id) { String path = ((TextView)view).getText().toString(); - if(!path.startsWith("http://")) + if(path.endsWith(".m3u8")) { - currentFolder += path; - } - else - { - currentFolder = path; - } - showResources(); - } - - public void showResources() - { - ArrayList entries = parser.parse(d.doInBackground(currentFolder)); - this.createEntries(entries); - } - - /*public void buttonClicked(Button b) - { - - // Descarrega de la p�gina HTML del directori i busqueda d'un .m3u8 en - // ella - Log.d(TAG, "Click on " + b.getText()); - String path = b.getText().toString(); - if (path.equals("")) - { - path = ""; - } - path += "/"; - d = new Descarrega(); - String str = d.doInBackground(url + "/" + path); - HTMLParser pars = new HTMLParser(); - - String urlvideo = pars.findvideo(str, url + "/" + path); - Log.d(TAG, urlvideo); - - // Descarrega de l'arxiu .m3u8 (si existeix) i parseig - if (urlvideo.equalsIgnoreCase("No s'ha trobat")) - { - Toast.makeText(this, "The directory " + b.getText() - + " does not contain any '.m3u8' file", Toast.LENGTH_LONG).show(); - } - else - { - d = new Descarrega(); - String m3u8 = d.doInBackground(urlvideo); - Log.d(TAG, m3u8); - Parser p = new Parser(urlvideo.substring(0, urlvideo.lastIndexOf("/") + 1), this); + path = currentFolder + path; + String playlist = d.doInBackground(path); + Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); try { - ArrayList m3u8parsed = p.parseFile(m3u8); - Log.d(TAG, "parsed completed"); - HLS h = new HLS(m3u8parsed); - h.start(); + ArrayList m3u8parsed = p.parseFile(playlist); + Log.d(TAG, "parsing completed"); + //HLS h = new HLS(m3u8parsed); + //h.start(); } catch (ErrorException e) @@ -149,14 +107,26 @@ public class Directoris extends Activity implements OnItemClickListener Log.d(TAG, e.getMessage()); } - }*/ - - /* - * String urlvid = null; ((UpcApp) getApplication()).setDesc(urlvid); - * - * startActivity(new Intent(this, VideoActivity.class)); - - }*/ + } + else //Se trata de una carpeta + { + if(!path.startsWith("http://")) + { + currentFolder += path; + } + else + { + currentFolder = path; + } + showResources(); + } + } + + public void showResources() + { + ArrayList entries = parser.parse(d.doInBackground(currentFolder)); + this.createEntries(entries); + } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) diff --git a/src/com/upc/pbe/upcnews/HTMLParser.java b/src/com/upc/pbe/upcnews/HTMLParser.java index aeb2c5a..d020572 100644 --- a/src/com/upc/pbe/upcnews/HTMLParser.java +++ b/src/com/upc/pbe/upcnews/HTMLParser.java @@ -24,7 +24,7 @@ public class HTMLParser resources.clear(); } parseDirectories(resources,code); - //parseFiles(resources,code); + parseFiles(resources,code); return resources; } @@ -69,13 +69,9 @@ public class HTMLParser } } - /*public ArrayList findvideo(String code, String direccio) + public void parseFiles(ArrayList resources, String code) { - // Donada la direcci� del directori i el html del mateix, troba l'arxiu - // .m3u8 i retorna - // la url directe. String[] split = code.split("\n"); - for (int i = 0; i < split.length; i++) { while (split[i].startsWith("