SlidingMenu icon indicating copy to clipboard operation
SlidingMenu copied to clipboard

All touch events are consumed by CustomViewAbove

Open rekire opened this issue 11 years ago • 31 comments

If I use the SlidingMenu together with ActionBarSherlock (maybe unrelated) and with this settings:

SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);

I cannot use the view behind which has the effect that I cannot react on onListItemClick(...) in my ListFragment after days of research I found out that there is a bug in the CustomViewAbove.

My primary fix is to change a break in onInterceptTouchEvent() to return mQuickReturn;. So the ACTION_DOWN event code will look like this:

case MotionEvent.ACTION_DOWN:
    int index = MotionEventCompat.getActionIndex(ev);
    mActivePointerId = MotionEventCompat.getPointerId(ev, index);
    if (mActivePointerId == INVALID_POINTER)
        break;
    mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
    mLastMotionY = MotionEventCompat.getY(ev, index);
    if (thisTouchAllowed(ev)) {
        mIsBeingDragged = false;
        mIsUnableToDrag = false;
        if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
            mQuickReturn = true;
        }
    } else {
        mIsUnableToDrag = true;
    }
    return mQuickReturn;

Update: And also the onTouchEvent you need to change the case MotionEvent.ACTION_DOWN. There you need to replace the break with another return mQuickReturn. The case will look like that:

case MotionEvent.ACTION_DOWN:
    /*
     * If being flinged and user touches, stop the fling. isFinished
     * will be false if being flinged.
     */
    completeScroll();

    // Remember where the motion event started
    int index = MotionEventCompat.getActionIndex(ev);
    mActivePointerId = MotionEventCompat.getPointerId(ev, index);
    mLastMotionX = mInitialMotionX = ev.getX();
    return mQuickReturn;

</update>

I also removed the setInternalPageChangeListener in initCustomViewAbove(). (The reason comes later.)

In the CustomViewBehind I changed the code of the functions onInterceptTouchEvent and onTouchEvent to use the code from the CustomViewAbove:

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    return !mChildrenEnabled;
}

@Override
public boolean onTouchEvent(MotionEvent e) {
    return !mChildrenEnabled;
}

Now the part with the ChildrenEnabled is not anymore used and the function setChildrenEnabled and the member mChildrenEnabled can be removed.

Hopfully this will help others. By the way I would like to make a PushRequest but I don't know how to make that.

rekire avatar Jun 05 '13 09:06 rekire

I have exactly the same issue but following your post I still unable to resolve it. Am I right that when you say "In the CustomViewBehind I changed the code of the functions onInterceptTouchEvent and onTouchEvent to use the code from the CustomViewAbove" you mean that your code becomes like this:

@Override public boolean onInterceptTouchEvent(MotionEvent e) { return mViewAbove.onInterceptTouchEvent(e); }

@Override public boolean onTouchEvent(MotionEvent e) { return mViewAbove.onTouchEvent(e); }

techy777 avatar Jun 05 '13 13:06 techy777

Yes that replaces the actual code.

rekire avatar Jun 05 '13 16:06 rekire

Hmmm, then I have no idea why your changes are not working in my case.

