MainActivity.java 2.63 KB
package com.upc.pbe.upcnews;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
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.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	final static String TAG = "Main";
	static String html;
	WifiManager wifi;

	Directoris dir;
	ImageButton buttonDescarrega;
	String file = "ejemplo.xml";
	String folder = "Environment.getExternalStorageDirectory.getPath()";
	TextView showText;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		/*
		 * FALTA:
		 * 			Boton de un color mas oscuro al darle
		 * 			Boton y texto centrados
		 * 			Boton mayor resolucion
		 */
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_activity);
		Log.d(TAG, "onCreated");
		buttonDescarrega = (ImageButton) findViewById(R.id.button);
		buttonDescarrega.setOnClickListener(this);
		showText = (TextView) findViewById(R.id.textViewXml);
		this.getUrl();
		
		new Thread() {
			public void run() {
				//Wifi Info
				int speed = 0;
				for (int i = 0; i < 5; i++) {
					wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
					WifiInfo info = wifi.getConnectionInfo();
					speed = speed + info.getLinkSpeed();
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					
				}
			
				String str = "Speed: " + speed/5;
				Log.d(TAG, str);
			}
		}.start();
		
	}

	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();
		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();
		Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show();
		html = (String) d.doInBackground(this.getUrl());
	}

	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;
		}
	}
}