Commit 0a050c2cedde9a76d5d5ae0f89e4bf5c4b328d44

Authored by Imanol-Mikel Barba Sabariego
1 parent 08b974e7

Fin de la claseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

AndroidManifest.xml
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 <uses-permission android:name="android.permission.INTERNET"/> 9 <uses-permission android:name="android.permission.INTERNET"/>
10 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 10 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11 11
  12 +
12 <application 13 <application
13 android:name=".UpcApp" 14 android:name=".UpcApp"
14 android:icon="@drawable/ic_launcher" 15 android:icon="@drawable/ic_launcher"
gen/com/upc/pbe/upcnews/R.java
@@ -16,23 +16,24 @@ public final class R { @@ -16,23 +16,24 @@ public final class R {
16 public static final int ic_menu_name=0x7f020002; 16 public static final int ic_menu_name=0x7f020002;
17 } 17 }
18 public static final class id { 18 public static final class id {
19 - public static final int AbsoluteLayout1=0x7f080008;  
20 - public static final int ImageView01=0x7f08000d;  
21 - public static final int ImageView1=0x7f08000c; 19 + public static final int AbsoluteLayout1=0x7f080009;
  20 + public static final int ImageView01=0x7f08000b;
  21 + public static final int ImageView1=0x7f08000a;
22 public static final int LinearLayout1=0x7f080000; 22 public static final int LinearLayout1=0x7f080000;
23 - public static final int button=0x7f08000a; 23 + public static final int button=0x7f08000d;
24 public static final int button1=0x7f080002; 24 public static final int button1=0x7f080002;
25 public static final int button2=0x7f080003; 25 public static final int button2=0x7f080003;
26 public static final int button3=0x7f080004; 26 public static final int button3=0x7f080004;
27 public static final int button4=0x7f080005; 27 public static final int button4=0x7f080005;
28 - public static final int itemhelp=0x7f080010;  
29 - public static final int itemprefs=0x7f08000f;  
30 - public static final int menu_settings=0x7f08000e;  
31 - public static final int textView1=0x7f080006;  
32 - public static final int textView2=0x7f080007;  
33 - public static final int textViewRoute=0x7f080009; 28 + public static final int button5=0x7f080006;
  29 + public static final int itemhelp=0x7f080011;
  30 + public static final int itemprefs=0x7f080010;
  31 + public static final int menu_settings=0x7f08000f;
  32 + public static final int textView1=0x7f080007;
  33 + public static final int textView2=0x7f080008;
  34 + public static final int textViewRoute=0x7f08000c;
34 public static final int textViewTitle=0x7f080001; 35 public static final int textViewTitle=0x7f080001;
35 - public static final int textViewXml=0x7f08000b; 36 + public static final int textViewXml=0x7f08000e;
36 } 37 }
37 public static final class layout { 38 public static final class layout {
38 public static final int dirs=0x7f030000; 39 public static final int dirs=0x7f030000;
res/layout/dirs.xml
@@ -7,12 +7,11 @@ @@ -7,12 +7,11 @@
7 android:orientation="vertical" > 7 android:orientation="vertical" >
8 8
9 <!-- Vista en llista --> 9 <!-- Vista en llista -->
10 - 10 +
11 <TextView 11 <TextView
12 android:id="@+id/textViewTitle" 12 android:id="@+id/textViewTitle"
13 android:layout_width="wrap_content" 13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content" 14 android:layout_height="wrap_content"
15 - android:layout_gravity="left"  
16 android:layout_marginLeft="14dp" 15 android:layout_marginLeft="14dp"
17 android:text="@string/title" 16 android:text="@string/title"
18 android:textAppearance="?android:attr/textAppearanceMedium" /> 17 android:textAppearance="?android:attr/textAppearanceMedium" />
@@ -41,4 +40,10 @@ @@ -41,4 +40,10 @@
41 android:layout_height="wrap_content" 40 android:layout_height="wrap_content"
42 android:layout_marginTop="38dp" /> 41 android:layout_marginTop="38dp" />
43 42
  43 + <Button
  44 + android:id="@+id/button5"
  45 + android:layout_width="match_parent"
  46 + android:layout_height="wrap_content"
  47 + android:layout_marginTop="38dp" />
  48 +
44 </LinearLayout> 49 </LinearLayout>
45 \ No newline at end of file 50 \ No newline at end of file
res/layout/main_activity.xml
@@ -15,47 +15,47 @@ @@ -15,47 +15,47 @@
15 android:text="@string/app_name" 15 android:text="@string/app_name"
16 android:textAppearance="?android:attr/textAppearanceLarge" /> 16 android:textAppearance="?android:attr/textAppearanceLarge" />
17 17
  18 + <ImageView
  19 + android:id="@+id/ImageView1"
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:layout_x="28dp"
  23 + android:layout_y="12dp"
  24 + android:src="@drawable/ic_launcher" />
  25 +
  26 + <ImageView
  27 + android:id="@+id/ImageView01"
  28 + android:layout_width="wrap_content"
  29 + android:layout_height="wrap_content"
  30 + android:layout_x="223dp"
  31 + android:layout_y="14dp"
  32 + android:src="@drawable/ic_launcher" />
  33 +
18 <TextView 34 <TextView
19 android:id="@+id/textViewRoute" 35 android:id="@+id/textViewRoute"
20 android:layout_width="250dp" 36 android:layout_width="250dp"
21 android:layout_height="22dp" 37 android:layout_height="22dp"
22 - android:layout_x="26dp"  
23 - android:layout_y="328dp" 38 + android:layout_x="28dp"
  39 + android:layout_y="306dp"
24 android:textSize="@android:dimen/thumbnail_height" /> 40 android:textSize="@android:dimen/thumbnail_height" />
25 41
26 <Button 42 <Button
27 android:id="@+id/button" 43 android:id="@+id/button"
28 android:layout_width="258dp" 44 android:layout_width="258dp"
29 android:layout_height="wrap_content" 45 android:layout_height="wrap_content"
30 - android:layout_x="24dp"  
31 - android:layout_y="352dp" 46 + android:layout_x="26dp"
  47 + android:layout_y="333dp"
32 android:text="@string/descarregar" /> 48 android:text="@string/descarregar" />
33 49
34 <TextView 50 <TextView
35 android:id="@+id/textViewXml" 51 android:id="@+id/textViewXml"
36 - android:layout_width="301dp" 52 + android:layout_width="wrap_content"
37 android:layout_height="wrap_content" 53 android:layout_height="wrap_content"
38 - android:layout_x="28dp"  
39 - android:layout_y="400dp" 54 + android:layout_x="18dp"
  55 + android:layout_y="384dp"
40 android:gravity="clip_vertical" 56 android:gravity="clip_vertical"
41 android:hint="@string/hint" 57 android:hint="@string/hint"
42 android:scrollbarStyle="insideInset" 58 android:scrollbarStyle="insideInset"
43 android:scrollbars="vertical" /> 59 android:scrollbars="vertical" />
44 60
45 - <ImageView  
46 - android:id="@+id/ImageView1"  
47 - android:layout_width="wrap_content"  
48 - android:layout_height="wrap_content"  
49 - android:layout_x="28dp"  
50 - android:layout_y="12dp"  
51 - android:src="@drawable/ic_launcher" />  
52 -  
53 - <ImageView  
54 - android:id="@+id/ImageView01"  
55 - android:layout_width="wrap_content"  
56 - android:layout_height="wrap_content"  
57 - android:layout_x="223dp"  
58 - android:layout_y="14dp"  
59 - android:src="@drawable/ic_launcher" />  
60 -  
61 </AbsoluteLayout> 61 </AbsoluteLayout>
62 \ No newline at end of file 62 \ No newline at end of file
res/values/strings.xml
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 <string name="app_name">UPC_NEWS</string> 3 <string name="app_name">UPC_NEWS</string>
4 <string name="menu_settings">Settings</string> 4 <string name="menu_settings">Settings</string>
5 <string name="title_activity_main">MainActivity</string> 5 <string name="title_activity_main">MainActivity</string>
6 - <string name="descarregar">Start</string>  
7 - <string name="hint">Click to Start Button.</string> 6 + <string name="descarregar">Start Application</string>
  7 + <string name="hint">Click to Start button or click Settins for Help</string>
8 <string name="url">URL server</string> 8 <string name="url">URL server</string>
9 <string name="urlhint">Set the route from the server (without http://)</string> 9 <string name="urlhint">Set the route from the server (without http://)</string>
10 <string name="prefs">Preferences</string> 10 <string name="prefs">Preferences</string>
src/com/upc/pbe/upcnews/Descarrega.java
@@ -89,11 +89,9 @@ public class Descarrega extends AsyncTask&lt;Object, Object, Object&gt;{ @@ -89,11 +89,9 @@ public class Descarrega extends AsyncTask&lt;Object, Object, Object&gt;{
89 89
90 in.close(); 90 in.close();
91 } catch (MalformedURLException e) { 91 } catch (MalformedURLException e) {
92 - Log.d(TAG, "excepcio 1");  
93 - e.printStackTrace(); 92 + Log.d(TAG, "excepcio 1, no sha trobat la URL");
94 } catch (IOException e) { 93 } catch (IOException e) {
95 Log.d(TAG, "excepcio 2"); 94 Log.d(TAG, "excepcio 2");
96 - e.printStackTrace();  
97 } 95 }
98 96
99 return html; 97 return html;
src/com/upc/pbe/upcnews/Directoris.java
@@ -11,6 +11,7 @@ import android.view.MenuItem; @@ -11,6 +11,7 @@ import android.view.MenuItem;
11 import android.view.View; 11 import android.view.View;
12 import android.view.View.OnClickListener; 12 import android.view.View.OnClickListener;
13 import android.widget.Button; 13 import android.widget.Button;
  14 +import android.widget.Toast;
14 15
15 public class Directoris extends Activity implements OnClickListener { 16 public class Directoris extends Activity implements OnClickListener {
16 17
@@ -73,24 +74,49 @@ public class Directoris extends Activity implements OnClickListener { @@ -73,24 +74,49 @@ public class Directoris extends Activity implements OnClickListener {
73 74
74 case R.id.button1: { 75 case R.id.button1: {
75 Log.d(TAG, "Click on button1"); 76 Log.d(TAG, "Click on button1");
76 - d = new Descarrega(url + "/" + buttons.get(0).getText() + "/", file,  
77 - folder); 77 + d = new Descarrega(url + "/" + buttons.get(0).getText() + "/",
  78 + file, folder);
78 String str = d.doInBackground(); 79 String str = d.doInBackground();
79 80
80 HTMLParser pars = new HTMLParser(); 81 HTMLParser pars = new HTMLParser();
81 - String urlvideo = pars.findvideo(str,  
82 - url + "/" + buttons.get(0).getText() + "/"); 82 + String urlvideo = pars.findvideo(str, url + "/"
  83 + + buttons.get(0).getText() + "/");
83 84
84 Log.d(TAG, urlvideo); 85 Log.d(TAG, urlvideo);
85 86
86 - d = new Descarrega(urlvideo, file, folder);  
87 - String m3u8 = d.doInBackground();  
88 -  
89 - Log.d(TAG, m3u8); 87 + if (urlvideo == "No s'ha trobat") {
  88 + Toast.makeText(this, "El directori no conté cap .m3u8",
  89 + Toast.LENGTH_LONG).show();
  90 + } else {
  91 + d = new Descarrega(urlvideo, file, folder);
  92 + String m3u8 = d.doInBackground();
  93 + }
  94 + // m3u8 --> PARSE!
  95 + break;
90 96
91 } 97 }
92 case R.id.button2: { 98 case R.id.button2: {
  99 + Log.d(TAG, "Click on button2");
  100 + d = new Descarrega(url + "/" + buttons.get(1).getText() + "/",
  101 + file, folder);
  102 + String str = d.doInBackground();
  103 +
  104 + HTMLParser pars = new HTMLParser();
  105 + String urlvideo = pars.findvideo(str, url + "/"
  106 + + buttons.get(1).getText() + "/");
93 107
  108 + Log.d(TAG, urlvideo);
  109 +
  110 + if (urlvideo == "No s'ha trobat") {
  111 + Toast.makeText(this, "El directori no conté cap .m3u8",
  112 + Toast.LENGTH_LONG).show();
  113 + } else {
  114 +
  115 + d = new Descarrega(urlvideo, file, folder);
  116 + String m3u8 = d.doInBackground();
  117 + }
  118 + // m3u8 --> PARSE!
  119 + break;
94 } 120 }
95 case R.id.button3: { 121 case R.id.button3: {
96 122
@@ -103,13 +129,13 @@ public class Directoris extends Activity implements OnClickListener { @@ -103,13 +129,13 @@ public class Directoris extends Activity implements OnClickListener {
103 129
104 public void crearButtons() { 130 public void crearButtons() {
105 131
106 -  
107 buttons.add((Button) findViewById(R.id.button1)); 132 buttons.add((Button) findViewById(R.id.button1));
108 buttons.add((Button) findViewById(R.id.button2)); 133 buttons.add((Button) findViewById(R.id.button2));
109 buttons.add((Button) findViewById(R.id.button3)); 134 buttons.add((Button) findViewById(R.id.button3));
110 buttons.add((Button) findViewById(R.id.button4)); 135 buttons.add((Button) findViewById(R.id.button4));
  136 + buttons.add((Button) findViewById(R.id.button5));
111 137
112 - for(int i = 0; i < buttons.size(); i++){ 138 + for (int i = 0; i < buttons.size(); i++) {
113 buttons.get(i).setOnClickListener(this); 139 buttons.get(i).setOnClickListener(this);
114 buttons.get(i).setVisibility(View.GONE); 140 buttons.get(i).setVisibility(View.GONE);
115 } 141 }
src/com/upc/pbe/upcnews/MainActivity.java
@@ -22,6 +22,7 @@ public class MainActivity extends Activity implements OnClickListener { @@ -22,6 +22,7 @@ public class MainActivity extends Activity implements OnClickListener {
22 String folder = "Environment.getExternalStorageDirectory.getPath()"; 22 String folder = "Environment.getExternalStorageDirectory.getPath()";
23 TextView showText, showRoute; 23 TextView showText, showRoute;
24 24
  25 +
25 @Override 26 @Override
26 public void onCreate(Bundle savedInstanceState) { 27 public void onCreate(Bundle savedInstanceState) {
27 super.onCreate(savedInstanceState); 28 super.onCreate(savedInstanceState);
@@ -31,6 +32,7 @@ public class MainActivity extends Activity implements OnClickListener { @@ -31,6 +32,7 @@ public class MainActivity extends Activity implements OnClickListener {
31 buttonDescarrega.setOnClickListener(this); 32 buttonDescarrega.setOnClickListener(this);
32 showText = (TextView) findViewById(R.id.textViewXml); 33 showText = (TextView) findViewById(R.id.textViewXml);
33 showRoute = (TextView) findViewById(R.id.textViewRoute); 34 showRoute = (TextView) findViewById(R.id.textViewRoute);
  35 +
34 this.getUrl(); 36 this.getUrl();
35 } 37 }
36 38