androidx.viewpager.widget.PagerAdapter Java Examples

The following examples show how to use androidx.viewpager.widget.PagerAdapter. 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: MediaKeyboard.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void present(@NonNull MediaKeyboardProvider provider,
                    @NonNull PagerAdapter pagerAdapter,
                    @NonNull MediaKeyboardProvider.TabIconProvider tabIconProvider,
                    @Nullable MediaKeyboardProvider.BackspaceObserver backspaceObserver,
                    @Nullable MediaKeyboardProvider.AddObserver addObserver,
                    @Nullable MediaKeyboardProvider.SearchObserver searchObserver,
                    int startingIndex)
{
  if (categoryPager == null) return;
  if (!provider.equals(providers[providerIndex])) return;
  if (keyboardListener != null) keyboardListener.onKeyboardProviderChanged(provider);

  boolean isSolo = providers.length == 1;

  presentProviderStrip(isSolo);
  presentCategoryPager(pagerAdapter, tabIconProvider, startingIndex);
  presentProviderTabs(providers, providerIndex);
  presentSearchButton(searchObserver);
  presentBackspaceButton(backspaceObserver, isSolo);
  presentAddButton(addObserver);
}
 
Example #2
Source File: RtlViewPager.java    From rtl-viewpager with Apache License 2.0 6 votes vote down vote up
@Override
public void onRtlPropertiesChanged(int layoutDirection) {
    super.onRtlPropertiesChanged(layoutDirection);
    int viewCompatLayoutDirection = layoutDirection == View.LAYOUT_DIRECTION_RTL ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
    if (viewCompatLayoutDirection != mLayoutDirection) {
        PagerAdapter adapter = super.getAdapter();
        int position = 0;
        if (adapter != null) {
            position = getCurrentItem();
        }
        mLayoutDirection = viewCompatLayoutDirection;
        if (adapter != null) {
            adapter.notifyDataSetChanged();
            setCurrentItem(position);
        }
    }
}
 
Example #3
Source File: TabPageIndicator.java    From material with Apache License 2.0 6 votes vote down vote up
private void notifyDataSetInvalidated() {
	PagerAdapter adapter = mViewPager.getAdapter();
	final int count = adapter.getCount();
       for (int i = 0; i < count; i++) {
       	TextView tv = getTabView(i);

           if(tv != null) {
               CharSequence title = adapter.getPageTitle(i);
               if (title == null)
                   title = "NULL";

               tv.setText(title);
           }
       }
       
       requestLayout();
}
 
Example #4
Source File: TabLayout.java    From a with GNU General Public License v3.0 6 votes vote down vote up
void setPagerAdapter(@Nullable final PagerAdapter adapter, final boolean addObserver) {
    if (mPagerAdapter != null && mPagerAdapterObserver != null) {
        // If we already have a PagerAdapter, unregister our observer
        mPagerAdapter.unregisterDataSetObserver(mPagerAdapterObserver);
    }

    mPagerAdapter = adapter;

    if (addObserver && adapter != null) {
        // Register our observer on the new adapter
        if (mPagerAdapterObserver == null) {
            mPagerAdapterObserver = new PagerAdapterObserver();
        }
        adapter.registerDataSetObserver(mPagerAdapterObserver);
    }

    // Finally make sure we reflect the new adapter
    populateFromPagerAdapter();
}
 
Example #5
Source File: ViewPagerActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Sets the specified adapter on <code>ViewPager</code>. */
public static ViewAction setAdapter(final @Nullable PagerAdapter adapter) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(ViewPager.class);
    }

    @Override
    public String getDescription() {
      return "ViewPager set adapter";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewPager viewPager = (ViewPager) view;
      viewPager.setAdapter(adapter);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example #6
Source File: TabPageIndicator.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example #7
Source File: DemoTabWithNotificationMarkActivity.java    From SmartTabLayout with Apache License 2.0 6 votes vote down vote up
@Override
public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
  LayoutInflater inflater = LayoutInflater.from(container.getContext());
  Resources res = container.getContext().getResources();
  View tab = inflater.inflate(R.layout.custom_tab_icon_and_notification_mark, container, false);
  View mark = tab.findViewById(R.id.custom_tab_notification_mark);
  mark.setVisibility(View.GONE);
  ImageView icon = (ImageView) tab.findViewById(R.id.custom_tab_icon);
  switch (position) {
    case 0:
      icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
      break;
    case 1:
      icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
      break;
    case 2:
      icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
      break;
    default:
      throw new IllegalStateException("Invalid position: " + position);
  }
  return tab;
}
 
Example #8
Source File: CarouselViewPager.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override public void setAdapter(PagerAdapter pagerAdapter) {
    super.setAdapter(pagerAdapter);
    if (pagerAdapter instanceof CarouselViewPagerAdapter) {
        adapter = (CarouselViewPagerAdapter) pagerAdapter;
    }

    addOnPageChangeListener(new PageChangeListener());
}
 
