Example usage for android.app ActionBar setDisplayHomeAsUpEnabled

List of usage examples for android.app ActionBar setDisplayHomeAsUpEnabled

Introduction

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

Prototype

public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);

Source Link

Document

Set whether home should be displayed as an "up" affordance.

Usage

From source file:com.guayaba.tapir.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}//from   w  w w. j  a v  a2 s. co  m
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialze the theme resources
    mResources = new ThemeUtils(this);
    // Set the overflow style
    mResources.setOverflowStyle(this);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = ApolloUtils.getImageFetcher(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    final ActionBar actionBar = getActionBar();
    mResources.themeActionBar(actionBar, getString(R.string.app_name));
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();
}

From source file:com.bt.download.android.gui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}/*from  w  w w.ja  va 2s  .  c o  m*/
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = ImageFetcher.getInstance(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    setTitle(R.string.now_playing);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();

    initGestures();
    mPlayPauseButton.setOnLongClickListener(new StopListener(this));
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void setupActionBar() {
    ActionBar bar = getActionBar();
    if (bar != null) {
        bar.setCustomView(R.layout.view_custom_actionbar);
        bar.setDisplayShowCustomEnabled(true);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);//from w w  w  .j a v a 2 s  . c  o m
    }
}

From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/*w  w  w.  ja va 2s.c  o m*/
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mPopupMenuHelper = new PopupMenuHelper(this, getSupportFragmentManager()) {
        private SearchResult mSelectedItem;

        @Override
        public PopupMenuType onPreparePopupMenu(int position) {
            mSelectedItem = mAdapter.getTItem(position);

            return PopupMenuType.SearchResult;
        }

        @Override
        protected long[] getIdList() {
            switch (mSelectedItem.mType) {
            case Artist:
                return MusicUtils.getSongListForArtist(SearchActivity.this, mSelectedItem.mId);
            case Album:
                return MusicUtils.getSongListForAlbum(SearchActivity.this, mSelectedItem.mId);
            case Song:
                return new long[] { mSelectedItem.mId };
            case Playlist:
                return MusicUtils.getSongListForPlaylist(SearchActivity.this, mSelectedItem.mId);
            default:
                return null;
            }
        }

        @Override
        protected long getSourceId() {
            return mSelectedItem.mId;
        }

        @Override
        protected Config.IdType getSourceType() {
            return mSelectedItem.mType.getSourceType();
        }

        @Override
        protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
            super.updateMenuIds(type, set);

            if (mSelectedItem.mType == ResultType.Album) {
                set.add(FragmentMenuItems.MORE_BY_ARTIST);
            }
        }

        @Override
        protected String getArtistName() {
            return mSelectedItem.mArtist;
        }
    };

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Set the layout
    setContentView(R.layout.activity_search);

    // get the input method manager
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Initialize the adapter
    SummarySearchAdapter adapter = new SummarySearchAdapter(this);
    mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter);
    // Set the prefix
    mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
    mAdapter.setupHeaderParameters(R.layout.list_search_header, false);
    mAdapter.setupFooterParameters(R.layout.list_search_footer, true);
    mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
        @Override
        public void onPopupMenuClicked(View v, int position) {
            mPopupMenuHelper.showPopupMenu(v, position);
        }
    });

    mLoadingEmptyContainer = (LoadingEmptyContainer) findViewById(R.id.loading_empty_container);
    // setup the no results container
    NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer();
    noResults.setMainText(R.string.empty_search);
    noResults.setSecondaryText(R.string.empty_search_check);

    initListView();

    // setup handler and runnable
    mHandler = new Handler();
    mLoadingRunnable = new Runnable() {
        @Override
        public void run() {
            setState(VisibleState.Loading);
        }
    };

    // Theme the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Get the query String
    mFilterString = getIntent().getStringExtra(SearchManager.QUERY);

    // if we have a non-empty search string, this is a 2nd lvl search
    if (!TextUtils.isEmpty(mFilterString)) {
        mTopLevelSearch = false;

        // get the search type to filter by
        int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1);
        if (type >= 0 && type < ResultType.values().length) {
            mSearchType = ResultType.values()[type];
        }

        int resourceId = 0;
        switch (mSearchType) {
        case Artist:
            resourceId = R.string.search_title_artists;
            break;
        case Album:
            resourceId = R.string.search_title_albums;
            break;
        case Playlist:
            resourceId = R.string.search_title_playlists;
            break;
        case Song:
            resourceId = R.string.search_title_songs;
            break;
        }
        actionBar.setTitle(getString(resourceId, mFilterString).toUpperCase());
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Set the prefix
        mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);

        // Start the loader for the query
        getSupportLoaderManager().initLoader(SEARCH_LOADER, null, this);
    } else {
        mTopLevelSearch = true;
        mSearchHistoryCallback = new SearchHistoryCallback();

        // Start the loader for the search history
        getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback);
    }

    // set the background on the root view
    getWindow().getDecorView().getRootView()
            .setBackgroundColor(getResources().getColor(R.color.background_color));
}

