use of android.widget.TabWidget 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.TabWidget in project android_frameworks_base by AOSPA.
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.TabWidget in project zype-android by zype.
the class SearchActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getIntent() != null) {
searchString = getIntent().getStringExtra(BundleConstants.SEARCH_STRING);
} else {
throw new IllegalStateException("VideoId can not be empty");
}
searchProgress = (ProgressBar) findViewById(R.id.search_progress);
tvSearchField = (TextView) findViewById(R.id.search_field);
tvSearchField.setText(searchString);
viewSearch = (SearchView) findViewById(R.id.viewSearch);
viewSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
startSearch();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
viewSearch.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return false;
}
});
viewSearch.setQuery(searchString, false);
viewSearch.setIconified(false);
viewSearch.setFocusable(false);
viewSearch.clearFocus();
// tvSearchField.setOnKeyListener(new View.OnKeyListener() {
//
// @Override
// public boolean onKey(View v, int keyCode, KeyEvent event) {
// if (event.getAction() == KeyEvent.ACTION_DOWN
// && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// startSearch();
// return true;
// }
//
// return false;
// }
// });
// tvSearchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
// @Override
// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// startSearch();
// return true;
// }
// return false;
// }
// });
mAdapter = new VideosCursorAdapter(this, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER, this, this);
ListView mListView = (ListView) findViewById(R.id.list_search);
mListView.setEmptyView(findViewById(R.id.empty));
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("tagAll");
tabSpec.setIndicator(getString(R.string.title_tab_search_all));
tabSpec.setContent(R.id.list_search);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tagGuests");
tabSpec.setIndicator(getString(R.string.title_tab_search_guests));
tabSpec.setContent(R.id.list_search);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tagTags");
tabSpec.setIndicator(getString(R.string.title_tab_search_tags));
tabSpec.setContent(R.id.list_search);
tabHost.addTab(tabSpec);
tabHost.setCurrentTabByTag("tagAll");
setTabColors(tabHost);
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {
setTabColors(tabHost);
}
});
TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
tabs.setVisibility(GONE);
requestSearchResult(1, searchString);
if (ZypeConfiguration.isNativeSubscriptionEnabled(this)) {
new BillingManager(this, this);
}
}
use of android.widget.TabWidget in project fdroidclient by f-droid.
the class TabsAdapter method onPageSelected.
@Override
public void onPageSelected(int position) {
// Unfortunately when TabHost changes the current tab, it kindly
// also takes care of putting focus on it when not in touch mode.
// The jerk.
// This hack tries to prevent this from pulling focus out of our
// ViewPager.
TabWidget widget = tabHost.getTabWidget();
int oldFocusability = widget.getDescendantFocusability();
widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
tabHost.setCurrentTab(position);
widget.setDescendantFocusability(oldFocusability);
// Scroll the current tab into visibility if needed.
View tab = widget.getChildTabViewAt(position);
tempRect.set(tab.getLeft(), tab.getTop(), tab.getRight(), tab.getBottom());
widget.requestRectangleOnScreen(tempRect, false);
// Make sure the scrollbars are visible for a moment after selection
final View contentView = tabs.get(position);
if (contentView instanceof CaffeinatedScrollView) {
((CaffeinatedScrollView) contentView).awakenScrollBars();
}
}
use of android.widget.TabWidget in project android_packages_apps_Launcher2 by CyanogenMod.
the class AppsCustomizeTabHost method onFinishInflate.
/**
* Setup the tab host and create all necessary tabs.
*/
@Override
protected void onFinishInflate() {
// Setup the tab host
setup();
final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
final TabWidget tabs = getTabWidget();
final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content);
mTabs = tabs;
mTabsContainer = tabsContainer;
mAppsCustomizePane = appsCustomizePane;
mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
if (tabs == null || mAppsCustomizePane == null)
throw new Resources.NotFoundException();
// Configure the tabs content factory to return the same paged view (that we change the
// content filter on)
TabContentFactory contentFactory = new TabContentFactory() {
public View createTabContent(String tag) {
return appsCustomizePane;
}
};
// Create the tabs
TextView tabView;
String label;
label = getContext().getString(R.string.all_apps_button_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
label = getContext().getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
setOnTabChangedListener(this);
// Setup the key listener to jump between the last tab view and the market icon
AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
lastTab.setOnKeyListener(keyListener);
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener);
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
}
Aggregations