use of android.widget.TabHost in project Ushahidi_Android by ushahidi.
the class ReportTabFragment method addTab.
private void addTab(String indicator, int drawableId, Class<?> c) {
TabHost tabHost = mTabHost;
TabHost.TabSpec spec = tabHost.newTabSpec(indicator);
Intent intent = new Intent(getActivity(), c);
View tabIndicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab_indicator, tabHost.getTabWidget(), false);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
use of android.widget.TabHost in project spring-data-document-examples by spring-projects.
the class MainTabWidget method onCreate.
//***************************************
// Activity methods
//***************************************
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent;
// add events tab
intent = new Intent();
intent.setClass(this, RestListingActivity.class);
tabSpec = tabHost.newTabSpec("restaurants");
tabSpec.setIndicator("Restaurants", res.getDrawable(R.drawable.ic_tab_events));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
// add profile tab
intent = new Intent();
intent.setClass(this, FavoritesListingActivity.class);
tabSpec = tabHost.newTabSpec("favorites");
tabSpec.setIndicator("Favorites", res.getDrawable(R.drawable.ic_tab_profile));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
// add info tab
intent = new Intent();
intent.setClass(this, InfoActivity.class);
tabSpec = tabHost.newTabSpec("info");
tabSpec.setIndicator("Info", res.getDrawable(R.drawable.ic_tab_info));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
}
use of android.widget.TabHost in project pictureapp by EyeSeeTea.
the class DashboardActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
handler = new Handler(Looper.getMainLooper());
mDashboardActivityStrategy = new DashboardActivityStrategy();
dashboardActivity = this;
setContentView(R.layout.tab_dashboard);
Survey.removeInProgress();
if (savedInstanceState == null) {
initImprove();
initMonitor();
if (GradleVariantConfig.isStockFragmentActive()) {
initStock();
}
initAssess();
}
initTabHost(savedInstanceState);
/* set tabs in order */
LayoutUtils.setTabHosts(this);
LayoutUtils.setTabDivider(this);
//set the tabs background as transparent
setTabsBackgroundColor(R.color.tab_unpressed_background);
//set first tab as selected:
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.tab_pressed_background));
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
/** If current tab is android */
//set the tabs background as transparent
setTabsBackgroundColor(R.color.tab_unpressed_background);
//If change of tab from surveyFragment or FeedbackFragment they could be closed.
if (isSurveyFragmentActive()) {
onSurveyBackPressed();
}
if (isReviewFragmentActive()) {
exitReviewOnChangeTab(null);
}
if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_assess))) {
if (!isReadOnly) {
unsentFragment.reloadData();
}
unsentFragment.reloadHeader(dashboardActivity);
} else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_improve))) {
sentFragment.reloadData();
sentFragment.reloadHeader(dashboardActivity);
} else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_stock))) {
mDashboardActivityStrategy.reloadStockFragment(dashboardActivity);
} else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_monitor))) {
monitorFragment.reloadData();
monitorFragment.reloadHeader(dashboardActivity);
}
tabHost.getCurrentTabView().setBackgroundColor(getResources().getColor(R.color.tab_pressed_background));
}
});
// init tabHost
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setFocusable(false);
}
getSurveysFromService();
}
use of android.widget.TabHost in project android_frameworks_base by crdroidandroid.
the class RenderSessionImpl method setupTabHost.
/**
* Sets up a {@link TabHost} object.
* @param tabHost the TabHost to setup.
* @param layoutlibCallback The project callback object to access the project R class.
* @throws PostInflateException
*/
private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException {
// look for the TabWidget, and the FrameLayout. They have their own specific names
View v = tabHost.findViewById(android.R.id.tabs);
if (v == null) {
throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
}
if (!(v instanceof TabWidget)) {
throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
}
v = tabHost.findViewById(android.R.id.tabcontent);
if (v == null) {
//noinspection SpellCheckingInspection
throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
}
if (!(v instanceof FrameLayout)) {
//noinspection SpellCheckingInspection
throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
}
FrameLayout content = (FrameLayout) v;
// now process the content of the frameLayout and dynamically create tabs for it.
final int count = content.getChildCount();
// this must be called before addTab() so that the TabHost searches its TabWidget
// and FrameLayout.
tabHost.setup();
if (count == 0) {
// Create a dummy child to get a single tab
TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details, null)).setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return new LinearLayout(getContext());
}
});
tabHost.addTab(spec);
} else {
// for each child of the frameLayout, add a new TabSpec
for (int i = 0; i < count; i++) {
View child = content.getChildAt(i);
String tabSpec = String.format("tab_spec%d", i + 1);
// child cannot be null.
@SuppressWarnings("ConstantConditions") int id = child.getId();
@SuppressWarnings("deprecation") Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id);
String name;
if (resource != null) {
name = resource.getSecond();
} else {
// default name if id is unresolved.
name = String.format("Tab %d", i + 1);
}
tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
}
}
}
use of android.widget.TabHost in project android_frameworks_base by crdroidandroid.
the class RenderSessionImpl method postInflateProcess.
/**
* Post process on a view hierarchy that was just inflated.
* <p/>
* At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
* {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
* based on the content of the {@link FrameLayout}.
* @param view the root view to process.
* @param layoutlibCallback callback to the project.
* @param skip the view and it's children are not processed.
*/
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
if (view == skip) {
return;
}
if (view instanceof TabHost) {
setupTabHost((TabHost) view, layoutlibCallback);
} else if (view instanceof QuickContactBadge) {
QuickContactBadge badge = (QuickContactBadge) view;
badge.setImageToDefault();
} else if (view instanceof AdapterView<?>) {
// get the view ID.
int id = view.getId();
BridgeContext context = getContext();
// get a ResourceReference from the integer ID.
ResourceReference listRef = context.resolveId(id);
if (listRef != null) {
SessionParams params = getParams();
AdapterBinding binding = params.getAdapterBindings().get(listRef);
// if there was no adapter binding, trying to get it from the call back.
if (binding == null) {
binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
}
if (binding != null) {
if (view instanceof AbsListView) {
if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
ListView list = (ListView) view;
boolean skipCallbackParser = false;
int count = binding.getHeaderCount();
for (int i = 0; i < count; i++) {
Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
if (pair.getFirst() != null) {
list.addHeaderView(pair.getFirst());
}
skipCallbackParser |= pair.getSecond();
}
count = binding.getFooterCount();
for (int i = 0; i < count; i++) {
Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
if (pair.getFirst() != null) {
list.addFooterView(pair.getFirst());
}
skipCallbackParser |= pair.getSecond();
}
}
if (view instanceof ExpandableListView) {
((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
} else {
((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
}
} else if (view instanceof AbsSpinner) {
((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
}
}
}
} else if (view instanceof ViewGroup) {
mInflater.postInflateProcess(view);
ViewGroup group = (ViewGroup) view;
final int count = group.getChildCount();
for (int c = 0; c < count; c++) {
View child = group.getChildAt(c);
postInflateProcess(child, layoutlibCallback, skip);
}
}
}
Aggregations