Example usage for android.app ActionBar setSelectedNavigationItem

List of usage examples for android.app ActionBar setSelectedNavigationItem

Introduction

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

Prototype

@Deprecated
public abstract void setSelectedNavigationItem(int position);

Source Link

Document

Set the selected navigation item in list or tabbed navigation modes.

Usage

From source file:com.github.riotopsys.malforandroid2.activity.HubActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate");
    setContentView(R.layout.main);//from   ww w .  j  av  a2 s . co m

    ActionBar actionBar = getActionBar();

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    actionBar
            .setListNavigationCallbacks(
                    new ArrayAdapter<String>(actionBar.getThemedContext(), android.R.layout.simple_list_item_1,
                            android.R.id.text1, getResources().getStringArray(R.array.drop_down_nav_options)),
                    this);

    setupAnimeAdapter();
    setupMangaAdapter();

    if (!state.isSyncScheduled()) {
        //somehow we hit this point with out starting the sync, so we'll do it now
        BootReciever.scheduleSync(state, this);
    }

    if (detailFrame != null) {
        transitionDetail(false);
    }

    if (savedInstanceState != null) {
        actionBar.setSelectedNavigationItem(savedInstanceState.getInt("MODE"));
    }

    apprater.onAppOpened(this);
}

From source file:net.networksaremadeofstring.rhybudd.FirstRunSettings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_run_settings);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setTitle(getString(R.string.FirstRunTitle));
    actionBar.setSubtitle(getString(R.string.FirstRunSubtitle));

    // 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);

    // 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/*from  ww  w. ja  va 2s.c om*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(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));
    }
}

From source file:com.example.team04adventure.Controller.OnlineStoryList.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_online_story_list);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    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);

    // 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//from w ww  . j  a va2 s .  c o m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(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));
    }
}

From source file:com.f8full.casserolesencours.CasserolesEnCoursV2.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

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

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

    // 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//from w  w  w  .ja v a 2 s  .  co m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(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));
    }

    try {
        // initialize the transport
        httpTransport = new NetHttpTransport();

        // authorization
        //Credential credential = new Credential();

        // set up global Fusiontables instance
        client = new Fusiontables.Builder(httpTransport, JSON_FACTORY, null)
                .setApplicationName(APPLICATION_NAME).build();

        //System.out.println("Success! Now add code here.");
        String fromTableID = "1cmlx9aChHUYTWwYivaZucr7NHNsP_ulvEPX1FoM";

        Sql sql = client.query().sql("SELECT * FROM " + fromTableID);

        new ViewerSetupTask().execute(sql);

    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.android.cts.uiautomator.Test4DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {

    View rootView = inflater.inflate(R.layout.test4_detail_fragment, container, false);

    // Set up the action bar.
    final ActionBar actionBar = getActivity().getActionBar();
    if (actionBar.getTabCount() > 0) {
        return rootView;
    }//from w  w  w.j  a  v a2  s. com
    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(getActivity().getSupportFragmentManager());

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

    // 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);
        }
    });

    // 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 listener for when this tab is
        // selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    return rootView;
}

From source file:com.manjiler.mathhelper.activities.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    mContext = this.getBaseContext();

    // 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.//w  w  w  .  j  av  a  2  s  . c  o m
    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));
    }
}

From source file:org.ounl.lifelonglearninghub.nfclearntracker.swipe.SwipeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipe);

    // 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./*  www  .ja  v a 2 s  .  c om*/
    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));
    }

}

From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java

