2

How to do smooth scrolling with viewpager on Google Glass? (in particular viewpagerindicator lib). I have implemented viewpagers and they work, however swiping on the touchpad quickly scrolls through the views. I would like to have smooth scrolling similar to the mirror api menus. Anyone have ideas? I have attempted to intercept touchevents using the code below, but the overriden methods are not called. Seems Glass takes the touch events and turns them into d-pad events. OnPageScrolled(which is useless for what I'm doing) is called, but the other methods are not.

class MyViewPager extends ViewPager{
    public MyViewPager(){
    }

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
    // TODO Auto-generated method stub
    super.onPageScrolled(arg0, arg1, arg2);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return super.onInterceptTouchEvent(arg0);
}

@Override
public boolean onTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return super.onTouchEvent(arg0);
}

}

Tony Allevato
  • 6,429
  • 1
  • 29
  • 34
Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141

2 Answers2

3

You can now use the GDK's CardScrollView (javadoc link) instead of ViewPager — it should have all of the functionality that you need.

Tony Allevato
  • 6,429
  • 1
  • 29
  • 34
  • Can CardScrollView support any arbitrary view layout? The documentation recommends to use a Card object, but there are some severe limitations in practice with these cards, for instance with more than a few images being loaded the scrolling becomes jerky and sometimes the app becomes unresponsive. – johnarleyburns Jan 22 '14 at 09:57
  • 1
    Yes, you can have the `CardScrollAdapter` return any kind of views, not just those generated by the `Card` class. – Tony Allevato Jan 23 '14 at 01:44
  • This works well, much better than Cards actually as the imageviews aren't GC'd and can be loaded asynchronously. However I can't get the slider scrollbar to show up on the bottom. – johnarleyburns Jan 27 '14 at 12:41
1

I added a GestureDetector to my FragmentActivity, and instead of using the onScroll() event, I used the onFling() event to trigger a page change.

This is the basis for the GestureDetector: http://b2cloud.com.au/how-to-guides/capture-glass-d-pad-events-for-android

And then when a fling was detected, I just updated the page like this:

protected void slideForward() {
    viewPager.setCurrentItem(mPager.getCurrentItem() + 1);
}

protected void slideBackward() {
    viewPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
Kevin
  • 11,521
  • 22
  • 81
  • 103
  • will give this a try. Although I was hoping to a smooth transition as the user slides forward similar to the Mirror menus. This is probably the will have to do for now. – Patrick Jackson Oct 09 '13 at 01:52