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.owo.android.mtPlease.MainActivity.java

@Override
public 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);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // setting for the sidedrawer
    // set the content view
    setBehindContentView(R.layout.drawer_search);
    getSlidingMenu().setFadeEnabled(true);
    getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
    getSlidingMenu().setShadowDrawable(R.drawable.shadow);
    getSlidingMenu().setFadeDegree(0.90f);

    searchDrawerCloseButton = (ImageButton) findViewById(R.id.button_search_drawer_close);
    searchDrawerCloseButton.setOnClickListener(new OnClickListener() {

        @Override/*from  w w  w . j av a2 s.co m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            getSlidingMenu().showContent();
        }

    });

    // 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
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    //         
    mViewPager.setOffscreenPageLimit(3);

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

    locationSelectSpinner = (Spinner) findViewById(R.id.spinner_location);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.location_array,
            R.layout.spinner_text);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    locationSelectSpinner.setAdapter(adapter);

    datePickerButton = (Button) findViewById(R.id.button_datepicker);
    datePickerButton.setText(modifiedDate);
    datePickerButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            FragmentManager dialogManager = getFragmentManager();
            CalendarDialogFragment calendarDialogFragment = new CalendarDialogFragment();
            calendarDialogFragment.setParentCaller(CalendarDialogFragment.PARENT_IS_ACTIVITY);
            calendarDialogFragment.show(dialogManager, "calendar_dialog_popped");
        }

    });
    // Activity    emailAddress(SESSION_ID)  MyPageFragment
    // .

    //    
    searchButton = (ImageButton) findViewById(R.id.imageButton_search);
    searchButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                String region = locationSelectSpinner.getSelectedItem().toString();
                if (region.equals("")) {
                    region = "1";
                } else if (region.equals("")) {
                    region = "2";
                } else {
                    region = "3";
                }

                String people = ((EditText) findViewById(R.id.editText_numberPeople)).getText().toString();

                String[] tmp = (datePickerButton.getText().toString()).split(" ");
                String date = tmp[0].substring(0, 4) + "-" + tmp[1].split("")[0] + "-"
                        + tmp[2].split("")[0];

                String query = "?region=" + region + "&people=" + people + "&date=" + date + "&flag=1";
                sendInfoToFragment(people, 2);
                sendInfoToFragment(query, 0);

                getSlidingMenu().showContent();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                Toast.makeText(getApplicationContext(), "  ", Toast.LENGTH_SHORT);
                e.printStackTrace();
            }
        }

    });

}

From source file:com.codebutler.farebot.activity.CardInfoActivity.java

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

    setContentView(R.layout.activity_card_info);
    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabPagerAdapter(this, viewPager);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.loading);

    new AsyncTask<Void, Void, Void>() {
        private Exception mException;
        public boolean mSpeakBalanceEnabled;

        @Override// ww  w .ja  v a  2  s  . co  m
        protected Void doInBackground(Void... voids) {
            try {
                Uri uri = getIntent().getData();
                Cursor cursor = getContentResolver().query(uri, null, null, null, null);
                startManagingCursor(cursor);
                cursor.moveToFirst();

                String data = cursor.getString(cursor.getColumnIndex(CardsTableColumns.DATA));

                mCard = Card.fromXml(FareBotApplication.getInstance().getSerializer(), data);
                mTransitData = mCard.parseTransitData();

                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CardInfoActivity.this);
                mSpeakBalanceEnabled = prefs.getBoolean("pref_key_speak_balance", false);
            } catch (Exception ex) {
                mException = ex;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            findViewById(R.id.loading).setVisibility(View.GONE);
            findViewById(R.id.pager).setVisibility(View.VISIBLE);

            if (mException != null) {
                if (mCard == null) {
                    Utils.showErrorAndFinish(CardInfoActivity.this, mException);
                } else {
                    Log.e("CardInfoActivity", "Error parsing transit data", mException);
                    showAdvancedInfo(mException);
                    finish();
                }
                return;
            }

            if (mTransitData == null) {
                showAdvancedInfo(new UnsupportedCardException());
                finish();
                return;
            }

            String titleSerial = (mTransitData.getSerialNumber() != null) ? mTransitData.getSerialNumber()
                    : Utils.getHexString(mCard.getTagId(), "");
            actionBar.setTitle(mTransitData.getCardName() + " " + titleSerial);

            Bundle args = new Bundle();
            args.putString(AdvancedCardInfoActivity.EXTRA_CARD,
                    mCard.toXml(FareBotApplication.getInstance().getSerializer()));
            args.putParcelable(EXTRA_TRANSIT_DATA, mTransitData);

            if (mTransitData instanceof UnauthorizedClassicTransitData) {
                mTabsAdapter.addTab(actionBar.newTab(), UnauthorizedCardFragment.class, args);
                return;
            }

            if (mTransitData.getBalanceString() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.balance), CardBalanceFragment.class,
                        args);
            }

            if (mTransitData.getTrips() != null || mTransitData.getRefills() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.history), CardTripsFragment.class,
                        args);
            }

            if (mTransitData.getSubscriptions() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.subscriptions),
                        CardSubscriptionsFragment.class, args);
            }

            if (mTransitData.getInfo() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.info), CardInfoFragment.class, args);
            }

            if (mTabsAdapter.getCount() > 1) {
                actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            }

            if (mTransitData.hasUnknownStations()) {
                findViewById(R.id.need_stations).setVisibility(View.VISIBLE);
            }

            boolean speakBalanceRequested = getIntent().getBooleanExtra(SPEAK_BALANCE_EXTRA, false);
            if (mSpeakBalanceEnabled && speakBalanceRequested) {
                mTTS = new TextToSpeech(CardInfoActivity.this, mTTSInitListener);
            }

            if (savedInstanceState != null) {
                viewPager.setCurrentItem(savedInstanceState.getInt(KEY_SELECTED_TAB, 0));
            }
        }
    }.execute();
}

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)) {/*from  ww  w .  j  a  va  2s.c  o 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:com.example.android.bluepayandroidsdk.MainActivity.java

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

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();

    actionBar.setHomeButtonEnabled(false);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   ww  w .  j  av  a 2s . c om*/
        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 < mAppSectionsPagerAdapter.getCount(); i++) {
        if (i == 0) {
            actionBar.addTab(actionBar.newTab().setText("Run Payment").setTabListener(this));
        } else if (i == 1) {
            actionBar.addTab(actionBar.newTab().setText("Store Token").setTabListener(this));
        } else if (i == 2) {
            actionBar.addTab(actionBar.newTab().setText("Swipe Card").setTabListener(this));
        } else {
            actionBar.addTab(
                    actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        }
    }

}

From source file:app.screen.MyActivity.java

/**
 * For more info on using view pager and tabs and action bar, <a href="http://goo.gl/7CsM9">checkout this article</a>
 * in the Android developer site's "Training" section.
 * <p/>// w ww . j ava2 s.c om
 * For more info on ViewPager, <a href="http://goo.gl/NgCUO">read this article</a>.
 */
private void _setupFragments() {
    // set up the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // create the FragmentPagerAdapter
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            try {
                return Fragments.values()[position].aClass.getConstructor(MyActivity.class)
                        .newInstance(MyActivity.this);
            } catch (Exception e) {
                AndroidUtils.logErr(IconPaths.MyApp, "MyActivity - problem creating fragments", e);
                // something has gone wrong - this shouldn't happen
                return new Fragment() {
                    /** make a fragment to house {@link R.layout#error_fragment} */
                    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
                        return super.onCreateView(inflater, container, savedInstanceState);
                    }
                };
            }
        }

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

        public CharSequence getPageTitle(int position) {
            try {
                return Fragments.values()[position].title;
            } catch (Exception e) {
                return "N/A";
            }
        }
    };

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setOffscreenPageLimit(Fragments.values().length); // keep all the pages in memory
    viewPager.setAdapter(fragmentPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        /**
         * 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.
         */
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // create TabListener
    ActionBar.TabListener tabListener = new

    ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction transaction) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction transaction) {
        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction transaction) {
        }
    };

    // setup tabs
    for (int i = 0; i < fragmentPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(fragmentPagerAdapter.getPageTitle(i)).setTabListener(tabListener));
    }

}

