Commit 4a7af269e99951ec9aca804c1ec2447d9b210bcd

Authored by Imanol-Mikel Barba Sabariego
1 parent 67cd50f1

<Marc> He creat una classe per a visualitzar els directoris correctament i he mo…

…dificat unes quantes coses més.
Ara estic mirant lo de "poder clicar a un directori per a visuaitzar-lo"
AndroidManifest.xml
@@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
25 </activity> 25 </activity>
26 <activity android:name=".Descarrega"></activity> 26 <activity android:name=".Descarrega"></activity>
27 <activity android:name=".Prefs" ></activity> 27 <activity android:name=".Prefs" ></activity>
  28 + <activity android:name=".Help" ></activity>
  29 + <activity android:name=".Directoris"></activity>
28 </application> 30 </application>
29 31
30 </manifest> 32 </manifest>
31 \ No newline at end of file 33 \ No newline at end of file
gen/com/upc/pbe/upcnews/R.java
@@ -15,30 +15,48 @@ public final class R { @@ -15,30 +15,48 @@ public final class R {
15 public static final int ic_launcher=0x7f020001; 15 public static final int ic_launcher=0x7f020001;
16 } 16 }
17 public static final class id { 17 public static final class id {
18 - public static final int AbsoluteLayout1=0x7f070000;  
19 - public static final int button=0x7f070003;  
20 - public static final int menu_settings=0x7f070004;  
21 - public static final int textViewRoute=0x7f070002;  
22 - public static final int textViewXml=0x7f070001; 18 + public static final int AbsoluteLayout1=0x7f080005;
  19 + public static final int LinearLayout1=0x7f080003;
  20 + public static final int button=0x7f080008;
  21 + public static final int buttonPlay=0x7f080000;
  22 + public static final int imageView1=0x7f080009;
  23 + public static final int itemhelp=0x7f08000c;
  24 + public static final int itemprefs=0x7f08000b;
  25 + public static final int menu_settings=0x7f08000a;
  26 + public static final int textView1=0x7f080001;
  27 + public static final int textView2=0x7f080004;
  28 + public static final int textViewRoute=0x7f080007;
  29 + public static final int textViewXml=0x7f080006;
  30 + public static final int text_out=0x7f080002;
23 } 31 }
24 public static final class layout { 32 public static final class layout {
25 - public static final int main_activity=0x7f030000; 33 + public static final int directori=0x7f030000;
  34 + public static final int dirs=0x7f030001;
  35 + public static final int help=0x7f030002;
  36 + public static final int main_activity=0x7f030003;
26 } 37 }
27 public static final class menu { 38 public static final class menu {
28 - public static final int activity_main=0x7f060000; 39 + public static final int activity_main=0x7f070000;
  40 + public static final int menu=0x7f070001;
29 } 41 }
30 public static final class string { 42 public static final class string {
31 - public static final int app_name=0x7f040000;  
32 - public static final int descarregar=0x7f040003;  
33 - public static final int help=0x7f040008;  
34 - public static final int hint=0x7f040004;  
35 - public static final int menu_settings=0x7f040001;  
36 - public static final int prefs=0x7f040007;  
37 - public static final int title_activity_main=0x7f040002;  
38 - public static final int url=0x7f040005;  
39 - public static final int urlhint=0x7f040006; 43 + public static final int app_name=0x7f050000;
  44 + public static final int desc=0x7f050009;
  45 + public static final int descarregar=0x7f050003;
  46 + public static final int dir=0x7f05000a;
  47 + public static final int directoris=0x7f05000b;
  48 + public static final int help=0x7f050008;
  49 + public static final int hint=0x7f050004;
  50 + public static final int menu_settings=0x7f050001;
  51 + public static final int prefs=0x7f050007;
  52 + public static final int title_activity_main=0x7f050002;
  53 + public static final int url=0x7f050005;
  54 + public static final int urlhint=0x7f050006;
40 } 55 }
41 public static final class style { 56 public static final class style {
42 - public static final int AppTheme=0x7f050000; 57 + public static final int AppTheme=0x7f060000;
  58 + }
  59 + public static final class xml {
  60 + public static final int prefs=0x7f040000;
43 } 61 }
44 } 62 }
res/layout/directori.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent" >
  5 +
  6 + <Button
  7 + android:id="@+id/buttonPlay"
  8 + style="?android:attr/buttonStyleSmall"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:layout_alignParentRight="true"
  12 + android:layout_alignParentTop="true"
  13 + android:layout_marginRight="36dp"
  14 + android:text="@string/desc" />
  15 +
  16 + <TextView
  17 + android:id="@+id/textView1"
  18 + android:layout_width="wrap_content"
  19 + android:layout_height="wrap_content"
  20 + android:layout_alignParentLeft="true"
  21 + android:layout_alignParentTop="true"
  22 + android:layout_marginLeft="42dp"
  23 + android:text="@string/dir"
  24 + android:textAppearance="?android:attr/textAppearanceLarge" />
  25 +
  26 +</RelativeLayout>
