Blame view

src/com/upc/pbe/upcnews/MainActivity.java 2.63 KB
1
2
3
package com.upc.pbe.upcnews;

import android.app.Activity;
Imanol-Mikel Barba Sabariego authored
4
import android.content.Context;
5
import android.content.Intent;
Imanol-Mikel Barba Sabariego authored
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;
Imanol-Mikel Barba Sabariego authored
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;
Imanol-Mikel Barba Sabariego authored
21
	WifiManager wifi;
22
23

	Directoris dir;
Imanol-Mikel Barba Sabariego authored
24
	ImageButton buttonDescarrega;
25
	String file = "ejemplo.xml";
Imanol-Mikel Barba Sabariego authored
26
	String folder = "Environment.getExternalStorageDirectory.getPath()";
Imanol-Mikel Barba Sabariego authored
27
	TextView showText;
28
29
30
31
	@Override
	public void onCreate(Bundle savedInstanceState) {
Imanol-Mikel Barba Sabariego authored
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");
Imanol-Mikel Barba Sabariego authored
41
		buttonDescarrega = (ImageButton) findViewById(R.id.button);
42
		buttonDescarrega.setOnClickListener(this);
43
		showText = (TextView) findViewById(R.id.textViewXml);
Imanol-Mikel Barba Sabariego authored
44
		this.getUrl();
Imanol-Mikel Barba Sabariego authored
45
46
47
48

		new Thread() {
			public void run() {
				//Wifi Info
Imanol-Mikel Barba Sabariego authored
49
				int speed = 0;
Imanol-Mikel Barba Sabariego authored
50
				for (int i = 0; i < 5; i++) {
Imanol-Mikel Barba Sabariego authored
51
52
					wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
					WifiInfo info = wifi.getConnectionInfo();
Imanol-Mikel Barba Sabariego authored
53
					speed = speed + info.getLinkSpeed();
Imanol-Mikel Barba Sabariego authored
54
					try {
Imanol-Mikel Barba Sabariego authored
55
						Thread.sleep(1000);
Imanol-Mikel Barba Sabariego authored
56
57
58
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
Imanol-Mikel Barba Sabariego authored
59
Imanol-Mikel Barba Sabariego authored
60
				}
Imanol-Mikel Barba Sabariego authored
61
62
63

				String str = "Speed: " + speed/5;
				Log.d(TAG, str);
Imanol-Mikel Barba Sabariego authored
64
65
66
			}
		}.start();
67
	}
68
69
70
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
Imanol-Mikel Barba Sabariego authored
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();
Imanol-Mikel Barba Sabariego authored
83
		((UpcApp) getApplication()).setDesc(html);
84
		startActivity(new Intent(this, Directoris.class));
85
	}
86
87

	public void descarregar() {
Imanol-Mikel Barba Sabariego authored
88
		Descarrega d = new Descarrega();
89
		Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show();
Imanol-Mikel Barba Sabariego authored
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));
Imanol-Mikel Barba Sabariego authored
101
			Log.d(TAG, "Help");
Imanol-Mikel Barba Sabariego authored
102
			return true;
103
104
105
		default:
			return false;
		}
106
107
	}
}