Example usage for android.app ActionBar newTab

List of usage examples for android.app ActionBar newTab

Introduction

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

Prototype

@Deprecated
public abstract Tab newTab();

Source Link

Document

Create and return a new Tab .

Usage

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

@UiThread
void reloadTabs() {
    Map<Integer, Integer> countsForBoxes;
    try {//from  ww  w  .  jav a 2s.co  m
        countsForBoxes = databaseHelper.getCountsForBoxes();
    } catch (SQLException e) {
        activityHelper.showError(e);
        return;
    }

    ActionBar actionBar = getActionBar();
    for (int i = 0; i < Card.BOX_MAX; i++) {
        ActionBar.Tab tab;
        if (actionBar.getTabCount() > i) {
            tab = actionBar.getTabAt(i);
        } else {
            tab = actionBar.newTab().setTag(i).setTabListener(this);
            actionBar.addTab(tab);
        }
        int box = i + 1;
        String label = String.format("BOX%d", box);
        if (i == 0) {
            label = "INBOX";
        }
        if (countsForBoxes.keySet().contains(box)) {
            label += String.format("(%d)", countsForBoxes.get(box));
        }
        tab.setText(label);
    }

    if (!isTabInitialized || isReloadRequired) {
        isTabInitialized = true;
        isReloadRequired = false;
        // TODO: not working
        int index = state.getBox() - 1;
        if (index < 0 || actionBar.getTabCount() < index) {
            index = 0;
        }
        actionBar.getTabAt(index).select();
        loadContents();
    }
}

From source file:com.piusvelte.cloudset.android.CloudSetMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   ww w .ja va  2s . c o m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

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

    SharedPreferences sp = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
    account = sp.getString(PREFERENCE_ACCOUNT_NAME, null);
    deviceId = sp.getLong(PREFERENCE_DEVICE_ID, INVALID_DEVICE_ID);
    setCurrentTab();

    // create the loader for registration, deregistration, and loading
    // devices
    LoaderManager loaderManager = getSupportLoaderManager();
    loaderManager.initLoader(0, null, this);

    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_LOADER_IDS)) {
        loaderIds = savedInstanceState.getIntegerArrayList(EXTRA_LOADER_IDS);
    } else {
        loaderIds = new ArrayList<Integer>();
    }

    for (int i = 0, s = loaderIds.size(); i < s; i++) {
        // reconnect to additional loaders for deregistering additional
        // devices
        loaderManager.initLoader(loaderIds.get(i), null, this);
    }
}

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  ww  w  .  j a va 2 s  . c o 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:com.example.mydemos.view.RingtonePickerActivity.java

private void setViewPager() {
    // need cancel these feature in onCreate
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    //using TabsPageAdapter
    mTabsAdapter = new TabsPageAdapter(this, mViewPager);

    mViewPager.setAdapter(mTabsAdapter);
    mViewPager.setOnPageChangeListener(mTabsAdapter);

    ActionBar actionBar = this.getActionBar();
    Tab tab1 = actionBar.newTab();
    mTabsAdapter.addTab(tab1, TabContentFragment.class, null);
    Tab tab2 = actionBar.newTab();//  w  ww .j ava2 s . c  o  m
    mTabsAdapter.addTab(tab2, TabContentFragment.class, null);
}

From source file:com.lifestats.MainActivity.java

/**
 * onCreate: Setup Tab structure and Action Bar.
 *
 * @param savedInstanceState saved instance state.
 *//*w w w .  j  a  va 2s  . c  om*/
@Override
public void onCreate(Bundle savedInstanceState) {

    /**
     * Routine create view.
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    /**
     * Setup the ViewPager and its Adapter.
     */
    PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setOffscreenPageLimit(0);

    /**
     * Change selected ActionBar title when swipe left or right.
     */
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @SuppressWarnings("ConstantConditions")
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    /**
     * Setup ActionBar displaying the Tab titles.
     */
    final ActionBar actionBar = getActionBar();
    assert actionBar != null;
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    /**
     * Setup TabListener to display the correct tab content.
     */
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            mPager.setCurrentItem(tab.getPosition());
        }

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

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }
    };

    /**
     * Add the actual Tabs to the page.
     * 1. Record activity tab.
     * 2. Show activity tab.
     */
    ActionBar.Tab recordTab = actionBar.newTab();
    recordTab.setText(R.string.recordActivities);
    recordTab.setTabListener(tabListener);
    actionBar.addTab(recordTab);

    ActionBar.Tab showTab = actionBar.newTab();
    showTab.setText(R.string.showActivities);
    showTab.setTabListener(tabListener);
    actionBar.addTab(showTab);

}

From source file:com.example.android.foodstorm.MainActivity.java

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

    dataSource = new FoodSQLiteHelper(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();
    actionBar.setHomeButtonEnabled(false); // no home/up button
    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//  ww w  .ja va 2  s . c  o  m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.fridge_main).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.chef_hat).setTabListener(this));
}

From source file:com.ibm.watson.developer_cloud.android.examples.IBMSpeechToText.java

/** public static class TTSCommands extends AsyncTask<Void, Void, JSONObject> {
        //from   w ww . j  av a 2  s  .  co m
protected JSONObject doInBackground(Void... none) {
        
    return TextToSpeech.sharedInstance().getVoices();
}
 }*/

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

    StorageReference mStorageRef;
    mStorageRef = FirebaseStorage.getInstance().getReference();

    // Strictmode needed to run the http/wss request for devices > Gingerbread
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    //setContentView(R.layout.activity_main);
    setContentView(R.layout.activity_tab_text);

    ActionBar action = getActionBar();
    action.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    tabSTT = action.newTab().setText("Meeting Recorder");
    // tabTTS = actionBar.newTab().setText("Text to Speech");

    tabSTT.setTabListener(new MyTabListener(fragmentTabSTT));
    // tabTTS.setTabListener(new MyTabListener(fragmentTabTTS));

    action.addTab(tabSTT);
    //  actionBar.addTab(tabTTS);

    //actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));
}

From source file:com.piusvelte.mosaic.android.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from ww  w.j  a v a2  s  .c  o  m*/

    pagerAdapter = new MosaicPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    //        actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(pagerAdapter);
    viewPager.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 (int i = 0; i < pagerAdapter.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(pagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.polychrom.cordova.ActionBarPlugin.java

private boolean buildTabs(ActionBar bar, JSONArray definition, String menu_var) {
    try {//from  w  ww  .  jav a 2  s. com
        for (int i = 0; i < definition.length(); ++i) {
            final JSONObject item_def = definition.getJSONObject(i);
            final String text = item_def.isNull("text") ? "" : item_def.getString("text");
            final Drawable icon = item_def.isNull("icon") ? null
                    : getDrawableForURI(item_def.getString("icon"));

            bar.addTab(bar.newTab().setText(text).setIcon(icon)
                    .setTabListener(new TabListener(this, menu_var + "[" + i + "]")));
        }
    } catch (JSONException e) {
        return false;
    }

    return true;
}

From source file:ca.psiphon.ploggy.ActivityMain.java

@Override
protected 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.
    mAppTabsPagerAdapter = new AppTabsPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

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

    // 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(mAppTabsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w w w .j  a  v a 2 s .  c o m
        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);
        }
    });

    actionBar.addTab(actionBar.newTab().setText(R.string.title_self_status_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_friend_list_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_message_list_fragment).setTabListener(this));
    mMessageListTabIndex = 2;

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