0 \ No newline at end of file 27 \ No newline at end of file
res/layout/dirs.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical" >
  6 +
  7 + <TextView
  8 + android:id="@+id/textView1"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:layout_gravity="center"
  12 + android:text="@string/directoris"
  13 + android:textAppearance="?android:attr/textAppearanceLarge" />
  14 +
  15 + <ScrollView
  16 + android:layout_width="match_parent"
  17 + android:layout_height="match_parent" >
  18 +
  19 + <TextView
  20 + android:id="@+id/text_out"
  21 + android:layout_width="match_parent"
  22 + android:layout_height="wrap_content"
  23 + android:textAppearance="?android:attr/textAppearanceMedium" />
  24 + </ScrollView>
  25 +
  26 +</LinearLayout>
0 \ No newline at end of file 27 \ No newline at end of file
res/layout/help.xml
@@ -10,15 +10,19 @@ @@ -10,15 +10,19 @@
10 android:layout_width="wrap_content" 10 android:layout_width="wrap_content"
11 android:layout_height="wrap_content" 11 android:layout_height="wrap_content"
12 android:layout_gravity="center" 12 android:layout_gravity="center"
  13 + android:layout_weight="0.04"
13 android:text="@string/help" 14 android:text="@string/help"
14 android:textAppearance="?android:attr/textAppearanceLarge" /> 15 android:textAppearance="?android:attr/textAppearanceLarge" />
15 -  
16 - <TextView  
17 - android:id="@+id/textView2"  
18 - android:layout_width="wrap_content"  
19 - android:layout_height="wrap_content"  
20 - android:layout_gravity="center_horizontal"  
21 - android:text="Help, I need somebody, Help!, not just anybody, Help!, you know I need someone... HEEEEELP!"  
22 - android:textAppearance="?android:attr/textAppearanceMedium" /> 16 +
  17 + <ScrollView
  18 + android:layout_width="match_parent"
  19 + android:layout_height="0dp"
  20 + android:layout_weight="0.87" >
  21 +
  22 + <TextView
  23 + android:id="@+id/textView2"
  24 + android:layout_width="match_parent"
  25 + android:layout_height="0dp" />
  26 + </ScrollView>
23 27
24 </LinearLayout> 28 </LinearLayout>
25 \ No newline at end of file 29 \ No newline at end of file
res/layout/main_activity.xml
@@ -5,11 +5,11 @@ @@ -5,11 +5,11 @@
5 android:layout_width="wrap_content" 5 android:layout_width="wrap_content"
6 android:layout_height="match_parent" 6 android:layout_height="match_parent"
7 tools:ignore="Deprecated" > 7 tools:ignore="Deprecated" >
8 - 8 +
9 <TextView 9 <TextView
10 android:id="@+id/textViewXml" 10 android:id="@+id/textViewXml"
11 android:layout_width="301dp" 11 android:layout_width="301dp"
12 - android:layout_height="386dp" 12 + android:layout_height="wrap_content"
13 android:layout_x="11dp" 13 android:layout_x="11dp"
14 android:layout_y="81dp" 14 android:layout_y="81dp"
15 android:gravity="clip_vertical" 15 android:gravity="clip_vertical"
@@ -32,5 +32,14 @@ @@ -32,5 +32,14 @@
32 android:layout_x="31dp" 32 android:layout_x="31dp"
33 android:layout_y="30dp" 33 android:layout_y="30dp"
34 android:text="@string/descarregar" /> 34 android:text="@string/descarregar" />
  35 +
  36 + <ImageView
  37 + android:id="@+id/imageView1"
  38 + android:layout_width="wrap_content"
  39 + android:layout_height="wrap_content"
  40 + android:layout_x="129dp"
  41 + android:layout_y="227dp"
  42 + android:scaleType="center"
  43 + android:src="@drawable/ic_launcher" />