From source file:com.idevity.card.read.ReadMain.java

/**
 * Method onCreate.//from w w  w  .j  a v a  2 s . c o  m
 * 
 * @param savedInstanceState
 *            Bundle
 */
@TargetApi(19)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_main);

    /*
     * We will take over the NFC Interface while in the foreground so there
     * is no additional read attempt.
     * 
     * If on KitKat, we will set a filter and ignore any callbacks.
     */
    /****************** Initialize NFC ******************/
    if (debug) {
        Log.d(TAG, "Getting Adaptor...");
    }
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
    /*
     * Platform version specific handling: KitKat
     */
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (debug) {
            Log.d(TAG, "Setting Adaptor up for KitKat");
        }
        ReaderCallback listener = new ReaderCallback() {
            public void onTagDiscovered(Tag tag) {
                /*
                 * Discard the tags here
                 */
                tag = null;
            }
        };
        int flags = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK
                | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS;
        adapter.enableReaderMode(this, listener, flags, null);
    }

    // Get preferences / settings that have been saved
    // get the show log

    this.sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean showLog = this.sharedPref.getBoolean(g.getShowLog(), false);

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

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

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

    /*
     * Use the following to determine content to show in the tabs. First,
     * check to see if there is an active intent Also, check to see if there
     * is an active saved instance state If, active intent - use active
     * intent; if active intent = null, and saved instance state !null, use
     * saved instance state; else return user to "main" instructions
     */
    boolean hasIntent = false;
    boolean hasSavedData = false;

    try {
        if (getIntent().getExtras().getByteArray(g.getCardData()) != null) {
            hasIntent = true;
        }
    } catch (Throwable e) {
        Log.e(TAG, "Error: intent " + e.getMessage());
    }

    try {
        if (g.getCard() != null) {
            hasSavedData = true;
        }
    } catch (Throwable e) {
        Log.e(TAG, "Error: saved instance state " + e.getMessage());
    }

    // if intent, populate the variables with the intent values
    // else if saved instance, populate the same variables with the saved
    // instance state
    // else return user to read800-73 activity to read a new card

    if (hasIntent) {
        logStringBuffer = getIntent().getExtras().getString(g.getReaderLog());
        byte[] _data = getIntent().getExtras().getByteArray(g.getCardData());
        this.carddata = new CardData80073(_data);
        if (debug) {
            Log.d(TAG, "Using new card data");
        }
        g.putCard(carddata.toByteArray());
        g.putLogData(logStringBuffer);

    } else if (hasSavedData) {
        logStringBuffer = g.getLogData();
        byte[] _data = g.getCard();
        this.carddata = new CardData80073(_data);
        Log.e(TAG, "Using saved card data");
    } else {
        Intent returnuser = new Intent(this, Read80073.class);
        startActivity(returnuser);
        Log.e(TAG, "No card data found; returning user to read a new card.");
    }

    /*
     * For each of the sections in the app, add a tab to the action bar.
     */
    Tab tabA = actionBar.newTab();
    tabA.setText(getString(R.string.TabRead_Title));
    tabA.setTabListener(this);
    actionBar.addTab(tabA);

    // this one will become the CAK tab
    Tab tabB = actionBar.newTab();
    tabB.setText(getString(R.string.TabCert_Title));
    tabB.setTabListener(this);
    actionBar.addTab(tabB);

    // this one will become the CHUID tab
    Tab tabC = actionBar.newTab();
    tabC.setText(getString(R.string.TabChuid_Title));
    tabC.setTabListener(this);
    actionBar.addTab(tabC);

    // this one will become the APDU log tab
    // only set up the tab is the preferences for Show Log = True

    if (showLog) {
        Tab tabD = actionBar.newTab();
        tabD.setText(getString(R.string.TabLog_Title));
        tabD.setTabListener(this);
        actionBar.addTab(tabD);
    }
}

From source file:se.dxapps.generic.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getActionBar();
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    mTitle = mDrawerTitle = getTitle();//from w  w w .  jav a  2  s  . c  o m
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    //        if (savedInstanceState == null) {
    //            selectItem(0);
    //        }

    //ViewPager stuff. 

    // 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.example.android.cardreader.MainActivity.java

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

    //TODO Stop Executing Eden
    //Globals.executeEden();
    getUsers(1);/*from   w w w  .jav  a2  s  .c om*/

    instance = this;
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle("           TartanHacks");
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
    actionBar.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg));
    actionBar.setDisplayShowHomeEnabled(true);

    frags.add(new PersonListFrag(Globals.pending));
    frags.add(new PersonListFrag(Globals.allUsers));
    frags.add(new PersonListFrag(Globals.checkedIn));

    mAdapter = new FragmentAdapter(getFragmentManager());

    fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View dialogView = View.inflate(instance, R.layout.dialog_signup, null);

            idField = (EditText) dialogView.findViewById(R.id.andrewIdField);
            pb = (ProgressBar) dialogView.findViewById(R.id.progress);
            nameField = (TextView) dialogView.findViewById(R.id.name);
            scanView = (TextView) dialogView.findViewById(R.id.scan_view);

            idField.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    String id = s.toString();
                    pb.setVisibility(View.VISIBLE);
                    queryId(id);

                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });

            AlertDialog.Builder builder;
            builder = new AlertDialog.Builder(instance);
            builder.setView(dialogView);
            builder.setCancelable(true);
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    Globals.adding = false;
                }
            });

            signupDialog = builder.show();
        }
    });

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(0);
    mViewPager.setAdapter(mAdapter);
    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);
        }
    });

    actionBar.addTab(actionBar.newTab().setText("Pending").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("All").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Checked In").setTabListener(this));

    mLoyaltyCardReader = new LoyaltyCardReader(this);

    // Disable Android Beam and register our card reader callback
    enableReaderMode();

    new UpdateThread().executeOnExecutor(Executors.newSingleThreadExecutor());
}

