Search in sources :

Example 1 with TabsPagerAdapter

use of org.ethack.orwall.adapter.TabsPagerAdapter in project orWall by EthACKdotOrg.

the class TabbedMain method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabbed_main);
    // Import old settings to SQLite, and remove them from SharedPreferences
    NatRules natRules = new NatRules(this);
    Set oldRules = getSharedPreferences(Preferences.PREFERENCES, MODE_PRIVATE).getStringSet("nat_rules", null);
    if (natRules.getRuleCount() == 0 && oldRules != null) {
        natRules.importFromSharedPrefs(oldRules);
        getSharedPreferences(Preferences.PREFERENCES, MODE_PRIVATE).edit().remove("nat_rules").apply();
    }
    // Is it the first application run?
    if (Preferences.isFirstRun(this)) {
        // Initialize orWall iptables rules - #72 should be better after that
        Iptables iptables = new Iptables(this);
        iptables.boot();
        // Start Wizard
        Intent wizard = new Intent(this, WizardActivity.class);
        startActivity(wizard);
    }
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // create the tab header
    for (String tab : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab).setTabListener(this));
    }
    // changer in order to take care of tab switching
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

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

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}
Also used : NatRules(org.ethack.orwall.lib.NatRules) Set(java.util.Set) Iptables(org.ethack.orwall.lib.Iptables) Intent(android.content.Intent) TabsPagerAdapter(org.ethack.orwall.adapter.TabsPagerAdapter) ViewPager(android.support.v4.view.ViewPager)

Aggregations

Intent (android.content.Intent)1 ViewPager (android.support.v4.view.ViewPager)1 Set (java.util.Set)1 TabsPagerAdapter (org.ethack.orwall.adapter.TabsPagerAdapter)1 Iptables (org.ethack.orwall.lib.Iptables)1 NatRules (org.ethack.orwall.lib.NatRules)1