Thanks much. I had found something similar elsewhere in my searching, and as you ended up making a subclass of SimpleOnGestureListener. As it happens, I made that class inside of my primary Activity class, so I didn't have to pass the object into the instantiator like you did, but the same "have to work back into the main object" effectively applies, and I see your point.
If I get to a point where I'm willing to ignore the 1.5 OS revision, I'll see what else can be done with the new gestures support added in API level 4... - Chris On May 25, 2010, at 3:50 AM, Justin Anderson wrote: > I know this is late, but hopefully it will help you and others out there > still programming stuff to be compatible with 1.5... This is a simplified > version of a class that I use to detect a vertical swipe on a Gallery object. > To see it in action and test it out you can take a look at "AppSwipe!" on > the market (It's free...) > > In order to get the swipe working exactly the way you want it to you may have > to fiddle around with the three integers used for detecting a swipe. > > public class GallerySwipeUpDetector extends SimpleOnGestureListener > implements OnTouchListener > { > private Gallery m_gallery; > GestureDetector m_detector; > int m_swipeMaxOffPath; //Maximum horizontal tolerance for detecting a > vertical swipe > int m_swipeMinDistance; //Minimum distance in order to detect a vertical > swipe > int m_swipeMinVelocity; //Minimum velocity (pixels/second) in order to > detect a vertical swipe > > public GallerySwipeUpDetector(Gallery gallery) > { > m_gallery = gallery; > m_detector = new GestureDetector(this); > m_swipeMaxOffPath = 25; > m_swipeMinDistance = 10; > m_swipeMinVelocity = 10; > } > > @Override > public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, > float velocityY) > { > if (Math.abs(e1.getX() - e2.getX()) < m_swipeMaxOffPath && > e1.getY() - e2.getY() >= m_swipeMinDistance && > Math.abs(velocityY) >= m_swipeMinVelocity) > { > int pos = m_gallery.pointToPosition((int)e1.getX(), > (int)e1.getY()); > int firstPos = m_gallery.getFirstVisiblePosition(); > int viewablePos = pos - firstPos; > View swipedView = m_gallery.getChildAt(viewablePos); > > if (swipedView != null) > executeSwipeUpAction(pos); > > return true; > } > > return false; > } > > protected void executeSwipeUpAction(int pos) > { > //Do stuff > } > > @Override > public boolean onTouch(View v, MotionEvent event) > { > return m_detector == null ? false : m_detector.onTouchEvent(event); > } > } > > I would then use this class as follows: > > Gallery myGallery = (Gallery) findViewById(R.id.myGalleryID); > myGallery.setOnTouchListener(new GallerySwipeUpDetector(myGallery)); > > There may be a better way to do this, but this worked for me. If someone > else has another solution that works better then I would be interested as > well. I really don't like having to call a method on my gallery and pass it > in as an argument to my listener (I think it's ugly and probably a poor > design), but that was the only thing I could think of to do and it works. > > Hope this helps, > Justin > > ---------------------------------------------------------------------- > There are only 10 types of people in the world... > Those who know binary and those who don't. > ---------------------------------------------------------------------- > > > On Fri, May 21, 2010 at 3:31 PM, Justin Anderson <magouyaw...@gmail.com> > wrote: > It is admittedly difficult to get it to work in 1.5... > > I have implemented it for my app on the market (AppSwipe!) but it was not > easy. It might be a day or two before I have a chance to sit down and look > at my code but as soon as I can, I will post something here to at least point > you in the right direction. > > Thanks, > > Justin > > ---------------------------------------------------------------------- > There are only 10 types of people in the world... > Those who know binary and those who don't. > ---------------------------------------------------------------------- > > > On Tue, May 18, 2010 at 11:58 AM, Chris Ross <cross+goo...@distal.com> wrote: > > Hi there. When searching for information about how to code up recognition > of a finger swipe across the screen, I find most references to the Gesture > API added in API level 4 (OS 1.6). However, there are still quite a few > devices (The HTC Droid Eris, for example. And the ole G1.) that are running > 1.5. > > The rest of my app is working just fine requiring only API level 3, but I > would like to add swipe recognition. The home screens on the afore-mentioned > OS 1.5 devices detect swipes to go across pages, so it must be possible in > there somewhere. It is just that it's really hard before the API level 4 > Gesture code came in, or is it really effectively not possible? > > Can anyone tell me how to detect swipes (just a directional swipe left or > right across the screen) in OS 1.5 (API level 3, or below) ? > > Thanks... > > - Chris > > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > > > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en