From source file:com.wbrenna.gtfsoffline.MainActivity.java

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

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    }//from w w  w. jav  a 2s .c o  m

    mProgress = (ProgressBar) findViewById(R.id.progress);

    //read in the preferences
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    Set<String> emptyString = new HashSet<String>();
    emptyString.clear();

    Set<String> initial_preferences = mPrefs.getStringSet(getString(R.string.pref_dbs), emptyString);
    mDBListPrefsOld = initial_preferences;

    //this is the list of currently checked databases
    String[] tmpDBActive = initial_preferences.toArray(new String[initial_preferences.size()]);

    //we have to be careful to exclude databases that aren't in our directory
    dbHelper = new DatabaseHelper(this);
    dbHelper.gatherFiles();
    mDBList = dbHelper.GetListofDB();
    List<String> workingDBList = new ArrayList<String>();

    for (int i = 0; i < tmpDBActive.length; i++) {
        if (mDBList.contains(tmpDBActive[i])) {
            workingDBList.add(tmpDBActive[i]);
        } else {
            initial_preferences.remove(tmpDBActive[i]);
        }
    }
    if (workingDBList.size() == 0) {
        mDBActive = null;
    } else {
        mDBActive = workingDBList.toArray(new String[workingDBList.size()]);
    }

    Editor prefsDBEditor = mPrefs.edit();
    prefsDBEditor.putStringSet(getString(R.string.pref_dbs), initial_preferences);
    prefsDBEditor.commit();

    //Set up the location management
    mLocationHelper = new LocationHelper(this);
    mLocation = mLocationHelper.startLocationManager();

    // Define a listener that responds to location updates
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (mLocationHelper.isBetterLocation(location, mLocation)) {
                mLocation = location;
                if (mLocation != null) {
                    //new ProcessBusStops().execute();
                    mSectionsPagerAdapter.notifyDataSetChanged();

                } else {
                    Toast.makeText(getBaseContext(), R.string.last_location_fix, Toast.LENGTH_LONG).show();
                    //Log.e(TAG, "No more location fixes ");
                }
            }
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }
    };

    //TODO: eventually add automated downloading of databases...

    // Create the adapter that will return a fragment for each of the
    // 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.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++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

}

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

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getApplicationContext();// www. java2s  . com

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (mBluetoothAdapter.isEnabled()) {
        mChatService = new BluetoothChatService(this, mHandler);
    }

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();

    assert actionBar != null;
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (B) {
                B = false;
                Toast.makeText(MainActivity.this, "Round theme cancelled", Toast.LENGTH_SHORT).show();
            }

            if (position == 0) {
            }
            if (position == 1) {
                updatespinner();
                setupChat();
            }
            if (position == 2) {

            }
            if (position == 3) {
                setupGroupMode();
            }
            actionBar.setSelectedNavigationItem(position);
        }
    });

    /*for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
            
    actionBar.addTab(actionBar.newTab()
            .setText(mAppSectionsPagerAdapter.getPageTitle(i))
            .setTabListener(this));
    }*/
    actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(0)).setTabListener(this)
            .setIcon(R.drawable.btn_group_control_icon));
    actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(1)).setTabListener(this)
            .setIcon(R.drawable.btn_light_control_icon));
    actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(2)).setTabListener(this)
            .setIcon(R.drawable.btn_group_configure_icon));
    actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(3)).setTabListener(this)
            .setIcon(R.drawable.btn_sceario_control_icon));
}