Search in sources :

Example 66 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project UltimateAndroid by cymcsg.

the class NavigationDrawerFragment method setUp.

/**
     * 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.
     */
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 = getActivity().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.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;
            }
            // 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).commit();
            }
            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }
    };
    // 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);
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ActionBar(android.app.ActionBar)

Example 67 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project FlexibleAdapter by davideas.

the class MainActivity method initializeDrawer.

private void initializeDrawer() {
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(toggle);
    toggle.syncState();
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    // Version
    TextView appVersion = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.app_version);
    appVersion.setText(getString(R.string.about_version, Utils.getVersionName(this), Integer.toString(Utils.getVersionCode(this))));
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) TextView(android.widget.TextView)

Example 68 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project Libraries-for-Android-Developers by eoecn.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.common_title_bg));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
    mContentLayout = (FrameLayout) findViewById(R.id.content_frame);
    mDrawerList = (ListView) findViewById(R.id.left_drawer_list_view);
    //        List<Object> items = new ArrayList<Object>();
    //        items.add(new Category(""));
    //        items.add(new Item("最新的", R.drawable.star));
    //        items.add(new Item("热门的", R.drawable.like_me));
    //        items.add(new Item("收藏的", R.drawable.star));
    //获取侧栏目数据 每次都更新不使用缓存
    SlideFactory.getInstance(this).getSlide(false, new SlideRevHandler() {

        @Override
        public void onSuccess(int statusCode, LibSlides slides) {
            //异步获取的,如果有缓存数据就直接返回
            System.err.println(statusCode + " " + slides.getData().get(0).getItems().get(0).getTitle());
        }

        @Override
        public void onFailure(int statusCode, Throwable throwable) {
            throwable.printStackTrace();
        }
    });
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // 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.app_name, /* "open drawer" description for accessibility */
    R.string.app_name) {

        /* "close drawer" description for accessibility */
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            // creates call to onPrepareOptionsMenu()
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // creates call to onPrepareOptionsMenu()
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        selectItem(0);
    }
}
Also used : LibSlides(cn.eoe.android.libraries.entity.LibSlides) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) SlideRevHandler(cn.eoe.android.libraries.entity.SlideFactory.SlideRevHandler) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 69 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project StickyListHeaders by emilsjolander.

the class TestActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    refreshLayout.setRefreshing(false);
                }
            }, 1000);
        }
    });
    mAdapter = new TestBaseAdapter(this);
    stickyList = (StickyListHeadersListView) findViewById(R.id.list);
    stickyList.setOnItemClickListener(this);
    stickyList.setOnHeaderClickListener(this);
    stickyList.setOnStickyHeaderChangedListener(this);
    stickyList.setOnStickyHeaderOffsetChangedListener(this);
    stickyList.addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null));
    stickyList.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null));
    stickyList.setEmptyView(findViewById(R.id.empty));
    stickyList.setDrawingListUnderStickyHeader(true);
    stickyList.setAreHeadersSticky(true);
    stickyList.setAdapter(mAdapter);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description */
    R.string.drawer_close);
    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    restoreButton = (Button) findViewById(R.id.restore_button);
    restoreButton.setOnClickListener(buttonListener);
    openExpandableListButton = (Button) findViewById(R.id.open_expandable_list_button);
    openExpandableListButton.setOnClickListener(buttonListener);
    updateButton = (Button) findViewById(R.id.update_button);
    updateButton.setOnClickListener(buttonListener);
    clearButton = (Button) findViewById(R.id.clear_button);
    clearButton.setOnClickListener(buttonListener);
    stickyCheckBox = (CheckBox) findViewById(R.id.sticky_checkBox);
    stickyCheckBox.setOnCheckedChangeListener(checkBoxListener);
    fadeCheckBox = (CheckBox) findViewById(R.id.fade_checkBox);
    fadeCheckBox.setOnCheckedChangeListener(checkBoxListener);
    drawBehindCheckBox = (CheckBox) findViewById(R.id.draw_behind_checkBox);
    drawBehindCheckBox.setOnCheckedChangeListener(checkBoxListener);
    fastScrollCheckBox = (CheckBox) findViewById(R.id.fast_scroll_checkBox);
    fastScrollCheckBox.setOnCheckedChangeListener(checkBoxListener);
    stickyList.setStickyHeaderTopOffset(-20);
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) Handler(android.os.Handler) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 70 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project MaterialViewPager by florent37.

the class DrawerActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
    mDrawer.setDrawerListener(mDrawerToggle);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setHomeButtonEnabled(true);
    }
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ActionBar(android.support.v7.app.ActionBar)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)80 View (android.view.View)76 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)34 TextView (android.widget.TextView)31 NavigationView (android.support.design.widget.NavigationView)30 AdapterView (android.widget.AdapterView)30 ListView (android.widget.ListView)29 Toolbar (android.support.v7.widget.Toolbar)25 DrawerLayout (android.support.v4.widget.DrawerLayout)23 ActionBar (android.support.v7.app.ActionBar)19 ImageView (android.widget.ImageView)16 SharedPreferences (android.content.SharedPreferences)14 Intent (android.content.Intent)12 RecyclerView (android.support.v7.widget.RecyclerView)8 SearchView (android.support.v7.widget.SearchView)8 Handler (android.os.Handler)6 PackageManager (android.content.pm.PackageManager)5 MenuItem (android.view.MenuItem)5 InjectView (butterknife.InjectView)5 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)5