From source file:com.frostwire.android.gui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}/*from   www.j  av a 2 s.  com*/
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = ImageFetcher.getInstance(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    setTitle(R.string.now_playing);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();

    initGestures();
    mPlayPauseButton.setOnLongClickListener(new StopListener(this));

    initSupportFrostWire();
}

From source file:se.liu.tddd77.bilsensor.MainActivity.java

/**
 * The menu consists of two parts, the record button and the settings. 
 * The record button is a checkable button. The settings is the collection 
 * of the other available options. They should all be added through the 
 * XML-file with the definition of the event here in onOptionsItemSelected.
 *//*w w w .  ja v a2  s . c  om*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    View view = getLayoutInflater().inflate(R.layout.actionbar, null);
    actionBar.setCustomView(view);

    final TextView projectName = (TextView) findViewById(R.id.project_name);
    Log.i("MainActivity", "Getting project name");
    Bundle projectnamebundle = getIntent().getExtras();
    projectname = projectnamebundle.getString("Project_name");
    serverIP = projectnamebundle.getString("Server_IP");
    if (projectname == null) {
        Log.i("MainActivity", "Projectname == null");
    } else {
        Log.i("MainActivity", "Projectname != null");
    }
    Log.i("MainActivity", projectname);
    projectName.setText(projectname);

    final ImageButton button = (ImageButton) findViewById(R.id.recButton);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            handleRecord(button);
        }
    });
    /*   final ImageButton playButton = (ImageButton) findViewById(R.id.playButton);
       playButton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
    handlePlay(playButton);
          }
       });*/
    final ImageButton buttonMenu = (ImageButton) findViewById(R.id.menuButton);
    buttonMenu.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {
                saveProfile("profil.txt");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    final ImageButton loadMenu = (ImageButton) findViewById(R.id.loadButton);
    loadMenu.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //try {
            //SelectViewNameDialog dialog = new SelectViewNameDialog(avb);
            //dialog.show(getFragmentManager(), null);
            try {
                loadProfile("profil.txt");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (BackendError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    //playButton.setMaxWidth(playButton.getHeight());

    return super.onCreateOptionsMenu(menu);
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

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

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        this.account = new AccountsRegistry(this).getAccount(extras.getInt("selected_account"));
    } else {//from w w  w . jav a 2  s.c o m
        this.account = Simplified.getCurrentAccount();
    }

    final ActionBar bar = this.getActionBar();
    if (android.os.Build.VERSION.SDK_INT < 21) {
        bar.setDisplayHomeAsUpEnabled(false);
        bar.setHomeButtonEnabled(true);
        bar.setIcon(R.drawable.ic_arrow_back);
    } else {
        bar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(false);
    }

    final DocumentStoreType docs = Simplified.getDocumentStore(this.account, getResources());

    final LayoutInflater inflater = NullCheck.notNull(this.getLayoutInflater());

    final FrameLayout content_area = this.getContentFrame();
    final ViewGroup layout = NullCheck
            .notNull((ViewGroup) inflater.inflate(R.layout.settings_account, content_area, false));
    content_area.addView(layout);
    content_area.requestLayout();

    final TextView in_barcode_label = NullCheck.notNull(this.findViewById(R.id.settings_barcode_label));
    final TextView in_barcode_text = NullCheck.notNull(this.findViewById(R.id.settings_barcode_text));
    final TextView in_pin_label = NullCheck.notNull(this.findViewById(R.id.settings_pin_label));
    final ImageView in_barcode_image = NullCheck.notNull(this.findViewById(R.id.settings_barcode_image));
    final TextView in_barcode_image_toggle = NullCheck
            .notNull(this.findViewById(R.id.settings_barcode_toggle_barcode));
    final TextView in_pin_text = NullCheck.notNull(this.findViewById(R.id.settings_pin_text));
    final CheckBox in_pin_reveal = NullCheck.notNull(this.findViewById(R.id.settings_reveal_password));

    if (!this.account.pinRequired()) {
        in_pin_label.setVisibility(View.INVISIBLE);
        in_pin_text.setVisibility(View.INVISIBLE);
        in_pin_reveal.setVisibility(View.INVISIBLE);
    }

    final Button in_login = NullCheck.notNull(this.findViewById(R.id.settings_login));
    final Button in_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup));

    this.sync_switch = findViewById(R.id.sync_switch);
    this.sync_table_row = findViewById(R.id.sync_table_row);
    this.sync_table_row.setVisibility(View.GONE);
    this.advanced_table_row = findViewById(R.id.link_advanced);
    this.advanced_table_row.setVisibility(View.GONE);

    this.advanced_table_row.setOnClickListener(view -> {
        final FragmentManager mgr = getFragmentManager();
        final FragmentTransaction transaction = mgr.beginTransaction();
        final SettingsAccountAdvancedFragment fragment = new SettingsAccountAdvancedFragment();
        transaction.add(R.id.settings_account_container, fragment).addToBackStack("advanced").commit();
    });

    final TableRow in_privacy = findViewById(R.id.link_privacy);
    final TableRow in_license = findViewById(R.id.link_license);

    final TextView account_name = NullCheck.notNull(this.findViewById(android.R.id.text1));
    final TextView account_subtitle = NullCheck.notNull(this.findViewById(android.R.id.text2));

    final ImageView in_account_icon = NullCheck.notNull(this.findViewById(R.id.account_icon));

    in_pin_text.setTransformationMethod(PasswordTransformationMethod.getInstance());
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        this.handle_pin_reveal(in_pin_text, in_pin_reveal);
    } else {
        in_pin_reveal.setVisibility(View.GONE);
    }

    final TableRow in_report_issue = findViewById(R.id.report_issue);

    if (this.account.getSupportEmail() == null) {
        in_report_issue.setVisibility(View.GONE);
    } else {
        in_report_issue.setVisibility(View.VISIBLE);
        in_report_issue.setOnClickListener(view -> {
            final Intent intent = new Intent(this, ReportIssueActivity.class);
            final Bundle b = new Bundle();
            b.putInt("selected_account", this.account.getId());
            intent.putExtras(b);
            startActivity(intent);
        });
    }

    final TableRow in_support_center = findViewById(R.id.support_center);
    if (this.account.supportsHelpCenter()) {
        in_support_center.setVisibility(View.VISIBLE);
        in_support_center.setOnClickListener(view -> {
            final HSHelpStack stack = HSHelpStack.getInstance(this);
            final HSDeskGear gear = new HSDeskGear("https://nypl.desk.com/", "4GBRmMv8ZKG8fGehhA", null);
            stack.setGear(gear);
            stack.showHelp(this);
        });
    } else {
        in_support_center.setVisibility(View.GONE);
    }

    //Get labels from the current authentication document.
    final AuthenticationDocumentType auth_doc = docs.getAuthenticationDocument();
    in_barcode_label.setText(auth_doc.getLabelLoginUserID());
    in_pin_label.setText(auth_doc.getLabelLoginPassword());

    final TableLayout in_table_with_code = NullCheck
            .notNull(this.findViewById(R.id.settings_login_table_with_code));
    in_table_with_code.setVisibility(View.GONE);
    final TableLayout in_table_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup_table));

    //    boolean locationpermission = false;
    //    if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    //      locationpermission = true;
    //    }
    //    else
    //    {
    //      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
    //    }

    if (this.account.supportsCardCreator() || this.account.getCardCreatorUrl() != null) {
        in_table_signup.setVisibility(View.VISIBLE);
    } else {
        in_table_signup.setVisibility(View.GONE);
    }

    in_login.setOnClickListener(v -> this.onLoginWithBarcode());

    final CheckBox in_age13_checkbox = NullCheck.notNull(this.findViewById(R.id.age13_checkbox));

    if (Simplified.getSharedPrefs().contains("age13")) {
        in_age13_checkbox.setChecked(Simplified.getSharedPrefs().getBoolean("age13"));
    } else if (account.getId() == 2) {
        showAgeGateOptionsDialog(in_age13_checkbox);
    }

    in_age13_checkbox.setOnCheckedChangeListener(this::showAgeChangeConfirmation);

    if (this.account.needsAuth()) {
        in_login.setVisibility(View.VISIBLE);
        in_age13_checkbox.setVisibility(View.GONE);
    } else {
        in_login.setVisibility(View.GONE);
        in_age13_checkbox.setVisibility(View.VISIBLE);
    }

    if (this.account.supportsCardCreator()) {
        in_signup.setOnClickListener(v -> {
            final Intent cardcreator = new Intent(this, CardCreatorActivity.class);
            startActivity(cardcreator);
        });
        in_signup.setText(R.string.need_card_button);

    } else if (this.account.getCardCreatorUrl() != null) {
        in_signup.setOnClickListener(v -> {
            final Intent e_card = new Intent(Intent.ACTION_VIEW);
            e_card.setData(Uri.parse(this.account.getCardCreatorUrl()));
            startActivity(e_card);
        });
        in_signup.setText(R.string.need_card_button);
    }

    final boolean permission = Simplified.getSharedPrefs().getBoolean("syncPermissionGranted",
            this.account.getId());
    this.sync_switch.setChecked(permission);

    /*
    If switching on, disable user interaction until server has responded.
    If switching off, disable applicable network requests by updating shared prefs flags.
     */
    this.sync_switch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            buttonView.setEnabled(false);
            annotationsManager.updateServerSyncPermissionStatus(true, (success) -> {
                if (success) {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), true);
                    this.sync_switch.setChecked(true);
                } else {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(),
                            false);
                    this.sync_switch.setChecked(false);
                }
                this.sync_switch.setEnabled(true);
                return kotlin.Unit.INSTANCE;
            });
        } else {
            Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), false);
            this.sync_switch.setChecked(false);
        }
    });

    if (this.account.getPrivacyPolicy() != null) {
        in_privacy.setVisibility(View.VISIBLE);
    } else {
        in_privacy.setVisibility(View.GONE);
    }
    if (this.account.getContentLicense() != null) {
        in_license.setVisibility(View.VISIBLE);
    } else {
        in_license.setVisibility(View.GONE);
    }

    in_license.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getContentLicense(), "Content Licenses",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    in_privacy.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getPrivacyPolicy(), "Privacy Policy",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    this.navigationDrawerSetActionBarTitle();

    this.account_name_text = account_name;
    this.account_subtitle_text = account_subtitle;
    this.account_icon = in_account_icon;
    this.barcode_text = in_barcode_text;
    this.pin_text = in_pin_text;
    this.barcode_image_toggle = in_barcode_image_toggle;
    this.barcode_image = in_barcode_image;
    this.login = in_login;
    this.table_with_code = in_table_with_code;
    this.table_signup = in_table_signup;

    final CheckBox in_eula_checkbox = NullCheck.notNull(this.findViewById(R.id.eula_checkbox));

    final OptionType<EULAType> eula_opt = docs.getEULA();

    if (eula_opt.isSome()) {
        final Some<EULAType> some_eula = (Some<EULAType>) eula_opt;
        final EULAType eula = some_eula.get();

        in_eula_checkbox.setChecked(eula.eulaHasAgreed());
        in_eula_checkbox.setEnabled(true);
        in_eula_checkbox.setOnCheckedChangeListener((button, checked) -> eula.eulaSetHasAgreed(checked));

        if (eula.eulaHasAgreed()) {
            LOG.debug("EULA: agreed");
        } else {
            LOG.debug("EULA: not agreed");
        }
    } else {
        LOG.debug("EULA: unavailable");
    }

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.amagi82.kerbalspaceapp.CelestialBodyActivity.java

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(R.string.app_name);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter, passing in the appropriate page
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setCurrentItem(getIntent().getIntExtra(EXTRA_PLANET_ID, 0));
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        // onPageSelected finds the current page. invalidateOptionsMenu() resets the action bar for each page.
        @Override/*from  w w  w  .j a  v  a  2s. c  om*/
        public void onPageSelected(int position) {
            mCurrentPage = position;
            invalidateOptionsMenu();
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
    });
    // Provides action bar settings on initial page creation
    mCurrentPage = getIntent().getIntExtra(EXTRA_PLANET_ID, 0);
}

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();//w  w w  . ja  va 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.inc.playground.playground.MainActivity.java

