use of android.widget.TabHost 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.TabHost 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.TabHost in project zype-android by zype.
the class AbstractTabFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mAdapter = new VideosCursorAdapter(getActivity(), CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER, mOnVideoItemActionListener, mOnLoginListener);
View view = inflater.inflate(R.layout.fragment_base_tab_list, null);
mListView = (ListView) view.findViewById(R.id.list_tab);
mEmpty = (TextView) view.findViewById(R.id.empty);
mListView.setEmptyView(mEmpty);
mListView.setOnItemClickListener(this);
mListView.setAdapter(mAdapter);
tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("tag1");
tabSpec.setIndicator(getString(R.string.title_tab_search_all));
tabSpec.setContent(R.id.list_tab);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tag2");
tabSpec.setIndicator(getString(R.string.title_tab_search_audio));
tabSpec.setContent(R.id.list_tab);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tag3");
tabSpec.setIndicator(getString(R.string.title_tab_search_video));
tabSpec.setContent(R.id.list_tab);
tabHost.addTab(tabSpec);
tabHost.setCurrentTabByTag("tag1");
setTabColors(tabHost);
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {
setTabColors(tabHost);
startLoadCursors(selectedTab);
}
});
return view;
}
use of android.widget.TabHost in project android-flowlayout by ApmeM.
the class MyActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
TabHost tabHost = super.getTabHost();
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("tag1");
tabSpec1.setIndicator(getResources().getString(R.string.flow_layout_activity));
tabSpec1.setContent(new Intent(this, FlowLayoutActivity.class));
tabHost.addTab(tabSpec1);
TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("tag2");
tabSpec2.setIndicator(getResources().getString(R.string.flow_layout_manager_activity));
tabSpec2.setContent(new Intent(this, FlowLayoutManagerActivity.class));
tabHost.addTab(tabSpec2);
}
use of android.widget.TabHost in project Shuttle by timusus.
the class TracksChooserDialog method setUpView.
private void setUpView(View view) {
ListView listView1 = view.findViewById(R.id.listview1);
ListView listView2 = view.findViewById(R.id.listview2);
TextView textEmptyMessageView = view.findViewById(R.id.text_empty_message);
TextView audioEmptyMessageView = view.findViewById(R.id.audio_empty_message);
partitionTracks();
mTextAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mTextTracks, mSelectedTextPosition);
mAudioVideoAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mAudioTracks, mSelectedAudioPosition);
listView1.setAdapter(mTextAdapter);
listView2.setAdapter(mAudioVideoAdapter);
TabHost tabs = view.findViewById(R.id.tabhost);
tabs.setup();
// create tab 1
TabHost.TabSpec tab1 = tabs.newTabSpec("tab1");
if (mTextTracks == null || mTextTracks.isEmpty()) {
listView1.setVisibility(View.INVISIBLE);
tab1.setContent(R.id.text_empty_message);
} else {
textEmptyMessageView.setVisibility(View.INVISIBLE);
tab1.setContent(R.id.listview1);
}
tab1.setIndicator(getString(R.string.ccl_caption_subtitles));
tabs.addTab(tab1);
// create tab 2
TabHost.TabSpec tab2 = tabs.newTabSpec("tab2");
if (mAudioTracks == null || mAudioTracks.isEmpty()) {
listView2.setVisibility(View.INVISIBLE);
tab2.setContent(R.id.audio_empty_message);
} else {
audioEmptyMessageView.setVisibility(View.INVISIBLE);
tab2.setContent(R.id.listview2);
}
tab2.setIndicator(getString(R.string.ccl_caption_audio));
tabs.addTab(tab2);
}
Aggregations