static boolean updateButtonBar(Activity a, int highlight) { final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar); boolean withtabs = false; Intent intent = a.getIntent(); if (intent != null) { withtabs = intent.getBooleanExtra("withtabs", false); } if (highlight == 0 || !withtabs) { ll.setVisibility(View.GONE); return withtabs; } else if (withtabs) { ll.setVisibility(View.VISIBLE); } for (int i = ll.getChildCount() - 1; i >= 0; i--) { View v = ll.getChildAt(i); boolean isActive = (v.getId() == highlight); if (isActive) { ll.setCurrentTab(i); sActiveTabIndex = i; } v.setTag(i); v.setOnFocusChangeListener( new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { for (int i = 0; i < ll.getTabCount(); i++) { if (ll.getChildTabViewAt(i) == v) { ll.setCurrentTab(i); processTabClick( (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId()); break; } } } } }); v.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { processTabClick( (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId()); } }); } return withtabs; }
static void processTabClick(Activity a, View v, int current) { int id = v.getId(); if (id == current) { return; } final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar); activateTab(a, id); if (id != R.id.nowplayingtab) { ll.setCurrentTab((Integer) v.getTag()); setIntPref(a, "activetab", id); } }
public void setCurrentTabToFocusedTab() { View tab = null; int index = -1; final int count = getTabCount(); for (int i = 0; i < count; ++i) { View v = getChildTabViewAt(i); if (v.hasFocus()) { tab = v; index = i; break; } } if (index > -1) { super.setCurrentTab(index); super.onFocusChange(tab, true); } }
@Override protected void onFinishInflate() { super.onFinishInflate(); // HACK: Without this, the onFinishInflate is called twice // This issue is due to a bug when Android inflates a layout with a // parent. Fixed in Honeycomb if (mInflated) return; mInflated = true; // This should be called before adding any tabs // to the TabHost. setup(); mListTouchListener = new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) hideSoftInput(view); return false; } }; mBackground = (Background) findViewById(R.id.awesomebar_background); mTabs = new AwesomeBarTab[] { new AllPagesTab(mContext), new BookmarksTab(mContext), new HistoryTab(mContext) }; final TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs); // hide the strip since we aren't using the TabHost... tabWidget.setStripEnabled(false); mViewPager = (ViewPager) findViewById(R.id.tabviewpager); mPagerAdapter = new AwesomePagerAdapter(); mViewPager.setAdapter(mPagerAdapter); mViewPager.setCurrentItem(0); mViewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { public void onPageScrollStateChanged(int state) {} public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} public void onPageSelected(int position) { tabWidget.setCurrentTab(position); styleSelectedTab(); hideSoftInput(mViewPager); } }); for (int i = 0; i < mTabs.length; i++) { mTabs[i].setListTouchListener(mListTouchListener); addAwesomeTab(mTabs[i].getTag(), mTabs[i].getTitleStringId(), i); } tabWidget.setCurrentTab(0); styleSelectedTab(); // Initialize "App Pages" list with no filter filter(""); }