Example usage for android.app ActionBar setHomeButtonEnabled

List of usage examples for android.app ActionBar setHomeButtonEnabled

Introduction

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

Prototype

public void setHomeButtonEnabled(boolean enabled) 

Source Link

Document

Enable or disable the "home" button in the corner of the action bar.

Usage

From source file:com.phonemetra.turbo.keyboard.latin.settings.SettingsActivity.java

@Override
protected void onCreate(final Bundle savedState) {
    super.onCreate(savedState);
    final ActionBar actionBar = getActionBar();
    final Intent intent = getIntent();
    if (actionBar != null) {
        mShowHomeAsUp = intent.getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true);
        actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp);
        actionBar.setHomeButtonEnabled(mShowHomeAsUp);
    }/*  w w w  .j a v  a2  s .c om*/

}

From source file:com.blueoxfords.peacecorpstinder.activities.MainActivity.java

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

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

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    final ActionBar actionBar = getActionBar();

    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(false);
        actionBar.setTitle(getString(R.string.app_name));
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override//from   www  .j  av a2  s. c om
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
        for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
            actionBar.addTab(
                    actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));
        }
    }
}

From source file:com.facebook.reflection.SwipeActivity.java

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

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

    Intent intent = getIntent();/*ww  w. ja va2  s. c  o m*/
    result = intent.getStringArrayListExtra("result");
    // 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(false);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mAppSectionsPagerAdapter.setResult(result);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int 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.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);/*ww  w. j a va 2 s  .  c o  m*/
    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.dragamstudios.waarisdezon.MainActivity.java

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

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    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.//from w w  w  .j  a v  a 2  s  .  c  o  m
    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.setOffscreenPageLimit(3);
    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.android.inputmethod.latin.settings.SettingsActivity.java

@Override
protected void onCreate(final Bundle savedState) {
    super.onCreate(savedState);
    final ActionBar actionBar = getActionBar();
    final Intent intent = getIntent();
    if (actionBar != null) {
        mShowHomeAsUp = intent.getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true);
        actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp);
        actionBar.setHomeButtonEnabled(mShowHomeAsUp);
    }//from   w  w  w  .  j a v  a 2  s. c  om
    StatsUtils.onSettingsActivity(intent.hasExtra(EXTRA_ENTRY_KEY) ? intent.getStringExtra(EXTRA_ENTRY_KEY)
            : EXTRA_ENTRY_VALUE_SYSTEM_SETTINGS);
}

From source file:com.lemontruck.thermo.MainActivity.java

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

    // Find the widget id from the intent. 
    Intent intent = getIntent();/*  ww  w  .ja v  a2 s  .  com*/
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        Log.w(LOG, "Invalid App Id");
        finish();
    }
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

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

    // 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(false);
    //actionBar.setDisplayShowTitleEnabled(false);

    // Set the result to CANCELED.  This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    // 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.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.
 */// ww  w.  ja v  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:com.hybris.mobile.activity.LoginActivity.java

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

    setContentView(R.layout.activity_login);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    Fragment[] frags = { new LoginFragment(), new RegistrationFragment() };
    FragmentPagerAdapter adapter = new TabsAdapter(getFragmentManager(), frags);
    mViewPager.setAdapter(adapter);/*from   ww  w . j  a v a2  s.  co m*/
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    MyTabListener tabListener = new MyTabListener(mViewPager, actionBar);
    Tab tab = actionBar.newTab().setText(R.string.tab_login).setTabListener(tabListener);
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.tab_register).setTabListener(tabListener);
    actionBar.addTab(tab);
    actionBar.setSelectedNavigationItem(0);

    // Handler to handle different asynchronous cases:
    // - When the user arrives from the scanning activity and scan a barcode that needs the user to be logged in, 
    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            // Error retrieving the data of the scanned value, we finish the activity and display a error message
            case BarCodeScannerActivity.MSG_DATA_ERROR:
                showMessage((String) msg.obj);
                finish();
                break;

            // Data available, we can start the activity associated with the intent
            case BarCodeScannerActivity.MSG_DATA_AVAILABLE:
                if (mIntentBarcodeAfterLogin != null) {
                    mIntentBarcodeAfterLogin.startActivity();
                    finish();
                }
                break;

            }

        }

    };

}

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.//ww  w .  ja  va 2s. 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);
}