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.inc.playground.playground.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();/*from w ww  .  j  a va  2  s.c  om*/
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(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().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });

    /*Setting button*/
    LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    ll_Setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this,
                    com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class);
            startActivity(iv);
            finish();
        }
    });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if (currentUser == null) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playground.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

From source file:org.tunesremote.LibraryBrowseActivity.java

@SuppressLint("NewApi")
@Override//ww  w  . ja v  a2s . c  om
public void onCreate(Bundle saved) {
    super.onCreate(saved);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (this.prefs.getBoolean(this.getString(R.string.pref_fullscreen), true)
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    setContentView(R.layout.act_browse_library);

    artists = new ArtistsListFragment();
    albums = new AllAlbumsListFragment();
    playlists = new PlaylistsFragment();

    isTablet = findViewById(R.id.frame_artists) != null;

    if (!isTablet) {

        (pager = (ViewPager) findViewById(R.id.view_pager))
                .setAdapter(new LibraryPagerAdapter(getSupportFragmentManager()));
        pager.setOnPageChangeListener(this);
        pager.setOffscreenPageLimit(2);
        findViewById(R.id.tab_artists).setSelected(true);

    } else {

        getSupportFragmentManager().beginTransaction().add(R.id.frame_artists, artists)
                .add(R.id.frame_albums, albums).add(R.id.frame_playlists, playlists).commit();
        registerListener(artists, albums, playlists);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        handler = new TabHandler();
        ActionBar ab = getActionBar();
        ab.setTitle(R.string.control_menu_library);

        if (!isTablet) {
            findViewById(R.id.legacy_tabs).setVisibility(View.GONE);
            ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            Tab artTab = ab.newTab().setText(R.string.control_menu_artists).setTabListener(handler);
            Tab albTab = ab.newTab().setText(R.string.control_menu_albums).setTabListener(handler);
            Tab plyTab = ab.newTab().setText(R.string.control_menu_playlists).setTabListener(handler);
            ab.addTab(artTab);
            ab.addTab(albTab);
            ab.addTab(plyTab);
        }

    }

}

From source file:ru.lizaalert.hotline.ui.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();
    assert actionBar != null;
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from  w ww.ja v a  2  s  .c  o  m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            if (position == 1) {
                if (getCurrentFocus() != null) {
                    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                            INPUT_METHOD_SERVICE);
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }

        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.jigarmjoshi.MainActivity.java

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

    if (SimpleDatabaseUtil.isFirstApplicationStart(this)) {
        Log.i(MainActivity.class.getSimpleName(), "creating database for the first time");
        SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION);
        databaseSimple.create(Report.class, LastLocation.class);
    } else if (SimpleDatabaseUtil.isFirstStartOnAppVersion(this, DATABASE_VERSION)) {
        Log.i(MainActivity.class.getSimpleName(),
                "creating database for the first time for this version " + DATABASE_VERSION);

        SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION);
        databaseSimple.create(Report.class, LastLocation.class);

    }/*from w  ww.jav  a  2s.  c  o  m*/
    // initialize services
    EntryDao.getInstance(this);
    LastLocationDao.getInstance(this);

    // scheduler
    mgr = (AlarmManager) getSystemService(ALARM_SERVICE);

    Intent i = new Intent(this, LocationPoller.class);
    com.jigarmjoshi.service.LocationManager locationManager = com.jigarmjoshi.service.LocationManager
            .getInstance(getApplicationContext());
    List<String> providers = locationManager.getAllProviders();
    boolean fusedSupported = false;
    for (String provider : providers) {
        if (com.jigarmjoshi.service.LocationManager.FUSED_PROVIDER.equals(provider)) {
            fusedSupported = true;
            break;
        }
    }
    i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, com.jigarmjoshi.reciever.LocationReceiver.class));
    i.putExtra(LocationPoller.EXTRA_PROVIDER,
            (fusedSupported ? LocationManager.FUSED_PROVIDER : LocationManager.GPS_PROVIDER));

    pi = PendingIntent.getBroadcast(this, 0, i, 0);
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0,
            Long.parseLong(ConfigService.get(ConfigService.GPS_TASK_INTERVAL, "40000")), pi);

    // upload task
    Timer timer = new Timer();
    TimerTask timerTask = new UploaderTask(this);
    timer.schedule(timerTask, 0,
            Long.parseLong(ConfigService.get(ConfigService.UPLOAD_TASK_INTERVAL, "40000")));

    selectedTextView = new TextView(this);
    selectedTextView.setTextColor(Color.BLACK);
    selectedTextView.setGravity(Gravity.CENTER);
    selectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);

    unSelectedTextView = new TextView(this);
    unSelectedTextView.setTextColor(Color.GRAY);
    unSelectedTextView.setGravity(Gravity.CENTER);
    unSelectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
    // create if first time

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080")));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080")));
    setContentView(R.layout.activity_main);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    boolean first = false;
    for (String tab_name : tabs) {
        Tab tab = actionBar.newTab().setText(tab_name).setTabListener(this);
        if (first) {
            first = false;
            selectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault()));
            tab.setCustomView(selectedTextView);
        } else {
            unSelectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault()));
            tab.setCustomView(unSelectedTextView);
        }
        actionBar.addTab(tab);
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
        }

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

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
    Toast.makeText(this, getString(R.string.wait_gps), Toast.LENGTH_LONG).show();
}

