Search code examples
androidgoogle-glassgoogle-gdk

Need to understand Horizontal tugging feedback in Google Glass


I am just a beginner in Google Glass.

I read about Horizontal tugging feedback here

It says "Many built-in immersions on Glass provide "tugging" feedback when swiping backward and forward don't perform an action. "

Also, we need to add this code to apply the effect :

Helper Class :

public class TuggableView extends CardScrollView {

private final View mContentView;

/**
 * Initializes a TuggableView that uses the specified layout
 * resource for its user interface.
 */
public TuggableView(Context context, int layoutResId) {
    this(context, LayoutInflater.from(context)
            .inflate(layoutResId, null));
}

/**
 * Initializes a TuggableView that uses the specified view
 * for its user interface.
 */
public TuggableView(Context context, View view) {
    super(context);

    mContentView = view;
    setAdapter(new SingleCardAdapter());
    activate();
}

/**
 * Overridden to return false so that all motion events still
 * bubble up to the activity's onGenericMotionEvent() method after
 * they are handled by the card scroller. This allows the activity
 * to handle TAP gestures using a GestureDetector instead of the
 * card scroller's OnItemClickedListener.
 */
@Override
protected boolean dispatchGenericFocusedEvent(MotionEvent event) {
    super.dispatchGenericFocusedEvent(event);
    return false;
}

/** Holds the single "card" inside the card scroll view. */
private class SingleCardAdapter extends CardScrollAdapter {

    @Override
    public int getPosition(Object item) {
        return 0;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return mContentView;
    }

    @Override
    public View getView(int position, View recycleView,
            ViewGroup parent) {
        return mContentView;
    }
}
}

Activity Class :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// was: setContentView(R.layout.main_activity);
setContentView(new TuggableView(this, R.layout.main_activity));
}

So my question is : What this effect does and how it affects our application?

Any help will be appreciated.


Solution

  • This code creates the effect of a card "bouncing back", if you would. Similar to how lists in Android allow you to scroll up or down past the end of the list but bounce back to the bottom/top of the list after the user lets go. It gives the illusion of a rubber banding effect.