List of usage examples for android.widget TabHost setCurrentTabByTag
public void setCurrentTabByTag(String tag)
From source file:org.geometerplus.android.fbreader.bookmark.EditBookmarkActivity.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.edit_bookmark); myBookmark = FBReaderIntents.getBookmarkExtra(getIntent()); if (myBookmark == null) { finish();//from w w w . j a v a 2s.c om return; } final DisplayMetrics dm = getResources().getDisplayMetrics(); final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm), dm.widthPixels * 9 / 10); final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm), dm.heightPixels * 9 / 10); final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost); tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height))); tabHost.setup(); addTab(tabHost, "text", R.id.edit_bookmark_content_text); addTab(tabHost, "style", R.id.edit_bookmark_content_style); addTab(tabHost, "delete", R.id.edit_bookmark_content_delete); final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text"); tabHost.setCurrentTabByTag(currentTabOption.getValue()); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { public void onTabChanged(String tag) { if (!"delete".equals(tag)) { currentTabOption.setValue(tag); } } }); final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text); editor.setText(myBookmark.getText()); final int len = editor.getText().length(); editor.setSelection(len, len); final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button); saveTextButton.setEnabled(false); saveTextButton.setText(myResource.getResource("saveText").getValue()); saveTextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { myCollection.bindToService(EditBookmarkActivity.this, new Runnable() { public void run() { myBookmark.setText(editor.getText().toString()); myCollection.saveBookmark(myBookmark); saveTextButton.setEnabled(false); } }); } }); editor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence sequence, int start, int before, int count) { final String originalText = myBookmark.getText(); saveTextButton.setEnabled(!originalText.equals(editor.getText().toString())); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button); deleteButton.setText(myResource.getResource("deleteBookmark").getValue()); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { myCollection.bindToService(EditBookmarkActivity.this, new Runnable() { public void run() { myCollection.deleteBookmark(myBookmark); finish(); } }); } }); }
From source file:ru.gkpromtech.exhibition.events.EventsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // restore saved positions int savedPosition = 0; if (savedInstanceState != null) { savedFilter = savedInstanceState.getInt(SAVE_FILTER, EventReader.EVENT_FILTER_ALL); savedPosition = savedInstanceState.getInt(SAVE_PAGE_NUMBER, 0); } else {/*w ww . j av a 2s. com*/ // calculate day to position ViewPager Calendar calendar = Calendar.getInstance(); Date d = calendar.getTime(); List<Date> days = new ArrayList<>(EventReader.getInstance(this).getDays()); if (days.contains(d)) savedPosition = days.indexOf(d); } FrameLayout view = (FrameLayout) findViewById(R.id.container); getLayoutInflater().inflate(R.layout.activity_events, view, true); TabHost tabHost = (TabHost) view.findViewById(R.id.tabHost); tabHost.setup(); tabHost.addTab(tabHost .newTabSpec("tag" + EventReader.EVENT_FILTER_ALL).setIndicator(createIndicatorView(tabHost, getResources().getString(R.string.all_uppercase), R.drawable.ic_events_all)) .setContent(R.id.tab1)); tabHost.addTab(tabHost .newTabSpec("tag" + EventReader.EVENT_FILTER_SHOW).setIndicator(createIndicatorView(tabHost, getResources().getString(R.string.event_status_business), R.drawable.ic_white_plane)) .setContent(R.id.tab2)); tabHost.addTab(tabHost .newTabSpec("tag" + EventReader.EVENT_FILTER_MY).setIndicator(createIndicatorView(tabHost, getResources().getString(R.string.event_status_my), R.drawable.ic_person)) .setContent(R.id.tab3)); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new EventsFragmentPagerAdapter(getSupportFragmentManager(), EventReader.getInstance(this), savedFilter); pager.setAdapter(pagerAdapter); // set saved page pager.setCurrentItem(savedPosition); tabHost.setCurrentTabByTag("tag" + savedFilter); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } }); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { switch (tabId) { case "tag" + EventReader.EVENT_FILTER_ALL: savedFilter = EventReader.EVENT_FILTER_ALL; break; case "tag" + EventReader.EVENT_FILTER_SHOW: savedFilter = EventReader.EVENT_FILTER_SHOW; break; case "tag" + EventReader.EVENT_FILTER_MY: savedFilter = EventReader.EVENT_FILTER_MY; break; } AnalyticsManager.sendEvent(EventsActivity.this, R.string.events_category, R.string.action_change, savedFilter); pagerAdapter.setFilter(savedFilter); } }); AnalyticsManager.sendEvent(this, R.string.events_category, R.string.action_open, savedFilter); }