Java Code Examples for com.google.android.material.tabs.TabLayout#Tab

The following examples show how to use com.google.android.material.tabs.TabLayout#Tab . 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: TeiDashboardMobileActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupTabletTabTitles(TabLayout.Tab tab, int position) {
    if (programUid != null) {
        switch (position) {
            case INDICATORS_LANDSCAPE_POS:
                tab.setText(getString(R.string.dashboard_indicators));
                break;
            case RELATIONSHIPS_LANDSCAPE_POS:
                tab.setText(getString(R.string.dashboard_relationships));
                break;
            case NOTES_LANDSCAPE_POS:
                tab.setText(getString(R.string.dashboard_notes));
                break;
            default:
                break;
        }
    }
}
 
Example 2
Source File: SensorCardPresenter.java    From science-journal with Apache License 2.0 6 votes vote down vote up
private void addSensorTab(String sensorId, int index, Context context) {
  final SensorAppearance appearance = appearanceProvider.getAppearance(sensorId);
  TabLayout.Tab tab = cardViewHolder.sensorTabLayout.newTab();
  tab.setContentDescription(appearance.getName(context));
  tab.setIcon(appearance.getIconDrawable(context));
  tab.setTag(sensorId);
  cardViewHolder.sensorTabLayout.addTab(tab, index, false);
  // HACK: we need to retrieve the view using View#findViewByTag to avoid adding lots of
  // callbacks and plumbing, just for a one time use case (feature discovery).
  // We also need to set the content description on the TabView so that FeatureDiscovery can
  // retrieve it properly. This does not seem to cause a double content description in
  // TalkBack, probably because the TabView's content description is otherwise unused.
  // Finding the TabView is dependent on the current implementation of TabLayout, but since
  // it comes from the support library, not worried about it changing on different devices.
  if (cardViewHolder.sensorTabLayout.getChildCount() > 0) {
    View tabView = ((ViewGroup) cardViewHolder.sensorTabLayout.getChildAt(0)).getChildAt(index);
    tabView.setTag(sensorId);
    tabView.setContentDescription(appearance.getName(context));
  }
}
 
Example 3
Source File: MainActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void whenTabReselected(TabLayout.Tab tab) {
    FragmentTrigger fragmentTrigger = null;
    switch (tab.getPosition()) {
        case 0:
            fragmentTrigger = findFragment(MainBookListFragment.class);
            break;
        case 1:
            fragmentTrigger = findFragment(FindBookFragment.class);
            break;
        case 2:
            fragmentTrigger = findFragment(AudioBookFragment.class);
    }

    if (fragmentTrigger != null) {
        fragmentTrigger.onReselected();
    }
}
 
Example 4
Source File: TravelTimePicker.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
private void updateTab(final Bundle savedInstanceState) {
    if (mTabLayout == null) {
        return;
    }
    mTabLayout.setVisibility(View.VISIBLE);
    int type = mTimeType.value();
    if (savedInstanceState != null) {
        type = savedInstanceState.getInt(TAB_SELECTED);
    }
    final TabLayout.Tab tab = mTabLayout.getTabAt(type);
    if (tab != null) {
        tab.select();
    }

    if (mVariety != Variety.BOTH) {
        mTabLayout.setVisibility(View.GONE);
    }
}
 
Example 5
Source File: SensorCardPresenter.java    From science-journal with Apache License 2.0 5 votes vote down vote up
public void setOnSensorSelectedListener(final OnSensorClickListener listener) {
  onSensorClickListener = listener;
  onTabSelectedListener =
      new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
          if (cardViewHolder != null) {
            String newSensorId = (String) tab.getTag();
            trySelectingNewSensor(newSensorId, sensorId);
          }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {}

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
          if (cardViewHolder != null) {
            String newSensorId = (String) tab.getTag();
            if (TextUtils.equals(sensorId, newSensorId) && sensorPresenter != null) {
              sensorPresenter.resetView();
              // Also need to pin the graph to now again.
              interactionListener.requestResetPinnedState();
            } else {
              trySelectingNewSensor(sensorId, newSensorId);
            }
          }
        }
      };
  if (cardViewHolder != null && isActive) {
    cardViewHolder.sensorTabLayout.clearOnTabSelectedListeners();
    cardViewHolder.sensorTabLayout.addOnTabSelectedListener(onTabSelectedListener);
  }
}
 