From source file:com.numberx.kkmctimer.DeskClock.java

private void createTabs(int selectedIndex) {
    mActionBar = getActionBar();/*from ww  w.j av a  2s .c o m*/

    if (mActionBar != null) {
        mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mAlarmTab = mActionBar.newTab();
        mAlarmTab.setIcon(R.drawable.alarm_tab);
        mAlarmTab.setContentDescription(R.string.menu_alarm);
        mTabsAdapter.addTab(mAlarmTab, AlarmClockFragment.class, ALARM_TAB_INDEX);

        mClockTab = mActionBar.newTab();
        mClockTab.setIcon(R.drawable.clock_tab);
        mClockTab.setContentDescription(R.string.menu_clock);
        mTabsAdapter.addTab(mClockTab, ClockFragment.class, CLOCK_TAB_INDEX);

        mTimerTab = mActionBar.newTab();
        mTimerTab.setIcon(R.mipmap.ic_notification);
        mTimerTab.setContentDescription(R.string.menu_timer);
        mTabsAdapter.addTab(mTimerTab, TimerFragment.class, TIMER_TAB_INDEX);

        //mStopwatchTab = mActionBar.newTab();
        //mStopwatchTab.setIcon(R.drawable.stopwatch_tab);
        //mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
        //mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class,STOPWATCH_TAB_INDEX);

        mActionBar.setSelectedNavigationItem(selectedIndex);
        mTabsAdapter.notifySelectedPage(selectedIndex);

        forceTabsInActionBar(mActionBar);
    }
}

