Java Code Examples for com.google.android.material.tabs.TabLayout#setupWithViewPager()

The following examples show how to use com.google.android.material.tabs.TabLayout#setupWithViewPager() . 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: GiphyActivity.java    From mollyim-android with GNU General Public License v3.0 7 votes vote down vote up
private void initializeResources() {
  ViewPager viewPager = ViewUtil.findById(this, R.id.giphy_pager);
  TabLayout tabLayout = ViewUtil.findById(this, R.id.tab_layout);

  this.gifFragment     = new GiphyGifFragment();
  this.stickerFragment = new GiphyStickerFragment();
  this.forMms          = getIntent().getBooleanExtra(EXTRA_IS_MMS, false);

  gifFragment.setClickListener(this);
  stickerFragment.setClickListener(this);

  viewPager.setAdapter(new GiphyFragmentPagerAdapter(this, getSupportFragmentManager(),
                                                     gifFragment, stickerFragment));
  tabLayout.setupWithViewPager(viewPager);
  tabLayout.setBackgroundColor(getConversationColor());
}
 
Example 2
Source File: MainActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    leftfrag = new FragLeft();
    midfrag = new FragMid();
    rightfrag = new FragRight();
    FragmentManager fragmentManager = getSupportFragmentManager();

    viewPager = findViewById(R.id.pager);
    ThreeFragmentPagerAdapter adapter = new ThreeFragmentPagerAdapter(fragmentManager);
    viewPager.setAdapter(adapter);

    //new Tablayout from the support design library
    TabLayout mTabLayout = findViewById(R.id.tablayout1);
    mTabLayout.setupWithViewPager(viewPager);

}
 
Example 3
Source File: NavigationDrawerFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    setupToolbar(toolbar);

    initDrawerLayout(view, toolbar);
    initNavigationView(view);

    mViewPager = view.findViewById(R.id.pager);
    TabLayout tabLayout = view.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

    super.onViewCreated(view, savedInstanceState);
    mPresenter.loadBoardInfo();
}
 
Example 4
Source File: MultiFragmentsActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multi_fragments);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
    tabLayout.setupWithViewPager(mViewPager);

}
 
Example 5
Source File: ManageCategoriesFragment.java    From Deadline with GNU General Public License v3.0 6 votes vote down vote up
private void setupTabLayout() {
    TabLayout tabLayout = getView().findViewById(R.id.manage_categories_tab);
    ViewPager viewPager = getView().findViewById(R.id.manage_categories_view_pager);

    String[] tabTitles = {getString(R.string.custom_categories), getString(R.string.smart_categories)};

    List<Fragment> fragments = new ArrayList<>();
    fragments.add(CustomCategoriesFragment.newInstance());
    fragments.add(SmartCategoriesFragment.newInstance());

    ManageCategoriesPagerAdapter pagerAdapter = new ManageCategoriesPagerAdapter(getChildFragmentManager(), fragments, tabTitles);
    viewPager.setAdapter(pagerAdapter);

    tabLayout.setupWithViewPager(viewPager);

    tabLayout.getTabAt(0).setText(R.string.custom_categories).setIcon(R.drawable.ic_category);
    tabLayout.getTabAt(1).setText(R.string.smart_categories).setIcon(R.drawable.ic_next_7_days);
}
 
Example 6
Source File: CrashReporterActivity.java    From loco-answers with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.crash_reporter_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.crash_reporter));
    toolbar.setSubtitle(getApplicationName());
    setSupportActionBar(toolbar);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 7
Source File: FragmentLegend.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null)
        layout = savedInstanceState.getInt("fair:layout");

    if (layout < 0) {
        TabLayout tabLayout = view.findViewById(R.id.tab_layout);
        tabLayout.setupWithViewPager(pager);

        Bundle args = getArguments();
        if (args != null) {
            String tab = args.getString("tab");
            if ("compose".equals(tab))
                pager.setCurrentItem(3);

            args.remove("tab");
            setArguments(args);
        }
    }
}
 
