Search in sources :

Example 11 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project BookReader by JustWayward.

the class SubjectBookListActivity method initDatas.

@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.subject_tabs));
    mTabContents = new ArrayList<>();
    mTabContents.add(SubjectFragment.newInstance("", 0));
    mTabContents.add(SubjectFragment.newInstance("", 1));
    mTabContents.add(SubjectFragment.newInstance("", 2));
    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) SubjectFragment(com.justwayward.reader.ui.fragment.SubjectFragment) Fragment(android.support.v4.app.Fragment)

Example 12 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project twicalico by moko256.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    subscription = new CompositeSubscription();
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.getChildAt(0).setOnClickListener(v -> {
        Fragment fragment = getMainFragment();
        if (fragment instanceof MovableTopInterface) {
            ((MovableTopInterface) fragment).moveToTop();
        }
    });
    drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    drawer.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
        }

        @Override
        public void onDrawerOpened(@NonNull View drawerView) {
        }

        @Override
        public void onDrawerClosed(@NonNull View drawerView) {
            if (isDrawerAccountsSelection) {
                changeIsDrawerAccountsSelection();
            }
        }

        @Override
        public void onDrawerStateChanged(int newState) {
        }
    });
    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(item -> {
        int id = item.getItemId();
        if (!item.isChecked()) {
            switch(id) {
                case R.id.nav_timeline:
                    replaceFragment(new HomeTimeLineFragment());
                    break;
                case R.id.nav_mentions:
                    replaceFragment(new MentionsFragment());
                    break;
                case R.id.nav_account:
                    startMyUserActivity();
                    break;
                case R.id.nav_follow_and_follower:
                    replaceFragment(new MyFollowFollowerFragment());
                    break;
                case R.id.nav_like:
                    replaceFragment(UserLikeFragment.newInstance(GlobalApplication.userId));
                    break;
                case R.id.nav_settings:
                    startActivity(new Intent(this, SettingsActivity.class));
                    break;
            }
        }
        drawer.closeDrawer(GravityCompat.START);
        return (id != R.id.nav_settings) && (id != R.id.nav_account);
    });
    headerView = navigationView.inflateHeaderView(R.layout.nav_header_main);
    userNameText = headerView.findViewById(R.id.user_name);
    userIdText = headerView.findViewById(R.id.user_id);
    userImage = headerView.findViewById(R.id.user_image);
    userBackgroundImage = headerView.findViewById(R.id.user_bg_image);
    userBackgroundImage.setOnClickListener(v -> changeIsDrawerAccountsSelection());
    updateDrawerImage();
    accountListView = new RecyclerView(this);
    accountListView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    accountListView.setLayoutManager(new LinearLayoutManager(this));
    accountListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    accountListView.setVisibility(View.GONE);
    navigationView.addHeaderView(accountListView);
    SelectAccountsAdapter adapter = new SelectAccountsAdapter(this);
    adapter.setOnImageButtonClickListener(accessToken -> {
        drawer.closeDrawer(GravityCompat.START);
        if (accessToken.getUserId() != GlobalApplication.userId) {
            PreferenceManager.getDefaultSharedPreferences(this).edit().putString("AccountKey", accessToken.getKeyString()).apply();
            ((GlobalApplication) getApplication()).initTwitter(accessToken);
            updateDrawerImage();
            clearAndPrepareFragment();
        }
    });
    adapter.setOnAddButtonClickListener(v -> {
        PreferenceManager.getDefaultSharedPreferences(this).edit().putString("AccountKey", "-1").apply();
        GlobalApplication.twitter = null;
        startActivity(new Intent(this, OAuthActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
    });
    adapter.setOnRemoveButtonClickListener(v -> new AlertDialog.Builder(this).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(this);
        helper.deleteAccessToken(helper.getAccessToken(defaultSharedPreferences.getString("AccountKey", "-1")));
        int point = helper.getSize() - 1;
        if (point != -1) {
            AccessToken accessToken = helper.getAccessTokens()[point];
            defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
            ((GlobalApplication) getApplication()).initTwitter(accessToken);
            updateDrawerImage();
            clearAndPrepareFragment();
        } else {
            adapter.getOnAddButtonClickListener().onClick(v);
        }
        helper.close();
    }).setNeutralButton(R.string.back, (dialog, i) -> dialog.cancel()).show());
    accountListView.setAdapter(adapter);
    subscription.add(Single.create(singleSubscriber -> {
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(this);
        AccessToken[] accessTokens = helper.getAccessTokens();
        helper.close();
        ArrayList<Pair<User, AccessToken>> r = new ArrayList<>(accessTokens.length);
        for (AccessToken accessToken : accessTokens) {
            long id = accessToken.getUserId();
            CachedUsersSQLiteOpenHelper userHelper = new CachedUsersSQLiteOpenHelper(this, id, accessToken.getType() == Type.TWITTER);
            User user = userHelper.getCachedUser(id);
            if (user == null) {
                try {
                    user = ((GlobalApplication) getApplication()).getTwitterInstance(accessToken).verifyCredentials();
                    userHelper.addCachedUser(user);
                } catch (TwitterException e) {
                    singleSubscriber.onError(e);
                    return;
                } finally {
                    userHelper.close();
                }
            }
            r.add(new Pair<>(user, accessToken));
        }
        singleSubscriber.onSuccess(r);
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
        ArrayList<Pair<User, AccessToken>> pairs = (ArrayList<Pair<User, AccessToken>>) o;
        adapter.getImagesList().addAll(pairs);
        adapter.notifyDataSetChanged();
    }, Throwable::printStackTrace));
    findViewById(R.id.fab).setOnClickListener(v -> startActivity(new Intent(this, PostActivity.class)));
    tabLayout = findViewById(R.id.toolbar_tab);
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            Fragment fragment = ((FragmentPagerAdapter) ((UseTabsInterface) getMainFragment()).getTabsViewPager().getAdapter()).getFragment(tab.getPosition());
            if (fragment instanceof MovableTopInterface) {
                ((MovableTopInterface) fragment).moveToTop();
            }
        }
    });
    tweetListViewPool = new RecyclerView.RecycledViewPool();
    userListViewPool = new RecyclerView.RecycledViewPool();
    getSupportFragmentManager().addOnBackStackChangedListener(() -> attachFragment(getMainFragment()));
    if (savedInstanceState == null) {
        prepareFragment();
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) LinearLayout(android.widget.LinearLayout) Type(com.github.moko256.twicalico.entity.Type) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) CachedUsersSQLiteOpenHelper(com.github.moko256.twicalico.database.CachedUsersSQLiteOpenHelper) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) GravityCompat(android.support.v4.view.GravityCompat) Single(rx.Single) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) User(twitter4j.User) View(android.view.View) TwitterException(twitter4j.TwitterException) PreferenceManager(android.preference.PreferenceManager) DrawerLayout(android.support.v4.widget.DrawerLayout) AccessToken(com.github.moko256.twicalico.entity.AccessToken) Fragment(android.support.v4.app.Fragment) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) FragmentPagerAdapter(com.github.moko256.twicalico.widget.FragmentPagerAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) User(twitter4j.User) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) AccessToken(com.github.moko256.twicalico.entity.AccessToken) TabLayout(android.support.design.widget.TabLayout) DrawerLayout(android.support.v4.widget.DrawerLayout) TwitterException(twitter4j.TwitterException) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) Pair(android.support.v4.util.Pair) SharedPreferences(android.content.SharedPreferences) CachedUsersSQLiteOpenHelper(com.github.moko256.twicalico.database.CachedUsersSQLiteOpenHelper) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayout(android.widget.LinearLayout)

