Hey,

I'm trying to develop a scrollable tile-based map system and I'm
having some trouble getting touch events to work correctly. I
currently have a surface view in a separate thread (almost identical
to the lunar lander example) and I am passing the touch events from
the view to my thread. The method in the thread is synchronized with
the holder as in the lunar lander example.

The following code works perfectly within the emulator:

boolean onTouchEvent(MotionEvent event) {
        synchronized (_cellMap.getHolder()) {
                // touch down
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        // start of a new event, reset the flag
                        mIsMoving = false;
                        // store the current touch coordinates for scroll
                        // calculation
                        mXTouch = (int) event.getX();
                        mYTouch = (int) event.getY();
                } else if (event.getAction() == MotionEvent.ACTION_MOVE) { // &&
                        // touch starts moving, set the flag
                        mIsMoving = true;
                        // mIsTap = false;

                        // get the new offset
                        mXOffset += mXTouch - (int) event.getX();
                        mYOffset += mYTouch - (int) event.getY();

                        // secure, that the offset is never out of view bounds
                        if (mXOffset < 0) {
                                mXOffset = 0;
                        } else if (mXOffset > mMapSize * mTerritorySize - 
getWidth() +
mTerritoryHalfSize) {
                                mXOffset = mMapSize * mTerritorySize - 
getWidth() + (int)
mTerritoryHalfSize;
                        }
                        if (mYOffset < 0) {
                                mYOffset = 0;
                        } else if (mYOffset > mMapSize * mTerritorySize - 
getHeight() -
mTerritorySize) {
                                mYOffset = mMapSize * mTerritorySize - 
getHeight() -
mTerritorySize;
                        }

                        // store the last position
                        mXTouch = (int) event.getX();
                        mYTouch = (int) event.getY();

                        calculateLoopBorders();
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                        // touch released
                        if (!mIsMoving) {
                                Territory terr = getTerritory(event.getX(), 
event.getY());
                                // show the id of the touched cell
                                if (terr != null) {
                                        selectTerritory(terr);
                                }
                        }
                }
                return true;
        }
}

and is sitting within my thread. As I said this works perfectly within
the emulator but does not work when testing on a Nexus One running 2.1
OR 2.2.

I assume this is because fingers have more contact time with the
screen than mouse clicks and tend to move a round a tiny bit and so
are being registered as tiny moves. They never register as clicks and
so my tiles never highlight. They DO, however, highlight on the
emulator.

Please can someone help me work out how to make it clear to the above
code the difference between a tap and a move?

Thanks a lot,

Patrick

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to