Example usage for android.view MotionEvent ACTION_HOVER_ENTER

List of usage examples for android.view MotionEvent ACTION_HOVER_ENTER

Introduction

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

Prototype

int ACTION_HOVER_ENTER

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

Click Source Link

Document

Constant for #getActionMasked : The pointer is not down but has entered the boundaries of a window or view.

Usage

From source file:Main.java

/**
 * Returns {@true} if the provided event is a touch exploration (e.g. hover)
 * event. This is used to determine whether the event should be processed by
 * the touch exploration code within the keyboard.
 *
 * @param event The event to check.//from  w w w .j  a  v a2  s.co  m
 * @return {@true} is the event is a touch exploration event
 */
public static boolean isTouchExplorationEvent(final MotionEvent event) {
    final int action = event.getAction();
    return action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_EXIT
            || action == MotionEvent.ACTION_HOVER_MOVE;
}

From source file:Main.java

public static String getMotionEventString(int action) {
    switch (action) {
    case (MotionEvent.ACTION_DOWN):
        return "action_down";
    case (MotionEvent.ACTION_UP):
        return "action_down";
    case (MotionEvent.ACTION_CANCEL):
        return "action_down";
    case (MotionEvent.ACTION_MOVE):
        return "action_move";
    case (MotionEvent.ACTION_OUTSIDE):
        return "action_outside";
    case (MotionEvent.ACTION_HOVER_ENTER):
        return "action_hover_enter";
    case (MotionEvent.ACTION_HOVER_EXIT):
        return "action_hover_exit";
    case (MotionEvent.ACTION_HOVER_MOVE):
        return "action_hover_move";
    case (MotionEvent.ACTION_MASK):
        return "action_mask";
    }/*from w w  w  .j a  v  a 2  s .co m*/
    return "unknown action event";
}

From source file:Main.java

/**
 * Gets the name of an action.//from w  w  w.j  av  a  2s  .  co 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.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when accessibility is turned on in SDK versions ICS
 * and higher.//from w  w  w. j a  va 2  s. c  om
 *
 * @param event The hover event.
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key key = tracker.getKeyOn(x, y);
    final Key previousKey = mLastHoverKey;

    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (pointInView(x, y) && (key != null)) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        } else {
            return onHoverKey(key, event);
        }
    }

    return false;
}

From source file:com.onyx.latinime.accessibility.AccessibilityUtils.java

/**
 * Returns {@true} if the provided event is a touch exploration (e.g. hover)
 * event. This is used to determine whether the event should be processed by
 * the touch exploration code within the keyboard.
 *
 * @param event The event to check.//from   w w w  .j  ava  2s.com
 * @return {@true} is the event is a touch exploration event
 */
public boolean isTouchExplorationEvent(final MotionEvent event) {
    final int action = event.getAction();
    return action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_EXIT
            || action == MotionEvent.ACTION_HOVER_MOVE;
}

From source file:com.android.utils.ExploreByTouchHelper.java

/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>//from w w w. java2  s  .  co  m
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>
 * &#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }

    int virtualViewId = getVirtualViewIdAt(event.getX(), event.getY());
    if (virtualViewId == INVALID_ID) {
        virtualViewId = ROOT_ID;
    }

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_ENTER:
    case MotionEvent.ACTION_HOVER_MOVE:
        setHoveredVirtualViewId(virtualViewId);
        break;
    case MotionEvent.ACTION_HOVER_EXIT:
        setHoveredVirtualViewId(virtualViewId);
        break;
    }

    return true;
}

From source file:com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when touch exploration is turned on in SDK versions
 * ICS and higher./*from w w  w. ja  va  2 s .  co m*/
 *
 * @param event The hover event.
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key previousKey = mLastHoverKey;
    final Key key;

    if (pointInView(x, y)) {
        key = tracker.getKeyOn(x, y);
    } else {
        key = null;
    }

    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (key != null) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        } else {
            return onHoverKey(key, event);
        }
    }

    return false;
}

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 ava 2 s . c om

    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:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Receives hover events when touch exploration is turned on in SDK versions ICS and higher.
 *
 * @param event The hover event.//ww  w. j  a  v  a 2  s . c o m
 * @return {@code true} if the event is handled.
 */
public boolean onHoverEvent(final MotionEvent event) {
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_HOVER_ENTER:
        onHoverEnter(event);
        break;
    case MotionEvent.ACTION_HOVER_MOVE:
        onHoverMove(event);
        break;
    case MotionEvent.ACTION_HOVER_EXIT:
        onHoverExit(event);
        break;
    default:
        Log.w(getClass().getSimpleName(), "Unknown hover event: " + event);
        break;
    }
    return true;
}

From source file:com.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT
 * on the previous key, a HOVER_ENTER on the current key, and a HOVER_MOVE
 * on the current key./*from   ww  w  .ja  v a 2  s.  c om*/
 *
 * @param currentKey The currently hovered key.
 * @param previousKey The previously hovered key.
 * @param event The event that triggered the transition.
 * @return {@code true} if the event was handled.
 */
private boolean onTransitionKey(Key currentKey, Key previousKey, MotionEvent event) {
    final int savedAction = event.getAction();

    event.setAction(MotionEvent.ACTION_HOVER_EXIT);
    onHoverKey(previousKey, event);

    event.setAction(MotionEvent.ACTION_HOVER_ENTER);
    onHoverKey(currentKey, event);

    event.setAction(MotionEvent.ACTION_HOVER_MOVE);
    final boolean handled = onHoverKey(currentKey, event);

    event.setAction(savedAction);

    return handled;
}