Example usage for android.view MotionEvent ACTION_SCROLL

List of usage examples for android.view MotionEvent ACTION_SCROLL

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_SCROLL.

Prototype

int ACTION_SCROLL

To view the source code for android.view MotionEvent ACTION_SCROLL.

Click Source Link

Document

Constant for #getActionMasked : The motion event contains relative vertical and/or horizontal scroll offsets.

Usage

From source file:com.example.alyshia.customsimplelauncher.launcher.GridFragment.java

private void ensureGrid() {
    if (mGrid != null) {
        return;//  w ww . ja va2 s .  c  o m
    }
    View root = getView();
    if (root == null) {
        throw new IllegalStateException("Content view not yet created");
    }
    if (root instanceof GridView) {
        mGrid = (GridView) root;
    } else {
        mStandardEmptyView = (TextView) root.findViewById(INTERNAL_EMPTY_ID);
        if (mStandardEmptyView == null) {
            mEmptyView = root.findViewById(android.R.id.empty);
        } else {
            mStandardEmptyView.setVisibility(View.GONE);
        }
        mProgressContainer = root.findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
        mGridContainer = root.findViewById(INTERNAL_LIST_CONTAINER_ID);
        View rawGridView = root.findViewById(android.R.id.list);
        if (!(rawGridView instanceof GridView)) {
            if (rawGridView == null) {
                throw new RuntimeException(
                        "Your content must have a GridView whose id attribute is " + "'android.R.id.list'");
            }
            throw new RuntimeException(
                    "Content has view with id attribute 'android.R.id.list' " + "that is not a GridView class");
        }
        mGrid = (GridView) rawGridView;
        if (mEmptyView != null) {
            mGrid.setEmptyView(mEmptyView);
        } else if (mEmptyText != null) {
            mStandardEmptyView.setText(mEmptyText);
            mGrid.setEmptyView(mStandardEmptyView);
        }
    }
    mGridShown = true;
    mGrid.setOnItemClickListener(mOnClickListener);
    mGrid.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int action = MotionEventCompat.getActionMasked(event);
            Log.d("ME", "action is " + action);
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                Log.d("CLICK", "ACTION_DOWN");

                mLastMotionX = event.getX();
                mLastMotionY = event.getY(); //   

                int _x = Math.round(mLastMotionX);
                int _y = Math.round(mLastMotionY);

                postCheckForLongClick(600); //  Long click message 

                if (mGrid.pointToPosition(_x, _y) == AdapterView.INVALID_POSITION) {
                    //empty spot.
                    Log.d("grid", "emtpdyspot " + mGrid.pointToPosition(_x, _y));

                } else {
                    Log.d("grid", "reomo" + +mGrid.pointToPosition(_x, _y));
                    removeLongPressCallback();

                }
                break;

            case MotionEvent.ACTION_SCROLL:
                Log.d("CLICK", "action scroll");
                removeLongPressCallback();
                break;

            case MotionEvent.ACTION_MOVE:
                Log.d("CLICK", "ACTION_MOVE");

                final float x = event.getX();
                final float y = event.getY();
                final int deltaX = Math.abs((int) (mLastMotionX - x));
                final int deltaY = Math.abs((int) (mLastMotionY - y));

                if (deltaX >= mTouchSlop || deltaY >= mTouchSlop) {
                    if (!mHasPerformedLongPress) {
                        removeLongPressCallback();
                    }

                }

                break;

            case MotionEvent.ACTION_CANCEL:
                if (!mHasPerformedLongPress) {
                    removeLongPressCallback();
                }
                break;

            case MotionEvent.ACTION_OUTSIDE:
                if (!mHasPerformedLongPress) {
                    removeLongPressCallback();
                }
                break;
            case MotionEvent.ACTION_UP:
                Log.d("CLICK", "ACTION_UP");

                if (!mHasPerformedLongPress) {
                    removeLongPressCallback();

                    if (timeout) {
                        Log.d("CLICK", "timeout");
                        return true;
                    } else {
                        Log.d("CLICK", " no time out");
                    }

                }

                break;

            default:
                break;
            }

            return false;
        }
    });
    if (mAdapter != null) {
        ListAdapter adapter = mAdapter;
        mAdapter = null;
        setGridAdapter(adapter);
    } else {
        // We are starting without an adapter, so assume we won't
        // have our data right away and start with the progress indicator.
        if (mProgressContainer != null) {
            setGridShown(false, false);
        }
    }
    mHandler.post(mRequestFocus);
}