Example #9
Source File: SliderPager.java    From Android-Image-Slider with Apache License 2.0 5 votes vote down vote up
/**
 * This method calls setViewPagerObserver defined in PagerAdapter by using
 * reflection.
 *
 * @param observer pager observer
 */
private void setAdapterViewPagerObserver(PagerObserver observer) {
    try {
        Method setViewPagerObserver = PagerAdapter.class.getDeclaredMethod("setViewPagerObserver", DataSetObserver.class);
        setViewPagerObserver.setAccessible(true);
        setViewPagerObserver.invoke(mAdapter, observer);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: FragmentArrayPagerAdapter.java    From assembly-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public int getItemPosition(@NonNull Object object) {
    if (notifyNumberPool != null && notifyNumberPool.get(object.hashCode()) != notifyNumber) {
        notifyNumberPool.put(object.hashCode(), notifyNumber);
        return PagerAdapter.POSITION_NONE;
    }
    return super.getItemPosition(object);
}
 
Example #11
Source File: MediaKeyboardProvider.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
void present(@NonNull MediaKeyboardProvider provider,
@NonNull PagerAdapter pagerAdapter,
@NonNull TabIconProvider iconProvider,
@Nullable BackspaceObserver backspaceObserver,
@Nullable AddObserver addObserver,
@Nullable SearchObserver searchObserver,
int startingIndex);
 
Example #12
Source File: MainFragment.java    From duo-navigation-drawer with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(), "Clicked a button!", Toast.LENGTH_SHORT).show();
        }
    });
    ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
    pager.setAdapter(new PagerAdapter());
    return view;
}
 
Example #13
Source File: OverScrollViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
private boolean canOverScrollAtEnd() {
    SwipeableViewPager viewPager = getOverScrollView();
    PagerAdapter adapter = viewPager.getAdapter();
    if (null != adapter && adapter.getCount() > 0) {
        if (viewPager.alphaExitTransitionEnabled() && viewPager.getCurrentItem() == adapter.getCount() - 1) {
            return true;
        }
        return false;
    }

    return false;
}
 
Example #14
Source File: FragmentFixedItem.java    From assembly-adapter with Apache License 2.0 5 votes vote down vote up
public void setData(@Nullable DATA data) {
    this.data = data;

    PagerAdapter adapter = itemFactory.getAdapter();
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
}
 
Example #15
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
protected void handleOnAdapterChanged(ViewPager viewPager, PagerAdapter oldAdapter, PagerAdapter newAdapter) {
    if (mViewPager != viewPager) {
        return;
    }

    if (oldAdapter != null) {
        oldAdapter.unregisterDataSetObserver(mInternalDataSetObserver);
    }
    if (newAdapter != null) {
        newAdapter.registerDataSetObserver(mInternalDataSetObserver);
    }

    setTabsFromPagerAdapter(mTabLayout, newAdapter, mViewPager.getCurrentItem());
}
 
Example #16
Source File: LoopViewPager.java    From CircleIndicator with Apache License 2.0 5 votes vote down vote up
@Override public void setAdapter(PagerAdapter adapter) {
    mAdapter = new LoopPagerAdapterWrapper(adapter);
    mAdapter.setBoundaryCaching(mBoundaryCaching);
    mAdapter.setBoundaryLooping(mBoundaryLooping);
    super.setAdapter(mAdapter);
    setCurrentItem(0, false);
}
 
Example #17
Source File: TagTabStrip.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
protected void onViewPagerAdapterChanged(@Nullable PagerAdapter oldAdapter,
                                         @Nullable PagerAdapter newAdapter) {
    super.onViewPagerAdapterChanged(oldAdapter, newAdapter);
    final int count = getPageCount();
    if (count == mCount)
        return;
    mCount = getPageCount();
    requestLayout();
    invalidate();
}
 
Example #18
Source File: TabLayout.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAdapterChanged(@NonNull ViewPager viewPager,
                             @Nullable PagerAdapter oldAdapter, @Nullable PagerAdapter newAdapter) {
    if (mViewPager == viewPager) {
        setPagerAdapter(newAdapter, mAutoRefresh);
    }
}
 
