Android Question [SOLVED] Regarding the scrim in B4ADrawer

Discussion in 'Android Questions' started by Sandman, Oct 2, 2018.

  1. Sandman

    Sandman Well-Known Member Licensed User

    This thread continues the topic of the dark area to the right of the open drawer. That area is called scrim, in Googles specifications. Here is that topic:

    [class] B4ADrawer - sliding drawer

    You're right. It did feel a bit off, so I played around with Gmail a bit more to figure out what the difference was. Turns out it was quite simple, I don't know why I missed it in the original thread.

    I thought the rule was to close the drawer on TOUCH_ACTION_DOWN, but it's not. It's TOUCH_ACTION_UP. (Which also ignores all swipes on the scrim, which also is exactly what happens in Gmail.)

    So all that needs to be changed is this

    If IsOpen And Action = mBasePanel.TOUCH_ACTION_DOWN Then this...

    If IsOpen And Action = mBasePanel.TOUCH_ACTION_UP Then
    Peter Simpson likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    V1.03 implements the behavior you are talking about. Any touch on the scrim area causes the drawer to close. It is not done with an additional listener.

    Adding a listener to DarkPanel is not good for two reasons:

    1. The DarkPanel sits above the center panel. It will prevent touches from reaching the center panel when the drawer is closed and the DarkPanel is invisible. This can be solved.

    2. This point is a bit more complicated. We want the user to be able to interact with the views in the left menu or on the left side of the screen and we want to detect swiping gestures. If the user touches a point that doesn't belong to any view (in the relevant area) then we can be almost sure that the user starts a swipe gesture. This is not the case if the point belongs to a view. In the later case we need to be careful not to "steal" the touch event too early or the user will have hard time interacting with the menu items (scrolling the list for example).
    The difference between the two cases is: 3dip horizontal movement vs. 10dip horizontal movement. You can see these values in the code.

    If you add a touch listener to the dark panel then you will lose the case where no view has consumed the touch event and it reached the base panel.
  3. Sandman

    Sandman Well-Known Member Licensed User

    I'm not sure I understand what you're talking about now, Erel. I haven't added a listener, I don't even know what they are.

    The only thing I did was to change this sub (copied from 1.03):

    Private Sub Base_OnTouchEvent (Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Dim LeftPanelRightSide As Int = mLeftPanel.Left + mLeftPanel.Width
    If HandlingSwipe = False And x > LeftPanelRightSide Then
    If IsOpen And Action = mBasePanel.TOUCH_ACTION_DOWN Then ' <--- CHANGED TO TOUCH_ACTION_UP
    Return False
    End If
    If IsOpen = False And x > LeftPanelRightSide + ExtraWidth Then
    Return False
    End If
    End If
    Select Action
    Case mBasePanel.TOUCH_ACTION_MOVE
    Dim dx As Float = x - TouchXStart
                TouchXStart = X
    If HandlingSwipe Or Abs(dx) > 3dip Then
                    HandlingSwipe = 
                    ChangeOffset(mLeftPanel.Left + dx, 
    End If
    Case mBasePanel.TOUCH_ACTION_UP
    If HandlingSwipe Then
    End If
                HandlingSwipe = 
    End Select
    Return True
    End Sub
    I changed the fourth line, that's all. So it's considered being a "touch" when the finger leaves, not when it presses down.
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    So that's what it was.
    I too thought there was something different, but unlike you it didn't bother me too much, I just went with the flow. Well spotted @Sandman, all my Google created apps do close with the finger up and not down action, I've just checked. Hey even the link you supplied above to Google Navigation Drawer does the exact same thing through my mobile phone browser. When you press the burger menu button, the scrim reacts to finger up and not finger down, that's continuity for you.

    Hmm, changing mBasePanel.TOUCH_ACTION_DOWN to
    mBasePanel.TOUCH_ACTION_UP is what I probably would have done too if I had noticed it, but without trying it out for myself, I have absolutely no idea if TOUCH_ACTION_UP would work correctly. I have a strange feeling that it would cause an issue though.
    Last edited: Oct 3, 2018
    Sandman likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    Never mind. I thought that you were talking about something else.
    Sandman and Peter Simpson like this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    V1.04 released with a similar change. There is a small difference, it only moves the menu when the finger reaches the menu. This is the same as the behavior in Google Play drawer.
    Sandman and Peter Simpson like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice