Java Code Examples for android.support.v4.view.ViewPager#getTag()

The following examples show how to use android.support.v4.view.ViewPager#getTag() . 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: ViewPagerAdapter.java    From MVVM-JueJin with MIT License 6 votes vote down vote up
/**
 * (δΌͺ)εŒε‘ databinding: 同 {@link RecyclerViewAdapter#setDataTwoWay(RecyclerView, ListVM, List)}
 *
 * @param container
 * @param vm
 * @param datas
 * @param <T>
 */
@BindingAdapter({"vm", "data"})
public static <T> void setDataTwoWay(final ViewPager container, final ListVM<T> vm, List<T> datas){
    if(vm == null){
        return ;
    }
    bind(container, vm, datas);

    if(vm instanceof TwoWayListVM) {
        boolean isInited = container.getTag(R.id.db_inited) != null;
        if (!isInited) {
            container.setTag(R.id.db_inited, true);
            loadData(container, (TwoWayListVM<T>) vm, null, null);
        }
    }
}
 
Example 2
Source File: BindingUtils.java    From android-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("adapter")
public static void bindAdapter(@NonNull ViewPager viewPager, @Nullable PagerAdapter adapter) {
    PagerAdapter oldAdapter = viewPager.getAdapter();

    // Disconnect previous adapter if its Connectable
    if (oldAdapter != null && oldAdapter instanceof Connectable) {
        Disposable subscription = (Disposable) viewPager.getTag(R.integer.tag_subscription);
        if (subscription != null && !subscription.isDisposed()) {
            subscription.dispose();
        }
        viewPager.setTag(R.integer.tag_subscription, null);
    }

    // Store connection (Subscription) if new adapter is Connectable
    if (adapter != null && adapter instanceof Connectable) {
        viewPager.setTag(R.integer.tag_subscription, ((Connectable) adapter).connect());
    }
    viewPager.setAdapter(adapter);
}
 
Example 3
Source File: SparkleMotionCompat.java    From SparkleMotion with MIT License 6 votes vote down vote up
/**
 * Sets a {@link android.support.v4.view.ViewPager.PageTransformer} to the given ViewPager.
 * Using this method to set PageTransformer is required for the ViewPagers that already have
 * {@link SparkleAnimationPresenter} installed.
 *
 * @param viewPager ViewPager instance.
 * @param reversDrawingOrder Whether the ViewPager should reverse it child Views' drawing
 * order.
 * @param transformer PageTransformer instance.
 * @see {@link ViewPager#setPageTransformer(boolean, ViewPager.PageTransformer)}
 * @see {@link android.support.v4.view.ViewPager.PageTransformer}
 */
public static void setPageTransformer(@NonNull ViewPager viewPager, boolean reversDrawingOrder,
        @Nullable final ViewPager.PageTransformer transformer) {
    Object tagObject = viewPager.getTag(R.id.presenter_id);
    if (tagObject == null || !(tagObject instanceof SparkleAnimationPresenter)) {
        viewPager.setPageTransformer(reversDrawingOrder, transformer);
        return;
    }

    final SparkleAnimationPresenter presenter = (SparkleAnimationPresenter) tagObject;
    ViewPager.PageTransformer transformerWrapper = new ViewPager.PageTransformer() {
        @Override
        public void transformPage(View page, float position) {
            int pageWidth = page.getWidth();
            float offset = pageWidth * -position;

            presenter.presentAnimations(page, position, offset);
            if (transformer != null) {
                transformer.transformPage(page, position);
            }
        }
    };

    viewPager.setPageTransformer(reversDrawingOrder, transformerWrapper);
}
 
Example 4
Source File: ReuseLayoutHook.java    From android_viewtracker with Apache License 2.0 5 votes vote down vote up
@Override
public void hookView(View view) {
    ViewPager viewPager = (ViewPager) view;
    Object tag = viewPager.getTag(HOOK_VIEW_TAG);
    if (tag != null && !(tag instanceof Boolean)) {
        return;
    }
    Boolean added = (Boolean) tag;
    if (added != null && added) {
        return;
    }
    viewPager.addOnPageChangeListener(new ViewPagerOnPageChangeListener());
    viewPager.setTag(HOOK_VIEW_TAG, true);
    TrackerLog.d("ViewPager addOnPageChangeListener.");
}
 
Example 5
Source File: SparkleMotionCompat.java    From SparkleMotion with MIT License 5 votes vote down vote up
/**
 * Gets the {@link SparkleAnimationPresenter} instance attached to the given ViewPager.
 *
 * @param viewPager ViewPager instance.
 * @return SparkleAnimationPresenter instance if set, or null.
 */
static SparkleAnimationPresenter getAnimationPresenter(ViewPager viewPager) {
    if (viewPager == null) {
        return null;
    }

    Object tagObject = viewPager.getTag(R.id.presenter_id);
    if (tagObject == null || !(tagObject instanceof SparkleAnimationPresenter)) {
        return null;
    }

    return (SparkleAnimationPresenter) tagObject;
}