Example 8
Source File: MyHelperAdapter.java    From MultiTypeRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
private void renderFoot(BaseViewHolder helper) {
    if (mContext instanceof FragmentActivity) {
        FragmentActivity activity = (FragmentActivity) mContext;
        TextView title = helper.getTextView(R.id.title);
        title.setText("为您精选");
        TabLayout tab = helper.getView(R.id.footer_tab, TabLayout.class);
        ViewPager pager = helper.getView(R.id.footer_pager, ViewPager.class);
        pager.setAdapter(new FooterVPAdapter(activity.getSupportFragmentManager()));
        tab.setupWithViewPager(pager);
    }
}
 
Example 9
Source File: StickerSelectActivity.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.scribble_select_sticker_activity);

  ViewPager viewPager = findViewById(R.id.camera_sticker_pager);
  viewPager.setAdapter(new StickerPagerAdapter(getSupportFragmentManager(), this));

  TabLayout tabLayout = findViewById(R.id.camera_sticker_tabs);
  tabLayout.setupWithViewPager(viewPager);

  for (int i=0;i<tabLayout.getTabCount();i++) {
    tabLayout.getTabAt(i).setIcon(TAB_TITLES[i]);
  }
}
 
Example 10
Source File: DownloadsActivity.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_downloads);

    initToolBar();

    SupportedDownloads.KernelContent content = new SupportedDownloads.KernelContent(getIntent().getStringExtra(JSON_INTENT));
    getSupportActionBar().setTitle(Utils.htmlFrom(content.getName()).toString());

    final ViewPager viewPager = findViewById(R.id.viewpager);

    LinkedHashMap<String, Fragment> items = new LinkedHashMap<>();

    List<SupportedDownloads.KernelContent.Feature> features = content.getFeatures();
    List<SupportedDownloads.KernelContent.Download> downloads = content.getDownloads();

    if (content.getShortDescription() != null && content.getLongDescription() != null) {
        items.put(getString(R.string.about), AboutFragment.newInstance(content));
    }

    if (features.size() > 0) {
        items.put(getString(R.string.features), FeaturesFragment.newInstance(features));
    }

    if (downloads.size() > 0) {
        items.put(getString(R.string.downloads), DownloadKernelFragment.newInstance(downloads));
    }

    viewPager.setOffscreenPageLimit(items.size());
    PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), items);
    viewPager.setAdapter(pagerAdapter);

    TabLayout tabLayout = findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(viewPager);

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
}
 
Example 11
Source File: HomeTopChartsFragment.java    From GooglePlayCloned with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_top_charts, container, false);

    CustomViewPager viewPager = view.findViewById(R.id.vp_app_list);
    setupViewPager(viewPager);

    TabLayout subTabLayout = view.findViewById(R.id.tl_app_list);
    subTabLayout.setupWithViewPager(viewPager);

    return view;
}
 
Example 12
Source File: ImageTransferFormatSelectorDialogFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

    // Set animations
    Dialog dialog = getDialog();
    if (dialog != null) {
        //dialog.setTitle(R.string.imagetransfer_resolution_choose);
        //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = dialog.getWindow();
        if (window != null) {
            window.setWindowAnimations(R.style.DialogAnimation);
        }
    }

    // Configure tabs and viewpager
    ViewPager viewPager = view.findViewById(R.id.viewpager);
    ResolutionsPageAdapter adapter = new ResolutionsPageAdapter(getChildFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, mResolution);
    viewPager.setAdapter(adapter);

    TabLayout tabLayout = view.findViewById(R.id.tabLayout);
    tabLayout.setupWithViewPager(viewPager);

    // Force titles
    TabLayout.Tab standardResolutions = tabLayout.getTabAt(0);
    if (standardResolutions != null) {
        standardResolutions.setText(R.string.imagetransfer_resolution_mode_standard);
    }
    TabLayout.Tab eInkResolutions = tabLayout.getTabAt(1);
    if (eInkResolutions != null) {
        eInkResolutions.setText(R.string.imagetransfer_resolution_mode_eink);
    }

    // Set initial item
    viewPager.setCurrentItem(mIsEInkModeEnabled ? 1 : 0);
}
 
