From 9acd4f95a5f6c88cdd86d1c442629d57ef0496b2 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Sun, 16 Dec 2012 15:23:26 +0000 Subject: [PATCH] --- src/com/upc/pbe/upcnews/Descarrega.java | 31 +++++++++++++++---------------- src/com/upc/pbe/upcnews/Directoris.java | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------- 2 files changed, 90 insertions(+), 116 deletions(-) diff --git a/src/com/upc/pbe/upcnews/Descarrega.java b/src/com/upc/pbe/upcnews/Descarrega.java index 5b02d86..fe151f5 100644 --- a/src/com/upc/pbe/upcnews/Descarrega.java +++ b/src/com/upc/pbe/upcnews/Descarrega.java @@ -11,41 +11,40 @@ import android.os.AsyncTask; import android.util.Log; import android.widget.Toast; -public class Descarrega extends AsyncTask -{ +public class Descarrega extends AsyncTask { final static String TAG = "Descarrega"; private Context ctx; - - public Descarrega(Context c) - { + + public Descarrega(Context c) { ctx = c; } - + @Override - protected String doInBackground(URL... urls){ - //Codi de la tasca en background + protected String doInBackground(URL... urls) { + // Codi de la tasca en background String html = ""; - // Iniciem la connexi� i creem els Streams + // Iniciem la connexió i creem els Streams try { URLConnection conn = urls[0].openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); - // Iniciem la descarrega, anem guardant al String i actualitzant la barra de progr�s + BufferedReader in = new BufferedReader(new InputStreamReader( + conn.getInputStream())); + // Iniciem la descarrega, anem guardant al String i actualitzant la + // barra de progrés int totalLength = conn.getContentLength(); String inputLine; Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + " bytes"); + Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + + " bytes"); while ((inputLine = in.readLine()) != null) { html += inputLine + "\n"; } in.close(); Log.d(TAG, "Descarrega finalitzada"); - } - catch(IOException e) - { + } catch (IOException e) { this.cancel(true); Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show(); return ""; } return html; - } + } } \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index c8e06db..a80e230 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -22,15 +22,13 @@ import android.widget.TextView; import android.widget.Toast; //Segona Activity, mostra els directoris i arxius del servidor -public class Directoris extends Activity implements OnItemClickListener -{ +public class Directoris extends Activity implements OnItemClickListener { final static String TAG = "Directoris"; private String URL, currentFolder; private HTMLParser parser; - public void onCreate(Bundle savedInstanceState) - { + public void onCreate(Bundle savedInstanceState) { // Creem el layout Log.d(TAG, "onCreated"); super.onCreate(savedInstanceState); @@ -46,151 +44,127 @@ public class Directoris extends Activity implements OnItemClickListener this.showResources(); } - public void showResources() - { + public void showResources() { // Actualitza la informacio que mostra la ListView a mesura que ens // desplacem pels directoris ArrayList entries; Descarrega d = new Descarrega(this); - try - { + try { d.execute(new URL(currentFolder)); entries = parser.parse(d.get()); this.createEntries(entries); - } - catch (InterruptedException e) - { + } catch (InterruptedException e) { e.printStackTrace(); - } - catch (ExecutionException e) - { + } catch (ExecutionException e) { e.printStackTrace(); - } - catch (IOException e) - { + } catch (IOException e) { // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!! } } - public void createEntries(ArrayList directories) - { + public void createEntries(ArrayList directories) { // Crea les entrades de la ListView String[] entries = directories.toArray(new String[directories.size()]); ListView listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(null); - ResourceAdapter adapter = new ResourceAdapter(this, R.layout.rowlayout, entries); + ResourceAdapter adapter = new ResourceAdapter(this, R.layout.rowlayout, + entries); listView.setAdapter(adapter); } - public void onItemClick(AdapterView parent, View view, int position, long id) { - //Determina el funcionament al clickar en una de les entrades de al ListView - String path = ((TextView)((RelativeLayout)view).findViewById(R.id.rowTextView)).getText().toString(); - //Si es un m3u8, el descarrega, parseja i inicia la reproduccio - if(path.endsWith(".m3u8")) - { + public void onItemClick(AdapterView parent, View view, int position, + long id) { + // Determina el funcionament al clickar en una de les entrades de al + // ListView + String path = ((TextView) ((RelativeLayout) view) + .findViewById(R.id.rowTextView)).getText().toString(); + // Si es un m3u8, el descarrega, parseja i inicia la reproduccio + if (path.endsWith(".m3u8")) { path = currentFolder + path; String playlist; - try - { - Descarrega d = new Descarrega(this); - //Descarreguem m3u8 - d.execute(new URL(path)); - playlist = d.get(); - Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); - try - { - //Parsing m3u8 - ArrayList m3u8parsed = p.parseFile(playlist); - Log.d(TAG, "Parsing completat"); - //Creem un gestor HLS - HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); - ((UpcApp)getApplication()).setHLS(h); - //Iniciem la reproduccio - Intent mIntent = new Intent(this, VideoActivity.class); - if(((UpcApp)getApplication()).getHLS() != null) - { - startActivity(mIntent); - } - else - { - Toast.makeText(this, "Error en gestor HLS", Toast.LENGTH_LONG).show(); - } + try { + Descarrega d = new Descarrega(this); + // Descarreguem m3u8 + d.execute(new URL(path)); + playlist = d.get(); + Parser p = new Parser(path.substring(0, + path.lastIndexOf("/") + 1), this); + try { + // Parsing m3u8 + ArrayList m3u8parsed = p.parseFile(playlist); + Log.d(TAG, "Parsing completat"); + // Creem un gestor HLS + HLS h = new HLS(m3u8parsed, + ((UpcApp) getApplication()).getLocalPath()); + ((UpcApp) getApplication()).setHLS(h); + // Iniciem la reproduccio + Intent mIntent = new Intent(this, VideoActivity.class); + if (((UpcApp) getApplication()).getHLS() != null) { + startActivity(mIntent); + } else { + Toast.makeText(this, "Error en gestor HLS", + Toast.LENGTH_LONG).show(); } - catch (ErrorException e) - { - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); - } - catch (WarningException e) - { - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); - } - catch (InfoException e) - { - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); - } - } - catch (IOException e1) - { - // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!! - } - catch (InterruptedException e1) - { - e1.printStackTrace(); - } - catch (ExecutionException e1) - { - e1.printStackTrace(); + } catch (ErrorException e) { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT) + .show(); + Log.d(TAG, e.getMessage()); + } catch (WarningException e) { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT) + .show(); + Log.d(TAG, e.getMessage()); + } catch (InfoException e) { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT) + .show(); + Log.d(TAG, e.getMessage()); } + } catch (IOException e1) { + // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL + // SERVIDOR!! + } catch (InterruptedException e1) { + e1.printStackTrace(); + } catch (ExecutionException e1) { + e1.printStackTrace(); } - //Si es una carpeta, hi entra i mostra el seu contingut - else - { - if(!path.startsWith("http://")) - { + } + // Si es una carpeta, hi entra i mostra el seu contingut + else { + if (!path.startsWith("http://")) { currentFolder += path; - } - else - { + } else { currentFolder = path; } showResources(); } } - public boolean onKeyDown(int keyCode, KeyEvent event) - { + public boolean onKeyDown(int keyCode, KeyEvent event) { // Determina el funcionament al apretar la tecla de tornar enrere - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) - { - if (currentFolder.equals(URL)) - { + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { + if (currentFolder.equals(URL)) { super.finish(); return true; } - currentFolder = currentFolder.substring(0, currentFolder.length() - 1); - currentFolder = currentFolder.substring(0, currentFolder.lastIndexOf("/") + 1); + currentFolder = currentFolder.substring(0, + currentFolder.length() - 1); + currentFolder = currentFolder.substring(0, + currentFolder.lastIndexOf("/") + 1); showResources(); return true; } return super.onKeyDown(keyCode, event); } - public boolean onCreateOptionsMenu(Menu menu) - { + public boolean onCreateOptionsMenu(Menu menu) { // Determina el funcionament al apretar la tecla d'opcions getMenuInflater().inflate(R.menu.menu, menu); Log.d(TAG, "Menu"); return true; } - public boolean onOptionsItemSelected(MenuItem item) - { + public boolean onOptionsItemSelected(MenuItem item) { // Determina el funcionament al clickar en el menu d'opcions - switch (item.getItemId()) - { + switch (item.getItemId()) { case R.id.itemprefs: startActivity(new Intent(this, Prefs.class)); Log.d(TAG, "Preferencies"); @@ -203,6 +177,7 @@ public class Directoris extends Activity implements OnItemClickListener return false; } } + @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); -- libgit2 0.22.2