public TiUIActionBarTabGroup(TabGroupProxy proxy, TiBaseActivity activity) { super(proxy, activity); tabActivity = new WeakReference<TiBaseActivity>(activity); activity.addOnLifecycleEventListener(this); // Setup the action bar for navigation tabs. actionBar = activity.getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(true); swipeable = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_SWIPEABLE), true); tabGroupPagerAdapter = new TabGroupPagerAdapter(((ActionBarActivity) activity).getSupportFragmentManager()); tabGroupViewPager = (new ViewPager(proxy.getActivity()) { @Override public boolean onTouchEvent(MotionEvent event) { return swipeable ? super.onTouchEvent(event) : false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { return swipeable ? super.onInterceptTouchEvent(event) : false; } }); tabGroupViewPager.setAdapter(tabGroupPagerAdapter); tabGroupViewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page simply select the tab actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) {} }); TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams(); params.autoFillsHeight = true; params.autoFillsWidth = true; ((ViewGroup) activity.getLayout()).addView(tabGroupViewPager, params); setNativeView(tabGroupViewPager); }
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { TiUIActionBarTab tabView = (TiUIActionBarTab) tab.getTag(); if (tabView.fragment == null) { // If not we will create it here then attach it // to the tab group activity inside the "content" container. tabView.initializeFragment(); } tabGroupViewPager.setCurrentItem(tab.getPosition()); TabProxy tabProxy = (TabProxy) tabView.getProxy(); ((TabGroupProxy) proxy).onTabSelected(tabProxy); if (tabClicked) { tabProxy.fireEvent(TiC.EVENT_CLICK, null); } else { tabClicked = true; } tabProxy.fireEvent(TiC.EVENT_SELECTED, null, false); }