public void setPlayGroundActionBar() {
    String userLoginId, userFullName, userEmail, userPhoto;
    Bitmap imageBitmap = null;//from w  w w  .  j av  a2 s.  c o m
    GlobalVariables globalVariables;
    final ActionBar actionBar = getActionBar();

    final String MY_PREFS_NAME = "Login";
    SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    globalVariables = ((GlobalVariables) this.getApplication());
    if (prefs.getString("userid", null) != null) {
        userLoginId = prefs.getString("userid", null);
        userFullName = prefs.getString("fullname", null);
        userEmail = prefs.getString("emilid", null);
        userPhoto = prefs.getString("picture", null);
        globalVariables.GetCurrentUser().setPhotoUrl(userPhoto);
        actionBar.setCustomView(R.layout.actionbar_custom_view_home);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        ImageView logo_image = (ImageView) findViewById(R.id.img_profile_action_bar);
        logo_image.setBackgroundResource(R.drawable.pg_logo2);
        TextView userName = (TextView) findViewById(R.id.email);
        userName.setText(userFullName.replace("%20", "  "));
        ImageView img_profile = (ImageView) findViewById(R.id.profile_image);
        imageBitmap = globalVariables.GetUserPictureBitMap();
        if (imageBitmap == null) {
            Log.i(TAG, "downloading");
            try {
                imageBitmap = new DownloadImageBitmapTask().execute(userPhoto).get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

        } else {
            Log.i(TAG, "Image found");
        }
        img_profile.setImageBitmap(imageBitmap);

        ImageView notificationBtn = (ImageView) findViewById(R.id.notification_btn);
        notificationBtn.setVisibility(View.VISIBLE);
        notificationBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent iv = new Intent(MainActivity.this, NotificationsList.class);
                startActivity(iv);
                finish();
            }
        });
        TextView notificationNumber = (TextView) findViewById(R.id.notification__numberTxt);
        if (globalVariables.GetNotifications() != null && globalVariables.GetNotifications().size() != 0) {
            notificationNumber.setText(Integer.toString(globalVariables.GetNotifications().size()));
            notificationNumber.setVisibility(View.VISIBLE);
        } else {
            notificationNumber.setVisibility(View.INVISIBLE);
        }

        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
        globalVariables.SetUserPictureBitMap(imageBitmap); // Make the imageBitMap global to all activities to avoid downloading twice
        loginTxt.setText("Logout");
        loginImg.setImageResource(R.drawable.pg_action_lock_close);
        // Register to notifications
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);

    }
}