Search in sources :

Example 21 with TabLayout

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;
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(de.danoeh.antennapod.activity.MainActivity) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) SharedPreferences(android.content.SharedPreferences) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) MainActivity(de.danoeh.antennapod.activity.MainActivity) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Example 22 with TabLayout

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;
}
Also used : Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) View(android.view.View)

Example 23 with TabLayout

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;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Bundle(android.os.Bundle) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) View(android.view.View)

Example 24 with TabLayout

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"));
        }
    });
}
Also used : CardInterface(app.insti.interfaces.CardInterface) TabAdapter(app.insti.adapter.TabAdapter) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) Role(app.insti.api.model.Role) TabLayout(com.google.android.material.tabs.TabLayout) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Event(app.insti.api.model.Event) TextView(android.widget.TextView) Body(app.insti.api.model.Body)

Example 25 with TabLayout

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;
        });
    }
}
Also used : CommandMatcher(ee.ioc.phon.android.speechutils.editor.CommandMatcher) RewritesSelectorActivity(ee.ioc.phon.android.speak.activity.RewritesSelectorActivity) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Paint(android.graphics.Paint) TabLayout(com.google.android.material.tabs.TabLayout) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

TabLayout (com.google.android.material.tabs.TabLayout)36 View (android.view.View)19 Bundle (android.os.Bundle)13 Toolbar (androidx.appcompat.widget.Toolbar)13 NonNull (androidx.annotation.NonNull)12 ViewPager (androidx.viewpager.widget.ViewPager)12 ViewPager2 (androidx.viewpager2.widget.ViewPager2)11 TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)11 Fragment (androidx.fragment.app.Fragment)10 Intent (android.content.Intent)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 TextView (android.widget.TextView)7 Nullable (androidx.annotation.Nullable)7 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)7 Context (android.content.Context)6 R (de.danoeh.antennapod.R)5 SharedPreferences (android.content.SharedPreferences)3 MenuItem (android.view.MenuItem)3 FrameLayout (android.widget.FrameLayout)3