-------- Исходное сообщение -------- От: rekire [email protected] Дата:
Кому: jfeinstein10/SlidingMenu [email protected] Cc: techy777 [email protected] Тема: Re: [SlidingMenu] All touch events are consumed by CustomViewAbove (#446)

Yes that replaces the actual code.

— Reply to this email directly or view it on GitHub.

techy777 avatar Jun 05 '13 17:06 techy777

Which is your target platform? I just reconized that this fix works on a API 17 device but not on a API 10 device. I'll try to fix that tomorrow.

rekire avatar Jun 05 '13 17:06 rekire

Great thanks. My target is API 10

-------- Исходное сообщение -------- От: rekire [email protected] Дата:
Кому: jfeinstein10/SlidingMenu [email protected] Cc: techy777 [email protected] Тема: Re: [SlidingMenu] All touch events are consumed by CustomViewAbove (#446)

Which is your target platform? I just reconized that this fix works on a API 17 device but not on a API 10 device. I'll try to fix that tomorrow.

— Reply to this email directly or view it on GitHub.

techy777 avatar Jun 05 '13 17:06 techy777

While removing all my debug messages I made a mistake I forgot to add another change: The onTouchEvent must be changed. In the case MotionEvent.ACTION_DOWN you need to replace the break with another return mQuickReturn. The case will look like that:

case MotionEvent.ACTION_DOWN:
    /*
     * If being flinged and user touches, stop the fling. isFinished
     * will be false if being flinged.
     */
    completeScroll();

    // Remember where the motion event started
    int index = MotionEventCompat.getActionIndex(ev);
    mActivePointerId = MotionEventCompat.getPointerId(ev, index);
    mLastMotionX = mInitialMotionX = ev.getX();
    return mQuickReturn;

rekire avatar Jun 06 '13 07:06 rekire

Great job! Thank you very much. Now it perfectly works!

techy777 avatar Jun 06 '13 07:06 techy777

I'd changed library as said by you, but problem is not solved. Still menu not sliding. This is my Sliding menu code SlidingMenu sm = getSlidingMenu(); DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); sm.setBehindOffset(metric.widthPixels/3); sm.setFadeDegree(0.35f); sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);

P.S. : now it is not possible to slide from the above view if there is no item in listview (it only slides from listview items)

ramannjindal avatar Jun 29 '13 10:06 ramannjindal

it is not possible to slide from the above view

lakeinchina avatar Mar 13 '14 03:03 lakeinchina

Just as ramannjindal said ,it is not possible to slide from the above view if there is no item in listview (it only slides from listview items).

tianxm avatar Mar 25 '14 08:03 tianxm

Hi, rekire, I follow your changes, but found that the left can slide off, but can not slide off the right side. Please help me. Thank you very much!

gtchjc avatar Aug 05 '14 09:08 gtchjc

Hi, rekire, I follow your changes, but found that the left can slide off, but can not slide off the right side. Please help me. Thank you very much!

gtchjc avatar Aug 07 '14 03:08 gtchjc

There is no one way, please help

gtchjc avatar Aug 07 '14 10:08 gtchjc

This issue has been resolved, then this I thank rekire, because before I did not view it leads to the right side of the slide can not add the View view after the OK Specific solutions, please refer to # 466 Thank you very much

gtchjc avatar Aug 08 '14 06:08 gtchjc

Nice,thanks very much.

dongliang0201 avatar Aug 09 '14 06:08 dongliang0201

It is Great!! Thanks very much!

wrf566 avatar Nov 20 '14 09:11 wrf566

Great job!!

beiliubei avatar Jan 13 '15 02:01 beiliubei

great job !

krmao avatar May 18 '15 15:05 krmao

the solution doesn't work for the right slidingmenu.

linginging avatar Jun 02 '15 14:06 linginging

thanks,but there is still some problems... I changed my code as you said,it really does work,the behind view can slide and the item can click, but the above view cannot slide,I am new to Android,I don't know how to fix it...

DawnYu9 avatar Aug 03 '15 09:08 DawnYu9

Sorry I do not use this project anymore. So I cannot support you.

rekire avatar Aug 11 '15 15:08 rekire

only add rekire solution and android:clickable="true" to your above screen layout root element and above can slide and behind is clickable :)

MicoDevelopers avatar Aug 22 '15 14:08 MicoDevelopers

@MicoDevelopers thank you very much!!!It works.

DawnYu9 avatar Aug 29 '15 02:08 DawnYu9

great job ! thanks!

syab11 avatar Nov 13 '15 12:11 syab11

I have a problem

dongerhuo avatar Jan 06 '16 08:01 dongerhuo

If you stil here???

dongerhuo avatar Jan 06 '16 08:01 dongerhuo

Well I am alive and I feel good. Happy new year by the way!

If you have a question about that library, that is a problem as I already wrote on 11 Aug 2015 "Sorry I do not use this project anymore. So I cannot support you.".

rekire avatar Jan 06 '16 10:01 rekire

也是

发自我的小米手机在 dongerhuo [email protected],2016年1月6日 下午4:57写道:If you stil here???

—Reply to this email directly or view it on GitHub.

coloraven avatar Jan 07 '16 05:01 coloraven

感谢楼主

ju4tin avatar Feb 04 '16 08:02 ju4tin

thanks

ssyandroid avatar Mar 29 '16 08:03 ssyandroid