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:net.seedboxer.seedroid.activities.MainActivity.java

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

    setContentView(R.layout.main_activity_view);

    // 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./*  www .  j  av  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);

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

    mAppSectionsPagerAdapter = new TabsAdapter(this, getSupportFragmentManager(), mViewPager);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_inprogres),
            StatusFragment.class, null);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_queue), InQueueFragment.class,
            null);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_downloads),
            DownloadsFragment.class, null);

    if (savedInstanceState != null) {
        actionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }

    GCMRegistrar.checkManifest(this);
    GCMRegistrar.checkDevice(this);
}

From source file:answer.example.answer.activity.FileChooserActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (HAS_ACTIONBAR) {
        boolean hasBackStack = mFragmentManager.getBackStackEntryCount() > 0;

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(hasBackStack);
        actionBar.setHomeButtonEnabled(hasBackStack);
    }//from   www. j a v a 2 s.  c  om

    return true;
}

From source file:app.screen.MyActivity.java

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

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

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

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

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setOffscreenPageLimit(Fragments.values().length); // keep all the pages in memory
    viewPager.setAdapter(fragmentPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        /**
         * When swiping between different app sections, select the corresponding tab.
         * We can also use ActionBar.Tab#select() to do this if we have a reference to the Tab.
         */
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // create TabListener
    ActionBar.TabListener tabListener = new

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

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

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

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

}

From source file:org.ounl.lifelonglearninghub.nfclearntracker.swipe.SwipeActivity.java

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

    // 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 va  2  s.  c om*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener
    // for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select
            // the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if
            // we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // 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:org.amahi.anywhere.activity.ServerActivity.java

private void setUpHomeNavigation() {
    ActionBar actionBar = getActionBar();

    actionBar.setHomeButtonEnabled(isNavigationDrawerAvailable());
    actionBar.setDisplayHomeAsUpEnabled(isNavigationDrawerAvailable());
}

From source file:org.ado.minesync.gui.MineSyncMainActivity.java

/**
 * Called when the activity is first created.
 *
 * @param savedInstanceState If the activity is being re-initialized after
 *                           previously being shut down then this Bundle contains the data it most
 *                           recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
 *///from w  w  w  . j  ava  2 s .c  o m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ALog.d(TAG, "onCreate. savedInstanceState [" + savedInstanceState + "].");
    setContentView(R.layout.activity_main);

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getApplicationContext(),
            getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    accountManager = getDropboxAccountManager(getApplicationContext());
    activityTracker = new ActivityTracker(getApplicationContext());
    minecraftDropboxStatus = new MinecraftDropboxStatus(this);
    upgradeManager = new UpgradeManager(getApplicationContext());

    upgradeManager.upgradeIfNeeded();
    startServicesIfNeeded();

    ALog.d(TAG, "var configProcessActive [" + configProcessActive + "]");
}

From source file:me.nereo.gztsg.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // setup shadow for drawer
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // setup content modal color
    mDrawerLayout.setScrimColor(Color.argb(100, 0, 0, 0));

    final ActionBar mActionBar = getActionBar();
    // display left to icon
    mActionBar.setDisplayHomeAsUpEnabled(true);
    // enable icon click
    mActionBar.setHomeButtonEnabled(true);
    mActionBar.setDisplayShowTitleEnabled(true);
    mActionBar.setTitle(R.string.app_name);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {//from  www .j a v a  2s  .  c  o m

        @Override
        public void onDrawerClosed(View drawerView) {
            mActionBar.setTitle(R.string.app_name);
            // recreate option menu
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            mActionBar.setTitle(R.string.setting_title);
            // recreate option menu
            invalidateOptionsMenu();
        }

    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        attachSearchBookFragment();
    }

}

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  a v a 2 s . com
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.krayzk9s.imgurholo.activities.ImgurHoloActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    apiCall = new ApiCall();
    apiCall.setSettings(settings);/*from w  w w  .j  a va  2  s .com*/
    theme = settings.getString("theme", MainActivity.HOLO_LIGHT);
    if (theme.equals(MainActivity.HOLO_LIGHT))
        setTheme(R.style.AppTheme);
    else
        setTheme(R.style.AppThemeDark);
    super.onCreate(savedInstanceState);
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (NoSuchFieldException e) {
        // Ignore
        Log.e("Error!", e.toString());
    } catch (IllegalAccessException e) {
        // Ignore
        Log.e("Error!", e.toString());
    }

    if (Integer
            .parseInt(settings.getString(getString(R.string.icon_size), getString(R.string.onetwenty))) < 120) { //getting rid of 90 because it may crash the app for large screens
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(getString(R.string.icon_size), getString(R.string.onetwenty));
        editor.commit();
    }
    setContentView(R.layout.activity_other);
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
    }
}

From source file:com.codebutler.farebot.activities.MainActivity.java

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

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);

    mDataCache = new HashMap<String, TransitIdentity>();

    registerForContextMenu(getListView());

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Intent intent = new Intent(this, ReadingTagActivity.class);
    intent.addFlags(/* ww w . j av  a 2  s .  com*/
            Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    mTechLists = new String[][] { new String[] { IsoDep.class.getName() },
            new String[] { MifareClassic.class.getName() }, new String[] { MifareUltralight.class.getName() },
            new String[] { NfcF.class.getName() } };

    setListAdapter(new CardsAdapter());
    getLoaderManager().initLoader(0, null, this);
}