use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.
the class DownloadsFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.pager_fragment, container, false);
Toolbar toolbar = root.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.downloads_label);
toolbar.inflateMenu(R.menu.downloads);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
viewPager = root.findViewById(R.id.viewpager);
viewPager.setAdapter(new DownloadsPagerAdapter(this));
viewPager.setOffscreenPageLimit(2);
super.setupPagedToolbar(toolbar, viewPager);
// Give the TabLayout the ViewPager
tabLayout = root.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_COMPLETED:
tab.setText(R.string.downloads_completed_label);
break;
case POS_LOG:
tab.setText(R.string.downloads_log_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 root;
}
use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.
the class StatisticsFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
viewPager = rootView.findViewById(R.id.viewpager);
toolbar = rootView.findViewById(R.id.toolbar);
viewPager.setAdapter(new StatisticsPagerAdapter(this));
// Give the TabLayout the ViewPager
tabLayout = rootView.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_LISTENED_HOURS:
tab.setText(R.string.playback_statistics_label);
break;
case POS_SPACE_TAKEN:
tab.setText(R.string.download_statistics_label);
break;
default:
break;
}
}).attach();
if (getActivity().getClass() == PreferenceActivity.class) {
rootView.findViewById(R.id.toolbar).setVisibility(View.GONE);
} else {
toolbar.setTitle(getString(R.string.statistics_label));
toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
}
return rootView;
}
use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.
the class ContributorsPagerFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
viewPager.setAdapter(new StatisticsPagerAdapter(this));
// Give the TabLayout the ViewPager
TabLayout tabLayout = rootView.findViewById(R.id.sliding_tabs);
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
switch(position) {
case POS_DEVELOPERS:
tab.setText(R.string.developers);
break;
case POS_TRANSLATORS:
tab.setText(R.string.translators);
break;
case POS_SPECIAL_THANKS:
tab.setText(R.string.special_thanks);
break;
default:
break;
}
}).attach();
rootView.findViewById(R.id.toolbar).setVisibility(View.GONE);
return rootView;
}
use of com.google.android.material.tabs.TabLayout in project IITB-App by wncc.
the class UserFragment method populateViews.
private void populateViews() {
if (getActivity() == null || getView() == null)
return;
userProfilePictureImageView = getActivity().findViewById(R.id.user_profile_picture_profile);
TextView userNameTextView = getActivity().findViewById(R.id.user_name_profile);
TextView userRollNumberTextView = getActivity().findViewById(R.id.user_rollno_profile);
final TextView userEmailIDTextView = getActivity().findViewById(R.id.user_email_profile);
TextView userContactNumberTextView = getActivity().findViewById(R.id.user_contact_no_profile);
FloatingActionButton userShareFab = getActivity().findViewById(R.id.share_user_button);
Picasso.get().load(user.getUserProfilePictureUrl()).placeholder(R.drawable.user_placeholder).into(userProfilePictureImageView);
userProfilePictureImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomImageFromThumb(userProfilePictureImageView);
}
});
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
if (!showingMin) {
/* Show tabs */
getActivity().findViewById(R.id.tab_layout).setVisibility(VISIBLE);
/* Load lists */
final List<Role> roleList = user.getUserRoles();
final List<Body> bodyList = user.getUserFollowedBodies();
final List<Event> eventList = user.getUserGoingEvents();
final List<Role> formerRoleList = user.getUserFormerRoles();
/* Construct user profile */
final List<CardInterface> profile = new ArrayList<>(roleList);
for (Role role : formerRoleList) {
Role temp = new Role(role);
temp.setRoleName("Former " + role.getRoleName() + " " + role.getRoleYear());
profile.add(temp);
}
profile.addAll(user.getUserAchievements());
List<Event> eventInterestedList = user.getUserInterestedEvents();
eventList.removeAll(eventInterestedList);
eventList.addAll(eventInterestedList);
GenericRecyclerViewFragment frag1 = GenericRecyclerViewFragment.newInstance(profile);
BodyRecyclerViewFragment frag2 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag3 = EventRecyclerViewFragment.newInstance(eventList);
frag1.parentFragment = this;
frag2.parentFragment = this;
frag3.parentFragment = this;
TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager());
tabAdapter.addFragment(frag1, "Profile");
tabAdapter.addFragment(frag2, "Following");
tabAdapter.addFragment(frag3, "Events");
// Set up the ViewPager with the sections adapter.
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
viewPager.setAdapter(tabAdapter);
viewPager.setOffscreenPageLimit(2);
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
userShareFab.show();
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
userNameTextView.setText(user.getUserName());
userRollNumberTextView.setText(user.getUserRollNumber());
if (user.getUserEmail() != null && !user.getUserEmail().equals("N/A")) {
userEmailIDTextView.setText(user.getUserEmail());
} else {
if (user.getUserRollNumber() != null)
userEmailIDTextView.setText(user.getUserRollNumber() + "@iitb.ac.in");
}
userEmailIDTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mail((String) userEmailIDTextView.getText());
}
});
if (!"N/A".equals(user.getUserContactNumber())) {
userContactNumberTextView.setText(user.getUserContactNumber());
userContactNumberTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
call(user.getUserContactNumber());
}
});
} else {
userContactNumberTextView.setVisibility(View.GONE);
}
userShareFab.setOnClickListener(new View.OnClickListener() {
String shareUrl = ShareURLMaker.getUserURL(user);
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i.putExtra(Intent.EXTRA_TEXT, shareUrl);
startActivity(Intent.createChooser(i, "Share URL"));
}
});
}
use of com.google.android.material.tabs.TabLayout in project K6nele by Kaljurand.
the class SpeechInputView method updateClipboard.
/**
* TODO: hide tabs without rewrites, or at least block the long press on an empty rewrites tab
*/
private void updateClipboard(Context context, String language, ComponentName service, ComponentName app) {
TabLayout tabs = findViewById(R.id.tlClipboardTabs);
tabs.clearOnTabSelectedListeners();
tabs.removeAllTabs();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Resources res = getResources();
Set<String> defaults = PreferenceUtils.getPrefStringSet(prefs, res, R.string.defaultRewriteTables);
if (defaults.isEmpty()) {
mLlEmpty.setVisibility(View.VISIBLE);
mRvClipboard.setVisibility(View.GONE);
tabs.setVisibility(View.GONE);
findViewById(R.id.buttonOpenRewrites).setOnClickListener(v -> {
Intent intent = new Intent(getContext(), RewritesSelectorActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
return;
} else {
mLlEmpty.setVisibility(View.GONE);
mRvClipboard.setVisibility(View.VISIBLE);
tabs.setVisibility(View.VISIBLE);
}
CommandMatcher commandMatcher = CommandMatcherFactory.createCommandFilter(language, service, app);
String[] names = defaults.toArray(EMPTY_STRING_ARRAY);
// TODO: defaults should be a list (not a set that needs to be sorted)
Arrays.sort(names);
String appId = app.flattenToShortString();
String selectedTabName = getTabName(prefs, res, appId);
tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
String name = tab.getText().toString();
if (NEW_TAB_LABEL.equals(tab.getTag())) {
Intent intent = new Intent(getContext(), RewritesSelectorActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
mRvClipboard.setAdapter(getClipboardAdapter(prefs, res, name, commandMatcher));
setTabName(prefs, res, appId, name);
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
for (String tabName : names) {
TabLayout.Tab tab = tabs.newTab();
tab.setText(tabName);
tabs.addTab(tab, tabName.equals(selectedTabName));
}
TabLayout.Tab tab = tabs.newTab();
tab.setText(NEW_TAB_LABEL);
tab.setTag(NEW_TAB_LABEL);
tabs.addTab(tab, false);
// we select the first one (but do not save it).
if (tabs.getSelectedTabPosition() == -1) {
tabs.getTabAt(0).select();
}
LinearLayout tabStrip = (LinearLayout) tabs.getChildAt(0);
// We exclude the NEW_TAB_LABEL
for (int i = 0; i < tabStrip.getChildCount() - 1; i++) {
String name = tabs.getTabAt(i).getText().toString();
// Long click loads the rewrites view (without populating the tab)
tabStrip.getChildAt(i).setOnLongClickListener(v -> {
Intent intent = new Intent(getContext(), RewritesActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(RewritesActivity.EXTRA_NAME, name);
intent.putExtra(RewritesActivity.EXTRA_LOCALE, language);
intent.putExtra(RewritesActivity.EXTRA_APP, appId);
intent.putExtra(RewritesActivity.EXTRA_SERVICE, service.flattenToShortString());
context.startActivity(intent);
return false;
});
}
}
Aggregations