Example usage for android.appwidget AppWidgetHostView setOnTouchListener

List of usage examples for android.appwidget AppWidgetHostView setOnTouchListener

Introduction

In this page you can find the example usage for android.appwidget AppWidgetHostView setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:com.launcher.silverfish.HomeScreenFragment.java

private void placeWidget(AppWidgetHostView hostView) {
    FrameLayout widget_area = (FrameLayout) rootView.findViewById(R.id.widget_area);

    widget_area.removeAllViews();/*  w  w  w.  j  ava  2  s  .c om*/
    widget_area.addView(hostView);

    // Let the widget host view take control of the long click action.
    hostView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            selectWidget();
            return true;
        }
    });

    hostView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            switch (MotionEventCompat.getActionMasked(event)) {
            case MotionEvent.ACTION_DOWN:
                updateTouchDown(event);
                break;

            case MotionEvent.ACTION_MOVE:
                tryConsumeSwipe(event);
                break;
            }

            return touchConsumed;
        }
    });
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

private void placeWidget(AppWidgetHostView hostView) {
    FrameLayout widget_area = (FrameLayout) rootView.findViewById(R.id.widget_area);

    widget_area.removeAllViews();//from  www  . j  a  va2 s  .co m
    widget_area.addView(hostView);

    // Let the widget host view take control of the long click action.
    hostView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            popupSelectWidget();
            return true;
        }
    });

    hostView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            switch (MotionEventCompat.getActionMasked(event)) {
            case MotionEvent.ACTION_DOWN:
                updateTouchDown(event);
                break;

            case MotionEvent.ACTION_MOVE:
                tryConsumeSwipe(event);
                break;
            }

            return touchConsumed;
        }
    });
}