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