Java Code Examples for androidx.viewpager.widget.ViewPager#setOffscreenPageLimit()

The following examples show how to use androidx.viewpager.widget.ViewPager#setOffscreenPageLimit() . 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: SampleFragments.java    From EasyPhotos with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_fragments);

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

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

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

}
 
Example 2
Source File: VPAnim2Activity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_vpanim2);
        initDatas();
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setPageMargin(20);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOffscreenPageLimit(3);
        mViewPager.setPageTransformer(true, new MyTranformer());
    }
 
Example 3
Source File: DeviceDetailFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = super.onCreateView(inflater, container, savedInstanceState);
    viewPager = (ViewPager) (view != null ? view.findViewById(R.id.fragment_device_detail_child_view_pager) : null);
    if (viewPager != null) {
        viewPager.setOffscreenPageLimit(1);
    }
    populate();

    viewPager.removeOnPageChangeListener(onPageChangeListener);
    viewPager.addOnPageChangeListener(onPageChangeListener);
    return view;
}
 
Example 4
Source File: SimpleChartDemo.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_awesomedesign);

    setTitle("SimpleChartDemo");

    ViewPager pager = findViewById(R.id.pager);
    pager.setOffscreenPageLimit(3);

    PageAdapter a = new PageAdapter(getSupportFragmentManager());
    pager.setAdapter(a);


    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle("This is a ViewPager.");
    b.setMessage("Swipe left and right for more awesome design examples!");
    b.setPositiveButton("OK", new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    b.show();
}
 
Example 5
Source File: DemoFragmentActivity.java    From ActivityTaskView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo_fragment);
    setTitle(getClass().getSimpleName());
    setActionBarBack();

    for(int i = 0; i < 3; i++){
        fragmentList.add(DemoFragment.newInstance(i));
    }
    ViewPager vp = (ViewPager) findViewById(R.id.vp);
    vp.setOffscreenPageLimit(1);
    vp.setAdapter(new DemoAdapter(getSupportFragmentManager()));
}
 
Example 6
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 7
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 8
Source File: AddressDetailActivity.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    address = getIntent().getStringExtra("ADDRESS");
    type = getIntent().getByteExtra("TYPE", SCANNED_WALLET);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    title = (TextView) findViewById(R.id.toolbar_title);
    String walletname = AddressNameConverter.getInstance(this).get(address);
    title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address");

    coord = (CoordinatorLayout) findViewById(R.id.main_content);
    appbar = (AppBarLayout) findViewById(R.id.appbar);

    fragments = new Fragment[3];
    fragments[0] = new FragmentDetailShare();
    fragments[1] = new FragmentDetailOverview();
    fragments[2] = new FragmentTransactions();
    Bundle bundle = new Bundle();
    bundle.putString("ADDRESS", address);
    bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0));
    bundle.putByte("TYPE", type);
    fragments[0].setArguments(bundle);
    fragments[1].setArguments(bundle);
    fragments[2].setArguments(bundle);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

    tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share);
    tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions);
    mViewPager.setCurrentItem(1);

    mViewPager.setOffscreenPageLimit(3);
}
 
Example 9
Source File: MainActivity.java    From Chorus-RF-Laptimer with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    /*
      The {@link android.support.v4.view.PagerAdapter} that will provide
    fragments for each of the sections. We use a
    {@link FragmentPagerAdapter} derivative, which will keep every
    loaded fragment in memory. If this becomes too memory intensive, it
    may be best to switch to a
    {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), getResources());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    if (mViewPager == null) return;

    mViewPager.setOffscreenPageLimit(4);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

    initBluetooth();
    initUDP();
    initBroadcastReceiverForUsbPermissions();
    initUSB();
    retrieveAndStoreAppVersion(getApplicationContext());
    AppState.getInstance().textSpeaker = new TextSpeaker(getApplicationContext(),
            AppState.getInstance().shouldSpeakEnglishOnly);
    AppState.getInstance().preferences = getPreferences(MODE_PRIVATE);
    AppPreferences.applyAll();

    AppState.getInstance().addListener(new IDataListener() {
        @Override
        public void onDataChange(DataAction dataItemName) {
            switch (dataItemName) {
                case WrongApiVersion:
                    MainActivity.this.showWrongApiDialog();
            }
        }
    });
    //Ensure permissions permissions before any disk IO
    ensurePermissions();
    //this will cleanup csv reports after 2 weeks (14 days)
    cleanUpCSVReports();
}
 
Example 10
Source File: EmojiPalettesView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
 
Example 11
Source File: AddressDetailActivity.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    address = getIntent().getStringExtra("ADDRESS");
    type = getIntent().getByteExtra("TYPE", SCANNED_WALLET);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    title = (TextView) findViewById(R.id.toolbar_title);
    String walletname = AddressNameConverter.getInstance(this).get(address);
    title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address");

    coord = (CoordinatorLayout) findViewById(R.id.main_content);
    appbar = (AppBarLayout) findViewById(R.id.appbar);

    fragments = new Fragment[3];
    fragments[0] = new FragmentDetailShare();
    fragments[1] = new FragmentDetailOverview();
    fragments[2] = new FragmentTransactions();
    Bundle bundle = new Bundle();
    bundle.putString("ADDRESS", address);
    bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0));
    bundle.putByte("TYPE", type);
    fragments[0].setArguments(bundle);
    fragments[1].setArguments(bundle);
    fragments[2].setArguments(bundle);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

    tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share);
    tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions);
    mViewPager.setCurrentItem(1);

    mViewPager.setOffscreenPageLimit(3);
}
 
Example 12
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
//        );
    }