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.hro.museapp.map.ClusteringMapActivity.java

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

    listType = getIntent().getIntExtra("type", TYPE_ALL);

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

    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    map = f.getExtendedMap();//from   w  ww  . ja v a 2  s  .  c om

    gps = new GPSTracker(ClusteringMapActivity.this);
    //gps = PlacesLoader.getGPS();

    // mapView = (MapView) this.findViewById(R.id.map);

    float cameraZoom = 8;
    LatLng cameraLatLng = new LatLng(52.281602, 5.503235);
    if (savedInstanceState != null) {
        double savedLat = savedInstanceState.getDouble("lat");
        double savedLng = savedInstanceState.getDouble("lng");
        cameraLatLng = new LatLng(savedLat, savedLng);

        cameraZoom = savedInstanceState.getFloat("zoom", 12);
    }
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom));

    map.setClustering(new ClusteringSettings().iconDataProvider(new DemoIconProvider(getResources()))
            .addMarkersDynamically(true));
    map.setMyLocationEnabled(true);

    map.setInfoWindowAdapter(new InfoWindowAdapter() {

        private TextView tv;
        {
            tv = new TextView(ClusteringMapActivity.this);
            tv.setTextColor(Color.BLACK);
        }

        private Collator collator = Collator.getInstance();
        private Comparator<Marker> comparator = new Comparator<Marker>() {
            public int compare(Marker lhs, Marker rhs) {
                String leftTitle = lhs.getTitle();
                String rightTitle = rhs.getTitle();
                if (leftTitle == null && rightTitle == null) {
                    return 0;
                }
                if (leftTitle == null) {
                    return 1;
                }
                if (rightTitle == null) {
                    return -1;
                }
                return collator.compare(leftTitle, rightTitle);
            }
        };

        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                int i = 0;
                String text = "";
                while (i < 3 && markers.size() > 0) {
                    Marker m = Collections.min(markers, comparator);
                    String title = m.getTitle();
                    if (title == null) {
                        break;
                    }
                    text += title + "\n";
                    markers.remove(m);
                    i++;
                }
                if (text.length() == 0) {
                    text = "Markers with mutable data";
                } else if (markers.size() > 0) {
                    text += "and " + markers.size() + " more...";
                } else {
                    text = text.substring(0, text.length() - 1);
                }
                tv.setText(text);
                return tv;
            } else {
                String title = marker.getTitle();
                tv.setText(title);
                return tv;
            }
        }
    });

    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                Builder builder = LatLngBounds.builder();
                for (Marker m : markers) {
                    builder.include(m.getPosition());
                }
                LatLngBounds bounds = builder.build();
                map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,
                        getResources().getDimensionPixelSize(R.dimen.padding)));
            } else {
                // String title = marker.getTitle();
                // String mid = MarkerGenerator.mapPlaceToId.get(title);
                String mid = (String) marker.getData();

                Intent in = new Intent(getApplicationContext(), ShowPlaceActivity.class);
                // sending mid to next activity
                in.putExtra(MarkerGenerator.TAG_MID, mid);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        }
    });

    // MarkerGenerator.addMarkers(map);
    new AddMarkersInBackground().execute();

}

From source file:com.example.android.foodstorm.MainActivity.java

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

    dataSource = new FoodSQLiteHelper(this);

    // 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();
    actionBar.setHomeButtonEnabled(false); // no home/up button
    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//ww  w .j a  v  a 2s. co m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.fridge_main).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.chef_hat).setTabListener(this));
}

From source file:com.ternup.caddisfly.fragment.NavigationDrawerFragment.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.
 *///from  ww  w .ja v  a2  s .c  om
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();
    if (actionBar != null) {
        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.drawer_open, /* "open drawer" description for accessibility */
            R.string.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 && !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);
}

From source file:ca.bitwit.postcard.PostcardAdaptor.java

@JavascriptInterface
public void hideBackButton() {
    activity.runOnUiThread(new Runnable() {
        @Override//from   w w  w  .j a v  a  2  s. co  m
        public void run() {
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null) {
                actionBar.setHomeButtonEnabled(false);
                actionBar.setDisplayHomeAsUpEnabled(false);
            }
        }
    });
}