@Override
protected void onStart() {
    Log.d(LOG_TAG, "onStart");
    super.onStart();
    stopped = false;/*w  w  w  .j a  v  a  2 s. co  m*/

    mainMenuDelegate = new MainMenuDelegate(this);

    listView = (AbsListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(clickListener);

    if (listView instanceof ListView) {
        // It is important that this is inflated with listView passed as the parent, despite the attach false parameter.
        // Otherwise, the view ends up with incorrect LayoutParams and we see crazy, crazy behavior.
        headerView = getLayoutInflater().inflate(R.layout.header_video_list, listView, false);
        ListView lv = (ListView) listView;
        if (lv.getHeaderViewsCount() == 0) {
            lv.addHeaderView(headerView);
        }
    } else { // GridView, fixed header
        headerView = findViewById(R.id.header_video_list);
    }

    /**  Responsive layout stuff 
     * 
     *  Based on screen width, we will find either
     *   narrow
     *     a listview with a header view
     *     items are a thumbnail to the left and a title on white space to the right.
     *     header is a thumbnail with overlaid title across the bottom
     * 
     *   middle
     *     a fixed header on top and a grid view below
     *     header is thumb to left, title above scrolling description to right
     *     items are thumbs with title overlaid across the bottom (3 across)
     *   
     *   wide
     *     a fixed header to the left and a grid view on the right
     *     header is thumb on top, title next, description at bottom
     *     items are thumbs with title overlaid across the bottom (3 across)
     *  
     *  
     *  So in this class, we 
     *    find view by id 'list'
     *    if it's a ListView, inflate and attach header view
     *    if not, then the header is fixed and already in the layout
     *    either way, now we can find header views by id
     *    adapter is the same either way
     *  
     *  
     *  
     *  **/

    ActionBar ab = getActionBar();
    displayOptionsAdapter = new ArrayAdapter<String>(getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1, displayOptions);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle("");
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ab.setListNavigationCallbacks(displayOptionsAdapter, navListener);
    ab.setSelectedNavigationItem(isShowingDownloadedVideosOnly ? 1 : 0);

    requestDataService(new ObjectCallback<KADataService>() {
        @Override
        public void call(KADataService dataService) {
            VideoListActivity.this.dataService = dataService;

            if (topicId != null) {
                Dao<Topic, String> topicDao;
                try {
                    topicDao = dataService.getHelper().getTopicDao();
                    topic = topicDao.queryForId(topicId);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e(LOG_TAG, "Topic id not set for video list");
                topic = dataService.getRootTopic();
                topicId = topic.getId();
            }

            thumbnailManager = dataService.getThumbnailManager();
            api = dataService.getAPIAdapter();
            api.registerUserUpdateListener(userUpdateListener);

            // This instead happens in ActionBar.OnNavigationListener#onNavigationItemSelected, which
            // fires after onResume.
            //            setParentTopic(topic);
        }
    });

    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_LIBRARY_UPDATE);
    filter.addAction(ACTION_BADGE_EARNED);
    filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED);
    filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE);
    filter.addAction(ACTION_TOAST);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
    thumbExecutor = Executors.newSingleThreadExecutor();
}

From source file:com.witmob.nocollapsetabs.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 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();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent./*from w ww .  j  ava 2s.co m*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.

    // 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));
    }
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}

From source file:com.decad3nce.aegis.AegisActivity.java

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

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);//w w w  .j ava  2 s .c o m
    setContentView(mViewPager);

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

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.alarm_section), SMSAlarmFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.lock_section), SMSLockFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.wipe_section), SMSWipeFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.locate_section), SMSLocateFragment.class, null);
    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    alarmEnabled = preferences.getBoolean(PREFERENCES_ALARM_ENABLED,
            this.getResources().getBoolean(R.bool.config_default_alarm_enabled));
    wipeEnabled = preferences.getBoolean(PREFERENCES_WIPE_ENABLED,
            this.getResources().getBoolean(R.bool.config_default_wipe_enabled));
    lockEnabled = preferences.getBoolean(PREFERENCES_LOCK_ENABLED,
            this.getResources().getBoolean(R.bool.config_default_lock_enabled));
    locateEnabled = preferences.getBoolean(PREFERENCES_LOCATE_ENABLED,
            this.getResources().getBoolean(R.bool.config_default_locate_enabled));

    invalidateOptionsMenu();

    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
}