use of android.support.v4.view.PagerAdapter in project Carbon by ZieIony.
the class PagerTabStrip method initTabs.
private void initTabs() {
content.removeAllViews();
if (viewPager == null)
return;
final PagerAdapter adapter = viewPager.getAdapter();
if (viewPager.getAdapter() == null)
return;
if (tabBuilder == null) {
tabBuilder = position -> {
View tab = inflate(getContext(), R.layout.carbon_tab, null);
((TextView) tab.findViewById(R.id.carbon_tabText)).setText(getViewPager().getAdapter().getPageTitle(position).toString().toUpperCase());
return tab;
};
}
for (int i = 0; i < adapter.getCount(); i++) {
View tab = tabBuilder.getView(i);
content.addView(tab, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
tab.setSelected(i == 0);
final int finalI = i;
tab.setOnClickListener(__ -> viewPager.setCurrentItem(finalI));
}
}
use of android.support.v4.view.PagerAdapter in project actor-platform by actorapp.
the class VerticalViewPager method setAdapter.
/**
* Set a PagerAdapter that will supply views for this pager as needed.
*
* @param adapter Adapter to use
*/
public void setAdapter(PagerAdapter adapter) {
if (mAdapter != null) {
mAdapter.unregisterDataSetObserver(mObserver);
mAdapter.startUpdate(this);
for (int i = 0; i < mItems.size(); i++) {
final ItemInfo ii = mItems.get(i);
mAdapter.destroyItem(this, ii.position, ii.object);
}
mAdapter.finishUpdate(this);
mItems.clear();
removeNonDecorViews();
mCurItem = 0;
scrollTo(0, 0);
}
final PagerAdapter oldAdapter = mAdapter;
mAdapter = adapter;
mExpectedAdapterCount = 0;
if (mAdapter != null) {
if (mObserver == null) {
mObserver = new PagerObserver();
}
mAdapter.registerDataSetObserver(mObserver);
mPopulatePending = false;
final boolean wasFirstLayout = mFirstLayout;
mFirstLayout = true;
mExpectedAdapterCount = mAdapter.getCount();
if (mRestoredCurItem >= 0) {
mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
setCurrentItemInternal(mRestoredCurItem, false, true);
mRestoredCurItem = -1;
mRestoredAdapterState = null;
mRestoredClassLoader = null;
} else if (!wasFirstLayout) {
populate();
} else {
requestLayout();
}
}
if (mAdapterChangeListener != null && oldAdapter != adapter) {
mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
}
}
use of android.support.v4.view.PagerAdapter in project storymaker by StoryMaker.
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;
tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
}
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 material-intro-screen by TangoAgency.
the class OverScrollViewPager method canOverScrollAtEnd.
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;
}
use of android.support.v4.view.PagerAdapter in project Reader by TheKeeperOfPie.
the class FragmentNewPost method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_new_post, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
scrollText = (NestedScrollView) view.findViewById(R.id.scroll_text);
textInfo = (TextView) view.findViewById(R.id.text_info);
textSubmit = (TextView) view.findViewById(R.id.text_submit);
editTextTitle = (EditText) view.findViewById(R.id.edit_title);
editTextBody = (EditText) view.findViewById(R.id.edit_body);
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.new_post));
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(v -> {
UtilsInput.hideKeyboard(editTextBody);
mListener.onNavigationBackClick();
});
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
setUpOptionsMenu();
textInfo.setText(getString(R.string.submitting_post, getArguments().getString(SUBREDDIT), getArguments().getString(USER)));
String submitTextHtml = getArguments().getString(SUBMIT_TEXT_HTML);
Log.d(TAG, "submitTextHtml: " + submitTextHtml);
if (TextUtils.isEmpty(submitTextHtml) || "null".equals(submitTextHtml)) {
textSubmit.setVisibility(View.GONE);
} else {
textSubmit.setText(UtilsReddit.getFormattedHtml(submitTextHtml));
}
textSubmit.setMovementMethod(LinkMovementMethod.getInstance());
if (Reddit.PostType.LINK == postType) {
editTextBody.setHint("URL");
} else {
editTextBody.setHint("Text");
}
View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
if (hasFocus) {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
};
editTextTitle.setOnFocusChangeListener(onFocusChangeListener);
editTextBody.setOnFocusChangeListener(onFocusChangeListener);
editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
textPreview = (TextView) view.findViewById(R.id.text_preview);
viewDivider = view.findViewById(R.id.view_divider);
toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
toolbarActions.inflateMenu(R.menu.menu_editor_actions);
toolbarActions.setOnMenuItemClickListener(this);
tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
viewPager = (ViewPager) view.findViewById(R.id.view_pager);
viewPager.setAdapter(new PagerAdapter() {
@Override
public CharSequence getPageTitle(int position) {
switch(position) {
case PAGE_POST:
return getString(R.string.page_post);
case PAGE_PREVIEW:
return getString(R.string.page_preview);
}
return super.getPageTitle(position);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
return viewPager.getChildAt(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}
@Override
public int getCount() {
if (Reddit.PostType.LINK == postType) {
tabLayout.setVisibility(View.GONE);
toolbarActions.setVisibility(View.GONE);
viewDivider.setVisibility(View.GONE);
itemHideActions.setVisible(false);
return 1;
}
return viewPager.getChildCount();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position == PAGE_POST && toolbarActions.getVisibility() == View.VISIBLE) {
float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider.getHeight());
viewDivider.setTranslationY(translationY);
toolbarActions.setTranslationY(translationY);
}
}
@Override
public void onPageSelected(int position) {
if (position == PAGE_PREVIEW) {
if (editTextBody.length() == 0) {
textPreview.setText(R.string.empty_reply_preview);
} else {
textPreview.setText(Html.fromHtml(Processor.process(editTextBody.getText().toString())));
}
}
if (Reddit.PostType.SELF == postType) {
itemHideActions.setVisible(position == PAGE_POST);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
layoutCaptcha = (RelativeLayout) view.findViewById(R.id.layout_captcha);
imageCaptcha = (ImageView) view.findViewById(R.id.image_captcha);
editCaptcha = (EditText) view.findViewById(R.id.edit_captcha);
buttonCaptchaRefresh = (ImageButton) view.findViewById(R.id.button_captcha_refresh);
buttonCaptchaRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadCaptcha();
}
});
if (getArguments().getBoolean(IS_EDIT, false)) {
loadEditValues();
} else {
reddit.needsCaptcha().subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(String response) {
if ("true".equalsIgnoreCase(response)) {
layoutCaptcha.setVisibility(View.VISIBLE);
loadCaptcha();
}
}
});
}
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Menu menu = toolbarActions.getMenu();
int maxNum = (int) (view.getWidth() / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()));
int numShown = 0;
for (int index = 0; index < menu.size(); index++) {
MenuItem menuItem = menu.getItem(index);
menuItem.getIcon().setColorFilter(themer.getColorFilterIcon());
if (numShown++ < maxNum - 1) {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
} else {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
// Toggle visibility to fix weird bug causing tabs to not be added
tabLayout.setVisibility(View.GONE);
tabLayout.setVisibility(View.VISIBLE);
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
return view;
}
Aggregations