Example 6
Source File: CustomTabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
@Override
protected TabLayout.Tab onCreateTab(TabLayout tabLayout, PagerAdapter adapter, int position) {
    // NOTE: should not call super method here!

    TabLayout.Tab tab = tabLayout.newTab();
    tab.setText(adapter.getPageTitle(position));
    View v = LayoutInflater.from(tabLayout.getContext()).inflate(R.layout.custom_tab, tabLayout, false);
    tab.setCustomView(v);

    return tab;
}
 
Example 7
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
protected void handleOnTabSelected(TabLayout.Tab tab) {
    if (mDuringSetTabsFromPagerAdapter) {
        return;
    }
    mViewPager.setCurrentItem(tab.getPosition());
    cancelPendingUpdateScrollPosition();
}
 
Example 8
Source File: ItemPagerAdapter.java    From materialistic with Apache License 2.0 5 votes vote down vote up
public void bind(ViewPager viewPager, TabLayout tabLayout,
                 FloatingActionButton navigationFab, FloatingActionButton genericFab) {
    viewPager.setPageMargin(viewPager.getResources().getDimensionPixelOffset(R.dimen.divider));
    viewPager.setPageMarginDrawable(R.color.blackT12);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setAdapter(this);
    tabLayout.setupWithViewPager(viewPager);
    mTabListener = new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            super.onTabSelected(tab);
            toggleFabs(viewPager.getCurrentItem() == 0, navigationFab, genericFab);
            Fragment fragment = getItem(viewPager.getCurrentItem());
            if (fragment != null) {
                ((LazyLoadFragment) fragment).loadNow();
            }
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            Fragment fragment = getItem(viewPager.getCurrentItem());
            if (fragment != null) {
                ((Scrollable) fragment).scrollToTop();
            }
        }
    };
    tabLayout.addOnTabSelectedListener(mTabListener);
    viewPager.setCurrentItem(mDefaultItem);
    toggleFabs(mDefaultItem == 0, navigationFab, genericFab);

}
 
Example 9
Source File: MyMainActivity.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private void updateTabItemIcon(boolean showMenu) {
    TabLayout.Tab tab = mTlIndicator.getTabAt(0);
    if (tab == null) return;
    View customView = tab.getCustomView();
    if (customView == null) return;
    ImageView im = customView.findViewById(R.id.tabicon);
    if (showMenu) {
        im.setImageResource(R.drawable.ic_arrow_drop_up);
    } else {
        im.setImageResource(R.drawable.ic_arrow_drop_down);
    }
}
 
Example 10
Source File: MainActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 更新Tab文字
 */
private void updateTabItemText(int group) {
    TabLayout.Tab tab = mTlIndicator.getTabAt(0);
    if (tab == null) return;
    View customView = tab.getCustomView();
    if (customView == null) return;
    TextView tv = customView.findViewById(R.id.tabtext);
    tv.setText(getResources().getStringArray(R.array.book_group_array)[group]);
    tab.setContentDescription(String.format("%s,%s", tv.getText(), getString(R.string.click_on_selected_show_menu)));
}
 