Example 13
Source File: SecondFragment.java    From ZhiHuIndex with Apache License 2.0 5 votes vote down vote up
private void InitView() {
    mTabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
    mViewPager = (ViewPager) rootView.findViewById(R.id.viewpager);

    //初始化TabLayout的title
    mTabLayout.addTab(mTabLayout.newTab().setText("推荐"));
    mTabLayout.addTab(mTabLayout.newTab().setText("圆桌"));
    mTabLayout.addTab(mTabLayout.newTab().setText("热门"));
    mTabLayout.addTab(mTabLayout.newTab().setText("收藏"));

    List<String> titles = new ArrayList<>();
    titles.add("推荐");
    titles.add("圆桌");
    titles.add("热门");
    titles.add("收藏");

    //初始化ViewPager的数据集
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(new SecondSubFragment());
    fragments.add(new SecondSubFragment());
    fragments.add(new SecondSubFragment());
    fragments.add(new SecondSubFragment());
    //创建ViewPager的adapter
    FragmentAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragments, titles);
    mViewPager.setAdapter(adapter);
    //千万别忘了,关联TabLayout与ViewPager
    //同时也要覆写PagerAdapter的getPageTitle方法,否则Tab没有title
    mTabLayout.setupWithViewPager(mViewPager);
    mTabLayout.setTabsFromPagerAdapter(adapter);

}
 
Example 14
Source File: MainActivity.java    From LollipopContactsRecyclerViewFastScroller with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //note : part of the design library sample code was taken from : https://github.com/sitepoint-editors/Design-Demo/

    DesignDemoPagerAdapter adapter = new DesignDemoPagerAdapter(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    ViewPager viewPager = findViewById(R.id.viewpager);
    viewPager.setAdapter(adapter);
    TabLayout tabLayout = findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 15
Source File: DetailsActivity.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);

    // Receive about details
    Intent intent = getIntent();
    appPackageName = intent.getStringExtra(INTENT_EXTRA_APP_PACKAGENAME);
    appUid = intent.getIntExtra(INTENT_EXTRA_APP_UID, -1);
    appName = intent.getStringExtra(INTENT_EXTRA_APP_NAME);

    // Set up paging
    DetailsPagesAdapter detailsPagesAdapter =
            new DetailsPagesAdapter(this,
                    getSupportFragmentManager(),
                    Common.getAppName(getPackageManager(), appUid),
                    appName,
                    appUid);
    ViewPager viewPager = findViewById(R.id.view_pager);
    viewPager.setAdapter(detailsPagesAdapter);
    TabLayout tabs = findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);

    // set toolbar and back arrow
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Set title
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    toolbar.setTitle(getString(R.string.app_info));
    toolbar.setSubtitle(appName);
}
 
Example 16
Source File: MainActivity.java    From onpc with GNU General Public License v3.0 4 votes vote down vote up
private void initGUI()
{
    setContentView(orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT ?
            R.layout.activity_main_port : R.layout.activity_main_land);

    if (configuration.isKeepScreenOn())
    {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_short_name);
    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null)
    {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.app_short_name);
        actionBar.setElevation(5.0f);
    }

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    pagerAdapter = new MainPagerAdapter(this, getSupportFragmentManager(), configuration);

    // Set up the ViewPager with the sections adapter.
    viewPager = findViewById(R.id.view_pager);
    viewPager.setAdapter(pagerAdapter);

    final TabLayout tabLayout = findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(viewPager);

    // Navigation drawer
    navigationDrawer = new MainNavigationDrawer(this, versionName);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, navigationDrawer.getDrawerLayout(), toolbar,
            R.string.drawer_open, R.string.drawer_open)
    {
        public void onDrawerOpened(View drawerView)
        {
            super.onDrawerOpened(drawerView);
            navigationDrawer.updateNavigationContent(stateHolder.getState());
        }
    };
    Utils.setDrawerListener(navigationDrawer.getDrawerLayout(), mDrawerToggle);
}
 
