Commit 9acd4f95a5f6c88cdd86d1c442629d57ef0496b2

Authored by Imanol-Mikel Barba Sabariego
1 parent 91c0e2fb

--no commit message

src/com/upc/pbe/upcnews/Descarrega.java
... ... @@ -11,41 +11,40 @@ import android.os.AsyncTask;
11 11 import android.util.Log;
12 12 import android.widget.Toast;
13 13  
14   -public class Descarrega extends AsyncTask<URL, Integer, String>
15   -{
  14 +public class Descarrega extends AsyncTask<URL, Integer, String> {
16 15 final static String TAG = "Descarrega";
17 16 private Context ctx;
18   -
19   - public Descarrega(Context c)
20   - {
  17 +
  18 + public Descarrega(Context c) {
21 19 ctx = c;
22 20 }
23   -
  21 +
24 22 @Override
25   - protected String doInBackground(URL... urls){
26   - //Codi de la tasca en background
  23 + protected String doInBackground(URL... urls) {
  24 + // Codi de la tasca en background
27 25 String html = "";
28   - // Iniciem la connexi i creem els Streams
  26 + // Iniciem la connexió i creem els Streams
29 27 try {
30 28 URLConnection conn = urls[0].openConnection();
31   - BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
32   - // Iniciem la descarrega, anem guardant al String i actualitzant la barra de progr�s
  29 + BufferedReader in = new BufferedReader(new InputStreamReader(
  30 + conn.getInputStream()));
  31 + // Iniciem la descarrega, anem guardant al String i actualitzant la
  32 + // barra de progrés
33 33 int totalLength = conn.getContentLength();
34 34 String inputLine;
35 35 Log.d(TAG, "\nDescarregant: \n");
36   - Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength + " bytes");
  36 + Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + totalLength
  37 + + " bytes");
37 38 while ((inputLine = in.readLine()) != null) {
38 39 html += inputLine + "\n";
39 40 }
40 41 in.close();
41 42 Log.d(TAG, "Descarrega finalitzada");
42   - }
43   - catch(IOException e)
44   - {
  43 + } catch (IOException e) {
45 44 this.cancel(true);
46 45 Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
47 46 return "";
48 47 }
49 48 return html;
50   - }
  49 + }
51 50 }
52 51 \ No newline at end of file
... ...
src/com/upc/pbe/upcnews/Directoris.java
... ... @@ -22,15 +22,13 @@ import android.widget.TextView;
22 22 import android.widget.Toast;
23 23  
24 24 //Segona Activity, mostra els directoris i arxius del servidor
25   -public class Directoris extends Activity implements OnItemClickListener
26   -{
  25 +public class Directoris extends Activity implements OnItemClickListener {
27 26  
28 27 final static String TAG = "Directoris";
29 28 private String URL, currentFolder;
30 29 private HTMLParser parser;
31 30  
32   - public void onCreate(Bundle savedInstanceState)
33   - {
  31 + public void onCreate(Bundle savedInstanceState) {
34 32 // Creem el layout
35 33 Log.d(TAG, "onCreated");
36 34 super.onCreate(savedInstanceState);
... ... @@ -46,151 +44,127 @@ public class Directoris extends Activity implements OnItemClickListener
46 44 this.showResources();
47 45 }
48 46  
49   - public void showResources()
50   - {
  47 + public void showResources() {
51 48 // Actualitza la informacio que mostra la ListView a mesura que ens
52 49 // desplacem pels directoris
53 50 ArrayList<String> entries;
54 51 Descarrega d = new Descarrega(this);
55   - try
56   - {
  52 + try {
57 53 d.execute(new URL(currentFolder));
58 54 entries = parser.parse(d.get());
59 55 this.createEntries(entries);
60   - }
61   - catch (InterruptedException e)
62   - {
  56 + } catch (InterruptedException e) {
63 57 e.printStackTrace();
64   - }
65   - catch (ExecutionException e)
66   - {
  58 + } catch (ExecutionException e) {
67 59 e.printStackTrace();
68   - }
69   - catch (IOException e)
70   - {
  60 + } catch (IOException e) {
71 61 // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!!
72 62 }
73 63 }
74 64  
75   - public void createEntries(ArrayList<String> directories)
76   - {
  65 + public void createEntries(ArrayList<String> directories) {
77 66 // Crea les entrades de la ListView
78 67 String[] entries = directories.toArray(new String[directories.size()]);
79 68 ListView listView = (ListView) findViewById(R.id.listView1);
80 69 listView.setAdapter(null);
81   - ResourceAdapter adapter = new ResourceAdapter(this, R.layout.rowlayout, entries);
  70 + ResourceAdapter adapter = new ResourceAdapter(this, R.layout.rowlayout,
  71 + entries);
82 72 listView.setAdapter(adapter);
83 73 }
84 74  
85   - public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
86   - //Determina el funcionament al clickar en una de les entrades de al ListView
87   - String path = ((TextView)((RelativeLayout)view).findViewById(R.id.rowTextView)).getText().toString();
88   - //Si es un m3u8, el descarrega, parseja i inicia la reproduccio
89   - if(path.endsWith(".m3u8"))
90   - {
  75 + public void onItemClick(AdapterView<?> parent, View view, int position,
  76 + long id) {
  77 + // Determina el funcionament al clickar en una de les entrades de al
  78 + // ListView
  79 + String path = ((TextView) ((RelativeLayout) view)
  80 + .findViewById(R.id.rowTextView)).getText().toString();
  81 + // Si es un m3u8, el descarrega, parseja i inicia la reproduccio
  82 + if (path.endsWith(".m3u8")) {
91 83 path = currentFolder + path;
92 84 String playlist;
93   - try
94   - {
95   - Descarrega d = new Descarrega(this);
96   - //Descarreguem m3u8
97   - d.execute(new URL(path));
98   - playlist = d.get();
99   - Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this);
100   - try
101   - {
102   - //Parsing m3u8
103   - ArrayList<ParentList> m3u8parsed = p.parseFile(playlist);
104   - Log.d(TAG, "Parsing completat");
105   - //Creem un gestor HLS
106   - HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath());
107   - ((UpcApp)getApplication()).setHLS(h);
108   - //Iniciem la reproduccio
109   - Intent mIntent = new Intent(this, VideoActivity.class);
110   - if(((UpcApp)getApplication()).getHLS() != null)
111   - {
112   - startActivity(mIntent);
113   - }
114   - else
115   - {
116   - Toast.makeText(this, "Error en gestor HLS", Toast.LENGTH_LONG).show();
117   - }
  85 + try {
  86 + Descarrega d = new Descarrega(this);
  87 + // Descarreguem m3u8
  88 + d.execute(new URL(path));
  89 + playlist = d.get();
  90 + Parser p = new Parser(path.substring(0,
  91 + path.lastIndexOf("/") + 1), this);
  92 + try {
  93 + // Parsing m3u8
  94 + ArrayList<ParentList> m3u8parsed = p.parseFile(playlist);
  95 + Log.d(TAG, "Parsing completat");
  96 + // Creem un gestor HLS
  97 + HLS h = new HLS(m3u8parsed,
  98 + ((UpcApp) getApplication()).getLocalPath());
  99 + ((UpcApp) getApplication()).setHLS(h);
  100 + // Iniciem la reproduccio
  101 + Intent mIntent = new Intent(this, VideoActivity.class);
  102 + if (((UpcApp) getApplication()).getHLS() != null) {
  103 + startActivity(mIntent);
  104 + } else {
  105 + Toast.makeText(this, "Error en gestor HLS",
  106 + Toast.LENGTH_LONG).show();
118 107 }
119   - catch (ErrorException e)
120   - {
121   - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
122   - Log.d(TAG, e.getMessage());
123   - }
124   - catch (WarningException e)
125   - {
126   - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
127   - Log.d(TAG, e.getMessage());
128   - }
129   - catch (InfoException e)
130   - {
131   - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
132   - Log.d(TAG, e.getMessage());
133   - }
134   - }
135   - catch (IOException e1)
136   - {
137   - // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!!
138   - }
139   - catch (InterruptedException e1)
140   - {
141   - e1.printStackTrace();
142   - }
143   - catch (ExecutionException e1)
144   - {
145   - e1.printStackTrace();
  108 + } catch (ErrorException e) {
  109 + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT)
  110 + .show();
  111 + Log.d(TAG, e.getMessage());
  112 + } catch (WarningException e) {
  113 + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT)
  114 + .show();
  115 + Log.d(TAG, e.getMessage());
  116 + } catch (InfoException e) {
  117 + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT)
  118 + .show();
  119 + Log.d(TAG, e.getMessage());
146 120 }
  121 + } catch (IOException e1) {
  122 + // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL
  123 + // SERVIDOR!!
  124 + } catch (InterruptedException e1) {
  125 + e1.printStackTrace();
  126 + } catch (ExecutionException e1) {
  127 + e1.printStackTrace();
147 128 }
148   - //Si es una carpeta, hi entra i mostra el seu contingut
149   - else
150   - {
151   - if(!path.startsWith("http://"))
152   - {
  129 + }
  130 + // Si es una carpeta, hi entra i mostra el seu contingut
  131 + else {
  132 + if (!path.startsWith("http://")) {
153 133 currentFolder += path;
154   - }
155   - else
156   - {
  134 + } else {
157 135 currentFolder = path;
158 136 }
159 137 showResources();
160 138 }
161 139 }
162 140  
163   - public boolean onKeyDown(int keyCode, KeyEvent event)
164   - {
  141 + public boolean onKeyDown(int keyCode, KeyEvent event) {
165 142 // Determina el funcionament al apretar la tecla de tornar enrere
166   - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
167   - {
168   - if (currentFolder.equals(URL))
169   - {
  143 + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  144 + if (currentFolder.equals(URL)) {
170 145 super.finish();
171 146 return true;
172 147 }
173   - currentFolder = currentFolder.substring(0, currentFolder.length() - 1);
174   - currentFolder = currentFolder.substring(0, currentFolder.lastIndexOf("/") + 1);
  148 + currentFolder = currentFolder.substring(0,
  149 + currentFolder.length() - 1);
  150 + currentFolder = currentFolder.substring(0,
  151 + currentFolder.lastIndexOf("/") + 1);
175 152 showResources();
176 153 return true;
177 154 }
178 155 return super.onKeyDown(keyCode, event);
179 156 }
180 157  
181   - public boolean onCreateOptionsMenu(Menu menu)
182   - {
  158 + public boolean onCreateOptionsMenu(Menu menu) {
183 159 // Determina el funcionament al apretar la tecla d'opcions
184 160 getMenuInflater().inflate(R.menu.menu, menu);
185 161 Log.d(TAG, "Menu");
186 162 return true;
187 163 }
188 164  
189   - public boolean onOptionsItemSelected(MenuItem item)
190   - {
  165 + public boolean onOptionsItemSelected(MenuItem item) {
191 166 // Determina el funcionament al clickar en el menu d'opcions
192   - switch (item.getItemId())
193   - {
  167 + switch (item.getItemId()) {
194 168 case R.id.itemprefs:
195 169 startActivity(new Intent(this, Prefs.class));
196 170 Log.d(TAG, "Preferencies");
... ... @@ -203,6 +177,7 @@ public class Directoris extends Activity implements OnItemClickListener
203 177 return false;
204 178 }
205 179 }
  180 +
206 181 @Override
207 182 public void onConfigurationChanged(Configuration newConfig) {
208 183 super.onConfigurationChanged(newConfig);
... ...