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);
}
}
}
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");
}
}
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);
}
}
}
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);
}
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);
}
});
}
Aggregations