Example 17
Source File: MyFollowActivity.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initPages() {
    pagerModels[followerPage()].readDataList(list ->
            adapters[followerPage()] = new MyFollowAdapter(this, list).setItemEventCallback(
                    new MyFollowItemEventHelper(this)
            )
    );

    pagerModels[followingPage()].readDataList(list ->
            adapters[followingPage()] = new MyFollowAdapter(this, list).setItemEventCallback(
                    new MyFollowItemEventHelper(this)
            )
    );

    List<View> pageList = new ArrayList<>(
            Arrays.asList(
                    new MyFollowUserView(
                            this,
                            adapters[followerPage()],
                            followerPage(),
                            this
                    ), new MyFollowUserView(
                            this,
                            adapters[followingPage()],
                            followingPage(),
                            this
                    )
            )
    );
    for (int i = 0; i < pageList.size(); i ++) {
        pagers[i] = (PagerView) pageList.get(i);
    }

    String[] myFollowTabs = getResources().getStringArray(R.array.my_follow_tabs);

    List<String> tabList = new ArrayList<>();
    Collections.addAll(tabList, myFollowTabs);
    PagerAdapter adapter = new PagerAdapter(viewPager, pageList, tabList);
    if (AuthManager.getInstance().getUser() != null) {
        adapter.titleList.set(
                followerPage(),
                AuthManager.getInstance().getUser().followers_count + " " + myFollowTabs[followerPage()]
        );
        adapter.titleList.set(
                followingPage(),
                AuthManager.getInstance().getUser().following_count + " " + myFollowTabs[followingPage()]
        );
        adapter.notifyDataSetChanged();
    }

    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(this);
    viewPager.setCurrentItem(getCurrentPagerPosition(), false);

    TabLayout tabLayout = findViewById(R.id.activity_my_follow_tabLayout);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabLayoutDoubleClickBackToTopPresenter(MyFollowActivity.this::backToTop));

    pagerManageModel.getPagerPosition().observe(this, position -> {
        for (int i = followerPage(); i < pageCount(); i ++) {
            pagers[i].setSelected(i == position);
        }
        if (pagerModels[position].getListSize() == 0
                && pagerModels[position].getListState() != ListResource.State.REFRESHING
                && pagerModels[position].getListState() != ListResource.State.LOADING) {
            PagerViewManagePresenter.initRefresh(pagerModels[position], adapters[position]);
        }
    });

    pagerModels[followerPage()].observeListResource(this, viewModel ->
            PagerViewManagePresenter.responsePagerListResourceChanged(
                    viewModel,
                    pagers[followerPage()],
                    adapters[followerPage()]
            )
    );
    pagerModels[followingPage()].observeListResource(this, viewModel ->
            PagerViewManagePresenter.responsePagerListResourceChanged(
                    viewModel,
                    pagers[followingPage()],
                    adapters[followingPage()]
            )
    );
}
 