From source file:it.mb.whatshare.Utils.java

/**
 * Returns a string that represents the symbolic name of the specified
 * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent
 * numeric constant such as "35" if unknown. By Google.
 * /*  w  w w.ja  v a2  s .c om*/
 * @param action
 *            The action.
 * @return The symbolic name of the specified action.
 */
public static String actionToString(int action) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "ACTION_DOWN";
    case MotionEvent.ACTION_UP:
        return "ACTION_UP";
    case MotionEvent.ACTION_CANCEL:
        return "ACTION_CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "ACTION_OUTSIDE";
    case MotionEvent.ACTION_MOVE:
        return "ACTION_MOVE";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "ACTION_HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "ACTION_SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "ACTION_HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "ACTION_HOVER_EXIT";
    }
    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        return "ACTION_POINTER_DOWN(" + index + ")";
    case MotionEvent.ACTION_POINTER_UP:
        return "ACTION_POINTER_UP(" + index + ")";
    default:
        return Integer.toString(action);
    }
}

From source file:com.hippo.widget.BothScrollView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (!mIsBeingDragged) {
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    final float hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (hscroll != 0) {
                        final int delta = (int) (hscroll * getHorizontalScrollFactor());
                        final int range = getHorizontalScrollRange();
                        int oldScrollX = getScrollX();
                        int newScrollX = oldScrollX + delta;
                        if (newScrollX < 0) {
                            newScrollX = 0;
                        } else if (newScrollX > range) {
                            newScrollX = range;
                        }/*from w w  w . ja  va  2  s  . c  o m*/
                        if (newScrollX != oldScrollX) {
                            super.scrollTo(newScrollX, getScrollY());
                            return true;
                        }
                    }
                } else {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * getVerticalScrollFactor());
                        final int range = getVerticalScrollRange();
                        int oldScrollY = getScrollY();
                        int newScrollY = oldScrollY - delta;
                        if (newScrollY < 0) {
                            newScrollY = 0;
                        } else if (newScrollY > range) {
                            newScrollY = range;
                        }
                        if (newScrollY != oldScrollY) {
                            super.scrollTo(getScrollX(), newScrollY);
                            return true;
                        }
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);

    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    ImageView imageView2 = (ImageView) convertView.findViewById(R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(//from w  w w . jav a  2 s. co  m
            pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));

    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;

        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }

    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }

    FrameLayout layout = (FrameLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(),
            entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.android.launcher2.PagedView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;//  www . j  a v  a  2s. co m
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                if (hscroll > 0 || vscroll > 0) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:cc.flydev.launcher.Page.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;//from www . j a  v a  2s.  c o  m
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                        : (hscroll > 0 || vscroll > 0);
                if (isForwardScroll) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.n2hsu.launcher.Page.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending
            // on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;/*from   ww  w.ja  va  2s.  c  om*/
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                        : (hscroll > 0 || vscroll > 0);
                if (isForwardScroll) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.glview.widget.AbsListView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vscroll != 0) {
                    final int delta = (int) (vscroll * getVerticalScrollFactor());
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }/*from  ww  w  . jav a2 s  .  co  m*/
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.example.libwidgettv.bak.AbsListView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vscroll != 0) {
                    final int delta = (int) (vscroll * 0.3);
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }//from  www .ja v a  2  s . c  o m
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.appunite.list.AbsHorizontalListView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override//  w w w  . j  a  v a 2 s.  co m
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (hscroll != 0) {
                    final int delta = (int) (hscroll * getHorizontalScrollFactorUnhide());
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}