Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

In this page you can find the example usage for android.app ActionBar NAVIGATION_MODE_TABS.

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

From source file:com.otaupdater.TabDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context context = getApplicationContext();
    cfg = Config.getInstance(context);/*from   w  w w  .j ava2 s.  c  om*/

    if (!Utils.haveProKey(context)) {
        cfg.setKeyExpiry(0);
    } else if (!cfg.hasValidProKey()) {
        if (cfg.isProKeyTemporary()) {
            if (cfg.getKeyExpires() < System.currentTimeMillis()) {
                Utils.verifyProKey(context);
            }
        } else {
            Utils.verifyProKey(context);
        }
    }

    if (!Utils.isRomOtaEnabled() && !Utils.isKernelOtaEnabled()) {
        if (!cfg.getIgnoredUnsupportedWarn()) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.alert_unsupported_title);
            alert.setMessage(R.string.alert_unsupported_message);
            alert.setCancelable(false);
            alert.setNegativeButton(R.string.alert_exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            alert.setPositiveButton(R.string.alert_ignore, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    cfg.setIgnoredUnsupportedWarn(true);
                    dialog.dismiss();
                }
            });
            alert.create().show();
        }

        if (Utils.marketAvailable(this)) {
            GCMRegistrar.checkDevice(context);
            GCMRegistrar.checkManifest(context);
            final String regId = GCMRegistrar.getRegistrationId(context);
            if (regId.length() != 0) {
                GCMRegistrar.unregister(context);
            }
        }

    } else {
        if (Utils.marketAvailable(this)) {
            GCMRegistrar.checkDevice(context);
            GCMRegistrar.checkManifest(context);
            final String regId = GCMRegistrar.getRegistrationId(context);
            if (regId.length() != 0) {
                if (cfg.upToDate()) {
                    Log.v(Config.LOG_TAG + "GCMRegister", "Already registered");
                } else {
                    Log.v(Config.LOG_TAG + "GCMRegister", "Already registered, out-of-date");
                    cfg.setValuesToCurrent();
                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            Utils.updateGCMRegistration(context, regId);
                            return null;
                        }
                    }.execute();
                }
            } else {
                GCMRegistrar.register(context, Config.GCM_SENDER_ID);
                Log.v(Config.LOG_TAG + "GCMRegister", "GCM registered");
            }
        } else {
            UpdateCheckReceiver.setAlarm(context);
        }
    }

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.app_name);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_rom), ROMTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_kernel), KernelTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_walls), WallsTab.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:com.univ.helsinki.app.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH,
            false)) {//ww w  . ja  va  2 s  . co m

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getActionBar().hide();

        hideTitle();
    }

    setContentView(R.layout.activity_main);

    splashLayout = (ViewGroup) findViewById(R.id.splashLayout);

    if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH,
            false)) {
        // record the fact that the app has been started at least once
        FeedResource.getInstance().getSharedPrefs().edit()
                .putBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH, false).commit();

        final ViewGroup splashLayout = (ViewGroup) findViewById(R.id.splashLayout);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                activateSplashScreen(splashLayout);
            }
        }, Constant.SPLASH_SCREEN_TIME_OUT);

    } else {
        splashLayout.setVisibility(View.GONE);
    }

    FeedResource.getInstance().inti(this);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    mSensorFeedAdapter = new SensorFeedAdapter(this);

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
            switch (position) {
            case 0: {
                // on focus when first fragment
                //Toast.makeText(getApplicationContext(), "onPageSelected :" + position, Toast.LENGTH_SHORT).show();

                List<SensorFeed> mtempAllowedSensorFeedList = new ArrayList<SensorFeed>();
                // update the list over here.. to avoid empty shell
                for (SensorFeed sensor : FeedResource.getInstance().getSensorFeedList()) {

                    boolean isChecked = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                            .getBoolean(sensor.getSensorKey(), false);

                    if (isChecked)
                        mtempAllowedSensorFeedList.add(sensor);
                }
                // update the list with new created list
                mSensorFeedAdapter.setFeedList(mtempAllowedSensorFeedList);

            }
                break;
            }// switch ends
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:it.durip_app.MACActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mac);
    data = new MACSource();
    isIperfRunning = isIperfRunning();//from  w  ww  . jav  a  2s.c o m
    isOlsrRunning = isOlsrRunning();
    // Get the message from the intent
    Intent intent = getIntent();
    paramUrl = intent.getStringExtra(MainActivity.PARAM_URL);
    paramT = intent.getIntExtra(MainActivity.PARAM_T, 200);
    paramI = intent.getIntExtra(MainActivity.PARAM_I, 5);
    paramMAC = intent.getStringExtra(MainActivity.PARAM_MAC);
    paramSleep = intent.getIntExtra(MainActivity.PARAM_SLEEP, 500);
    paramPort = intent.getIntExtra(MainActivity.PARAM_PORT, 4000);
    paramVerbose = intent.getIntExtra(MainActivity.PARAM_VERBOSE, 1);
    data.setUrl(paramUrl);
    data.setT(paramT);
    data.setI(paramI);
    data.setPort(paramPort);
    data.setSleep(paramSleep);
    data.setVerbose(paramVerbose);
    data.setMAC(paramMAC);
    // kick off the data generating thread:
    //mySource = new Thread(data);
    //mySource.start();
    data.startMAC();

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    // Show the Up button in the action bar.

}

