MainActivity.java
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.upc.pbe.upcnews;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
final static String TAG = "Main";
static String html;
Directoris dir;
Button buttonDescarrega;
String file = "ejemplo.xml";
String folder = "Environment.getExternalStorageDirectory.getPath()";
TextView showText, showRoute;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Log.d(TAG, "onCreated");
buttonDescarrega = (Button) findViewById(R.id.button);
buttonDescarrega.setOnClickListener(this);
showText = (TextView) findViewById(R.id.textViewXml);
showRoute = (TextView) findViewById(R.id.textViewRoute);
this.getUrl();
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
Log.d(TAG, "Menu");
return true;
}
public String getUrl() {
String u = ((UpcApp) getApplication()).getUrl();
showRoute.setText("Server: " + u);
return u;
}
public void onClick(View v) {
Log.d(TAG, "onClicked");
this.descarregar();
((UpcApp) getApplication()).setDesc(html);
startActivity(new Intent(this, Directoris.class));
}
public void descarregar() {
Descarrega d = new Descarrega(this.getUrl(), file, folder);
Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show();
html = (String) d.doInBackground();
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.itemprefs:
startActivity(new Intent(this, Prefs.class));
Log.d(TAG, "Preferences");
return true;
case R.id.itemhelp:
startActivity(new Intent(this, Help.class));
Log.d(TAG, "Help");
return true;
default:
return false;
}
}
}