Search in sources :

Example 81 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project double-espresso by JakeWharton.

the class DrawerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawer_activity);
    ListAdapter listAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.drawer_row, R.id.drawer_row_name, DRAWER_CONTENTS);
    final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ListView drawerList = (ListView) findViewById(R.id.drawer_list);
    drawerList.setAdapter(listAdapter);
    final TextView textView = (TextView) findViewById(R.id.drawer_text_view);
    drawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            textView.setText("You picked: " + DRAWER_CONTENTS[(int) id]);
            drawerLayout.closeDrawers();
        }
    });
    // TODO(user): use compat lib for lower API levels
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }
    title = getTitle();
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.nav_drawer_open, R.string.nav_drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                getActionBar().setTitle(title);
            }
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                getActionBar().setTitle(title);
            }
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);
}
Also used : ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) TextView(android.widget.TextView) DrawerLayout(android.support.v4.widget.DrawerLayout) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 82 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project double-espresso by JakeWharton.

the class DrawerActions method registerListener.

/**
   * Returns a {@link ViewAction} that adds an {@link IdlingDrawerListener} as a drawer listener to
   * the {@link DrawerLayout}. The idling drawer listener wraps any listener that already exists.
   */
private static ViewAction registerListener() {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(DrawerLayout.class);
        }

        @Override
        public String getDescription() {
            return "register idling drawer listener";
        }

        @Override
        public void perform(UiController uiController, View view) {
            DrawerLayout drawer = (DrawerLayout) view;
            DrawerListener existingListener = getDrawerListener(drawer);
            if (existingListener instanceof IdlingDrawerListener) {
                // listener is already registered. No need to assign.
                return;
            }
            drawer.setDrawerListener(IdlingDrawerListener.getInstance(existingListener));
        }
    };
}
Also used : ViewAction(com.google.android.apps.common.testing.ui.espresso.ViewAction) UiController(com.google.android.apps.common.testing.ui.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener)

Example 83 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project LollipopDrawerToggle by 03lafaye.

the class ToolbarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_toolbar);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close);
    toggle.setDrawerIndicatorEnabled(true);
    drawerLayout.setDrawerListener(toggle);
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 84 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project android-bootstrap by AndroidBootstrap.

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) {
    fragmentContainerView = getActivity().findViewById(fragmentId);
    this.drawerLayout = drawerLayout;
    // set a custom shadow that overlays the main content when the drawer opens
    //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.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 (!userLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                userLearnedDrawer = true;
                prefs.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }
            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }
    };
    // per the navigation drawer design guidelines.
    if (!userLearnedDrawer && !fromSavedInstanceState) {
        this.drawerLayout.openDrawer(fragmentContainerView);
    }
    // Defer code dependent on restoration of previous instance state.
    this.drawerLayout.post(new Runnable() {

        @Override
        public void run() {
            drawerToggle.syncState();
        }
    });
    this.drawerLayout.setDrawerListener(drawerToggle);
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ActionBar(android.support.v7.app.ActionBar)

Example 85 with DrawerLayout

use of android.support.v4.widget.DrawerLayout 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 = 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).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)

Aggregations

DrawerLayout (android.support.v4.widget.DrawerLayout)63 View (android.view.View)59 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)33 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 AdapterView (android.widget.AdapterView)22 NavigationView (android.support.design.widget.NavigationView)21 ListView (android.widget.ListView)21 Intent (android.content.Intent)19 Toolbar (android.support.v7.widget.Toolbar)19 TextView (android.widget.TextView)15 ImageView (android.widget.ImageView)12 ActionBar (android.support.v7.app.ActionBar)9 SharedPreferences (android.content.SharedPreferences)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 ViewPager (android.support.v4.view.ViewPager)6 SuppressLint (android.annotation.SuppressLint)5 TabLayout (android.support.design.widget.TabLayout)5 ArrayList (java.util.ArrayList)5 ActionBar (android.app.ActionBar)4 TypedArray (android.content.res.TypedArray)4