From source file:net.sourceforge.lifeograph.ActivityDiary.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(Lifeograph.TAG, "ActivityDiary.onCreate()");

    Lifeograph.sContext = this;
    Lifeograph.updateScreenSizes();/* w w w.j a  va 2 s . c  o m*/
    Lifeograph.sNumberOfDiaryEditingActivities++;

    // PICKING UP THE APPROPRIATE LAYOUT
    if (Lifeograph.getScreenWidth() >= 4.0) {
        setContentView(R.layout.diary_wide);

        mButtonCalendar = (Button) findViewById(R.id.button_calendar);
        mButtonCalendar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                new DialogCalendar(ActivityDiary.this, !Diary.diary.is_read_only()).show();
            }
        });

        ViewPager pagerCalendar = (ViewPager) findViewById(R.id.pager_calendar);
        mCalPagerAdapter = new PagerAdapterCalendar(pagerCalendar);
    } else {
        mCalPagerAdapter = null;
        setContentView(R.layout.diary);
    }

    // FILLING WIDGETS
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //mInflater = ( LayoutInflater ) getSystemService( Activity.LAYOUT_INFLATER_SERVICE );

    // LISTENERS
    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        public void onDrawerSlide(View view, float v) {
        }

        public void onDrawerOpened(View view) {

            for (FragmentElemList fragment : mDiaryFragments) {
                if (fragment.isVisible())
                    fragment.getListView().setEnabled(false);
            }

            // alternative way:
            //                for( int i = 0; i < 3; i++ ) {
            //                    FragmentElemList fragment = ( FragmentElemList ) getFragmentManager()
            //                            .findFragmentByTag( TabsAdapter.makeFragmentName( i ) );
            //                    if( fragment != null )
            //                        if( fragment.isVisible() )
            //                            fragment.getListView().setEnabled( false );
            //                }
        }

        public void onDrawerClosed(View view) {
            for (FragmentElemList fragment : mDiaryFragments) {
                if (fragment.isVisible())
                    fragment.getListView().setEnabled(true);
            }
        }

        public void onDrawerStateChanged(int i) {
        }
    });

    // ACTIONBAR
    mActionBar = getActionBar();
    if (mActionBar != null) {
        mActionBar.setDisplayHomeAsUpEnabled(true);
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        mActionBar.setIcon(R.drawable.ic_diary);
        setTitle(Diary.diary.get_title_str());
        mActionBar.setSubtitle(Diary.diary.get_info_str());
    }

    mPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, mPager);

    Bundle args = new Bundle();
    args.putInt("tab", 0);
    mTabsAdapter.addTab(mActionBar.newTab().setText(R.string.all_entries), FragmentElemList.class, args);
    args = new Bundle();
    args.putInt("tab", 1);
    mTabsAdapter.addTab(mActionBar.newTab().setText(R.string.chapters), FragmentElemList.class, args);
    args = new Bundle();
    args.putInt("tab", 2);
    mTabsAdapter.addTab(mActionBar.newTab().setText(R.string.tags), FragmentElemList.class, args);

    if (savedInstanceState != null) {
        mActionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }

    if (!Lifeograph.getAddFreeNotPurchased()) {
        LinearLayout container = (LinearLayout) findViewById(R.id.main_container);
        View ad = findViewById(R.id.fragmentAd);
        container.removeView(ad);
    }

    Lifeograph.sLoginStatus = Lifeograph.LoginStatus.LOGGED_IN;
}

From source file:it.durip_app.TCPActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_graph);
    data = new TCPSource();
    // Get the message from the intent
    isIperfRunning = isIperfRunning();/*  ww  w  .j ava 2 s. com*/
    Intent intent = getIntent();
    paramUrl = intent.getStringExtra(MainActivity.PARAM_URL);
    paramT = intent.getIntExtra(MainActivity.PARAM_T, 200);
    paramI = intent.getIntExtra(MainActivity.PARAM_I, 5);
    paramPort = intent.getIntExtra(MainActivity.PARAM_PORT, 4000);
    paramSleep = intent.getIntExtra(MainActivity.PARAM_SLEEP, 500);
    paramVerbose = intent.getIntExtra(MainActivity.PARAM_VERBOSE, 1);
    //         frequency = paramPort/1000;
    data.setUrl(paramUrl);
    data.setT(paramT);
    data.setI(paramI);
    data.setPort(paramPort);
    data.setSleep(paramSleep);
    data.setVerbose(paramVerbose);
    data.startTCP();
    // kick off the data generating thread:
    /*
    mySource = new Thread(data);
    mySource.start();
    */
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    // Show the Up button in the action bar.

}

From source file:com.github.wakhub.monodict.activity.FlashcardActivity.java

@AfterViews
void afterViews() {
    Log.d(TAG, "state: " + state.toString());
    commonActivityTrait.initActivity(preferences);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}

From source file:info.corne.performancetool.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    Intent service2 = new Intent(getApplicationContext(), UpdateService.class);
    getApplicationContext().startService(service2);

    setContentView(R.layout.activity_main);

    // Set up the action bar.
    actionBar = getActionBar();/*  w  ww.java2  s .co  m*/
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(3);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            currentTab = position;
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    getHardwareInfo();

}

From source file:de.ncoder.sensorsystem.android.app.MainActivity.java

private void onCreateTabs() {
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar == null) {
        return;//from w  w w  .j a  v  a2s  . co m
    }
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return tab fragments
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:heartware.com.heartware_master.MainActivity.java

private void setupActionTabs() {
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mActionBar = getActionBar();//from w  w  w. j  a v a  2 s  . co  m
    mTabsAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    mViewPager.setAdapter(mTabsAdapter);
    mViewPager.setOnPageChangeListener(new SwipedListener());
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mActionBar.setHomeButtonEnabled(false);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {
            mViewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {

        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {

        }
    };

    // Now that listeners are in place we can safely add the tabs
    mActionBar.addTab(mActionBar.newTab().setText(getString(R.string.profile_tab)).setIcon(R.drawable.ic_arrow)
            .setTabListener(tabListener));
    mActionBar.addTab(mActionBar.newTab().setText(getString(R.string.friends_tab))
            .setIcon(R.drawable.ic_action_friends).setTabListener(tabListener));
    mActionBar.addTab(
            mActionBar.newTab().setText(getString(R.string.meetups_tab)).setIcon(R.drawable.ic_action_workout)

                    .setTabListener(tabListener));

}