Skip to content

Commit

Permalink
Add a more precise method to create custom tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Mottier committed Jun 27, 2011
1 parent 2688f5b commit 269bcce
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions GreenDroid/src/greendroid/app/GDTabActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TabHost;
import android.widget.TextView;
Expand Down Expand Up @@ -69,8 +70,7 @@ public void onContentChanged() {
public void onPreContentChanged() {
mActionBarHost = (ActionBarHost) findViewById(R.id.gd_action_bar_host);
if (mActionBarHost == null) {
throw new RuntimeException(
"Your content must have an ActionBarHost whose id attribute is R.id.gd_action_bar_host");
throw new RuntimeException("Your content must have an ActionBarHost whose id attribute is R.id.gd_action_bar_host");
}
mActionBarHost.getActionBar().setOnActionBarListener(mActionBarListener);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public void onPostContentChanged() {
// Do nothing
}
}

final int visibility = intent.getIntExtra(ActionBarActivity.GD_ACTION_BAR_VISIBILITY, View.VISIBLE);
getActionBar().setVisibility(visibility);
}
Expand All @@ -127,15 +127,15 @@ public ActionBar getActionBar() {
public ActionBarItem addActionBarItem(ActionBarItem item) {
return getActionBar().addItem(item);
}

public ActionBarItem addActionBarItem(ActionBarItem item, int itemId) {
return getActionBar().addItem(item, itemId);
}

public ActionBarItem addActionBarItem(ActionBarItem.Type actionBarItemType) {
return getActionBar().addItem(actionBarItemType);
}

public ActionBarItem addActionBarItem(ActionBarItem.Type actionBarItemType, int itemId) {
return getActionBar().addItem(actionBarItemType, itemId);
}
Expand Down Expand Up @@ -183,18 +183,32 @@ public void addTab(String tag, int labelId, Intent intent) {
public void addTab(String tag, CharSequence label, Intent intent) {
final TabHost host = getTabHost();

View indicator = createTabIndicator(label);
View indicator = createTabIndicator(tag, label, getTabWidget());
if (indicator == null) {
final TextView textIndicator = (TextView) getLayoutInflater().inflate(R.layout.gd_tab_indicator,
getTabWidget(), false);
final TextView textIndicator = (TextView) getLayoutInflater().inflate(R.layout.gd_tab_indicator, getTabWidget(), false);
textIndicator.setText(label);
indicator = textIndicator;
}

host.addTab(host.newTabSpec(tag).setIndicator(indicator).setContent(intent));
}

@Deprecated
protected View createTabIndicator(CharSequence label) {
return createTabIndicator(null, label, getTabWidget());
}

/**
* Callback allowing client to create their own tabs.
*
* @param tag The tag of the tab to create
* @param label The label that need to be displayed in the tab
* @param parent The parent in which the tab will be added.Please note you
* shouldn't add the newly created/inflated View to the parent.
* GDTabActivity will deal with this automatically.
* @return
*/
protected View createTabIndicator(String tag, CharSequence label, ViewGroup parent) {
return null;
}

Expand Down

0 comments on commit 269bcce

Please sign in to comment.