35 44
36 </AbsoluteLayout> 45 </AbsoluteLayout>
37 \ No newline at end of file 46 \ No newline at end of file
res/values/strings.xml
@@ -9,5 +9,8 @@ @@ -9,5 +9,8 @@
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>
11 <string name="help">Help!</string> 11 <string name="help">Help!</string>
  12 + <string name="desc">Play</string>
  13 + <string name="dir">Directory</string>
  14 + <string name="directoris">Directoris</string>
12 15
13 </resources> 16 </resources>
14 \ No newline at end of file 17 \ No newline at end of file
src/com/upc/pbe/upcnews/Directoris.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +import java.util.ArrayList;
  4 +
  5 +import android.app.Activity;
  6 +import android.os.Bundle;
  7 +import android.util.Log;
  8 +import android.widget.TextView;
  9 +
  10 +public class Directoris extends Activity {
  11 +
  12 + final static String TAG = "Directoris";
  13 +
  14 + TextView textout;
  15 + String s;
  16 +
  17 + public void onCreate(Bundle savedInstanceState) {
  18 +
  19 + super.onCreate(savedInstanceState);
  20 + setContentView(R.layout.dirs);
  21 +
  22 + textout = (TextView) findViewById(R.id.text_out);
  23 +
  24 + s = ((UpcApp) getApplication()).getDesc();
  25 + HTMLParser pars = new HTMLParser((String) s);
  26 + ArrayList<String> dirs = pars.parse();
  27 +
  28 + for (int i = 0; i < dirs.size(); i++) {
  29 +
  30 + Log.d(TAG, "Directori " +i);
  31 + textout.append(String.format("\nDirectori: %s\n",dirs.get(i).toString()));
  32 + }
  33 +
  34 + }
  35 +
  36 +}
src/com/upc/pbe/upcnews/Help.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +import android.app.Activity;
  4 +import android.os.Bundle;
  5 +import android.util.Log;
  6 +import android.widget.TextView;
  7 +
  8 +public class Help extends Activity{
  9 +
  10 + final static String TAG = "Help";
  11 + final static String HELP = "Help, I need somebody, Help, not just anybody, Help, you know I need someone, help. ";
  12 +
  13 + public void onCreate(Bundle savedInstanceState) {
  14 + Log.d(TAG, "onCreated");
  15 + super.onCreate(savedInstanceState);
  16 + setContentView(R.layout.help);
  17 + TextView text = (TextView) findViewById(R.id.textView2);
  18 + text.setText(HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP + HELP);
  19 +}
  20 + public void onStop(){
  21 + Log.d(TAG, "onStoped");
  22 + super.onStop();
  23 + }
  24 +}