From source file:de.da_sense.moses.client.WelcomeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(LOG_TAG, "onCreate() called");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    thisInstance = this;

    mAppSectionsPagerAdapter = new WelcomeActivityPagerAdapter(getSupportFragmentManager(), this);

    // get ActionBar and set NavigationMode
    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//  w  ww . ja v a2s. com
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

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

    // Moses got called to view a UserStudy
    boolean isShowUserStudyCall = getIntent()
            .getStringExtra(ViewUserStudyActivity.EXTRA_USER_STUDY_APK_ID) != null;

    if (isShowUserStudyCall) {
        onLoginCompleteShowUserStudy = getIntent()
                .getStringExtra(ViewUserStudyActivity.EXTRA_USER_STUDY_APK_ID);
    }

    if (!isLoginInformationComplete(this) && !waitingForResult) {
        // Here, the activity is called to display the login screen, and,
        // when filled in, redirect the user to the user study that was
        // meant to be displayed originally
        waitingForResult = true;
        // set flag that on login credentials arrival show a user study

        // set the deviceID in the SharedPreferences before attempting to
        // login
        String theDeviceID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
        PreferenceManager.getDefaultSharedPreferences(this).edit()
                .putString(MosesPreferences.PREF_DEVICEID, theDeviceID).commit();
        Intent loginDialog = new Intent(WelcomeActivity.this, LoginActivity.class);
        startActivityForResult(loginDialog, 1);
    }

    if (HistoryExternalApplicationsManager.getInstance() == null) {
        HistoryExternalApplicationsManager.init(this);
    }
    if (InstalledExternalApplicationsManager.getInstance() == null) {
        InstalledExternalApplicationsManager.init(this);
    }
    if (UserstudyNotificationManager.getInstance() == null) {
        UserstudyNotificationManager.init(this);
    }

    // initialize the UI elements
    initControls(savedInstanceState);

}

From source file:com.embeddedlog.LightUpDroid.DeskClock.java

private void createTabs(int selectedIndex) {
    mActionBar = getActionBar();/*from   w  ww .  j  a v  a 2 s.c  o  m*/

    if (mActionBar != null) {
        mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mAlarmTab = mActionBar.newTab();
        mAlarmTab.setIcon(R.drawable.alarm_tab);
        mAlarmTab.setContentDescription(R.string.menu_alarm);
        mTabsAdapter.addTab(mAlarmTab, AlarmClockFragment.class, ALARM_TAB_INDEX);

        mClockTab = mActionBar.newTab();
        mClockTab.setIcon(R.drawable.clock_tab);
        mClockTab.setContentDescription(R.string.menu_clock);
        mTabsAdapter.addTab(mClockTab, ClockFragment.class, CLOCK_TAB_INDEX);

        //mTimerTab = mActionBar.newTab();
        //mTimerTab.setIcon(R.drawable.timer_tab);
        //mTimerTab.setContentDescription(R.string.menu_timer);
        //mTabsAdapter.addTab(mTimerTab, TimerFragment.class, TIMER_TAB_INDEX);

        //mStopwatchTab = mActionBar.newTab();
        //mStopwatchTab.setIcon(R.drawable.stopwatch_tab);
        //mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
        //mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class,STOPWATCH_TAB_INDEX);

        mActionBar.setSelectedNavigationItem(selectedIndex);
        mTabsAdapter.notifySelectedPage(selectedIndex);

        forceTabsInActionBar(mActionBar);
    }
}

From source file:ca.mymenuapp.ui.activities.MainActivity.java

/** Setup the tabs to display our fragments. */
private void setupTabs(int tab) {
    DelegateOnPageChangeListener delegateOnPageChangeListener = new DelegateOnPageChangeListener();
    viewPager.setOnPageChangeListener(delegateOnPageChangeListener);

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    SwipeableActionBarTabsAdapter tabsAdapter = new SwipeableActionBarTabsAdapter(this, viewPager,
            delegateOnPageChangeListener);
    tabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.map)), RestaurantsMapFragment.class, null);
    tabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.specials)), SpecialsGridFragment.class,
            null);/* w ww .j a v a 2  s .  co m*/
    if (!userPreference.get().isGuest()) {
        tabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.dietary_preferences)),
                DietaryPreferencesFragment.class, null);
        tabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.settings)), SettingsFragment.class,
                null);
    }
    actionBar.setSelectedNavigationItem(tab);

    delegateOnPageChangeListener.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == 0) {
                // Enable user to slide the drawer layout
                drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
                drawerToggle.setDrawerIndicatorEnabled(true);
                getActionBar().setDisplayHomeAsUpEnabled(true);
                getActionBar().setHomeButtonEnabled(true);
            } else {
                // Disable user from sliding the drawer layout
                drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                drawerToggle.setDrawerIndicatorEnabled(false);
                getActionBar().setDisplayHomeAsUpEnabled(false);
                getActionBar().setHomeButtonEnabled(false);
            }
        }

        @Override
        public void onPageSelected(int position) {
            // ignore
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            // ignore
        }
    });
}

