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:Main.java

/**
 * Gets the name of an action.//from  w w  w . j  a  va 2  s.c  o m
 * 
 * @param action        The action being performed.
 * @param isMotionEvent Whether or not the action is a motion event.
 * 
 * @return The name of the action being performed.
 */
public static String getActionName(int action, boolean isMotionEvent) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "DOWN";
    case MotionEvent.ACTION_UP:
        return "UP";
    case MotionEvent.ACTION_MOVE:
        return isMotionEvent ? "MOVE" : "MULTIPLE";
    case MotionEvent.ACTION_CANCEL:
        return "CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "OUTSIDE";
    case MotionEvent.ACTION_POINTER_DOWN:
        return "POINTER_DOWN";
    case MotionEvent.ACTION_POINTER_UP:
        return "POINTER_UP";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "HOVER_EXIT";
    default:
        return "ACTION_" + Integer.toString(action);
    }
}

From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java

@Override
public @NonNull View getView(int position, View convertView, final @NonNull ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.row_alt : R.layout.row,
                parent, false);/*from   w ww. j  a  v  a 2 s. c o  m*/

    final AppEntry entry = getItem(position);
    assert entry != null;

    final SharedPreferences pref = U.getSharedPreferences(getContext());

    TextView textView = (TextView) convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());

    Intent intent = new Intent();
    intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
    ActivityInfo activityInfo = intent.resolveActivityInfo(getContext().getPackageManager(), 0);

    if (activityInfo != null)
        textView.setTypeface(null, isTopApp(activityInfo) ? Typeface.BOLD : Typeface.NORMAL);

    switch (pref.getString("theme", "light")) {
    case "light":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color));
        break;
    case "dark":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_dark));
        break;
    }

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(entry.getIcon(getContext()));

    LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        LocalBroadcastManager.getInstance(getContext())
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
        U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(),
                entry.getUserId(getContext()), null, false, 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 backgroundTint = pref.getBoolean("transparent_start_menu", false)
                        ? U.getAccentColor(getContext())
                        : U.getBackgroundTint(getContext());

                //noinspection ResourceAsColor
                backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2);
                v.setBackgroundColor(backgroundTint);
            }

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

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), 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:cn.ieclipse.af.view.AutoPlayView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_SCROLL:
        stop();/*from   www.j  av a 2  s  .  c o  m*/
        break;
    case MotionEvent.ACTION_UP:
        start();
        break;
    }
    return false;
}

From source file:org.mariotaku.twidere.view.TabPageIndicator.java

@Override
public boolean onGenericMotionEvent(final MotionEvent event) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
        return false;
    if (mAdapter == null)
        return false;
    if ((MotionEventAccessor.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            final float vscroll = MotionEventAccessor.getAxisValue(event, MotionEvent.AXIS_VSCROLL);
            if (vscroll < 0) {
                if (mCurrentItem + 1 < mAdapter.getCount()) {
                    setCurrentItem(mCurrentItem + 1);
                }//w w  w .  ja v a 2s .  c om
            } else if (vscroll > 0) {
                if (mCurrentItem - 1 >= 0) {
                    setCurrentItem(mCurrentItem - 1);
                }
            }
            // if (vscroll != 0) {
            // final int delta = (int) (vscroll *
            // getVerticalScrollFactor());
            // if (!trackMotionScroll(delta, delta)) {
            // return true;
            // }
            // }
        }
        }
    }
    return true;
}

From source file:com.afayear.android.client.view.TabPageIndicator.java

@Override
public boolean onGenericMotionEvent(final MotionEvent event) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
        return false;
    if (mTabProvider == null)
        return false;
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            if (vscroll < 0) {
                if (mCurrentItem + 1 < mTabProvider.getCount()) {
                    setCurrentItem(mCurrentItem + 1);
                }/*  ww w.j  a v  a 2 s.  com*/
            } else if (vscroll > 0) {
                if (mCurrentItem - 1 >= 0) {
                    setCurrentItem(mCurrentItem - 1);
                }
            }
        }
        }
    }
    return true;
}

From source file:org.connectbot.util.TerminalTextViewOverlay.java

@Override
@TargetApi(12)/*from   w w  w .j  a v  a 2s . c om*/
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            // Process scroll wheel movement:
            float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);

            vt320 vtBuffer = (vt320) terminalView.bridge.buffer;
            boolean mouseReport = vtBuffer.isMouseReportEnabled();
            if (mouseReport) {
                int row = (int) Math.floor(event.getY() / terminalView.bridge.charHeight);
                int col = (int) Math.floor(event.getX() / terminalView.bridge.charWidth);

                vtBuffer.mouseWheel(yDistance > 0, col, row,
                        (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_META_ON) != 0);
                return true;
            }
        }
    }

    return super.onGenericMotionEvent(event);
}

From source file:com.cnh.library.materialdrawer.view.BezelImageView.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Check for clickable state and do nothing if disabled
    if (!this.isClickable()) {
        this.isSelected = false;
        return super.onTouchEvent(event);
    }/*from w w w.j ava 2 s  .  c  o  m*/

    // Set selected state based on Motion Event
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        this.isSelected = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_SCROLL:
    case MotionEvent.ACTION_OUTSIDE:
    case MotionEvent.ACTION_CANCEL:
        this.isSelected = false;
        break;
    }

    // Redraw image and return super type
    this.invalidate();
    return super.dispatchTouchEvent(event);
}

From source file:org.connectbot.TerminalView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            // Process scroll wheel movement:
            float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);
            if (yDistance != 0) {
                int base = bridge.buffer.getWindowBase();
                bridge.buffer.setWindowBase(base - Math.round(yDistance));
                return true;
            }//  w  w  w.  j  a  v  a 2 s.c  o  m
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
    final View drawerView = findDrawerView();
    if (drawerView != null && ev.getAction() == MotionEvent.ACTION_SCROLL && mDrawerControllerListener != null
            && mDrawerControllerListener.onScroll()) {
        return true;
    }/*  ww  w  .  java 2 s.  c  om*/
    return super.dispatchGenericMotionEvent(ev);
}

From source file:com.jinfukeji.jinyihuiup.indexBannerClick.ZhiboActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:

        break;/*w ww.j  ava 2 s  .c  o m*/
    case MotionEvent.ACTION_MOVE:
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        float rawX = ev.getRawX();
        float rawY = ev.getRawY();
        float x = ev.getX();
        float y = ev.getY();
        if (rawX < width / 2) {
            if (rawY < y) {
                streamVolume++;
                changeAudio(streamVolume);
            } else {
                streamVolume--;
                changeAudio(streamVolume);
            }
        } else {
            if (rawY < y) {

            } else {

            }
        }
        break;
    case MotionEvent.ACTION_UP:

        break;
    case MotionEvent.ACTION_SCROLL:

        break;
    }
    return super.dispatchTouchEvent(ev);
}