Search in sources :

Example 1 with PagerAdapter

use of androidx.viewpager.widget.PagerAdapter in project SmartTabLayout by ogaclejapan.

the class SmartTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = viewPager.getAdapter();
    for (int i = 0; i < adapter.getCount(); i++) {
        final View tabView = (tabProvider == null) ? createDefaultTabView(adapter.getPageTitle(i)) : tabProvider.createTabView(tabStrip, i, adapter);
        if (tabView == null) {
            throw new IllegalStateException("tabView is null.");
        }
        if (distributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }
        if (internalTabClickListener != null) {
            tabView.setOnClickListener(internalTabClickListener);
        }
        tabStrip.addView(tabView);
        if (i == viewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}
Also used : HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(androidx.viewpager.widget.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 2 with PagerAdapter

use of androidx.viewpager.widget.PagerAdapter in project xabber-android by redsolution.

the class ImageViewerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_viewer);
    // get params
    Intent intent = getIntent();
    Bundle args = intent.getExtras();
    if (args == null) {
        finish();
        return;
    }
    String imageUrl = args.getString(IMAGE_URL);
    String messageId = args.getString(MESSAGE_ID);
    int imagePosition = args.getInt(ATTACHMENT_POSITION);
    // setup toolbar
    toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.inflateMenu(R.menu.menu_image_viewer);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(ImageViewerActivity.this);
        }
    });
    // get imageAttachments
    Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
    MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
    if (imageUrl != null) {
        Attachment attachment = new Attachment();
        attachment.setFileUrl(imageUrl);
        imageAttachments.add(attachment);
    } else {
        RealmList<Attachment> attachments = messageItem.getAttachments();
        for (Attachment attachment : attachments) {
            if (attachment.isImage())
                imageAttachments.add(attachment);
        }
    }
    // get account jid
    this.accountJid = messageItem.getAccount();
    // find views
    progressBar = findViewById(R.id.progressBar);
    ivCancelDownload = findViewById(R.id.ivCancelDownload);
    ivCancelDownload.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onCancelDownloadClick();
        }
    });
    viewPager = findViewById(R.id.viewPager);
    PagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            Attachment attachment = imageAttachments.get(position);
            return ImageViewerFragment.newInstance(attachment.getFilePath(), attachment.getFileUrl(), attachment.getUniqueId());
        }

        @Override
        public int getCount() {
            return imageAttachments.size();
        }
    };
    viewPager.setAdapter(pagerAdapter);
    viewPager.setCurrentItem(imagePosition);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            updateToolbar();
            unsubscribeAttachmentState();
            subscribeForAttachment(imageAttachments.get(position));
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    if (imageAttachments.size() > imagePosition)
        subscribeForAttachment(imageAttachments.get(imagePosition));
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Bundle(android.os.Bundle) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) Intent(android.content.Intent) Attachment(com.xabber.android.data.database.messagerealm.Attachment) ImageView(android.widget.ImageView) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) PagerAdapter(androidx.viewpager.widget.PagerAdapter) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) Realm(io.realm.Realm)

Example 3 with PagerAdapter

use of androidx.viewpager.widget.PagerAdapter in project CircleIndicator by ongakuer.

the class CircleIndicator method createIndicators.

private void createIndicators() {
    PagerAdapter adapter = mViewpager.getAdapter();
    int count;
    if (adapter == null) {
        count = 0;
    } else {
        count = adapter.getCount();
    }
    createIndicators(count, mViewpager.getCurrentItem());
}
Also used : PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Example 4 with PagerAdapter

use of androidx.viewpager.widget.PagerAdapter in project UltimateRecyclerView by cymcsg.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final 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(androidx.viewpager.widget.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 5 with PagerAdapter

use of androidx.viewpager.widget.PagerAdapter in project SeriesGuide by UweTrottmann.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = viewPager.getAdapter();
    if (adapter == null)
        return;
    populateTabStrip(adapter.getCount(), position -> {
        CharSequence titleOrNull = adapter.getPageTitle(position);
        return titleOrNull == null ? "" : titleOrNull.toString();
    });
}
Also used : PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Aggregations

PagerAdapter (androidx.viewpager.widget.PagerAdapter)15 View (android.view.View)8 TextView (android.widget.TextView)5 ViewPager (androidx.viewpager.widget.ViewPager)5 ViewGroup (android.view.ViewGroup)4 LinearLayout (android.widget.LinearLayout)4 HorizontalScrollView (android.widget.HorizontalScrollView)3 NonNull (androidx.annotation.NonNull)3 FragmentPagerAdapter (androidx.fragment.app.FragmentPagerAdapter)2 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Parcel (android.os.Parcel)1