Example 11
Source File: TabsActivity.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Override
public void onPostItemClick(View v, List<ChanPost> posts, final int position, final String boardTitle, final String boardName, final long threadId) {
    final TabLayout.Tab threadTab = tabLayout.newTab();
    final TabPagerAdapter.TabItem threadTabItem;
    final Bundle args = new Bundle();

    args.putLong(Extras.EXTRAS_THREAD_ID, threadId);
    args.putString(Extras.EXTRAS_BOARD_NAME, boardName);
    args.putString(Extras.EXTRAS_BOARD_TITLE, boardTitle);
    args.putBoolean(Extras.EXTRAS_STICKY_AUTO_REFRESH, true);

    if (posts != null && posts.size() > position) {
        ChanPost firstPost = posts.get(position);
        if (firstPost != null) {
            args.putParcelable(Extras.EXTRAS_THREAD_FIRST_POST, firstPost);
        }
    }

    View tabView = createTabView(threadId, boardName);
    threadTab.setCustomView(tabView);
    threadTab.select();

    threadTabItem = new TabPagerAdapter.TabItem(TabPagerAdapter.TabType.THREAD, args, threadId, boardName, String.valueOf(threadId));
    final int itemCount = tabPagerAdapter.getCount();
    final int pos = tabPagerAdapter.addItem(threadTabItem);

    if (pos < 0) {
        return;
    } else if (pos >= itemCount) {
        tabLayout.addTab(threadTab);
    }
    tabPager.setCurrentItem(pos, true);
}
 
Example 12
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onTabUnselected(TabLayout.Tab tab) {
    //viewPager.setCurrentItem(tab.getPosition(), true);
}
 
Example 13
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param tabLayout TabLayout instance
 * @param viewPager ViewPager instance
 */
public TabLayoutHelper(@NonNull TabLayout tabLayout, @NonNull ViewPager viewPager) {
    PagerAdapter adapter = viewPager.getAdapter();

    if (adapter == null) {
        throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
    }

    mTabLayout = tabLayout;
    mViewPager = viewPager;

    mInternalDataSetObserver = new DataSetObserver() {
        @Override
        public void onChanged() {
            handleOnDataSetChanged();
        }
    };

    mInternalOnTabSelectedListener = new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            handleOnTabSelected(tab);
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            handleOnTabUnselected(tab);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            handleOnTabReselected(tab);
        }
    };

    mInternalTabLayoutOnPageChangeListener = new FixedTabLayoutOnPageChangeListener(mTabLayout);

    mInternalOnAdapterChangeListener = new ViewPager.OnAdapterChangeListener() {
        @Override
        public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter oldAdapter, @Nullable PagerAdapter newAdapter) {
            handleOnAdapterChanged(viewPager, oldAdapter, newAdapter);
        }
    };

    setupWithViewPager(mTabLayout, mViewPager);
}
 
Example 14
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 4 votes vote down vote up
/**
 * Override this method if you want to use custom tab layout
 *
 * @param tab Tab
 */
protected void onUpdateTab(TabLayout.Tab tab) {
    if (tab.getCustomView() == null) {
        tab.setCustomView(null); // invokes update() method internally.
    }
}
 
Example 15
Source File: SimpleOnTabSelectedListener.java    From SimpleSearchView with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabSelected(TabLayout.Tab tab) {
    // No action
}
 
Example 16
Source File: TabLayoutMediator.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabUnselected(TabLayout.Tab tab) {
    // No-op
}
 
Example 17
Source File: TabLayoutDoubleClickBackToTopPresenter.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onTabSelected(TabLayout.Tab tab) {
    clicked = false;
    currentPosition = tab.getPosition();
}
 
Example 18
Source File: TabLayoutMediator.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabReselected(TabLayout.Tab tab) {
    // No-op
}
 
Example 19
Source File: TransportModePanel.java    From msdkui-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabUnselected(final TabLayout.Tab tab) {
    if (mOnSelectedListener != null) {
        mOnSelectedListener.onUnselected(tab.getPosition(), (TabView) tab.getCustomView());
    }
}
 
Example 20
Source File: TabLayoutMediator.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabSelected(TabLayout.Tab tab) {
    mViewPager.setCurrentItem(tab.getPosition(), true);
}