package com.lysdev.transperthcached.activities;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

import com.lysdev.transperthcached.R;

public class MainActivity extends TabActivity {
    public TabSpec tab(Class<?> cls, String tab_spec, int resource_id) {
        return getTabHost()
            .newTabSpec(tab_spec)
            .setIndicator("", getResources().getDrawable(resource_id))
            .setContent(
                new Intent().setClass(this, cls)
            )
        ;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources resources = getResources();
        TabHost tabHost = getTabHost();

        TabSpec tabSpecTrain = tab(
            TrainActivity.class, "Train", R.drawable.icon_train_config
        );

        TabSpec tabSpecFavouriteStops = tab(
            FavouriteStopsActivity.class, "FavouriteStops", R.drawable.icon_star_config
        );

        TabSpec tabSpecStopTimetable = tab(
            StopTimetableActivity.class, "StopTimetable", R.drawable.icon_timetable_config
        );

        // // Blackberry tab
        // Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
        // TabSpec tabSpecBerry = tabHost
        //   .newTabSpec("Berry")
        //   .setIndicator("", resources.getDrawable(R.drawable.icon_blackberry_config))
        //   .setContent(intentBerry);

        // // add all tabs
        tabHost.addTab(tabSpecTrain);
        tabHost.addTab(tabSpecFavouriteStops);
        tabHost.addTab(tabSpecStopTimetable);
        // tabHost.addTab(tabSpecBerry);

        //set StopTimetable tab as default (zero based)
        tabHost.setCurrentTab(0);
    }
}

@@ -74,16 +74,68 @@
 tivity;%0A
+import android.os.Bundle;%0Aimport android.util.Log;%0A%0A
 import a
@@ -199,33 +199,8 @@
 es;%0A
-import android.os.Bundle;
 %0Aimp
@@ -306,16 +306,17 @@
 hed.R;%0A%0A
+%0A
 public c
@@ -370,32 +370,30 @@
 lic 
-TabSpec tab(Class%3C?%3E cls
+void tab(Intent intent
 , St
@@ -399,22 +399,17 @@
 tring ta
-b_spec
+g
 , int re
@@ -433,14 +433,40 @@
     
-return
+getTabHost().addTab(%0A           
  get
@@ -505,14 +505,9 @@
 c(ta
-b_spec
+g
 )%0A  
@@ -599,16 +599,23 @@
 Content(
+intent)
 %0A       
@@ -619,71 +619,135 @@
     
+);%0A
     
+%7D%0A%0A
     
-new Intent().setClass(this, cls)%0A            )%0A        
+public void tab(Class%3C?%3E cls, String tag, int resource_id) %7B%0A        tab(new Intent(this, cls), tag, resource_id)
 ;%0A  
@@ -901,164 +901,59 @@
     
-Resources resources = getResources();%0A        TabHost tabHost = getTabHost();%0A%0A        TabSpec tabSpecTrain = tab(%0A            TrainActivity.class, %22Train%22,
+tab(TrainActivity.class,          %22Train%22,         
  R.d
@@ -977,37 +977,27 @@
 n_config
-%0A        
 );%0A
-%0A
         
 TabSpec 
@@ -992,57 +992,12 @@
     
-TabSpec tabSpecFavouriteStops = tab(%0A            
+tab(
 Favo
@@ -1067,37 +1067,27 @@
 r_config
-%0A        
 );%0A
-%0A
         
 TabSpec 
@@ -1082,56 +1082,12 @@
     
-TabSpec tabSpecStopTimetable = tab(%0A            
+tab(
 Stop
@@ -1110,16 +1110,17 @@
 y.class,
+ 
  %22StopTi
@@ -1128,16 +1128,17 @@
 etable%22,
+ 
  R.drawa
@@ -1162,25 +1162,16 @@
 e_config
-%0A        
 );%0A%0A    
@@ -1178,592 +1178,20 @@
     
-// // Blackberry tab%0A        // Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);%0A        // TabSpec tabSpecBerry = tabHost%0A        //   .newTabSpec(%22Berry%22)%0A        //   .setIndicator(%22%22, resources.getDrawable(R.drawable.icon_blackberry_config))%0A        //   .setContent(intentBerry);%0A%0A        // // add all tabs%0A        tabHost.addTab(tabSpecTrain);%0A        tabHost.addTab(tabSpecFavouriteStops);%0A        tabHost.addTab(tabSpecStopTimetable);%0A        // tabHost.addTab(tabSpecBerry);%0A%0A        //set StopTimetable tab as default (zero based)%0A        tabHost
+getTabHost()
 .set

Refactor tab adding