<commit_before>package com.gh4a;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;

public abstract class LoadingFragmentPagerActivity extends LoadingFragmentActivity {
    private FragmentAdapter mAdapter;
    private ViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (hasErrorView()) {
            return;
        }

        mAdapter = new FragmentAdapter();
        setContentView(R.layout.view_pager);
        mPager = setupPager();
    }

    protected void invalidateFragments() {
        mAdapter.notifyDataSetChanged();
    }

    protected ViewPager getPager() {
        return mPager;
    }

    public void setTabsEnabled(boolean enabled) {
        mPager.setEnabled(enabled);
        if (enabled) {
            mPager.setCurrentItem(getSupportActionBar().getSelectedTab().getPosition());
        }
    }

    private ViewPager setupPager() {
        final ActionBar actionBar = getSupportActionBar();
        int[] titleResIds = getTabTitleResIds();
        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(mAdapter);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrollStateChanged(int state) {}

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

            @Override
            public void onPageSelected(int position) {
                actionBar.getTabAt(position).select();
            }
        });

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0; i < titleResIds.length; i++) {
            actionBar.addTab(actionBar.newTab()
                .setText(titleResIds[i])
                .setTabListener(new TabListener(i, pager)));
        }

        return pager;
    }

    protected abstract int[] getTabTitleResIds();
    protected abstract Fragment getFragment(int position);
    protected boolean fragmentNeedsRefresh(Fragment object) {
        return false;
    }

    private class FragmentAdapter extends FragmentStatePagerAdapter {
        public FragmentAdapter() {
            super(getSupportFragmentManager());
        }

        @Override
        public int getCount() {
            return getTabTitleResIds().length;
        }

        @Override
        public Fragment getItem(int position) {
            return getFragment(position);
        }

        @Override
        public int getItemPosition(Object object) {
            if (object instanceof Fragment && fragmentNeedsRefresh((Fragment) object)) {
                return POSITION_NONE;
            }
            return POSITION_UNCHANGED;
        }
    }

    private static class TabListener implements ActionBar.TabListener {
        private final int mTag;
        private ViewPager mPager;

        public TabListener(int tag, ViewPager pager) {
            mTag = tag;
            mPager = pager;
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (mPager.isEnabled()) {
                mPager.setCurrentItem(mTag);
            }
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }
    }
}<commit_msg>Make sure to keep all fragments alive.<commit_after>package com.gh4a;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;

public abstract class LoadingFragmentPagerActivity extends LoadingFragmentActivity {
    private FragmentAdapter mAdapter;
    private ViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (hasErrorView()) {
            return;
        }

        mAdapter = new FragmentAdapter();
        setContentView(R.layout.view_pager);
        mPager = setupPager();
    }

    protected void invalidateFragments() {
        mAdapter.notifyDataSetChanged();
    }

    protected ViewPager getPager() {
        return mPager;
    }

    public void setTabsEnabled(boolean enabled) {
        mPager.setEnabled(enabled);
        if (enabled) {
            mPager.setCurrentItem(getSupportActionBar().getSelectedTab().getPosition());
        }
    }

    private ViewPager setupPager() {
        final ActionBar actionBar = getSupportActionBar();
        int[] titleResIds = getTabTitleResIds();
        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(mAdapter);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // We never have many pages, make sure to keep them all alive
        pager.setOffscreenPageLimit(titleResIds.length - 1);

        pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrollStateChanged(int state) {}

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

            @Override
            public void onPageSelected(int position) {
                actionBar.getTabAt(position).select();
            }
        });

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0; i < titleResIds.length; i++) {
            actionBar.addTab(actionBar.newTab()
                .setText(titleResIds[i])
                .setTabListener(new TabListener(i, pager)));
        }

        return pager;
    }

    protected abstract int[] getTabTitleResIds();
    protected abstract Fragment getFragment(int position);
    protected boolean fragmentNeedsRefresh(Fragment object) {
        return false;
    }

    private class FragmentAdapter extends FragmentStatePagerAdapter {
        public FragmentAdapter() {
            super(getSupportFragmentManager());
        }

        @Override
        public int getCount() {
            return getTabTitleResIds().length;
        }

        @Override
        public Fragment getItem(int position) {
            return getFragment(position);
        }

        @Override
        public int getItemPosition(Object object) {
            if (object instanceof Fragment && fragmentNeedsRefresh((Fragment) object)) {
                return POSITION_NONE;
            }
            return POSITION_UNCHANGED;
        }
    }

    private static class TabListener implements ActionBar.TabListener {
        private final int mTag;
        private ViewPager mPager;

        public TabListener(int tag, ViewPager pager) {
            mTag = tag;
            mPager = pager;
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (mPager.isEnabled()) {
                mPager.setCurrentItem(mTag);
            }
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }
    }
}
{'fraction_non_alphanumeric': 0.08132530120481928, 'fraction_numerical': 0.0017024620220010478, 'mean_word_length': 2.394222222222222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5135735', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1985, 'n_words': 436}