use of com.google.android.material.tabs.TabLayout in project Timber by naman14.
the class MainFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
if (viewPager != null) {
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(2);
}
TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
return rootView;
}
use of com.google.android.material.tabs.TabLayout in project materialistic by hidroh.
the class HelpLazyLoadView method onFinishInflate.
@Override
protected void onFinishInflate() {
super.onFinishInflate();
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.comments));
tabLayout.addTab(tabLayout.newTab().setText(R.string.article));
Preferences.StoryViewMode defaultView = Preferences.getDefaultStoryView(getContext());
int defaultTab;
switch(defaultView) {
case Comment:
default:
defaultTab = 0;
break;
case Article:
case Readability:
defaultTab = 1;
break;
}
// noinspection ConstantConditions
tabLayout.getTabAt(defaultTab).select();
}
use of com.google.android.material.tabs.TabLayout in project materialistic by hidroh.
the class UserActivity method onCreate.
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUsername = getIntent().getStringExtra(EXTRA_USERNAME);
if (TextUtils.isEmpty(mUsername)) {
mUsername = AppUtils.getDataUriId(getIntent(), PARAM_ID);
}
if (TextUtils.isEmpty(mUsername)) {
finish();
return;
}
setTaskTitle(mUsername);
AppUtils.setStatusBarDim(getWindow(), true);
setContentView(R.layout.activity_user);
findViewById(R.id.touch_outside).setOnClickListener(v -> finish());
mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch(newState) {
case BottomSheetBehavior.STATE_HIDDEN:
finish();
break;
case BottomSheetBehavior.STATE_EXPANDED:
AppUtils.setStatusBarDim(getWindow(), false);
mRecyclerView.setLayoutFrozen(false);
break;
case BottomSheetBehavior.STATE_COLLAPSED:
case BottomSheetBehavior.STATE_DRAGGING:
case BottomSheetBehavior.STATE_HALF_EXPANDED:
case BottomSheetBehavior.STATE_SETTLING:
default:
AppUtils.setStatusBarDim(getWindow(), true);
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// no op
}
});
mTitle = (TextView) findViewById(R.id.title);
mTitle.setText(mUsername);
mInfo = (TextView) findViewById(R.id.user_info);
mAbout = (TextView) findViewById(R.id.about);
mEmpty = findViewById(R.id.empty);
mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
// no op
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
// no op
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
scrollToTop();
}
});
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(this, true));
mRecyclerView.addItemDecoration(new CommentItemDecoration(this));
mScrollableHelper = new KeyDelegate.RecyclerViewHelper(mRecyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM);
if (savedInstanceState != null) {
mUser = savedInstanceState.getParcelable(STATE_USER);
}
if (mUser == null) {
load();
} else {
bind();
}
if (!AppUtils.hasConnection(this)) {
Snackbar.make(findViewById(R.id.content_frame), R.string.offline_notice, Snackbar.LENGTH_LONG).show();
}
}
use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.
the class GpodnetMainFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.pager_fragment, container, false);
setupToolbar(root.findViewById(R.id.toolbar));
ViewPager2 viewPager = root.findViewById(R.id.viewpager);
GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(this);
viewPager.setAdapter(pagerAdapter);
// Give the TabLayout the ViewPager
TabLayout tabLayout = root.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_TAGS:
tab.setText(R.string.gpodnet_taglist_header);
break;
// Fall-through
case POS_TOPLIST:
default:
tab.setText(R.string.gpodnet_toplist_header);
break;
}
}).attach();
return root;
}
use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.
the class EpisodesFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
Toolbar toolbar = rootView.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.episodes_label);
toolbar.inflateMenu(R.menu.episodes);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
viewPager.setAdapter(new EpisodesPagerAdapter(this));
viewPager.setOffscreenPageLimit(2);
super.setupPagedToolbar(toolbar, viewPager);
// Give the TabLayout the ViewPager
tabLayout = rootView.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_NEW_EPISODES:
tab.setText(R.string.new_episodes_label);
break;
case POS_ALL_EPISODES:
tab.setText(R.string.all_episodes_short_label);
break;
case POS_FAV_EPISODES:
tab.setText(R.string.favorite_episodes_label);
break;
default:
break;
}
}).attach();
// restore our last position
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
viewPager.setCurrentItem(lastPosition, false);
return rootView;
}
Aggregations