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:biz.wiz.android.wallet.ui.AddressBookActivity.java

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

    setContentView(R.layout.address_book_content);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final FragmentManager fragmentManager = getFragmentManager();

    walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT);
    sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT);

    final FragmentTransaction removal = fragmentManager.beginTransaction();

    if (walletAddressesFragment == null)
        walletAddressesFragment = new WalletAddressesFragment();
    else// ww w. j a  va2s. c  om
        removal.remove(walletAddressesFragment);

    if (sendingAddressesFragment == null)
        sendingAddressesFragment = new SendingAddressesFragment();
    else
        removal.remove(sendingAddressesFragment);

    if (!removal.isEmpty()) {
        removal.commit();
        fragmentManager.executePendingTransactions();
    }

    final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager);
    if (pager != null) {
        pager.setAdapter(
                new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment));

        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs);
        pagerTabs.addTabLabels(R.string.address_book_list_receiving_title,
                R.string.address_book_list_sending_title);

        pager.setOnPageChangeListener(pagerTabs);
        final int position = 1;
        pager.setCurrentItem(position);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        pagerTabs.onPageSelected(position);
        pagerTabs.onPageScrolled(position, 0, 0);
    } else {
        fragmentManager.beginTransaction()
                .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT)
                .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit();
    }

    updateFragments();
}

From source file:com.trin.nilmobile.imageloader.ImagePagerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_image_pager);

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

    Bundle bundle = getIntent().getExtras();
    assert bundle != null;
    String[] imageUrls = bundle.getStringArray(Extra.IMAGES);
    int pagerPosition = bundle.getInt(Extra.IMAGE_POSITION, 0);

    if (savedInstanceState != null) {
        pagerPosition = savedInstanceState.getInt(STATE_POSITION);
    }/*from  w  w  w.ja va  2 s.  c om*/

    options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error).resetViewBeforeLoading(true).cacheOnDisk(true)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
            .displayer(new FadeInBitmapDisplayer(300)).build();

    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new ImagePagerAdapter(imageUrls));
    pager.setCurrentItem(pagerPosition);
}

From source file:org.droidupnp.DrawerFragment.java

/**
 * Users of this fragment must call this method to set up the navigation drawer interactions.
 *
 * @param fragmentId   The android:id of this fragment in its activity's layout.
 * @param drawerLayout The DrawerLayout containing this fragment's UI.
 *//* w  w  w. j  ava2s.co  m*/
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:com.android.talkback.TalkBackShortcutPreferencesActivity.java

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

    setTitle(getString(R.string.title_pref_category_manage_gestures));

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }//from  w  w w.  j  a  v  a  2 s  .c om

    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new TalkBackShortcutPreferenceFragment()).commit();
}

From source file:com.Candy.center.CandyCenter.java

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

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

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

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

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   w  w w  .  jav  a 2 s .co m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.commonsware.android.feedfrags.FeedsTabActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_nav);/*from  w  w w.j  a va 2s  . c om*/

    for (final Feed feed : Feed.getFeeds()) {
        addNewFeed(feed);
    }

    ActionBar bar = getActionBar();

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setDisplayHomeAsUpEnabled(true);

    int screenLayout = getResources().getConfiguration().screenLayout;

    if (((screenLayout & Configuration.SCREENLAYOUT_SIZE_NORMAL) == Configuration.SCREENLAYOUT_SIZE_NORMAL)
            || ((screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_SMALL) == Configuration.SCREENLAYOUT_SIZE_SMALL)) {
        bar.setDisplayShowHomeEnabled(false);
    }

    if (savedInstanceState != null) {
        cleanUpFragments();
    }
}