From source file:com.project.binbinfu.the_city.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.

    //mHotPagerAdapter = new HotPagerAdapter(getSupportFragmentManager());
    fragmentmanager = 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./* ww  w .  j  a  v  a 2  s .  com*/
    actionBar.setHomeButtonEnabled(false);

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

    // For each of the sections in the app, add a tab to the action bar.

    actionBar.addTab(actionBar.newTab().setText(R.string.title_section1).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section2).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section3).setTabListener(this));
}

From source file:ca.bitwit.postcard.PostcardAdaptor.java

/**
 * Postcard Specific methods// ww w.  j a  v  a 2 s. com
 */

@JavascriptInterface
public void showBackButton() {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null) {
                actionBar.setHomeButtonEnabled(true);
                actionBar.setDisplayHomeAsUpEnabled(true);
            }
        }
    });
}

From source file:us.cboyd.android.dicom.DcmBrowser.java

public void onFileSelected(int position, ArrayList<String> fileList, File currDir) {
    // The user selected a DICOM file from the DcmListFragment
    position -= 1;//from w ww  . ja  v  a 2s .  c om
    if ((position < 0) || (position > fileList.size())) {
        // TODO: Error
        return;
    }

    if (mFragmented && mListFragment.isVisible()) {
        // If we're in the one-pane layout and need to swap fragments

        // Enable the Home/Up button to allow the user to go back to 
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Create fragment and give it an argument for the selected article
        Bundle args = new Bundle();
        args.putInt(DcmVar.POSITION, position);
        args.putStringArrayList(DcmVar.FILELIST, fileList);
        args.putString(DcmVar.CURRDIR, currDir.getPath());
        mInfoFragment.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, mInfoFragment);
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null).commit();

        // set up the drawer's list view with items and click listener
        mDrawerList.setAdapter(mListFragment.getListAdapter());
    } else {
        // If we're in the two-pane layout or already displaying the DcmInfoFragment

        // Call a method in the DcmInfoFragment to update its content
        mInfoFragment.updateDicomInfo(position, fileList, currDir.getPath());
    }
    setTitle(fileList.get(position));
}

From source file:com.borqs.browser.ComboViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().addFlags(Window.FEATURE_ACTION_BAR);

    setResult(RESULT_CANCELED);// w  ww  .j av  a 2  s. c o m
    Bundle extras = getIntent().getExtras();
    Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
    String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
    ComboViews startingView = svStr != null ? ComboViews.valueOf(svStr) : ComboViews.Bookmarks;
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.tab_view);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (BrowserActivity.isTablet(this)) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO);
        bar.setHomeButtonEnabled(true);
    } else {
        bar.setDisplayOptions(0);
    }

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks), BrowserBookmarksPage.class, args);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history), BrowserHistoryPage.class, args);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots), BrowserSnapshotPage.class, args);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
    } else {
        switch (startingView) {
        case Bookmarks:
            mViewPager.setCurrentItem(0);
            break;
        case History:
            mViewPager.setCurrentItem(1);
            break;
        case Snapshots:
            mViewPager.setCurrentItem(2);
            break;
        }
    }
}

From source file:com.vurf.vurfx.view.Place_template.java

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

    // 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();
    final String TitleNames[] = new String[] { "About", "Main", "Photos" };

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from  w ww. j av a 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);
        }
    });
    // TODO swipy tabs 
    //PagerTitleStrip  mPagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);

    // 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(TitleNames[i]).setTabListener(this));
    }
    actionBar.hide();
    //mViewPager.setCurrentItem(tab.getPosition())
    mViewPager.setCurrentItem(1);
}

From source file:com.dabay6.android.apps.carlog.ui.SettingsActivity.java

/**
 * {@inheritDoc}/*ww w . ja  v a2 s  .c  o m*/
 */
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (AndroidUtils.isAtLeastHoneycomb()) {
        @SuppressLint("AppCompatMethod")
        final android.app.ActionBar actionBar = getActionBar();

        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setSubtitle(getString(string.settings));

            if (AndroidUtils.isAtLeastICS()) {
                actionBar.setHomeButtonEnabled(true);
            }
        }
    }

    if (AndroidUtils.isVersionBefore(VERSION_CODES.HONEYCOMB)) {
        addPreferencesFromResource(xml.settings);
    }
}