Search in sources :

Example 91 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project SimplifyReader by chentao0707.

the class SmartTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();
    final LayoutInflater inflater = LayoutInflater.from(getContext());
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        if (mTabViewLayoutId != NO_ID) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = inflater.inflate(mTabViewLayoutId, mTabStrip, false);
        }
        if (mTabViewTextViewId != NO_ID && tabView != null) {
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }
        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }
        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }
        if (tabTitleView == null) {
            throw new IllegalStateException("tabTitleView not found.");
        }
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }
        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 92 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project BGARefreshLayout-Android by bingoogolapple.

the class BGAStickyNavLayout method regetNestedContentView.

/**
     * 重新获取嵌套的内容视图
     */
private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
        Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
        mNestedContentView = item.getView();
        // 清空之前的
        mNestedNormalView = null;
        mNestedAbsListView = null;
        mNestedRecyclerView = null;
        mNestedScrollView = null;
        mNestedWebView = null;
        if (mNestedContentView instanceof AbsListView) {
            mNestedAbsListView = (AbsListView) mNestedContentView;
            mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedAbsListView.setSelection(0);
            }
        } else if (mNestedContentView instanceof RecyclerView) {
            mNestedRecyclerView = (RecyclerView) mNestedContentView;
            mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
            mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedRecyclerView.scrollToPosition(0);
            }
        } else if (mNestedContentView instanceof ScrollView) {
            mNestedScrollView = (ScrollView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
            }
        } else if (mNestedContentView instanceof WebView) {
            mNestedWebView = (WebView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
            }
        } else {
            mNestedNormalView = mNestedContentView;
        }
    } else {
        throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(android.support.v4.app.Fragment) PagerAdapter(android.support.v4.view.PagerAdapter) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter)

Example 93 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project iosched by google.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }
        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }
        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }
        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }
        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}
Also used : TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 94 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project vlayout by alibaba.

the class OnePlusNLayoutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });
    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText("Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    // layoutManager.setReverseLayout(true);
    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {

        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };
    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.setRecycledViewPool(viewPool);
    // recyclerView.addItemDecoration(itemDecoration);
    viewPool.setMaxRecycledViews(0, 20);
    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);
    recyclerView.setAdapter(delegateAdapter);
    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1)
                    return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this).inflate(R.layout.view_pager, parent, false));
                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {
            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;
                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(4f);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }
    if (HORIZONTAL_SCROLL_LAYOUT) {
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(3f);
        adapters.add(new SubAdapter(this, layoutHelper, 2));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(10, 10, 10, 10);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 3) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            //                    layoutParams.leftMargin = 10;
            //                    layoutParams.topMargin = 10;
            //                    layoutParams.rightMargin = 10;
            //                    layoutParams.bottomMargin = 10;
            //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 4));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f });
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f });
        helper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 6));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f });
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xffed7612);
        //            helper.setMargin(10, 10, 10, 10);
        //            helper.setPadding(10, 10, 10, 10);
        helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f });
        adapters.add(new SubAdapter(this, helper, 7) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            //                    layoutParams.leftMargin = 10;
            //                    layoutParams.topMargin = 10;
            //                    layoutParams.rightMargin = 10;
            //                    layoutParams.bottomMargin = 10;
            //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }
    if (SCROLL_FIX_LAYOUT) {
        ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20);
        layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);
        adapters.add(new SubAdapter(this, layoutHelper, 1) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(50, 50);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100));
    delegateAdapter.setAdapters(adapters);
    final Handler mainHandler = new Handler(Looper.getMainLooper());
    trigger = new Runnable() {

        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
        // mainHandler.postDelayed(trigger, 1000);
        }
    };
    mainHandler.postDelayed(trigger, 1000);
}
Also used : ScrollFixLayoutHelper(com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) GridLayoutHelper(com.alibaba.android.vlayout.layout.GridLayoutHelper) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) StickyLayoutHelper(com.alibaba.android.vlayout.layout.StickyLayoutHelper) OnePlusNLayoutHelperEx(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelperEx) EditText(android.widget.EditText) Rect(android.graphics.Rect) LayoutParams(com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams) LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) ViewGroup(android.view.ViewGroup) Handler(android.os.Handler) OnePlusNLayoutHelper(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) LinkedList(java.util.LinkedList) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager)

Example 95 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project GestureViews by alexvasilkov.

the class Ex6AdvancedDemoActivity method initPager.

private void initPager() {
    // Setting up pager views
    pagerAdapter = new PhotoPagerAdapter(views.pager);
    pagerAdapter.setSetupListener(settingsMenu);
    pagerListener = new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            onPhotoInPagerSelected(position);
        }
    };
    views.pager.setAdapter(pagerAdapter);
    views.pager.addOnPageChangeListener(pagerListener);
    views.pager.setPageTransformer(true, new DepthPageTransformer());
    views.pagerToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    views.pagerToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(@NonNull View view) {
            onBackPressed();
        }
    });
    onCreateOptionsMenuFullMode(views.pagerToolbar.getMenu());
    views.pagerToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelectedFullMode(item);
        }
    });
}
Also used : DepthPageTransformer(com.alexvasilkov.gestures.commons.DepthPageTransformer) PhotoPagerAdapter(com.alexvasilkov.gestures.sample.adapters.PhotoPagerAdapter) MenuItem(android.view.MenuItem) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)111 View (android.view.View)49 ViewPager (android.support.v4.view.ViewPager)44 TextView (android.widget.TextView)33 ViewGroup (android.view.ViewGroup)19 HorizontalScrollView (android.widget.HorizontalScrollView)19 LinearLayout (android.widget.LinearLayout)13 Toolbar (android.support.v7.widget.Toolbar)12 ImageView (android.widget.ImageView)11 TabLayout (android.support.design.widget.TabLayout)10 ArrayList (java.util.ArrayList)9 RecyclerView (android.support.v7.widget.RecyclerView)8 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)6 MenuItem (android.view.MenuItem)5 ImageButton (android.widget.ImageButton)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)4 LargeTest (android.support.test.filters.LargeTest)4 MediumTest (android.support.test.filters.MediumTest)4