Example 13 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project SmartCampus by Vegen.

the class HomeFragment method setupUI.

@Override
protected void setupUI() {
    showContentView();
    ImmersionBar.setTitleBar(getActivity(), toolbar);
    float marginHeight = SystemUtils.getStatusBarHeight(getContext()) + SystemUtils.getActionBarHeight(getContext());
    viewTop.getLayoutParams().height = (int) marginHeight;
    banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
    banner.setIndicatorGravity(BannerConfig.CENTER);
    banner.setImageLoader(new GlideImageLoader());
    banner.setOnBannerListener(position -> {
        if (bannerList.isEmpty())
            return;
        TopFunArticleDetailActivity.start(getContext(), bannerList.get(position).getTitle(), bannerList.get(position).getNextUrl());
    });
    List<Fragment> fragments = new ArrayList<>();
    flashFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_FLASH);
    focusFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_FOCUS);
    comprehensiveFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_COMPREHENSIVE);
    otherFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_OTHER);
    fragments.add(flashFragment);
    fragments.add(focusFragment);
    fragments.add(comprehensiveFragment);
    fragments.add(otherFragment);
    List<String> strings = new ArrayList<>();
    strings.add("快讯");
    strings.add("要闻");
    strings.add("综合");
    strings.add("其他");
    fragmentPagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), fragments, strings);
    viewPager.setAdapter(fragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    viewPager.setOffscreenPageLimit(fragments.size());
}
Also used : ArrayList(java.util.ArrayList) BaseFragmentPagerAdapter(com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter) GlideImageLoader(com.itculturalfestival.smartcampus.utils.GlideImageLoader) AppBaseFragment(com.itculturalfestival.smartcampus.AppBaseFragment) Fragment(android.support.v4.app.Fragment)

