Search in sources :

Example 46 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project Reachability by sakebook.

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 = 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();
        }
    };
    // 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 47 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project IITB-App by wncc.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    session = new SessionManager(getApplicationContext());
    session.checkLogin();
    Toast.makeText(getApplicationContext(), "Log In status: " + session.isLoggedIn(), Toast.LENGTH_LONG).show();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    FeedFragment feedFragment = new FeedFragment();
    updateFragment(feedFragment);
    fetchNotifications();
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) FeedFragment(in.ac.iitb.gymkhana.iitbapp.fragment.FeedFragment) Toolbar(android.support.v7.widget.Toolbar)

Example 48 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialNavigationDrawer method initDrawer.

public void initDrawer() {
    if (deviceSupportMultiPane()) {
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, drawerViewGroup);
        DrawerLayout.LayoutParams params = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.setMargins((int) (320 * displayDensity), 0, 0, 0);
        contentViewGroup.setLayoutParams(params);
        drawerLayout.setScrimColor(Color.TRANSPARENT);
        drawerLayout.openDrawer(drawerViewGroup);
        drawerLayout.setMultipaneSupport(true);
    // drawerLayout.requestDisallowInterceptTouchEvent(true);
    } else {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        // don't use the constructor with toolbar, or onOptionsItemSelected() method will not be called
        actionBarToggle = new ActionBarDrawerToggle(this, drawerLayout, /*, toolbar*/
        R.string.nothing, R.string.nothing) {

            public void onDrawerClosed(View view) {
                invalidateOptionsMenu();
                drawerTouchLocked = false;
                if (drawerStateListener != null)
                    drawerStateListener.onDrawerClosed(view);
            }

            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu();
                if (drawerStateListener != null)
                    drawerStateListener.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                // if user wants the sliding arrow it compare
                if (slidingDrawerEffect)
                    super.onDrawerSlide(drawerView, slideOffset);
                else
                    super.onDrawerSlide(drawerView, 0);
                if (drawerStateListener != null)
                    drawerStateListener.onDrawerSlide(drawerView, slideOffset);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                super.onDrawerStateChanged(newState);
                if (drawerStateListener != null)
                    drawerStateListener.onDrawerStateChanged(newState);
            }
        };
        drawerLayout.setDrawerListener(actionBarToggle);
        drawerLayout.setMultipaneSupport(false);
    }
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 49 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project NeuCardReader by liuyanyi.

the class MainActivity method viewInit.

private void viewInit() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 50 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project DevRing by LJYcoder.

the class MovieActivity method initEvent.

@Override
protected void initEvent() {
    // 设置TabLayout选项卡的点击事件
    mTlMovie.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            switch(tab.getPosition()) {
                case 0:
                    clickPlaying();
                    break;
                case 1:
                    clickComming();
                    break;
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    // 设置DrawerLayout滑动的相关监听
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }
    };
    mDrawerToggle.syncState();
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            View mContent = mDrawerLayout.getChildAt(0);
            mContent.setTranslationX(drawerView.getMeasuredWidth() * slideOffset);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerStateChanged(int newState) {
        }
    });
    // 设置侧滑栏中的菜单项点击事件
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch(item.getItemId()) {
                case R.id.nav_item_collect:
                    startActivity(new Intent(MovieActivity.this, CollectActivity.class));
                    break;
                case R.id.nav_item_upload:
                    startActivity(new Intent(MovieActivity.this, UploadActivity.class));
                    break;
                case R.id.nav_item_download:
                    startActivity(new Intent(MovieActivity.this, DownloadActivity.class));
                    break;
            }
            // true则点击的菜单项会变成选中状态,,false则不会变成选中状态
            return false;
        }
    });
    mIvAvatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            RingToast.show(R.string.github_star);
        }
    });
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) MenuItem(android.view.MenuItem) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TabLayout(android.support.design.widget.TabLayout) DrawerLayout(android.support.v4.widget.DrawerLayout)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)218 View (android.view.View)153 NavigationView (android.support.design.widget.NavigationView)118 Toolbar (android.support.v7.widget.Toolbar)98 DrawerLayout (android.support.v4.widget.DrawerLayout)96 TextView (android.widget.TextView)85 AdapterView (android.widget.AdapterView)51 ImageView (android.widget.ImageView)48 ListView (android.widget.ListView)48 Intent (android.content.Intent)45 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)35 ActionBar (android.support.v7.app.ActionBar)31 SharedPreferences (android.content.SharedPreferences)30 RecyclerView (android.support.v7.widget.RecyclerView)23 Bundle (android.os.Bundle)20 FloatingActionButton (android.support.design.widget.FloatingActionButton)20 LinearLayout (android.widget.LinearLayout)19 MenuItem (android.view.MenuItem)17 BindView (butterknife.BindView)15 ArrayList (java.util.ArrayList)15