package com.ethostream.ethoandroid;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;

public class PropTabs extends TabActivity
{
	public void onCreate(Bundle savedInstanceState) 
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.proptabs);
	    
	    Bundle bundle = getIntent().getExtras();
		Integer propID = Integer.parseInt(bundle.getString("ID"));
		if (propID < 1)
		{
			Log.e(this.toString(), "Invalid ID, quitting.");
			setResult(RESULT_CANCELED);
			finish();
		}

	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab
	    
	    CharSequence propinfoLabel = "Info";
	    CharSequence propcontactsLabel = "Contacts";
	    CharSequence propdocsLabel = "Documents";
	    CharSequence propnotesLabel = "Notes";

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, PropInfo.class);
	    intent.putExtra("ID", propID.toString());

	    // Initialize a TabSpec for each tab and add it to the TabHost
	    // PropInfo
	    spec = tabHost.newTabSpec(propinfoLabel.toString()).setIndicator(propinfoLabel,
	                      res.getDrawable(R.drawable.ic_tab_info_grey))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    // PropContacts
	    intent = new Intent().setClass(this, PropContacts.class);
	    intent.putExtra("ID", propID.toString());
	    spec = tabHost.newTabSpec(propcontactsLabel.toString()).setIndicator(propcontactsLabel,
	                      res.getDrawable(R.drawable.ic_tab_info_grey))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // PropDocs
	    intent = new Intent().setClass(this, PropDocs.class);
	    intent.putExtra("ID", propID.toString());
	    spec = tabHost.newTabSpec(propdocsLabel.toString()).setIndicator(propdocsLabel,
	                      res.getDrawable(R.drawable.ic_tab_info_grey))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    // PropNotes
	    intent = new Intent().setClass(this, PropNotes.class);
	    intent.putExtra("ID", propID.toString());
	    spec = tabHost.newTabSpec(propnotesLabel.toString()).setIndicator(propnotesLabel,
	                      res.getDrawable(R.drawable.ic_tab_info_grey))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(0);
	}
}