Example 18
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!MobiComUserPreference.getInstance(this).isLoggedIn()) {
        finish();
    }
    setContentView(R.layout.people_activity);
    String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }

    onContactsInteractionListener = this;
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);
    // Set up the action bar.
    actionBar = getSupportActionBar();
    if (!TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimary()) && !TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimaryDark())) {
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(alCustomizationSettings.getThemeColorPrimary())));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.parseColor(alCustomizationSettings.getThemeColorPrimaryDark()));
        }
    }
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);


    intentExtra = getIntent();
    action = intentExtra.getAction();
    type = intentExtra.getType();

    if (getIntent().getExtras() != null) {
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            actionBar.setTitle(getString(R.string.send_message_to));
        } else {
            actionBar.setTitle(getString(R.string.search_title));
            userIdArray = getIntent().getStringArrayExtra(USER_ID_ARRAY);
        }
    } else {
        actionBar.setTitle(getString(R.string.search_title));
    }
    appContactFragment = new AppContactFragment(userIdArray);
    appContactFragment.setAlCustomizationSettings(alCustomizationSettings);
    channelFragment = new ChannelFragment();
    setSearchListFragment(appContactFragment);
    if (alCustomizationSettings.isGroupsSectionTabHidden() || ApplozicSetting.getInstance(this).isGroupsSectionTabHidden()) {
        addFragment(this, appContactFragment, "AppContactFragment");
    } else {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        viewPager.setVisibility(View.VISIBLE);
        setupViewPager(viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabLayout.setVisibility(View.VISIBLE);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.addOnTabSelectedListener(this);
    }

    // This flag notes that the Activity is doing a search, and so the result will be
    // search results rather than all contacts. This prevents the Activity and Fragment
    // from trying to a search on search results.
    isSearchResultView = true;
}
 
Example 19
Source File: MainActivity.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        context = getApplicationContext();
        fragmentManager = getSupportFragmentManager();

        YouTubeSqlDb.getInstance().init(this);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        }

        playbackControlsFragment = (PlaybackControlsFragment) fragmentManager
                .findFragmentById(R.id.fragment_playback_controls);

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setOffscreenPageLimit(3);
        setupViewPager(viewPager);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);

        setupTabIcons();
        loadColor();

        checkAndRequestPermissions();
        networkConf = new NetworkHelper(this);


        // Connect a media browser just to get the media session token. There are other ways
        // this can be done, for example by sharing the session token directly.
//        mMediaBrowser = new MediaBrowserCompat(
//                this,
//                new ComponentName(this, BackgroundExoAudioService.class),
//                mConnectionCallback, null
//        );
    }
 
Example 20
Source File: TabLayoutActivity.java    From WhatsApp-Cleaner with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);

    TabLayout tabLayout = findViewById(R.id.tabs);
    ViewPager viewPager = findViewById(R.id.viewpager);
    String category = getIntent().getStringExtra("category");
    String pathname = getIntent().getStringExtra("pathname");
    TabsAdapter tabsAdapter;

    settings = getSharedPreferences(PREFS, MODE_PRIVATE);
    editor = settings.edit();


    // First time running app?
    if (!settings.contains("lastRun"))
        enableNotification(null);
    else
        recordRunTime();

    Log.v(TAG, "Starting CheckRecentRun service...");
    startService(new Intent(this, CheckRecentRun.class));

    switch (category) {

        case DataHolder.IMAGE:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.IMAGE, DataHolder.imagesReceivedPath, DataHolder.imagesSentPath);
            break;
        case DataHolder.DOCUMENT:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.DOCUMENT, DataHolder.documentsReceivedPath, DataHolder.documentsSentPath);
            break;
        case DataHolder.VIDEO:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.VIDEO, DataHolder.videosReceivedPath, DataHolder.videosSentPath);
            break;
        case DataHolder.AUDIO:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.AUDIO, DataHolder.audiosReceivedPath, DataHolder.audiosSentPath);
            break;
        case DataHolder.GIF:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.GIF, DataHolder.gifReceivedPath, DataHolder.gifSentPath);
            break;
        case DataHolder.WALLPAPER:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.WALLPAPER, DataHolder.wallReceivedPath, DataHolder.wallgifSentPath);
            break;
        case DataHolder.VOICE:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.VOICE, DataHolder.voiceReceivedPath, DataHolder.voicegifSentPath);
            break;
        case DataHolder.STATUS:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.STATUS, DataHolder.statuscache, DataHolder.statusdownload);
            break;
        default:
            tabsAdapter = new TabsAdapter(getSupportFragmentManager(), DataHolder.NONDEFAULT, pathname, pathname);
            break;
    }

    viewPager.setAdapter(tabsAdapter);

    tabLayout.setupWithViewPager(viewPager);
}