Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1653] Android: Need support for Android long press event

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-07-19T17:03:30.000+0000
Affected Version/sRelease 1.6.2
Fix Version/sSprint 2011-29, Release 1.8.0
ComponentsAndroid
Labelsklist
ReporterDawson Toth
AssigneeBill Dawson
Created2011-04-15T02:58:30.000+0000
Updated2012-02-08T17:55:31.000+0000

Description

It's not currently possible to add an event listener for a 'long press' event on Android (pressing and holding the finger on a widget for a second or two), which is very frequently used for things like context menus on Android.

In StatusNet Mobile's accounts list we're trying to use a long-click to trigger a context menu for controls such as deletion to provide a more native-feeling interface (on iPhone we use the TableView's native editing mode, which is iOS-specific).

Since the native event isn't available, for now we're trying to emulate it by listening for touchstart, touchend etc. This seems to interfere with the natural behavior of the tableview rows; here's the entry in our bug tracker for this:

http://status.net/open-source/issues/2571">http://status.net/open-source/issues/2571

On the Android side, SimpleGestureListener has an onLongPress stub method which could be overridden to fire a 'longpress' event; it looks like long press support might need to be activated on the GestureDetector by calling setIsLongpressEnabled (I'm uncertain what the default value is, but if it's on scroll events don't work, so perhaps it should only be set when a listener is present):

http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html"> http://developer.android.com/reference/android/view/GestureDetector...

http://developer.android.com/reference/android/view/GestureDetector.html"> http://developer.android.com/reference/android/view/GestureDetector...

Attachments

FileDateSize
app.js2011-07-18T16:06:42.000+00003771

Comments

  1. Zipcar (Goss) 2011-04-15

    What's the status of this?

  2. Dawson Toth 2011-06-10

    Updated priority to match this tickets dependency, [TIMOB-3492]. Both have a decent amount of interest from customers now.
  3. Dawson Toth 2011-06-20

    Sample Code

    The following code is an example of how we could utilize the long press from JavaScript. Drop it in an app.js and long press the label! (Hold down on the label for a couple of seconds, and an alert would be displayed.)
       var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
       var label = Ti.UI.createLabel({
           text:'Long press this label, I dare you.',
           height:'auto',
           backgroundColor:'red'
       });
       win.add(label);
       label.addEventListener('longpress', function(evt) {
           alert('PASS: You long pressed the label!');
       });
       win.open();
       
  4. Bill Dawson 2011-07-07

    Though we can (and will, via this ticket) provide longpress events, isn't the real issue that we should support registering context menus on views? Because for the real native experience you'd want a true Android context menu.
  5. Dawson Toth 2011-07-07

    @Bill: yup; [TIMOB-3492]
  6. Bill Dawson 2011-07-18

    longpress and longclick added. TESTING NOTES: * KitchenSink: Base UI -> Window Events has a longpress test. * KitchenSink: Base UI -> Views -> Table Views -> Basic has longclick events on the tableview rows. * The attached app.js is the test app I used while developing this. It's got a few touch-related events on each of the views/controls that it displays. But it only shows the results via log messages, so you'll have to use logcat to use it.
  7. Bill Dawson 2011-07-18

    The app I used for testing while developing. (see attached app.js)
  8. Don Thorp 2011-07-19

    code review and functional test.
  9. Sindre Sorhus 2011-10-28

    What about long press for iOS?
  10. Don Thorp 2011-10-28

    longpress was added to iOS in TIMOB-4508
  11. Shawn Lipscomb 2012-01-18

    But no longpress event at the TableView level? Please add it.
  12. Michael Pettiford 2012-02-08

    Closing issue Tested with Ti Studio build 1.0.8.201201262211 Ti Mob SDK 1.9.0.v20120207171634 OSX Lion 10.7.3 Nexus S OS 2.3.6 v8/rhino Verified that long press events are implemented and work correctly

JSON Source