Search in sources :

Example 1 with FragmentPagerAdapter

use of androidx.fragment.app.FragmentPagerAdapter 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 2 with FragmentPagerAdapter

use of androidx.fragment.app.FragmentPagerAdapter in project xabber-android by redsolution.

the class TutorialActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) {
        return;
    }
    setContentView(R.layout.activity_tutorial);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    FragmentPagerAdapter pagerAdapter = new TutorialAdapter(getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(viewPager);
    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(XabberLoginActivity.createIntent(TutorialActivity.this, XabberLoginActivity.FRAGMENT_LOGIN));
        }
    });
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (BuildConfig.FLAVOR_destribution.equals("store")) {
                startActivity(XabberLoginActivity.createIntent(TutorialActivity.this, XabberLoginActivity.FRAGMENT_SIGNUP_STEP1));
            } else {
                String url = HttpApiManager.XABBER_SIGNUP_URL;
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        }
    });
    ivSettings = (ImageView) findViewById(R.id.ivSettings);
    ivSettings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(PreferenceEditor.createIntent(TutorialActivity.this));
        }
    });
}
Also used : FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) CircleIndicator(me.relex.circleindicator.CircleIndicator) Intent(android.content.Intent) TutorialAdapter(com.xabber.android.ui.adapter.TutorialAdapter) ViewPager(androidx.viewpager.widget.ViewPager) ImageView(android.widget.ImageView) View(android.view.View)

Example 3 with FragmentPagerAdapter

use of androidx.fragment.app.FragmentPagerAdapter in project Android-SpinKit by ybq.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        String[] titles = new String[] { "Style", "Widget" };

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return StyleFragment.newInstance();
            } else {
                return WidgetFragment.newInstance();
            }
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    });
    mTabLayout.setupWithViewPager(mViewPager);
}
Also used : FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) Fragment(androidx.fragment.app.Fragment)

Example 4 with FragmentPagerAdapter

use of androidx.fragment.app.FragmentPagerAdapter 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(androidx.fragment.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(androidx.recyclerview.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(androidx.fragment.app.Fragment) PagerAdapter(androidx.viewpager.widget.PagerAdapter) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter)

Aggregations

FragmentPagerAdapter (androidx.fragment.app.FragmentPagerAdapter)4 Intent (android.content.Intent)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 Fragment (androidx.fragment.app.Fragment)2 PagerAdapter (androidx.viewpager.widget.PagerAdapter)2 ViewPager (androidx.viewpager.widget.ViewPager)2 Bundle (android.os.Bundle)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1 ScrollView (android.widget.ScrollView)1 FragmentStatePagerAdapter (androidx.fragment.app.FragmentStatePagerAdapter)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Attachment (com.xabber.android.data.database.messagerealm.Attachment)1 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)1 TutorialAdapter (com.xabber.android.ui.adapter.TutorialAdapter)1 Realm (io.realm.Realm)1 CircleIndicator (me.relex.circleindicator.CircleIndicator)1