How to detect that Navigation Drawer has been opened with an edge swipe (and not home icon)?
Asked Answered
T

2

7

I am using a Navigation Drawer in my Android app.

As this is a pattern that I find really hard to discover, my plan was to add a little message at the bottom of the screen until the user finally discover it and succesfully opened it with a swipe.

I know that I could use:

public void onDrawerOpened(View drawerView) {
    // Stop telling the user, he know how it works
}

But this action is also triggered when opening it with the upper left button in the ActionBar.

Any suggestion to detect a succesfull swipe would be warmly welcome.

Troat answered 18/6, 2013 at 20:8 Comment(4)
Why does it matter whether the user opens it via a swipe or via the action bar? So long as they can get to it, they know how to get to it.Fauteuil
Because I have been asked to do so and will get paid by doing so. Seems legit.Troat
I think that making a user discover a feature he doesn't know in a non intrusive and non repetitive way sounds something appreciated inside an application. edge swipe is the only non intuitive feature of my app, so it sounds nice to make it doscover.Troat
+1, just what I was looking for. In our case, we want to investigate (via TestFlight analytics) how many people discover the edge swipe option (to better plan overall navigation in our app).Beker
B
10

You need to listen to the state change callback:

        @Override
        public void onDrawerStateChanged(int newState) {                
            if (newState == DrawerLayout.STATE_DRAGGING) {
                Log.v(TAG, "Drawer opened by dragging");
            }
        }

This state only occurs when user drags the drawer into view. Tapping on home icon does not induce this - which is exactly what you want.

Bremble answered 2/12, 2014 at 12:38 Comment(0)
A
2

Without extending DrawerLayout you could use a combination of the DrawerListener and a boolean flag for Home button press.

Implement DrawerListener with onDrawerSlide method. Inside this method you can check the Home Button flag and if this is false and the drawer is sliding open then you know this was action through the slide.

Bit messy.

Other than that override DrawerLayout and override the onTouchEvent and catch move events.

Abbie answered 9/7, 2013 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.