Example 14 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project xabber-android by redsolution.

the class TutorialActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    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(getFragmentManager());
    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));
        }
    });
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = XabberAccountInfoActivity.createIntent(TutorialActivity.this);
            intent.putExtra(XabberAccountInfoActivity.CALL_FROM, XabberAccountInfoActivity.CALL_FROM_LOGIN);
            startActivity(intent);
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v13.app.FragmentPagerAdapter) CircleIndicator(me.relex.circleindicator.CircleIndicator) Intent(android.content.Intent) TutorialAdapter(com.xabber.android.ui.adapter.TutorialAdapter) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Example 15 with FragmentPagerAdapter

use of android.support.v4.app.FragmentPagerAdapter in project AndroidDevMetrics by frogermcs.

the class MetricsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adm_activity_metrics);
    btnActivities = (Button) findViewById(R.id.btnActivities);
    btnDagger2 = (Button) findViewById(R.id.btnDagger2);
    vpMetrics = (ViewPager) findViewById(R.id.vpMetrics);
    activitiesMetricsFragment = new ActivitiesMetricsFragment();
    dagger2MetricsFragment = new Dagger2MetricsFragment();
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return activitiesMetricsFragment;
            } else if (position == 1) {
                return dagger2MetricsFragment;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }
    };
    vpMetrics.setAdapter(fragmentPagerAdapter);
    vpMetrics.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

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

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                activitiesPageSelected();
            } else if (position == 1) {
                daggerPageSelected();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    btnActivities.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(0);
        }
    });
    btnDagger2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(1);
        }
    });
    activitiesPageSelected();
}
Also used : Dagger2MetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.Dagger2MetricsFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ActivitiesMetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.ActivitiesMetricsFragment) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Aggregations

FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)29 Fragment (android.support.v4.app.Fragment)26 ViewPager (android.support.v4.view.ViewPager)10 View (android.view.View)7 Intent (android.content.Intent)6 TabLayout (android.support.design.widget.TabLayout)5 Bundle (android.os.Bundle)3 RecyclerView (android.support.v7.widget.RecyclerView)3 Toolbar (android.support.v7.widget.Toolbar)3 TextView (android.widget.TextView)3 FragmentPagerAdapter (android.support.v13.app.FragmentPagerAdapter)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 AlertDialog (android.support.v7.app.AlertDialog)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 LinearLayout (android.widget.LinearLayout)2 PageIndicator (com.viewpagerindicator.PageIndicator)2 TabPageIndicator (com.viewpagerindicator.TabPageIndicator)2 ArrayList (java.util.ArrayList)2