Commit 0a050c2cedde9a76d5d5ae0f89e4bf5c4b328d44

Authored by Imanol-Mikel Barba Sabariego
1 parent 08b974e7

Fin de la claseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

AndroidManifest.xml
... ... @@ -9,6 +9,7 @@
9 9 <uses-permission android:name="android.permission.INTERNET"/>
10 10 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11 11  
  12 +
12 13 <application
13 14 android:name=".UpcApp"
14 15 android:icon="@drawable/ic_launcher"
... ...
gen/com/upc/pbe/upcnews/R.java
... ... @@ -16,23 +16,24 @@ public final class R {
16 16 public static final int ic_menu_name=0x7f020002;
17 17 }
18 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 22 public static final int LinearLayout1=0x7f080000;
23   - public static final int button=0x7f08000a;
  23 + public static final int button=0x7f08000d;
24 24 public static final int button1=0x7f080002;
25 25 public static final int button2=0x7f080003;
26 26 public static final int button3=0x7f080004;
27 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 35 public static final int textViewTitle=0x7f080001;
35   - public static final int textViewXml=0x7f08000b;
  36 + public static final int textViewXml=0x7f08000e;
36 37 }
37 38 public static final class layout {
38 39 public static final int dirs=0x7f030000;
... ...
res/layout/dirs.xml
... ... @@ -7,12 +7,11 @@
7 7 android:orientation="vertical" >
8 8  
9 9 <!-- Vista en llista -->
10   -
  10 +
11 11 <TextView
12 12 android:id="@+id/textViewTitle"
13 13 android:layout_width="wrap_content"
14 14 android:layout_height="wrap_content"
15   - android:layout_gravity="left"
16 15 android:layout_marginLeft="14dp"
17 16 android:text="@string/title"
18 17 android:textAppearance="?android:attr/textAppearanceMedium" />
... ... @@ -41,4 +40,10 @@
41 40 android:layout_height="wrap_content"
42 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 49 </LinearLayout>
45 50 \ No newline at end of file
... ...
res/layout/main_activity.xml
... ... @@ -15,47 +15,47 @@
15 15 android:text="@string/app_name"
16 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 34 <TextView
19 35 android:id="@+id/textViewRoute"
20 36 android:layout_width="250dp"
21 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 40 android:textSize="@android:dimen/thumbnail_height" />
25 41  
26 42 <Button
27 43 android:id="@+id/button"
28 44 android:layout_width="258dp"
29 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 48 android:text="@string/descarregar" />
33 49  
34 50 <TextView
35 51 android:id="@+id/textViewXml"
36   - android:layout_width="301dp"
  52 + android:layout_width="wrap_content"
37 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 56 android:gravity="clip_vertical"
41 57 android:hint="@string/hint"
42 58 android:scrollbarStyle="insideInset"
43 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 61 </AbsoluteLayout>
62 62 \ No newline at end of file
... ...
res/values/strings.xml
... ... @@ -3,8 +3,8 @@
3 3 <string name="app_name">UPC_NEWS</string>
4 4 <string name="menu_settings">Settings</string>
5 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 8 <string name="url">URL server</string>
9 9 <string name="urlhint">Set the route from the server (without http://)</string>
10 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 89  
90 90 in.close();
91 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 93 } catch (IOException e) {
95 94 Log.d(TAG, "excepcio 2");
96   - e.printStackTrace();
97 95 }
98 96  
99 97 return html;
... ...
src/com/upc/pbe/upcnews/Directoris.java
... ... @@ -11,6 +11,7 @@ import android.view.MenuItem;
11 11 import android.view.View;
12 12 import android.view.View.OnClickListener;
13 13 import android.widget.Button;
  14 +import android.widget.Toast;
14 15  
15 16 public class Directoris extends Activity implements OnClickListener {
16 17  
... ... @@ -73,24 +74,49 @@ public class Directoris extends Activity implements OnClickListener {
73 74  
74 75 case R.id.button1: {
75 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 79 String str = d.doInBackground();
79 80  
80 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 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 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 121 case R.id.button3: {
96 122  
... ... @@ -103,13 +129,13 @@ public class Directoris extends Activity implements OnClickListener {
103 129  
104 130 public void crearButtons() {
105 131  
106   -
107 132 buttons.add((Button) findViewById(R.id.button1));
108 133 buttons.add((Button) findViewById(R.id.button2));
109 134 buttons.add((Button) findViewById(R.id.button3));
110 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 139 buttons.get(i).setOnClickListener(this);
114 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 22 String folder = "Environment.getExternalStorageDirectory.getPath()";
23 23 TextView showText, showRoute;
24 24  
  25 +
25 26 @Override
26 27 public void onCreate(Bundle savedInstanceState) {
27 28 super.onCreate(savedInstanceState);
... ... @@ -31,6 +32,7 @@ public class MainActivity extends Activity implements OnClickListener {
31 32 buttonDescarrega.setOnClickListener(this);
32 33 showText = (TextView) findViewById(R.id.textViewXml);
33 34 showRoute = (TextView) findViewById(R.id.textViewRoute);
  35 +
34 36 this.getUrl();
35 37 }
36 38  
... ...