From source file:capsrock.beta.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    timeSheet = new TimeSheet();
    PebbleData = new PebbleDictionary();
    //Set up to Receive messages from the pebble and handle them correctly
    PebbleKit.registerReceivedDataHandler(this, new PebbleKit.PebbleDataReceiver(PEBBLE_APP_UUID) {
        @Override// www.  j a v  a2s  .  c o  m
        public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
            String mode = data.getString(1);
            //((TextView)findViewById(R.id.pebbleText)).setText(mode);
            if (mode.substring(9).equals("Break") || mode.substring(9).equals("Work")) {
                ((TimeEntryFragment) getSupportFragmentManager()
                        .findFragmentByTag("android:switcher:" + R.id.pager + ":0"))
                                .onTimeEntry(findViewById(R.id.StartButton), false);
            } else {
                ((TimeEntryFragment) getSupportFragmentManager()
                        .findFragmentByTag("android:switcher:" + R.id.pager + ":0"))
                                .onTimeEntry(findViewById(R.id.StopButton), false);
            }
            PebbleKit.sendAckToPebble(getApplicationContext(), transactionId);
        }
    });
    //Set up the timer thread
    thr = new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            Message mes = new Message();
                            if (strDate != null) {
                                long seconds = Calendar.getInstance().getTimeInMillis()
                                        - strDate.getTimeInMillis();
                                long minutes = seconds / 1000 / 60;
                                minutes %= 60;

                                long hours = seconds / 1000 / 60 / 60;
                                hours %= 24;

                                seconds /= 1000;
                                seconds %= 60;

                                String sec = hours + ":" + minutes + ":" + seconds;
                                mes.obj = sec;
                                mHandler.sendMessage(mes);
                            } else {
                                mes.obj = "00:00:00";
                                mHandler.sendMessage(mes);
                            }
                        }
                    });
                } catch (Exception e) {

                }
            }
        }
    });

    //Start Login Screen
    Intent intent = new Intent();
    intent.setClassName("capsrock.beta", "capsrock.beta.LoginActivity");
    //startActivity(intent);
    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();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.

    // 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++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

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

    startSettingsActivityIfNoDeviceIdSet();

    setContentView(R.layout.main_activity_layout);

    boolean showProgressDialog = false;

    /*/*from  w  w  w. j a v  a 2s  .  c om*/
     * Old Activity is recreated and the Activity has not been removed from
     * memory. The latter part is important because if it was, we have to
     * abort any ongoing refresh.
     */
    if ((savedInstanceState != null) && (refreshBg != null)) {
        curPodSync = new AtomicInteger(savedInstanceState.getInt(KEY_CUR_POD_SYNC, 0));
        numPodSync = new AtomicInteger(savedInstanceState.getInt(KEY_NUM_POD_SYNC, -1));
        showProgressDialog = savedInstanceState.getBoolean(KEY_SHOW_PROGRESS_DIALOG, false);
    } else {
        podcastHandler = new PodcastHandler();
        feedHandler = new FeedHandler();
        episodeActionHandler = new EpisodeActionHandler();
    }

    if (refreshBg == null) {
        refreshBg = Executors.newSingleThreadExecutor();
    }

    MediaPlayerNotification.create(this, false, null);

    // 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 action bar.
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

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

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

    /* Ready the progress dialog */
    progressDialog = new ProgressDialog(this);
    prepareProgressDialog();
    if ((numPodSync.get() != -1) && showProgressDialog) {
        progressDialog.show();
    }

    playlistDAO = Singletons.i().getPlaylistDAO();
}