Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a javascript gesture library that works with the Samsung galaxy tab?

i have been experimenting with javascript gesture libraries. They all work great with the iPad mini, however, when I try them on my Samsung Galaxy Tab (GT-P7510, Android 4.04), the results are at best intermittent.

The best results I get are in portrait mode. In landscape mode, virtually nothing works.

I have tried, amongst others, the following libraries, all of which I found from this post: http://www.queness.com/post/11755/11-multi-touch-and-touch-events-javascript-libraries

  • hammer.js
  • quo.js
  • touchy
  • doubletap
  • jgestures
  • touchswipe

Touchswipe worked best, but all the others just didn't really play ball.

The Hammer page has a demo, which works fine on the ipad but not the android:

http://eightmedia.github.com/hammer.js/

So, does anybody know of any way I can get swipe gestures to play nice on my galaxy?

I have viewed the quirksmode page that a previous stackoverflow question pointed to, but that was out of date and no longer maintained, from what I could see. Also, it didn't actually mention any libraries.

like image 623
Relaxing In Cyprus Avatar asked Feb 13 '13 13:02

Relaxing In Cyprus


3 Answers

I had good luck with this one:

https://github.com/HotStudio/touchy

It has long-press, pinch, rotate, and swipe gestures, and the code is fairly easy to customize.

Note that the combinations of gestures need to be handled-- for example, a swipe will almost always trigger a long touch as well, so you have to set flags or otherwise handle that.

like image 149
NoelHunter Avatar answered Nov 14 '22 03:11

NoelHunter


Here is a CodePen gesture compare tool. http://jsfiddle.net/icoxfog417/uQBvP/

We abandon Hammer.JS after extensive work and moved to Quo which we are finding ok. Things may have changed and be different now.

  document.head.insertAdjacentHTML( 'beforeEnd', '<meta name="viewport" content="target-densitydpi=device-dpi,width=device-width,initial-scale=1.0" />' );

$(function(){
  //initialization 
  $(".detector").bind("click touchstart",function(e){
    $(".detector").removeClass("selected");
    $(this).addClass("selected");

    unbindLibrary();
    bindLibrary($(this).prop("id"));
  });

  //bind library to gesture pad
  bindLibrary = function(id){
    var $pad = $("#gesture-pad");
    var events = [];
    var eventStr = "";
    $("#" + id + "List li").each(function(){
      events.push($(this).text());
    })
    //make target event list from each library's gestureList
    eventStr = events.join(" ");

    switch(id){
      case "hammer":
        hammer = Hammer($pad.get(0), {
          prevent_default: true
        })
        .on(eventStr, logEvent);
        break;
      case "quojs":
        for(var i = 0;i<events.length;i++){
          $$("#gesture-pad").on(events[i], logEvent);
        }
        $$("#gesture-pad").on("touchstart",function(e){
          e.preventDefault();
        });
        break;
      case "touchSwipe":
        var options = {};
        var touchSwipeHandler = function(name){
          if(name.indexOf("pinch") < 0){
            return function(event, distance, duration, fingerCount){ 
                     var e = {}; e["type"] = name; logEvent(e);        
                   };
          }else{
            return function(e, direction, distance, d, f, pinchZoom){ 
                     var e = {}; e["type"] = name; logEvent(e);        
                   };
          }
        };

        for(var i = 0;i<events.length;i++){
            options[events[i]] = new touchSwipeHandler(events[i]); 
        }
        $pad.swipe(options);
        break;
      case "touchy" :
        var handler = function(name){
            return function(event, phase, $target, data){
                     var e = {}; e["type"] = name; logEvent(e);
                   }
        }
        for(var i = 0;i<events.length;i++){
            $pad.bind(events[i],new handler(events[i]));
        }
        break;      
    }
  }

  //unbind library from gesture pad
  unbindLibrary = function(){
    var element = $("#gesture-pad").clone();
    $("#gesture-pad").replaceWith(element);
    $(".gesturelist .selected").removeClass("selected");
  }

  //log detected gesture
  logEvent = function(e){
    $("#detected").text(e.type);
    var selected = $(".detector.selected").prop("id");
    $("#" + selected + "List li").each(function(){
        if($(this).text() == e.type){
            $(this).addClass("selected");
`enter code here`        };
    })          
    return false;
  }

  $(".detector").first().addClass("selected");
  bindLibrary($(".detector.selected").prop("id"));

})
like image 45
Path Avatar answered Nov 14 '22 03:11

Path


I know this is an old question, but I tried several libraries and wasn't happy with any of them, so rolled my own. It's MIT licensed and available at

https://github.com/aerik/GestureListener.js

with a test / demo page at

http://aerik.github.io/GestureListener/example.htm

I use it routinely on my Galaxy S4 phone, a couple of Ipads, and several Windows 8 touchscreen devices. We are using it for production software at work.

Bug reports (with examples) welcome.

like image 23
Aerik Avatar answered Nov 14 '22 04:11

Aerik