Example #19
Source File: CircularViewPager.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Deprecated
public void setAdapter(@Nullable PagerAdapter adapter) {
    if (adapter instanceof Adapter) {
        setAdapter((Adapter) adapter);
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #20
Source File: LoopBarView.java    From LoopBar with MIT License 5 votes vote down vote up
/**
 * You can setup {@code {@link LoopBarView#mOuterAdapter }} through {@link ViewPager} adapter.
 * Your {@link ViewPager} adapter must implement {@link ILoopBarPagerAdapter} otherwise - the icons will not be shown
 *
 * @param viewPager - viewPager, which must have {@link ILoopBarPagerAdapter}
 */
public void setupWithViewPager(@NonNull ViewPager viewPager) {
    PagerAdapter pagerAdapter = viewPager.getAdapter();
    List<ICategoryItem> categoryItems = new ArrayList<>(pagerAdapter.getCount());
    ILoopBarPagerAdapter loopBarPagerAdapter =
            pagerAdapter instanceof ILoopBarPagerAdapter
                    ? (ILoopBarPagerAdapter) pagerAdapter : null;
    for (int i = 0, size = pagerAdapter.getCount(); i < size; i++) {
        categoryItems.add(new CategoryItem(
                loopBarPagerAdapter != null ? loopBarPagerAdapter.getPageDrawable(i) : null,
                String.valueOf(pagerAdapter.getPageTitle(i))
        ));
    }
    setCategoriesAdapter(new SimpleCategoriesAdapter(categoryItems));
}
 
Example #21
Source File: RtlViewPager.java    From rtl-viewpager with Apache License 2.0 5 votes vote down vote up
@Override
public void setCurrentItem(int position, boolean smoothScroll) {
    PagerAdapter adapter = super.getAdapter();
    if (adapter != null && isRtl()) {
        position = adapter.getCount() - position - 1;
    }
    super.setCurrentItem(position, smoothScroll);
}
 
Example #22
Source File: RtlViewPager.java    From rtl-viewpager with Apache License 2.0 5 votes vote down vote up
@Override
public void setCurrentItem(int position) {
    PagerAdapter adapter = super.getAdapter();
    if (adapter != null && isRtl()) {
        position = adapter.getCount() - position - 1;
    }
    super.setCurrentItem(position);
}
 
Example #23
Source File: RtlViewPager.java    From rtl-viewpager with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageSelected(int position) {
    PagerAdapter adapter = RtlViewPager.super.getAdapter();
    if (isRtl() && adapter != null) {
        position = adapter.getCount() - position - 1;
    }
    mListener.onPageSelected(position);
}
 
Example #24
Source File: ArrayPagerAdapter.java    From assembly-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public int getItemPosition(@NonNull Object object) {
    if (notifyNumberPool != null && notifyNumberPool.get(object.hashCode()) != notifyNumber) {
        notifyNumberPool.put(object.hashCode(), notifyNumber);
        return PagerAdapter.POSITION_NONE;
    }
    return super.getItemPosition(object);
}
 
Example #25
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
protected void setupWithViewPager(@NonNull TabLayout tabLayout, @NonNull ViewPager viewPager) {
    final PagerAdapter adapter = viewPager.getAdapter();
    if (adapter == null) {
        throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
    }

    setTabsFromPagerAdapter(tabLayout, adapter, viewPager.getCurrentItem());

    viewPager.getAdapter().registerDataSetObserver(mInternalDataSetObserver);

    viewPager.addOnPageChangeListener(mInternalTabLayoutOnPageChangeListener);
    viewPager.addOnAdapterChangeListener(mInternalOnAdapterChangeListener);

    tabLayout.addOnTabSelectedListener(mInternalOnTabSelectedListener);
}
 
Example #26
Source File: CircularViewPager.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Deprecated
public void setAdapter(@Nullable PagerAdapter adapter) {
    if (adapter instanceof Adapter) {
        setAdapter((Adapter) adapter);
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #27
Source File: PagerBullet.java    From PagerBullet with MIT License 5 votes vote down vote up
public void invalidateBullets(PagerAdapter adapter) {
    final boolean hasSeparator = hasSeparator();
    textIndicator.setVisibility(hasSeparator ? VISIBLE : INVISIBLE);
    layoutIndicator.setVisibility(hasSeparator ? INVISIBLE : VISIBLE);

    if (!hasSeparator) {
        initIndicator(adapter.getCount());
    }
    setIndicatorItem(viewPager.getCurrentItem());
}
 
Example #28
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAdapterChanged(
    @NonNull ViewPager viewPager,
    @Nullable PagerAdapter oldAdapter,
    @Nullable PagerAdapter newAdapter) {
  if (TabLayout.this.viewPager == viewPager) {
    setPagerAdapter(newAdapter, autoRefresh);
  }
}
 
Example #29
Source File: LoopViewPager.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@Override
public void setAdapter(PagerAdapter adapter) {
    mAdapter = new LoopPagerAdapterWrapper(adapter);
    mAdapter.setBoundaryCaching(mBoundaryCaching);
    super.setAdapter(mAdapter);
    setCurrentItem(0, false);
}
 
Example #30
Source File: PagerBullet.java    From PagerBullet with MIT License 5 votes vote down vote up
private void setItemText(int index) {
    final PagerAdapter adapter = viewPager.getAdapter();
    if (null != adapter) {
        final int count = adapter.getCount();
        textIndicator.setText(
                String.format(getContext().getString(R.string.pager_bullet_separator),
                        String.valueOf(index + 1),
                        String.valueOf(count)
                )
        );
    }
}