From source file:com.pickr.activities.FlickrActivity.java

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.flickrDrawerLayout);
    mDrawerList = (ListView) findViewById(R.id.flickrListDrawer);
    TextView userInfosTextView = (TextView) findViewById(R.id.flickrUserInfosTextView);
    ImageView userInfosImageView = (ImageView) findViewById(R.id.flickrUserInfosImageView);

    // configure the action bar
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // Configure the drawer
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name,
            R.string.app_name);//  w  w w  .j  a  v a  2s  .c  om
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mUser = (BaseUser) getIntent().getSerializableExtra(Constants.PARAM_USER);
    boolean isMe = getIntent().getBooleanExtra(Constants.PARAM_IS_ME, false);

    // Load user infos
    new UserInfosLoader(mUser, userInfosTextView, userInfosImageView).execute();

    // Set the adapter for the list view
    mDrawerListItems = new ArrayList<Item<FlickrFragment>>();
    // if(isMe) {
    mDrawerListItems.add(
            new Item<FlickrFragment>(R.string.title_profile, R.drawable.ic_personal, new GalleryFragment()));
    // }
    mDrawerListItems.add(
            new Item<FlickrFragment>(R.string.title_albums, R.drawable.ic_albums, new PhotosetsFragment()));
    mDrawerListItems.add(new Item<FlickrFragment>(R.string.title_favorites, R.drawable.ic_favorites,
            new FavoritesFragment()));
    mDrawerListItems.add(
            new Item<FlickrFragment>(R.string.title_contacts, R.drawable.ic_contacts, new ContactsFragment()));

    mDrawerListAdapter = new DrawerListAdapter<FlickrFragment>(mDrawerListItems, this);
    mDrawerList.setAdapter(mDrawerListAdapter);
    mDrawerList.setOnItemClickListener(this);

    Bundle fragmentsBundle = new Bundle();
    fragmentsBundle.putSerializable(Constants.PARAM_USER, mUser);
    for (Item<FlickrFragment> item2 : mDrawerListItems) {
        item2.getValue().setArguments(fragmentsBundle);
    }

    // Show first fragment
    showFragment(mDrawerListItems.get(0));
}

From source file:com.pickr.activities.PhotosPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler(this);
    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_photos_pager);

    ActionBar actionBar = getActionBar();
    actionBar.setTitle(null);/* www . java  2s . c  o  m*/
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#99333333")));

    mPager = (ViewPager) findViewById(R.id.photosPager);
    mPager.setOnPageChangeListener(this);
    mPager.setPageMargin(10);
}

From source file:com.google.dartino.githubsample.NavigationDrawerFragment.java

/**
 * Users of this fragment must call this method to set up the navigation drawer interactions.
 *
 * @param drawerLayout The DrawerLayout containing this fragment's UI.
 * @param presenter    The Drawer.PanePresenter associated with this fragment.
 *///from www .j av a  2  s  .  c om
@Override
public void setup(DrawerLayout drawerLayout, Drawer.PanePresenter presenter) {
    this.drawerLayout = drawerLayout;
    this.panePresenter = presenter;

    // set a custom shadow that overlays the main content when the drawer opens
    this.drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    drawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
            NavigationDrawerFragment.this.drawerLayout, /* DrawerLayout object */
            R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }
            NavigationDrawerFragment.this.panePresenter.close();
            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }
            NavigationDrawerFragment.this.panePresenter.open();
            if (!userLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                userLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!userLearnedDrawer && !fromSavedInstanceState) {
        this.drawerLayout.openDrawer(getView());
    }

    // Defer code dependent on restoration of previous instance state.
    this.drawerLayout.post(new Runnable() {
        @Override
        public void run() {
            drawerToggle.syncState();
        }
    });

    this.drawerLayout.setDrawerListener(drawerToggle);
}

From source file:it.polimi.spf.app.navigation.NavigationDrawerFragment.java

/**
 * Users of this fragment must call this method to set up the navigation
 * drawer interactions./*  w  ww.  j a  v a  2 s  .  com*/
 * 
 * @param fragmentId
 *            The android:id of this fragment in its activity's layout.
 * @param drawerLayout
 *            The DrawerLayout containing this fragment's UI.
 */
public void setUpDrawer(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

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

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open, /*
                                             * "open drawer" description for
                                             * accessibility
                                             */
            R.string.navigation_drawer_close /*
                                             * "close drawer" description for
                                             * accessibility
                                             */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to
                // prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce
    // them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}