@Override protected void onCreate(Bundle savedInstanceState) { TAG = "TabHost2"; super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.tab2); addTabView(getString(R.string.view1), null, View1.class); addTabView(getString(R.string.view2), null, View2.class); // TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); TabHost tabHost = getTabHost(); TabWidget tw = tabHost.getTabWidget(); tw.setBackgroundResource(R.drawable.tab_bg); for (int i = 0, n = tw.getChildCount(); i < n; i++) { View view = (View) tw.getChildTabViewAt(i); view.setBackgroundResource(R.drawable.none); TextView tv = (TextView) view.findViewById(android.R.id.title); tv.setTextSize(10); tv.setGravity(Gravity.CENTER_HORIZONTAL); tv.setText("Label" + (i + 1)); ImageView img = (ImageView) view.findViewById(android.R.id.icon); img.setBackgroundResource(R.drawable.none); img.setImageResource(R.drawable.tab_button); } tabHost.setOnTabChangedListener(this); onTabChanged(getString(R.string.view1)); }
public void o(int paramInt) { TabWidget localTabWidget = this.Rk.getTabWidget(); int i = localTabWidget.getDescendantFocusability(); localTabWidget.setDescendantFocusability(393216); this.Rk.setCurrentTab(paramInt); localTabWidget.setDescendantFocusability(i); }
private void styleSelectedTab() { int selIndex = mViewPager.getCurrentItem(); TabWidget tabWidget = getTabWidget(); boolean isPrivate = false; if (mTarget != null && mTarget.equals(AwesomeBar.Target.CURRENT_TAB.name())) { Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) isPrivate = tab.isPrivate(); } for (int i = 0; i < tabWidget.getTabCount(); i++) { GeckoTextView view = (GeckoTextView) tabWidget.getChildTabViewAt(i); if (isPrivate) { view.setPrivateMode((i == selIndex) ? false : true); } else { if (i == selIndex) view.resetTheme(); else if (mActivity.getLightweightTheme().isEnabled()) view.setTheme(mActivity.getLightweightTheme().isLightTheme()); else view.resetTheme(); } if (i == selIndex) continue; if (i == (selIndex - 1)) view.getBackground().setLevel(1); else if (i == (selIndex + 1)) view.getBackground().setLevel(2); else view.getBackground().setLevel(0); } if (selIndex == 0) findViewById(R.id.tab_widget_left).getBackground().setLevel(1); else findViewById(R.id.tab_widget_left).getBackground().setLevel(0); if (selIndex == (tabWidget.getTabCount() - 1)) findViewById(R.id.tab_widget_right).getBackground().setLevel(2); else findViewById(R.id.tab_widget_right).getBackground().setLevel(0); }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (type == Type.Centered) { if (maxTabWidth == Integer.MIN_VALUE) { for (int i = 0; i < tabWidget.getTabCount(); i++) { View tabView = tabWidget.getChildTabViewAt(i); if (tabView.getMeasuredWidth() > maxTabWidth) { maxTabWidth = tabView.getMeasuredWidth(); } } if (maxTabWidth > 0) { for (int i = 0; i < tabWidget.getTabCount(); i++) { View tabView = tabWidget.getChildTabViewAt(i); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabView.getLayoutParams(); params.width = maxTabWidth; tabView.setLayoutParams(params); } } } } super.onLayout(changed, left, top, right, bottom); }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (getChildCount() == 0) { return; } final Drawable d = indicator; View tabView = tabWidget.getChildTabViewAt(position); if (tabView == null) { return; } View nextTabView = position + 1 < tabWidget.getTabCount() ? tabWidget.getChildTabViewAt(position + 1) : null; int tabWidth = tabView.getWidth(); int nextTabWidth = nextTabView == null ? tabWidth : nextTabView.getWidth(); int indicatorWidth = (int) (nextTabWidth * positionOffset + tabWidth * (1 - positionOffset)); int indicatorLeft = (int) (getPaddingLeft() + tabView.getLeft() + positionOffset * tabWidth); int height = getHeight(); d.setBounds(indicatorLeft, height - indicatorHeight, indicatorLeft + indicatorWidth, height); d.draw(canvas); }
private void ensureHierarchy(Context context) { // If owner hasn't made its own view hierarchy, then as a convenience // we will construct a standard one here. if (findViewById(android.R.id.tabs) == null) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); addView( ll, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TabWidget tw = new TabWidget(context); tw.setId(android.R.id.tabs); tw.setOrientation(TabWidget.HORIZONTAL); ll.addView( tw, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); FrameLayout fl = new FrameLayout(context); fl.setId(android.R.id.tabcontent); ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0)); mRealTabContent = fl = new FrameLayout(context); mRealTabContent.setId(mContainerId); ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1)); } }
/** * Creates the widget that holds the actual tabs. * * @param activity Activity to create the widgets in. * @return the widget that holds the actual tabs. */ private TabWidget createTabWidget(Activity activity) { TabWidget tabWidget = new TabWidget(activity); tabWidget.setId(android.R.id.tabs); LinearLayout.LayoutParams tabWidgetParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); tabWidgetParams.weight = 0; tabWidget.setLayoutParams(tabWidgetParams); return tabWidget; }
/** 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); LayoutParams params = (LayoutParams) mContent.getLayoutParams(); params.topMargin += Utils.getStatusBarSize(getResources()); mContent.setLayoutParams(params); 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); }
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 = mTabHost.getTabWidget(); int oldFocusability = widget.getDescendantFocusability(); widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); mTabHost.setCurrentTab(position); widget.setDescendantFocusability(oldFocusability); }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.mainfragment, container, false); screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth(); event = (EventBean) getActivity().getApplicationContext(); mTabHost = (TabHost) v.findViewById(android.R.id.tabhost); hs = (HorizontalScrollView) v.findViewById(R.id.horizontalScrollView1); mViewPager = (ViewPager) v.findViewById(R.id.pager); categories = event.getCategories(); events_upcoming = event.getObject(); category_id = new ArrayList<Integer>(); category_name = new ArrayList<String>(); initialiseTabHost(); List<Fragment> fragments = getFragments(); pageAdapter = new MyPageAdapter(getFragmentManager(), fragments); mViewPager.setOffscreenPageLimit(1); mViewPager.setAdapter(pageAdapter); mViewPager.setOnPageChangeListener(this); TabWidget widget = mTabHost.getTabWidget(); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(Color.parseColor("#ffffff")); if (isTabletDevice(getResources()) == true) { tv.setTextSize(17); } else { tv.setTextSize(14); } tv.setTypeface(event.getTextBold()); // tv.setEllipsize(TextUtils.TruncateAt.END); if (Build.VERSION.SDK_INT > 11) { tv.setAllCaps(false); } View v1 = widget.getChildAt(i); // v1.setPadding(0,0,0,0); v1.setBackgroundResource(R.drawable.tab_selector_drawable); } return v; }
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 centerTabItem(int position) { System.out.println("position " + position); mTabHost.setCurrentTab(position); final TabWidget tabWidget = mTabHost.getTabWidget(); final int leftX = tabWidget.getChildAt(position).getLeft(); int newX = 0; newX = leftX + (tabWidget.getChildAt(position).getWidth() / 2) - (screenWidth / 2); if (newX < 0) { newX = 0; } hs.scrollTo(newX, 0); }
/** 在初始化TabWidget前调用 和TabWidget有关的必须在这里初始化 */ @Override protected void prepare() { TabItem home = new TabItem( "我的病人", // title R.drawable.icon_home, // icon R.drawable.example_tab_item_bg, // background new Intent(this, MyPatientsActivity.class)); // intent TabItem info = new TabItem( "我的病区", R.drawable.icon_selfinfo, R.drawable.example_tab_item_bg, new Intent(this, MyInpatientAreaActivity.class)); TabItem msg = new TabItem( "其他病区", R.drawable.icon_meassage, R.drawable.example_tab_item_bg, new Intent(this, FrontierActivity.class)); // TabItem square = new TabItem( // "广场", // R.drawable.icon_square, // R.drawable.example_tab_item_bg, // new Intent(this, MainActivity.class)); TabItem more = new TabItem( "更多", R.drawable.icon_more, R.drawable.example_tab_item_bg, new Intent(this, FrontierActivity.class)); mItems = new ArrayList<TabItem>(); mItems.add(home); mItems.add(info); mItems.add(msg); // mItems.add(square); mItems.add(more); // 设置分割线 TabWidget tabWidget = getTabWidget(); tabWidget.setDividerDrawable(R.drawable.tab_divider); mLayoutInflater = getLayoutInflater(); }
@Override public void onTabChanged(String tabId) { int tabID = Integer.valueOf(tabId); for (int i = 0; i < mTabWidget.getChildCount(); i++) { View view = mTabWidget.getChildAt(i); TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text); if (tabID == i) { view.setBackgroundResource(R.drawable.number_bg_pressed); title.setTextColor(Color.rgb(255, 255, 255)); } else { view.setBackgroundResource(R.drawable.number_bg); title.setTextColor(Color.rgb(0, 0, 0)); } } }
/** * add new tab with title text * * @param title title text */ public void addTab(CharSequence title) { int layoutId = getLayoutId(type); TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false); tv.setText(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple); } else { // create background using colorControlActivated StateListDrawable d = new StateListDrawable(); d.addState( new int[] {android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated)); d.setAlpha(180); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { tv.setBackgroundDrawable(d); } else { tv.setBackgroundDrawable(d); } } int tabId = tabWidget.getTabCount(); addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent)); }
private void open_files() throws FileNotFoundException { // Adjust view mbtn_start.setEnabled(false); mbtn_stop.setEnabled(true); mTabWidget.setEnabled(false); // Refs CSensorStates lSenStates = mSenStates; CLocProvStates lLPStates = mLPStates; DataOutputStream[] lfout = fout; // Open the files and register the listeners if (lSenStates.getNumAct() > 0) { lfout[0] = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file_location("_sensors.bin")))); } else lfout[0] = null; if (lLPStates.getNumAct() > 0) { lfout[1] = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file_location("_locprovider.bin")))); } else lfout[1] = null; if (mGPSState) { lfout[2] = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file_location("_gpsstate.bin")))); } else lfout[2] = null; }
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); } }
private void initTabHost(Bundle args) { mTabHost = (TabHost) v.findViewById(android.R.id.tabhost); mTabHost.setup(); TabInfo tabInfo = null; // Create Child Tab1 Personal.AddTab( this, this.mTabHost, this.mTabHost.newTabSpec("subtab1").setIndicator(createTabView(mContext, "登入")), (tabInfo = new TabInfo("Tab1", PersonalLogin.class, args))); this.mHashMapTabInfo.put(tabInfo.tag, tabInfo); // Create Child Tab2 Personal.AddTab( this, this.mTabHost, this.mTabHost.newTabSpec("subtab2").setIndicator(createTabView(mContext, "悠遊卡登入")), (tabInfo = new TabInfo("Tab2", PersonalLoginEasyCard.class, args))); this.mHashMapTabInfo.put(tabInfo.tag, tabInfo); mTabHost.setCurrentTab(0); // Create Child Tab3 Personal.AddTab( this, this.mTabHost, this.mTabHost.newTabSpec("subtab3").setIndicator(createTabView(mContext, "註冊")), (tabInfo = new TabInfo("Tab3", PersonalRegister.class, args))); this.mHashMapTabInfo.put(tabInfo.tag, tabInfo); mTabHost.setCurrentTab(0); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; TabWidget tabWidget = mTabHost.getTabWidget(); int count = tabWidget.getChildCount(); if (count > 1) { for (int i = 0; i < count; i++) { tabWidget.getChildTabViewAt(i).setMinimumWidth((screenWidth) / 1); } } mTabHost.setOnTabChangedListener(this); }
/** * 获取TabHost * * @param mContext * @param gravity tabs的位置,上面TOP 下面BOTTOM,目前只支持两个 * @return */ public static EasyFragmentTabHostSaveState getKFragmentTabHostSaveStateView( Context mContext, int gravity) { // init FragmentTabHost EasyFragmentTabHostSaveState tabhost = new EasyFragmentTabHostSaveState(mContext); tabhost.setId(android.R.id.tabhost); tabhost.setLayoutParams( new FragmentTabHost.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); LinearLayout mLinearLayout = new LinearLayout(mContext); mLinearLayout.setOrientation(LinearLayout.VERTICAL); mLinearLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // init FrameLayout FrameLayout realtabcontent = new FrameLayout(mContext); realtabcontent.setId(EasyR.id.realtabcontent); realtabcontent.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f)); // init TabWidget TabWidget tabs = new TabWidget(mContext); tabs.setId(android.R.id.tabs); tabs.setLayoutParams( new TabWidget.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0)); tabs.setOrientation(LinearLayout.HORIZONTAL); FrameLayout tabcontent = new FrameLayout(mContext); tabcontent.setId(android.R.id.tabcontent); tabcontent.setLayoutParams(new LinearLayout.LayoutParams(0, 0, 0f)); tabhost.addView(mLinearLayout); switch (gravity) { case TabGravity.BOTTOM: mLinearLayout.addView(realtabcontent); mLinearLayout.addView(tabs); // wiget在下面 mLinearLayout.addView(tabcontent); break; case TabGravity.TOP: mLinearLayout.addView(tabs); // wiget在上面 mLinearLayout.addView(tabcontent); mLinearLayout.addView(realtabcontent); break; } return tabhost; }
/** * 获取TabHost * * @param mContext * @param gravity tabs的位置,上面TOP 下面BOTTOM,目前只支持两个 * @return */ public static TabHost getTabHostAndPagerView(Context mContext, int tabGravity) { // init TabHost TabHost tabhost = new TabHost(mContext); tabhost.setId(android.R.id.tabhost); tabhost.setLayoutParams( new FragmentTabHost.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); LinearLayout mLinearLayout = new LinearLayout(mContext); mLinearLayout.setOrientation(LinearLayout.VERTICAL); mLinearLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // init TabWidget TabWidget tabs = new TabWidget(mContext); tabs.setId(android.R.id.tabs); tabs.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0)); tabs.setOrientation(LinearLayout.HORIZONTAL); FrameLayout tabcontent = new FrameLayout(mContext); tabcontent.setId(android.R.id.tabcontent); tabcontent.setLayoutParams(new LinearLayout.LayoutParams(0, 0, 0f)); ViewPager viewPager = new ViewPager(mContext); viewPager.setId(EasyR.id.pager); viewPager.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f)); tabhost.addView(mLinearLayout); switch (tabGravity) { case TabGravity.BOTTOM: mLinearLayout.addView(viewPager); mLinearLayout.addView(tabs); // wiget在下面 mLinearLayout.addView(tabcontent); break; case TabGravity.TOP: default: mLinearLayout.addView(tabs); // wiget在上面 mLinearLayout.addView(tabcontent); mLinearLayout.addView(viewPager); break; } return tabhost; }
private void customTabs() { /* 对Tab标签的定制 */ mTabWidget = mTabHost.getTabWidget(); for (int i = 0; i < mTabWidget.getChildCount(); i++) { /* 得到每个标签的视图 */ View view = mTabWidget.getChildAt(i); TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text); /* 设置每个标签的背景 */ if (mTabHost.getCurrentTab() == i) { view.setBackgroundResource(R.drawable.number_bg_pressed); title.setTextColor(Color.rgb(255, 255, 255)); } else { view.setBackgroundResource(R.drawable.number_bg); title.setTextColor(Color.rgb(0, 0, 0)); } } }
public void setType(Type type) { this.type = type; switch (type) { case FullScreenWidth: tabWidget.setGravity(Gravity.LEFT); setPadding(0, 0, 0, 0); break; case Centered: tabWidget.setGravity(Gravity.CENTER_HORIZONTAL); setPadding(0, 0, 0, 0); break; case LeftOffset: tabWidget.setGravity(Gravity.LEFT); setPadding(leftOffset, 0, 0, 0); break; default: tabWidget.setGravity(Gravity.LEFT); setPadding(0, 0, 0, 0); } }
private void stop_recording() { // Stop Recording mSenMan.unregisterListener(this); mLocMan.removeGpsStatusListener(this); mLocMan.removeUpdates(this); // Close files close_files(); // Adjust view mbtn_start.setEnabled(true); mbtn_stop.setEnabled(false); mTabWidget.setEnabled(true); }
private void initFragmentTabHost(Context paramContext, AttributeSet paramAttributeSet) { TypedArray localTypedArray = paramContext.obtainStyledAttributes(paramAttributeSet, new int[] { 16842995 }, 0, 0); this.mContainerId = localTypedArray.getResourceId(0, 0); localTypedArray.recycle(); super.setOnTabChangedListener(this); if (findViewById(16908307) != null) return; LinearLayout localLinearLayout = new LinearLayout(paramContext); localLinearLayout.setOrientation(1); addView(localLinearLayout, new FrameLayout.LayoutParams(-1, -1)); TabWidget localTabWidget = new TabWidget(paramContext); localTabWidget.setId(16908307); localTabWidget.setOrientation(0); localLinearLayout.addView(localTabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0F)); FrameLayout localFrameLayout1 = new FrameLayout(paramContext); localFrameLayout1.setId(16908305); localLinearLayout.addView(localFrameLayout1, new LinearLayout.LayoutParams(0, 0, 0.0F)); FrameLayout localFrameLayout2 = new FrameLayout(paramContext); this.mRealTabContent = localFrameLayout2; this.mRealTabContent.setId(this.mContainerId); localLinearLayout.addView(localFrameLayout2, new LinearLayout.LayoutParams(-1, 0, 1.0F)); }
@SuppressLint("NewApi") public void testTabsAreSelectable() throws Throwable { String[] colorChooserTags = { mSolo.getString(R.string.color_pre), mSolo.getString(R.string.color_rgb) }; assertTrue("Waiting for DrawingSurface", mSolo.waitForView(DrawingSurface.class, 1, TIMEOUT)); mSolo.clickOnView(mButtonTopColor); mSolo.sleep(COLOR_PICKER_DIALOGUE_APPERANCE_DELAY); TabHost tabHost = (TabHost) mSolo.getView(R.id.colorview_tabColors); TabWidget colorTabWidget = tabHost.getTabWidget(); assertEquals("Wrong tab count ", colorTabWidget.getTabCount(), colorChooserTags.length); for (int tabChildIndex = 0; tabChildIndex < colorTabWidget.getChildCount(); tabChildIndex++) { mSolo.clickOnView(colorTabWidget.getChildAt(tabChildIndex), true); mSolo.sleep(500); if (colorChooserTags[tabChildIndex].equalsIgnoreCase(mSolo.getString(R.string.color_pre))) assertFalse( "In preselection tab and rgb (red) string found", mSolo.searchText(mSolo.getString(R.string.color_red))); else if (colorChooserTags[tabChildIndex].equalsIgnoreCase( mSolo.getString(R.string.color_rgb))) { assertTrue( "In rgb tab and red string not found", mSolo.searchText(mSolo.getString(R.string.color_red))); assertTrue( "In rgb tab and green string not found", mSolo.searchText(mSolo.getString(R.string.color_green))); assertTrue( "In rgb tab and blue string not found", mSolo.searchText(mSolo.getString(R.string.color_blue))); } } mSolo.goBack(); }
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; }
/** * add new tab with specified view * * @param view tab view */ public void addTab(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // view.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple); } else { // create background using colorControlActivated StateListDrawable d = new StateListDrawable(); d.addState( new int[] {android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated)); d.setAlpha(180); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackgroundDrawable(d); } else { view.setBackgroundDrawable(d); } } int tabId = tabWidget.getTabCount(); addTab( newTabSpec(String.valueOf(tabId)).setIndicator(view).setContent(android.R.id.tabcontent)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LOGTAG, "creating awesomebar"); mResolver = Tabs.getInstance().getContentResolver(); LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance()); setContentView(R.layout.awesomebar); mGoButton = (ImageButton) findViewById(R.id.awesomebar_button); mText = (AwesomeBarEditText) findViewById(R.id.awesomebar_text); TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs); tabWidget.setDividerDrawable(null); mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs); mAwesomeTabs.setOnUrlOpenListener( new AwesomeBarTabs.OnUrlOpenListener() { public void onUrlOpen(String url) { openUrlAndFinish(url); } public void onSearch(String engine, String text) { openSearchAndFinish(text, engine); } public void onEditSuggestion(final String text) { GeckoApp.mAppContext.mMainHandler.post( new Runnable() { public void run() { mText.setText(text); mText.setSelection(mText.getText().length()); mText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT); } }); } }); mGoButton.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { openUserEnteredAndFinish(mText.getText().toString()); } }); Intent intent = getIntent(); String currentUrl = intent.getStringExtra(CURRENT_URL_KEY); mTarget = intent.getStringExtra(TARGET_KEY); if (currentUrl != null) { mText.setText(currentUrl); mText.selectAll(); } mText.setOnKeyPreImeListener( new AwesomeBarEditText.OnKeyPreImeListener() { public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) { // We only want to process one event per tap if (event.getAction() != KeyEvent.ACTION_DOWN) return false; if (keyCode == KeyEvent.KEYCODE_ENTER) { // If the AwesomeBar has a composition string, don't submit the text yet. // ENTER is needed to commit the composition string. Editable content = mText.getText(); if (!hasCompositionString(content)) { openUserEnteredAndFinish(content.toString()); return true; } } // If input method is in fullscreen mode, we want to dismiss // it instead of closing awesomebar straight away. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (keyCode == KeyEvent.KEYCODE_BACK && !imm.isFullscreenMode()) { // Let mAwesomeTabs try to handle the back press, since we may be in a // bookmarks sub-folder. if (mAwesomeTabs.onBackPressed()) return true; // If mAwesomeTabs.onBackPressed() returned false, we didn't move up // a folder level, so just exit the activity. cancelAndFinish(); return true; } return false; } }); mText.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { String text = s.toString(); mAwesomeTabs.filter(text); // If the AwesomeBar has a composition string, don't call updateGoButton(). // That method resets IME and composition state will be broken. if (!hasCompositionString(s)) { updateGoButton(text); } // cancel previous query if (mSuggestTask != null) { mSuggestTask.cancel(true); } if (mSuggestClient != null) { mSuggestTask = new AsyncTask<String, Void, ArrayList<String>>() { protected ArrayList<String> doInBackground(String... query) { return mSuggestClient.query(query[0]); } protected void onPostExecute(ArrayList<String> suggestions) { mAwesomeTabs.setSuggestions(suggestions); } }; mSuggestTask.execute(text); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // do nothing } public void onTextChanged(CharSequence s, int start, int before, int count) { // do nothing } }); mText.setOnKeyListener( new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() != KeyEvent.ACTION_DOWN) return true; openUserEnteredAndFinish(mText.getText().toString()); return true; } else { return false; } } }); registerForContextMenu(mAwesomeTabs.findViewById(R.id.all_pages_list)); registerForContextMenu(mAwesomeTabs.findViewById(R.id.bookmarks_list)); registerForContextMenu(mAwesomeTabs.findViewById(R.id.history_list)); GeckoAppShell.registerGeckoEventListener("SearchEngines:Data", this); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null)); }
@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(""); }
public MaterialTabHost(Context context, AttributeSet attrs) { super(context, attrs); inflater = LayoutInflater.from(context); TypedValue outValue = new TypedValue(); Resources.Theme theme = context.getTheme(); // use ?attr/colorPrimary as background color // theme.resolveAttribute(R.attr.colorPrimary, outValue, true); // setBackgroundColor(outValue.data); // use ?attr/colorControlActivated as default indicator color // theme.resolveAttribute(R.attr.colorControlActivated, outValue, true); // colorControlActivated = outValue.data; setBackgroundColor(0xff0CACF4); colorControlActivated = 0xffBEEAFC; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0); int indicatorColor = a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, colorControlActivated); a.recycle(); // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable indicator = new ShapeDrawable(); indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP); Resources res = context.getResources(); indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height); leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset); // int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height); tabWidget = new TabWidget(context); tabWidget.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tabWidget.setId(android.R.id.tabs); tabWidget.setStripEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); } addView(tabWidget); FrameLayout fl = new FrameLayout(context); fl.setLayoutParams(new LayoutParams(0, 0)); fl.setId(android.R.id.tabcontent); addView(fl); setup(); setOnTabChangedListener( new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (listener != null) { listener.onTabSelected(Integer.valueOf(tabId)); } } }); float density = getResources().getDisplayMetrics().density; // set elevation for App bar // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation ViewCompat.setElevation(this, APP_TAB_ELEVATION * density); }