use of android.widget.TabHost in project platform_frameworks_base by android.
the class MediaDump method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: Read/Write the settings.
setContentView(R.layout.main);
TabHost tab = getTabHost();
// Setup video dumping tab
TabHost.TabSpec videoDumpTab = tab.newTabSpec("VideoDump");
videoDumpTab.setIndicator("VideoDump");
Intent videoDumpIntent = new Intent(this, VideoDumpActivity.class);
videoDumpTab.setContent(videoDumpIntent);
tab.addTab(videoDumpTab);
// Setup rgb player tab
TabHost.TabSpec rgbPlayerTab = tab.newTabSpec("RgbPlayer");
rgbPlayerTab.setIndicator("RgbPlayer");
Intent rgbPlayerIntent = new Intent(this, RgbPlayerActivity.class);
rgbPlayerTab.setContent(rgbPlayerIntent);
tab.addTab(rgbPlayerTab);
}
use of android.widget.TabHost in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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);
}
}
}
use of android.widget.TabHost in project Shuttle by timusus.
the class TracksChooserDialog method setUpView.
private void setUpView(View view) {
ListView listView1 = (ListView) view.findViewById(R.id.listview1);
ListView listView2 = (ListView) view.findViewById(R.id.listview2);
TextView textEmptyMessageView = (TextView) view.findViewById(R.id.text_empty_message);
TextView audioEmptyMessageView = (TextView) 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 = (TabHost) 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);
}
use of android.widget.TabHost in project android_frameworks_base by DirtyUnicorns.
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));
}
}
}
Aggregations