CCTableView and Touch System bug

hi there i have two issues :

  1. I have used CCTableView , but when i tested it on android “tableCellTouched” method never called when i try to touch on the cell, instead the table drags/scrolls little bit.
  2. When i use ccTouchBegan , ccTouchMoved , ccTouchEnded just one tap calls all the three methods but ccTouchMoved should not be called.

recreating issue 1 :

  1. create a table view and try to detect tap on every cell, the table will scroll little bit or sometimes “tableCellTouched” is called.
    tested on : Samsung S3, HCL ME Tablet, Samsung Note.

recreating issue 2 :

  1. try to detect single tap on the layer , just a little touch on the layer without dragging your finger , the ccTouchMoved will also called.

Possible problem :

  1. The touch sensitivity of the high end devices in android is very sensitive.

regards

anybody came across these issues?

Yes, it’s a bug on some android device.
So do you have any solutions for this issue?

hello, James Chen,

I am thankful to you , you have taken interest in this bug , it is not bug that cocos2dx framework is producing it is fault of over sensitive touch screens,
I have two solutions but i do not think they could be perfect ,

  1. as on devices which have sensitive touch screens. There should be a threshold is terms of dragging or time. I mean to say if user touches screen to do a TAP the framework detect it as drag because of the sensitive screen, so if there is threshold of 10-15 DPI with coordination with time between onTouchBegan and onTouchMoved , onTouchEnded or with standard delegate onTouchesBegan, onTouchesMoved, onTouchesEnded the will understand if user is only tapping or doing other gestures. The problem with this solution is it will behave wired on the normal device or on apple devices.

  2. another solution can be if sensitivity of the phone is lowered. The problem with this solution is i can’t find any way to lower the sensitivity of the device.

Another thing i need to mention CCMenu is behaving perfectly on the sensitive devices.

i am sorry for my bad english that is my suggestion,

regards,

Nitesh Purohit

anyone have tested issues ?

I come across with the same problem, is there anyone who can help me??

to came up this problem CCScrollView has to be modified, i have modified it but not giving me acceptable results , the touch methods in CCScrollView.cpp ,

  1. in ccTouchBegin record touchPoint ,
  2. in ccTouchMoved record touchPoint in different variable ,
  3. in ccTouchEnded , if difference between two points is < ccp(5,5) then cell should be selected, otherwise it is a normal scrolling.

hope it helps,
Nitesh

Thank you Nitesh, I think this is a good way to solve this problem before they change this bug!

Do we need to consider the DPI for different devices? High DPI device might use long distance which more than ccp(5, 5). However the current cocos2d-x api doesn’t contain the function to get device DPI. :frowning:
Nitesh Purohit wrote:

to came up this problem CCScrollView has to be modified, i have modified it but not giving me acceptable results , the touch methods in CCScrollView.cpp ,
>

  1. in ccTouchBegin record touchPoint ,
  2. in ccTouchMoved record touchPoint in different variable ,
  3. in ccTouchEnded , if difference between two points is < ccp(5,5) then cell should be selected, otherwise it is a normal scrolling.
    >
    hope it helps,
    Nitesh

even android SDK donot have any function to return value related to DPI. We need to calculate it. I can across of some formulas

Density=Square root((wp*wp)+(hp*hp))/di

where wp is width resolution in pixels, hp is height resolution in pixels and di is diagonal size in inches.
  1. other one is

    // The gesture threshold expressed in dp
    private static final float GESTURE_THRESHOLD_DP = 16.0f;

    // Get the screen’s density scale
    final float scale = getResources().getDisplayMetrics().density;
    // Convert the dps to pixels, based on density scale
    mGestureThreshold = (int) (GESTURE_THRESHOLD_DP * scale + 0.5f);

    // Use mGestureThreshold as a distance in pixels…

got from android developer website

http://developer.android.com/guide/practices/screens_support.html#screen-independence
  1. got from stack overflow

    // Converting dips to pixels
    float dips = 20.0f;
    float scale = getContext().getResources().getDisplayMetrics().density;
    int pixels = Math.round(dips * scale);

    // Converting pixels to dips
    int pixels = 15;
    float scale = getContext().getResources().getDisplayMetrics().density;
    float dips = pixels / scale;

I have seen similar behavior on these devices (in emulator works perfectly):

  • Nexus One (Android 2.3): Does not register tableCellTouched at all. ccTouchBegan and ccTouchMove registered (sometimes with 0px distance…)
  • Galaxy Tab 10.1 (Android 3.2): Registers tableCellTouched about half the time. ccTouchBegan and ccTouchMove registered.

Is cocos2d-x going to incorporate a workaround in CCScrollView?

i have not found anything promising enough to resolve this issue. It around 2 month i have posted this issue with tableview, i managed my view without tableview, but with due respect it is an important improvement tobe done.

