long press in Javascript in browser component

13 views
Skip to first unread message

Ivan

unread,
Feb 7, 2019, 5:21:49 AM2/7/19
to CodenameOne Discussions
Hi guys,

I embedded https://fullcalendar.io/ into my application using cn1 BrowserComponent and I added longpress event handling using https://github.com/vaidik/jquery-longpress (to create task in calendar)
Everything worked ok.
After longer time I want to create new version of the application but this longpress stuff stopped working, but ONLY ON REAL DEVICE (it works in browser, and on simulator too).
On device the longpress does not work I have to tap with two fingers instead to invoke "longpress" event.

What could cause this changed behaviour?

Thanks
Ivan

IDE: Eclipse
Desktop OS: Ubuntu 16.04
Simulator : Samsung S8
Device: Xiaomi Redmi Note 6, Android 8

Shai Almog

unread,
Feb 7, 2019, 10:19:52 PM2/7/19
to CodenameOne Discussions
Hi,
how did you add the long press?
Did you do that after the onLoad callback?
Which Java code did you use?

Ivan

unread,
Feb 8, 2019, 4:41:25 AM2/8/19
to CodenameOne Discussions
Javascript:

$(document).ready(function() {

        $
('#calendar').fullCalendar({
      theme
: true   ,
      defaultView
: 'month',
      header
: {
                left
: 'prev,next today',
                center
: 'title',
                right
: 'month,agendaDay'
           
},
            editable
: false,
            eventLimit
: true, // allow "more" link when too many events
            events
: loadEvents,
      height
: "parent",
      locale
: "sk",
      dayClick
: dayClick,
      eventAfterAllRender
: attachLongPress,
      eventClick
: eventClick,
      eventRender
: eventRender,
      eventRenderWait
: 100,
      defaultTimedEventDuration
:"00:15:00"
     
});
 
});

 
var attachLongPress = function(view) {
   
if (view.name === 'agendaDay') {
     
var date = view.start.format('YYYY-MM-DD');
     
var tds = $('.fc-slats .ui-widget-content').not('.fc-axis');
      tds
.longpress(function(evt) {
       
var dateWs = date + " " + evt.target.parentElement.attributes['data-time'].value;
        log
('Create event: ' + dateWs);
        createNewEvent
(dateWs)
     
}, undefined, 1000);
   
} else
   
if (view.name === 'month') {
     
var tds = $('td.fc-day.ui-widget-content');
      tds
.longpress(function(evt) {
        longPress
= true;
       
var dateWs = evt.target.attributes['data-date'].value;
        log
('Create event: ' + dateWs);
        createNewEvent
(dateWs);
        evt
.stopPropagation();
        evt
.preventDefault();
     
}, undefined, 1000);
   
}
 
};


Java code:

public JSCalendarFrame(CalendarData dataProvider, TsviewExt view, final ListContainer lc, Date activeDate,
           
int scrollToY) {
       
this.dataProvider = dataProvider;
       
this.view = view;
       
this.lc = lc;

        setLayout
(new BorderLayout());
       
this.activeDate = (activeDate == null ? new Date() : activeDate);
        createBrowserComponent
();
       
String url = getCalendarUrl();
        bc
.setURL(url);
        setupJSCallbacks
();
       
Log.p("Callbacks", Log.ERROR);
        revalidate
();

   
}


   
private void createBrowserComponent() {
       
this.bc = new BrowserComponent();
       
this.bc.setProperty("AllowFileAccessFromFileURLs", Boolean.TRUE);
       
this.bc.setProperty("AllowUniversalAccessFromFileURLs", Boolean.TRUE);
       
this.add(BorderLayout.CENTER, bc);
        bc
.addWebEventListener("onLoad", new ActionListener<ActionEvent>() {
           
public void actionPerformed(ActionEvent evt) {
               
Log.p("onLoad", Log.DEBUG);
                setupJSCallbacks
();
                bc
.execute("refreshCalendar()");
           
}
       
});
   
}


private String getCalendarUrl() {
       
       
String home = DocumentHelper.getDefaultDataDirectory();
       
if (!home.startsWith("file://")) {
            home
= "file://" + home;
       
}
       
return home + "calendar/calendar.html";
   
}


Shai Almog

unread,
Feb 9, 2019, 12:57:27 AM2/9/19
to CodenameOne Discussions
Not sure. Maybe Steve has an idea.

Steve Hannah

unread,
Feb 11, 2019, 8:08:14 AM2/11/19
to codenameone...@googlegroups.com
It is possible that there is a conflict with event dispatching on Android, since all pointer events in webviews are handled by CN1 and routed to the webview.  I took a quick look at the jquery longpress plugin and it doesn't look like it uses anything special (other than just regular touch start/end events and timers) for detecting a long press, so our event dispatching should work properly.  Please file an issue in the issue tracker.  If you can provide a smaller, self-contained test case that will help to ensure a faster fix.  E.g. Create a simple page that only includes a single button that is set up to detect a longpress event, and make it easy to demonstrate whether the event is received or not.

On Fri, Feb 8, 2019 at 9:57 PM Shai Almog <shai....@gmail.com> wrote:
Not sure. Maybe Steve has an idea.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/0a708247-3916-42d1-b52b-5d5f461fee82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Steve Hannah
Software Developer
Codename One
Reply all
Reply to author
Forward
0 new messages