Java Code Examples for android.widget.TabHost#setOnTabChangedListener()
The following examples show how to use
android.widget.TabHost#setOnTabChangedListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From financisto with GNU General Public License v2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); greenRobotBus = GreenRobotBus_.getInstance_(this); requestWindowFeature(Window.FEATURE_NO_TITLE); initialLoad(); final TabHost tabHost = getTabHost(); setupAccountsTab(tabHost); setupBlotterTab(tabHost); setupBudgetsTab(tabHost); setupReportsTab(tabHost); setupMenuTab(tabHost); MyPreferences.StartupScreen screen = MyPreferences.getStartupScreen(this); tabHost.setCurrentTabByTag(screen.tag); tabHost.setOnTabChangedListener(this); }
Example 2
Source File: MyTabHostActivity.java From sa-sdk-android with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.main_tab, tabHost.getTabContentView(), true); /* 以上创建和添加标签页也可以用如下代码实现 */ tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("标签页一").setContent(R.id.tab01)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("标签页二").setContent(R.id.tab02)); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("标签页三").setContent(R.id.tab03)); tabHost.setOnTabChangedListener(tabId -> { }); }
Example 3
Source File: GestionAlumnos.java From android with GNU General Public License v2.0 | 6 votes |
private void cargaPestanas() { Resources res = getResources(); TabHost tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(); TabSpec tbListadoAlumnos = tabHost.newTabSpec(res.getString(R.string.listado_alumnos_title)); tbListadoAlumnos.setContent(R.id.tab1); tbListadoAlumnos.setIndicator(res.getString(R.string.listado_alumnos_title), res.getDrawable(android.R.drawable.ic_menu_slideshow)); tabHost.addTab(tbListadoAlumnos); TabSpec tbNuevoAlumno = tabHost.newTabSpec(res.getString(R.string.nuevo_alumno_title)); tbNuevoAlumno.setContent(R.id.tab2); tbNuevoAlumno.setIndicator(res.getString(R.string.nuevo_alumno_title), res.getDrawable(android.R.drawable.ic_menu_edit)); tabHost.addTab(tbNuevoAlumno); tabHost.setCurrentTab(0); tabHost.setOnTabChangedListener(this); }
Example 4
Source File: SlideTabsActivity.java From GPS2SMS with GNU General Public License v3.0 | 5 votes |
private void initialiseTabHost() { mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); SlideTabsActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec(getString(R.string.tab_mycoords)).setIndicator(getString(R.string.tab_mycoords))); SlideTabsActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec(getString(R.string.tab_mysms)).setIndicator(getString(R.string.tab_mysms))); SlideTabsActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec(getString(R.string.tab_mysms_out)).setIndicator(getString(R.string.tab_mysms_out))); mTabHost.setOnTabChangedListener(this); }
Example 5
Source File: MainActivity.java From AndroidCacheFoundation with Apache License 2.0 | 5 votes |
private void showTabs() { initTabInfo(); tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setOnTabChangedListener(this); tabHost.setup(); viewPager = (MyViewPager) findViewById(R.id.viewpager); viewPager.setOffscreenPageLimit(5); viewPager.setAdapter(new TabAdapter(this, viewPager, tabInfos)); viewPager.setSwipeEnabled(false); for (TabInfo tabInfo : tabInfos) { TabHost.TabSpec tabSpec = tabHost.newTabSpec(tabInfo.getId()); tabSpec.setIndicator(tabInfo.getIndicatorView()); tabSpec.setContent(new TabHost.TabContentFactory() { @Override public View createTabContent(String arg0) { View v = new View(MainActivity.this); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } }); tabHost.addTab(tabSpec); } }
Example 6
Source File: RMBTResultPagerFragment.java From open-rmbt with Apache License 2.0 | 5 votes |
private View createView(View v, LayoutInflater inflater, int currentPage) { tabHost = (TabHost) v.findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setOnTabChangedListener(this); for (int i = 0; i < pagerAdapter.getCount(); i++) { TabSpec tab = tabHost.newTabSpec(String.valueOf(i)); //tab.setIndicator(getActivity().getResources().getStringArray(R.array.result_page_title)[i]); tab.setContent(android.R.id.tabcontent); View indicator = inflater.inflate(R.layout.tabhost_indicator, null); TextView title = (TextView) indicator.findViewById(android.R.id.title); title.setText(getActivity().getResources().getStringArray(R.array.result_page_title)[RMBTResultPagerAdapter.RESULT_PAGE_TAB_TITLE_MAP.get(i)]); if (MAP_INDICATOR_DYNAMIC_VISIBILITY) { if (i == RMBTResultPagerAdapter.RESULT_PAGE_MAP) { indicator.setVisibility(View.GONE); } } tab.setIndicator(indicator); tabHost.addTab(tab); } scroller = (HorizontalScrollView) v.findViewById(R.id.tabwidget_scrollview); viewPager = (ExtendedViewPager) v.findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(this); setCurrentPosition(currentPage); return v; }
Example 7
Source File: TabHostTestActivity.java From AutoTrackAppClick6 with Apache License 2.0 | 5 votes |
@SuppressWarnings("Convert2Lambda") private void initTabHost() { TabHost tabHost = findViewById(R.id.tabhost); tabHost.setup(); LayoutInflater.from(this).inflate(R.layout.tab1, tabHost.getTabContentView()); LayoutInflater.from(this).inflate(R.layout.tab2, tabHost.getTabContentView()); LayoutInflater.from(this).inflate(R.layout.tab3, tabHost.getTabContentView()); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("标签页一").setContent(R.id.tab01)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("标签页二").setContent(R.id.tab02)); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("标签页三").setContent(R.id.tab03)); //标签切换事件处理,setOnTabChangedListener tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override // tabId是newTabSpec第一个参数设置的tab页名,并不是layout里面的标识符id public void onTabChanged(String tabId) { if (tabId.equals("tab1")) { //第一个标签 Toast.makeText(TabHostTestActivity.this, "点击标签页一", Toast.LENGTH_SHORT).show(); } if (tabId.equals("tab2")) { //第二个标签 Toast.makeText(TabHostTestActivity.this, "点击标签页二", Toast.LENGTH_SHORT).show(); } if (tabId.equals("tab3")) { //第三个标签 Toast.makeText(TabHostTestActivity.this, "点击标签页三", Toast.LENGTH_SHORT).show(); } } }); }
Example 8
Source File: QoSTestDetailPagerFragment.java From open-rmbt with Apache License 2.0 | 5 votes |
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View v = inflater.inflate(R.layout.result_tabhost_pager, container, false); tabHost = (TabHost) v.findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setOnTabChangedListener(this); for (int i = 0; i < pagerAdapter.getCount(); i++) { TabSpec tab = tabHost.newTabSpec(String.valueOf(i)); //tab.setIndicator(getActivity().getResources().getStringArray(R.array.result_page_title)[i]); tab.setContent(android.R.id.tabcontent); View indicator = inflater.inflate(R.layout.tabhost_indicator, null); TextView title = (TextView) indicator.findViewById(android.R.id.title); title.setText(pagerAdapter.getPageTitle(i)); tab.setIndicator(indicator); tabHost.addTab(tab); } viewPager = (ExtendedViewPager) v.findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(this); setCurrentPosition(0); scroller = (HorizontalScrollView) v.findViewById(R.id.tabwidget_scrollview); viewPager.setCurrentItem(initPageIndex); return v; }
Example 9
Source File: DocActivityView.java From Mupdf with Apache License 2.0 | 5 votes |
protected void setupTabs() { tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(); // get the tab tags. mTagHidden = getResources().getString(R.string.hidden_tab); mTagFile = getResources().getString(R.string.file_tab); mTagAnnotate = getResources().getString(R.string.annotate_tab); mTagPages = getResources().getString(R.string.pages_tab); // first tab is and stays hidden. // when the search tab is selected, we programmatically "select" this hidden tab // which results in NO tabs appearing selected in this tab host. setupTab(tabHost, mTagHidden, R.id.hiddenTab, R.layout.tab); tabHost.getTabWidget().getChildTabViewAt(0).setVisibility(View.GONE); // these tabs are shown. setupTab(tabHost, mTagFile, R.id.fileTab, R.layout.tab_left); setupTab(tabHost, mTagAnnotate, R.id.annotateTab, R.layout.tab); setupTab(tabHost, mTagPages, R.id.pagesTab, R.layout.tab_right); // start by showing the edit tab tabHost.setCurrentTabByTag(mTagFile); tabHost.setOnTabChangedListener(this); }
Example 10
Source File: DisplayNovelPagerActivity.java From coolreader with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager); } else { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager_fix); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager_fix); } tabHost = (TabHost) findViewById(android.R.id.tabhost); lam = new LocalActivityManager(this, false); lam.dispatchCreate(savedInstanceState); tabHost.setup(lam); isInverted = UIHelper.getColorPreferences(this); // First Tab - Normal Novels TabSpec firstSpec = tabHost.newTabSpec(MAIN_SPEC); firstSpec.setIndicator(MAIN_SPEC); Intent firstIntent = new Intent(this, DisplayLightNovelListActivity.class); firstIntent.putExtra(Constants.EXTRA_ONLY_WATCHED, false); firstSpec.setContent(firstIntent); // Second Tab - Teasers TabSpec secondSpec = tabHost.newTabSpec(TEASER_SPEC); secondSpec.setIndicator(TEASER_SPEC); Intent secondIntent = new Intent(this, DisplayTeaserListActivity.class); secondSpec.setContent(secondIntent); // Third Tab - Original TabSpec thirdSpec = tabHost.newTabSpec(ORIGINAL_SPEC); thirdSpec.setIndicator(ORIGINAL_SPEC); Intent thirdIntent = new Intent(this, DisplayOriginalListActivity.class); thirdSpec.setContent(thirdIntent); // Adding all TabSpec to TabHost tabHost.addTab(firstSpec); // Adding First tab tabHost.addTab(secondSpec); // Adding Second tab tabHost.addTab(thirdSpec); // Adding third tab //setTabColor(); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { public void onTabChanged(String tabId) { //setTabColor(); currentActivity = lam.getActivity(tabId); } }); // Cheap preload list hack. tabHost.setCurrentTabByTag(TEASER_SPEC); tabHost.setCurrentTabByTag(ORIGINAL_SPEC); tabHost.setCurrentTabByTag(MAIN_SPEC); Log.d(TAG, "Created"); }
Example 11
Source File: AbstractCommentFragment.java From Plumble with GNU General Public License v3.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = LayoutInflater.from(getActivity()); View view = inflater.inflate(R.layout.dialog_comment, null, false); mCommentView = (WebView) view.findViewById(R.id.comment_view); mCommentEdit = (EditText) view.findViewById(R.id.comment_edit); mTabHost = (TabHost) view.findViewById(R.id.comment_tabhost); mTabHost.setup(); if(mComment == null) { mCommentView.loadData("Loading...", null, null); requestComment(mProvider.getService()); } else { loadComment(mComment); } TabHost.TabSpec viewTab = mTabHost.newTabSpec("View"); viewTab.setIndicator(getString(R.string.comment_view)); viewTab.setContent(R.id.comment_tab_view); TabHost.TabSpec editTab = mTabHost.newTabSpec("Edit"); editTab.setIndicator(getString(isEditing() ? R.string.comment_edit_source : R.string.comment_view_source)); editTab.setContent(R.id.comment_tab_edit); mTabHost.addTab(viewTab); mTabHost.addTab(editTab); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if("View".equals(tabId)) { // When switching back to view tab, update with user's HTML changes. mCommentView.loadData(mCommentEdit.getText().toString(), "text/html", "UTF-8"); } else if("Edit".equals(tabId) && "".equals(mCommentEdit.getText().toString())) { // Load edittext content for the first time when the tab is selected, to improve performance with long messages. mCommentEdit.setText(mComment); } } }); mTabHost.setCurrentTab(isEditing() ? 1 : 0); AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); adb.setView(view); if (isEditing()) { adb.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { editComment(mProvider.getService(), mCommentEdit.getText().toString()); } }); } adb.setNegativeButton(R.string.close, null); return adb.create(); }
Example 12
Source File: WizardActivity.java From CameraV with GNU General Public License v3.0 | 4 votes |
public void initLayout() { pager = new TabPager(getSupportFragmentManager()); tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setOnTabChangedListener(pager); viewPager.setAdapter(pager); viewPager.setOnPageChangeListener(pager); viewPager.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TabHost.TabSpec tabSpec = null; @SuppressWarnings("unused") View indicator = null; int i = 1; for(Fragment f : fragments) { tabSpec = tabHost.newTabSpec(f.getClass().getSimpleName()) .setIndicator(indicator = new Indicator(String.valueOf(i), this).tab) .setContent(new TabHost.TabContentFactory() { @Override public View createTabContent(String tag) { View view = new View(WizardActivity.this); view.setMinimumHeight(0); view.setMinimumWidth(0); return view; } }); tabHost.addTab(tabSpec); i++; } if(getIntent().hasExtra(Codes.Extras.CHANGE_LOCALE)) { getIntent().removeExtra(Codes.Extras.CHANGE_LOCALE); viewPager.setCurrentItem(1); } }
Example 13
Source File: QoSCategoryPagerFragment.java From open-rmbt with Apache License 2.0 | 4 votes |
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_QOS_RESULTS)) { try { setQoSResult(new QoSServerResultCollection(new JSONArray(savedInstanceState.getString(BUNDLE_QOS_RESULTS)))); setDetailType(DetailType.valueOf(savedInstanceState.getString(BUNDLE_DETAIL_TYPE))); } catch (JSONException e) { //e.printStackTrace(); } } //DetailType detailType = DetailType.valueOf(args.getString(ARG_DETAIL_TYPE)); pagerAdapter = new QoSCategoryPagerAdapter((RMBTMainActivity) getActivity(), handler, results); View v = inflater.inflate(R.layout.result_tabhost_pager, container, false); tabHost = (TabHost) v.findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setOnTabChangedListener(this); for (int i = 0; i < pagerAdapter.getCount(); i++) { TabSpec tab = tabHost.newTabSpec(String.valueOf(i)); //tab.setIndicator(getActivity().getResources().getStringArray(R.array.result_page_title)[i]); tab.setContent(android.R.id.tabcontent); View indicator = inflater.inflate(R.layout.tabhost_indicator, null); TextView title = (TextView) indicator.findViewById(android.R.id.title); title.setText(pagerAdapter.getPageTitle(i)); tab.setIndicator(indicator); tabHost.addTab(tab); } viewPager = (ExtendedViewPager) v.findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(this); setCurrentPosition(0); scroller = (HorizontalScrollView) v.findViewById(R.id.tabwidget_scrollview); if (initPosition != null) { viewPager.setCurrentItem(initPosition); } return v; }
Example 14
Source File: DisplayAlternativeNovelPagerActivity.java From coolreader with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager); } else { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager_fix); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager_fix); } tabHost = (TabHost) findViewById(android.R.id.tabhost); lam = new LocalActivityManager(this, false); lam.dispatchCreate(savedInstanceState); tabHost.setup(lam); isInverted = UIHelper.getColorPreferences(this); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { public void onTabChanged(String tabId) { setTabColor(); currentActivity = lam.getActivity(tabId); } }); /* Dynamically add Tabs */ ArrayList<String> Choice = new ArrayList<String>(); Iterator<Entry<String, AlternativeLanguageInfo>> it = AlternativeLanguageInfo.getAlternativeLanguageInfo().entrySet().iterator(); while (it.hasNext()) { AlternativeLanguageInfo info = it.next().getValue(); boolean isChosen = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(info.getLanguage(), true); if (isChosen) { Choice.add(info.getLanguage()); Log.d("Language Added: ", info.getLanguage()); } it.remove(); } TabSpec[] allSpec = new TabSpec[Choice.size()]; for (int i = 0; i < Choice.size(); i++) { allSpec[i] = tabHost.newTabSpec(Choice.get(i)); allSpec[i].setIndicator(Choice.get(i)); Intent firstIntent = new Intent(this, DisplayAlternativeNovelListActivity.class); firstIntent.putExtra("LANG", Choice.get(i)); allSpec[i].setContent(firstIntent); // Adding all TabSpec to TabHost tabHost.addTab(allSpec[i]); // Cheap preload list hack. tabHost.setCurrentTabByTag(Choice.get(i)); } // Tab color setTabColor(); }
Example 15
Source File: EmojiPalettesView.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
@Override protected void onFinishInflate() { mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost); mTabHost.setup(); for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) { addTab(mTabHost, properties.mCategoryId); } mTabHost.setOnTabChangedListener(this); final TabWidget tabWidget = mTabHost.getTabWidget(); tabWidget.setStripEnabled(mCategoryIndicatorEnabled); if (mCategoryIndicatorEnabled) { // On TabWidget's strip, what looks like an indicator is actually a background. // And what looks like a background are actually left and right drawables. tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId); tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId); tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId); } mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this); mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager); mEmojiPager.setAdapter(mEmojiPalettesAdapter); mEmojiPager.setOnPageChangeListener(this); mEmojiPager.setOffscreenPageLimit(0); mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE); mEmojiLayoutParams.setPagerProperties(mEmojiPager); mEmojiCategoryPageIndicatorView = (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view); mEmojiCategoryPageIndicatorView.setColors( mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground); mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView); setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */); final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar); mEmojiLayoutParams.setActionBarProperties(actionBar); // deleteKey depends only on OnTouchListener. mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete); mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId); mDeleteKey.setTag(Constants.CODE_DELETE); mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on // {@link View.OnClickListener} as well as {@link View.OnTouchListener}. // {@link View.OnTouchListener} is used as the trigger of key-press, while // {@link View.OnClickListener} is used as the trigger of key-release which does not occur // if the event is canceled by moving off the finger from the view. // The text on alphabet keys are set at // {@link #startEmojiPalettes(String,int,float,Typeface)}. mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left); mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId); mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyLeft.setOnTouchListener(this); mAlphabetKeyLeft.setOnClickListener(this); mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right); mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId); mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyRight.setOnTouchListener(this); mAlphabetKeyRight.setOnClickListener(this); mSpacebar = findViewById(R.id.emoji_keyboard_space); mSpacebar.setBackgroundResource(mSpacebarBackgroundId); mSpacebar.setTag(Constants.CODE_SPACE); mSpacebar.setOnTouchListener(this); mSpacebar.setOnClickListener(this); mEmojiLayoutParams.setKeyProperties(mSpacebar); mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon); }
Example 16
Source File: MainActivity.java From ssj with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if the activity has started before on this app version... String name = "LAST_VERSION"; String ssjVersion = Pipeline.getVersion(); SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); firstStart = !getPrefs.getString(name, "").equalsIgnoreCase(ssjVersion); //save current version in preferences so the next time this won't run again SharedPreferences.Editor e = getPrefs.edit(); e.putString(name, ssjVersion); e.apply(); if(firstStart) startTutorial(); setContentView(R.layout.activity_main); loadAnimations(); init(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); final TabHost tabHost = (TabHost) findViewById(R.id.id_tabHost); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { int currentTabId = tabHost.getCurrentTab(); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // Show floating action button only if canvas tab is selected. if (currentTabId == 0) { fab.show(); fab.setEnabled(true); } else { if (actionButtonsVisible) { toggleActionButtons(false); } fab.hide(); fab.setEnabled(false); } } }); }
Example 17
Source File: EmojiPalettesView.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 4 votes |
@Override protected void onFinishInflate() { mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost); mTabHost.setup(); for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) { addTab(mTabHost, properties.mCategoryId); } mTabHost.setOnTabChangedListener(this); final TabWidget tabWidget = mTabHost.getTabWidget(); tabWidget.setStripEnabled(mCategoryIndicatorEnabled); if (mCategoryIndicatorEnabled) { // On TabWidget's strip, what looks like an indicator is actually a background. // And what looks like a background are actually left and right drawables. tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId); tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId); tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId); } mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this); mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager); mEmojiPager.setAdapter(mEmojiPalettesAdapter); mEmojiPager.setOnPageChangeListener(this); mEmojiPager.setOffscreenPageLimit(0); mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE); mEmojiLayoutParams.setPagerProperties(mEmojiPager); mEmojiCategoryPageIndicatorView = (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view); mEmojiCategoryPageIndicatorView.setColors( mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground); mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView); setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */); final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar); mEmojiLayoutParams.setActionBarProperties(actionBar); // deleteKey depends only on OnTouchListener. mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete); mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId); mDeleteKey.setTag(Constants.CODE_DELETE); mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on // {@link View.OnClickListener} as well as {@link View.OnTouchListener}. // {@link View.OnTouchListener} is used as the trigger of key-press, while // {@link View.OnClickListener} is used as the trigger of key-release which does not occur // if the event is canceled by moving off the finger from the view. // The text on alphabet keys are set at // {@link #startEmojiPalettes(String,int,float,Typeface)}. mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left); mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId); mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyLeft.setOnTouchListener(this); mAlphabetKeyLeft.setOnClickListener(this); mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right); mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId); mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyRight.setOnTouchListener(this); mAlphabetKeyRight.setOnClickListener(this); mSpacebar = findViewById(R.id.emoji_keyboard_space); mSpacebar.setBackgroundResource(mSpacebarBackgroundId); mSpacebar.setTag(Constants.CODE_SPACE); mSpacebar.setOnTouchListener(this); mSpacebar.setOnClickListener(this); mEmojiLayoutParams.setKeyProperties(mSpacebar); mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon); }