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

import java.io.File;
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.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	private final static String TAG = "Main";
	private static String html;
	private ImageButton buttonDescarrega;

	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_activity);
		Log.d(TAG, "onCreated");
		File tempFolder = new File(((UpcApp)getApplication()).getLocalPath());
		if(tempFolder.mkdirs())
		{
			Log.d(TAG,"Directory " + tempFolder.toString() + " created");
		}
		buttonDescarrega = (ImageButton) findViewById(R.id.button);
		buttonDescarrega.setOnClickListener(this);
		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();
		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;
		}
	}
}