Example usage for android.appwidget AppWidgetHostView setOnLongClickListener

List of usage examples for android.appwidget AppWidgetHostView setOnLongClickListener

Introduction

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

Prototype

public void setOnLongClickListener(@Nullable OnLongClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked and held.

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  a v a2 s.com*/
    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  w ww  .ja  v a 2  s  . c o  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;
        }
    });
}