src/com/upc/pbe/upcnews/MainActivity.java
1 package com.upc.pbe.upcnews; 1 package com.upc.pbe.upcnews;
2 2
3 -  
4 -import java.util.ArrayList;  
5 -  
6 import android.app.Activity; 3 import android.app.Activity;
7 import android.content.Intent; 4 import android.content.Intent;
8 import android.os.Bundle; 5 import android.os.Bundle;
@@ -17,7 +14,9 @@ import android.widget.Toast; @@ -17,7 +14,9 @@ import android.widget.Toast;
17 14
18 public class MainActivity extends Activity implements OnClickListener { 15 public class MainActivity extends Activity implements OnClickListener {
19 final static String TAG = "Main"; 16 final static String TAG = "Main";
20 - 17 + static String html;
  18 +
  19 + Directoris dir;
21 Button buttonDescarrega; 20 Button buttonDescarrega;
22 String file = "ejemplo.xml"; 21 String file = "ejemplo.xml";
23 String folder = "Environment.getExternalStorageDirectory.getPath()"; 22 String folder = "Environment.getExternalStorageDirectory.getPath()";
@@ -35,15 +34,14 @@ public class MainActivity extends Activity implements OnClickListener { @@ -35,15 +34,14 @@ public class MainActivity extends Activity implements OnClickListener {
35 this.getUrl(); 34 this.getUrl();
36 35
37 } 36 }
38 -  
39 - 37 +
40 public boolean onCreateOptionsMenu(Menu menu) { 38 public boolean onCreateOptionsMenu(Menu menu) {
41 getMenuInflater().inflate(R.menu.menu, menu); 39 getMenuInflater().inflate(R.menu.menu, menu);
42 return true; 40 return true;
43 } 41 }
44 -  
45 - public String getUrl(){  
46 - String u = ((UpcApp)getApplication()).getUrl(); 42 +
  43 + public String getUrl() {
  44 + String u = ((UpcApp) getApplication()).getUrl();
47 showRoute.setText("Server: " + u); 45 showRoute.setText("Server: " + u);
48 return u; 46 return u;
49 } 47 }
@@ -51,21 +49,22 @@ public class MainActivity extends Activity implements OnClickListener { @@ -51,21 +49,22 @@ public class MainActivity extends Activity implements OnClickListener {
51 public void onClick(View v) { 49 public void onClick(View v) {
52 50
53 Log.d(TAG, "onClicked"); 51 Log.d(TAG, "onClicked");
54 - this.descarregarIMostrar();  
55 -  
56 - 52 + this.descarregar();
  53 + ((UpcApp)getApplication()).setDesc(html);
  54 + startActivity(new Intent(this, Directoris.class));
57 55
58 } 56 }
59 -  
60 - public void descarregarIMostrar(){ 57 +
  58 + public void descarregar() {
61 Descarrega d = new Descarrega(this.getUrl(), file, folder); 59 Descarrega d = new Descarrega(this.getUrl(), file, folder);
62 Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show(); 60 Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show();
63 - String html = (String) d.doInBackground();  
64 - showText.setText((CharSequence) html); 61 + html = (String) d.doInBackground();
  62 +
  63 + //HTMLParser pars = new HTMLParser((String) html);
  64 + //ArrayList<String> dirs = pars.parse();
  65 +
  66 + //showText.setText(dirs.toString());
65 67
66 - HTMLParser pars = new HTMLParser((String) html);  
67 - ArrayList<String> directoris = pars.parse();  
68 - showText.setText((CharSequence) directoris.toString());  
69 68
70 } 69 }
71 70
@@ -75,8 +74,8 @@ public class MainActivity extends Activity implements OnClickListener { @@ -75,8 +74,8 @@ public class MainActivity extends Activity implements OnClickListener {
75 startActivity(new Intent(this, Prefs.class)); 74 startActivity(new Intent(this, Prefs.class));
76 Log.d(TAG, "Preferences"); 75 Log.d(TAG, "Preferences");
77 return true; 76 return true;
78 - case R.id.itemhelp:  
79 - setContentView(R.layout.help); 77 + case R.id.itemhelp:
  78 + startActivity(new Intent(this, Help.class));
80 return true; 79 return true;
81 default: 80 default:
82 return false; 81 return false;
src/com/upc/pbe/upcnews/UpcApp.java
@@ -13,6 +13,7 @@ public class UpcApp extends Application implements OnSharedPreferenceChangeListe @@ -13,6 +13,7 @@ public class UpcApp extends Application implements OnSharedPreferenceChangeListe
13 SharedPreferences prefs; 13 SharedPreferences prefs;
14 String defaultUrl = "10.0.2.100"; 14 String defaultUrl = "10.0.2.100";
15 String url = null; 15 String url = null;
  16 + String desc;
16 17
17 public String getUrl() { 18 public String getUrl() {
18 url = "http://" + prefs.getString("s", defaultUrl); 19 url = "http://" + prefs.getString("s", defaultUrl);
@@ -42,5 +43,14 @@ public class UpcApp extends Application implements OnSharedPreferenceChangeListe @@ -42,5 +43,14 @@ public class UpcApp extends Application implements OnSharedPreferenceChangeListe
42 Log.d(TAG, "onSharedPreferenceChanged for key: " + key); 43 Log.d(TAG, "onSharedPreferenceChanged for key: " + key);
43 44
44 } 45 }
  46 +
  47 + public void setDesc(String s){
  48 + desc = s;
  49 +
  50 + }
  51 +
  52 + public String getDesc(){
  53 + return desc;
  54 + }
45 55
46 } 56 }