|
1
2
3
|
package com.upc.pbe.upcnews;
import android.app.Activity;
|
|
4
|
import android.content.Context;
|
|
5
|
import android.content.Intent;
|
|
6
7
|
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
|
|
8
9
|
import android.os.Bundle;
import android.util.Log;
|
|
10
11
|
import android.view.Menu;
import android.view.MenuItem;
|
|
12
13
|
import android.view.View;
import android.view.View.OnClickListener;
|
|
14
|
import android.widget.ImageButton;
|
|
15
|
import android.widget.TextView;
|
|
16
|
import android.widget.Toast;
|
|
17
18
19
|
public class MainActivity extends Activity implements OnClickListener {
final static String TAG = "Main";
|
|
20
|
static String html;
|
|
21
|
WifiManager wifi;
|
|
22
23
|
Directoris dir;
|
|
24
|
ImageButton buttonDescarrega;
|
|
25
|
String file = "ejemplo.xml";
|
|
26
|
String folder = "Environment.getExternalStorageDirectory.getPath()";
|
|
27
|
TextView showText;
|
|
28
|
|
|
29
|
|
|
30
31
|
@Override
public void onCreate(Bundle savedInstanceState) {
|
|
32
33
34
35
36
37
|
/*
* FALTA:
* Boton de un color mas oscuro al darle
* Boton y texto centrados
* Boton mayor resolucion
*/
|
|
38
39
40
|
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Log.d(TAG, "onCreated");
|
|
41
|
buttonDescarrega = (ImageButton) findViewById(R.id.button);
|
|
42
|
buttonDescarrega.setOnClickListener(this);
|
|
43
|
showText = (TextView) findViewById(R.id.textViewXml);
|
|
44
|
this.getUrl();
|
|
45
46
47
48
|
new Thread() {
public void run() {
//Wifi Info
|
|
49
|
int speed = 0;
|
|
50
|
for (int i = 0; i < 5; i++) {
|
|
51
52
|
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
|
|
53
|
speed = speed + info.getLinkSpeed();
|
|
54
|
try {
|
|
55
|
Thread.sleep(1000);
|
|
56
57
58
|
} catch (InterruptedException e) {
e.printStackTrace();
}
|
|
59
|
|
|
60
|
}
|
|
61
62
63
|
String str = "Speed: " + speed/5;
Log.d(TAG, str);
|
|
64
65
66
|
}
}.start();
|
|
67
|
}
|
|
68
|
|
|
69
70
|
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
|
|
71
|
Log.d(TAG, "Menu");
|
|
72
73
|
return true;
}
|
|
74
75
76
|
public String getUrl() {
String u = ((UpcApp) getApplication()).getUrl();
|
|
77
78
|
return u;
}
|
|
79
80
81
|
public void onClick(View v) {
Log.d(TAG, "onClicked");
|
|
82
|
this.descarregar();
|
|
83
|
((UpcApp) getApplication()).setDesc(html);
|
|
84
|
startActivity(new Intent(this, Directoris.class));
|
|
85
|
}
|
|
86
87
|
public void descarregar() {
|
|
88
|
Descarrega d = new Descarrega();
|
|
89
|
Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show();
|
|
90
|
html = (String) d.doInBackground(this.getUrl());
|
|
91
|
}
|
|
92
93
94
95
96
97
98
|
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.itemprefs:
startActivity(new Intent(this, Prefs.class));
Log.d(TAG, "Preferences");
return true;
|
|
99
100
|
case R.id.itemhelp:
startActivity(new Intent(this, Help.class));
|
|
101
|
Log.d(TAG, "Help");
|
|
102
|
return true;
|
|
103
104
105
|
default:
return false;
}
|
|
106
107
|
}
}
|