Regards,
Nitesh Purohit

I can confirm these problems also appear on HTC Desire S. It works a bit better on Nexus 7, however on some occasions a touch is also detected as a scroll.
Please fix this issue.

Thanks.

Hmmm, met the same issue. Try using the following hack in my own widget to ignore some moves, but not that accurate:

void DDChoiceTabs::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) {
    float delta = pTouch->getDelta().x;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    if (fabsf(delta) < 1.0f) { // some android is too sensitive
        return;
    }
#endif
   // mark isDragging=true
}

@Nitesh Purohit
Issue #1672 was created for this bug. I will try to fix it. Thanks.

Nitesh Purohit wrote:

i have not found anything promising enough to resolve this issue. It around 2 month i have posted this issue with tableview, i managed my view without tableview, but with due respect it is an important improvement tobe done.
>
Regards,
Nitesh Purohit

I come across with the same problemCan you tell me how to solve this problem?
Thanks!
James Chen wrote:

@Nitesh Purohit
Issue #1672 was created for this bug. I will try to fix it. Thanks.
>
Nitesh Purohit wrote:
> i have not found anything promising enough to resolve this issue. It around 2 month i have posted this issue with tableview, i managed my view without tableview, but with due respect it is an important improvement tobe done.
>
> Regards,
> Nitesh Purohit

The latest codes on the github have resolved the issue.
CCScrollview will not deal with sensitive moving as a move action.
Please see the codes below:

static float convertDistanceFromPointToInch(float pointDis)
{
    float factor = ( CCEGLView::sharedOpenGLView()->getScaleX() + CCEGLView::sharedOpenGLView()->getScaleY() ) / 2;
    return pointDis * factor / CCDevice::getDPI();
}

void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
........
.......
            newPoint     = this->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(0));
            moveDistance = ccpSub(newPoint, m_tTouchPoint);

            float dis = 0.0f;
            if (m_eDirection == kCCScrollViewDirectionVertical)
            {
                dis = moveDistance.y;
            }
            else if (m_eDirection == kCCScrollViewDirectionHorizontal)
            {
                dis = moveDistance.x;
            }
            else
            {
                dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);
            }

            if (!m_bTouchMoved && fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH )
            {
                //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y);
                return;
            }

Zhiqiang Li wrote:

I come across with the same problemCan you tell me how to solve this problem?
Thanks!
James Chen wrote:
> @Nitesh Purohit
> Issue #1672 was created for this bug. I will try to fix it. Thanks.
>
> Nitesh Purohit wrote:
> > i have not found anything promising enough to resolve this issue. It around 2 month i have posted this issue with tableview, i managed my view without tableview, but with due respect it is an important improvement tobe done.
> >
> > Regards,
> > Nitesh Purohit

Thank you very much
James Chen wrote:

The latest codes on the github have resolved the issue.
CCScrollview will not deal with sensitive moving as a move action.
Please see the codes below:
[…]

Zhiqiang Li wrote:

I come across with the same problem)![](Can you tell me how to solve this problem?
Thanks)
> James Chen wrote:
> > @Nitesh Purohit
> > Issue #1672 was created for this bug. I will try to fix it. Thanks.
> >
> > Nitesh Purohit wrote:
> > > i have not found anything promising enough to resolve this issue. It around 2 month i have posted this issue with tableview, i managed my view without tableview, but with due respect it is an important improvement tobe done.
> > >
> > > Regards,
> > > Nitesh Purohit

https://github.com/cocos2d/cocos2d-x
Zhiqiang Li wrote:

Thank you very much!Can you tell me the address of the github ?:slight_smile:

I according to this(https://github.com/dumganhar/cocos2d-x/commit/7743f0778a59a67ec6ca16530e57496d424b47ad) to change
But why Android appear the following error
@
02-25 17:47:49.369: E/AndroidRuntime(22468): FATAL EXCEPTION: GLThread 10
02-25 17:47:49.369: E/AndroidRuntime(22468): java.lang.NoSuchMethodError: getDPI
02-25 17:47:49.369: E/AndroidRuntime(22468): at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesMove(Native Method)
02-25 17:47:49.369: E/AndroidRuntime(22468): at org.cocos2dx.lib.Cocos2dxRenderer.handleActionMove(Cocos2dxRenderer.java:128)
02-25 17:47:49.369: E/AndroidRuntime(22468): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$6.run(Cocos2dxGLSurfaceView.java:217)
02-25 17:47:49.369: E/AndroidRuntime(22468): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1346)
02-25 17:47:49.369: E/AndroidRuntime(22468): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)
@
Because of didn’t wrote native method name?
James Chen wrote:

https://github.com/cocos2d/cocos2d-x
Zhiqiang Li wrote:
> Thank you very much!Can you tell me the address of the github ?:slight_smile: