android.view.PointerIcon Java Examples

The following examples show how to use android.view.PointerIcon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TabLayoutTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@UiThreadTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
@TargetApi(Build.VERSION_CODES.N)
public void testPointerIcon() {
  final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
  final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs_items, null);
  final PointerIcon expectedIcon =
      PointerIcon.getSystemIcon(activityTestRule.getActivity(), PointerIcon.TYPE_HAND);

  final int tabCount = tabLayout.getTabCount();
  assertEquals(3, tabCount);

  final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0);
  for (int i = 0; i < tabCount; i++) {
    assertEquals(expectedIcon, tabLayout.getTabAt(i).view.onResolvePointerIcon(event, 0));
  }
}
 
Example #2
Source File: BottomNavigationViewTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test
@SmallTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
@TargetApi(Build.VERSION_CODES.N)
public void testPointerIcon() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final PointerIcon expectedIcon = PointerIcon.getSystemIcon(activity, PointerIcon.TYPE_HAND);
  final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0);
  final Menu menu = bottomNavigation.getMenu();
  for (int i = 0; i < menu.size(); i++) {
    final MenuItem item = menu.getItem(i);
    assertTrue(item.isEnabled());
    final View itemView = activity.findViewById(item.getItemId());
    assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0));
    item.setEnabled(false);
    assertEquals(null, itemView.onResolvePointerIcon(event, 0));
    item.setEnabled(true);
    assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0));
  }
}
 
Example #3
Source File: TabWidget.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void addView(View child) {
    if (child.getLayoutParams() == null) {
        final LinearLayout.LayoutParams lp = new LayoutParams(
                0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
        lp.setMargins(0, 0, 0, 0);
        child.setLayoutParams(lp);
    }

    // Ensure you can navigate to the tab with the keyboard, and you can touch it
    child.setFocusable(true);
    child.setClickable(true);

    if (child.getPointerIcon() == null) {
        child.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND));
    }

    super.addView(child);

    // TODO: detect this via geometry with a tabwidget listener rather
    // than potentially interfere with the view's listener
    child.setOnClickListener(new TabClickListener(getTabCount() - 1));
}
 
Example #4
Source File: Chip.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@TargetApi(VERSION_CODES.N)
public PointerIcon onResolvePointerIcon(@NonNull MotionEvent event, int pointerIndex) {
  if (getCloseIconTouchBounds().contains(event.getX(), event.getY()) && isEnabled()) {
    return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
  }
  return null;
}
 
Example #5
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void updateAccessibilityLargePointerFromSettings() {
    final int accessibilityConfig = Settings.Secure.getIntForUser(
            mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON,
            0, UserHandle.USER_CURRENT);
    PointerIcon.setUseLargeIcons(accessibilityConfig == 1);
    nativeReloadPointerIcons(mPtr);
}
 
Example #6
Source File: InputManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
public void setCustomPointerIcon(PointerIcon icon) {
    try {
        mIm.setCustomPointerIcon(icon);
    } catch (RemoteException ex) {
        throw ex.rethrowFromSystemServer();
    }
}
 
Example #7
Source File: Button.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (getPointerIcon() == null && isClickable() && isEnabled()) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #8
Source File: RadialTimePickerView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (!isEnabled()) {
        return null;
    }
    final int degrees = getDegreesFromXY(event.getX(), event.getY(), false);
    if (degrees != -1) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #9
Source File: Spinner.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (getPointerIcon() == null && isClickable() && isEnabled()) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #10
Source File: TabWidget.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (!isEnabled()) {
        return null;
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #11
Source File: RadialTimePickerView.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N)
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (!isEnabled()) {
        return null;
    }
    final int degrees = getDegreesFromXY(event.getX(), event.getY(), false);
    if (degrees != -1) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #12
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (!isEnabled()) {
        return null;
    }
    // Add 0.5f to event coordinates to match the logic in onTouchEvent.
    final int x = (int) (event.getX() + 0.5f);
    final int y = (int) (event.getY() + 0.5f);
    final int dayUnderPointer = getDayAtLocation(x, y);
    if (dayUnderPointer >= 0) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #13
Source File: ImageButton.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (getPointerIcon() == null && isClickable() && isEnabled()) {
        return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #14
Source File: FastScroller.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (mState == STATE_DRAGGING || isPointInside(event.getX(), event.getY())) {
        return PointerIcon.getSystemIcon(mList.getContext(), PointerIcon.TYPE_ARROW);
    }
    return null;
}
 
Example #15
Source File: DocumentView.java    From spline with Apache License 2.0 4 votes vote down vote up
/**
 * Adds support for different mouse pointer icons depending on document state and mouse position
 */
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    int icon = PointerIcon.TYPE_DEFAULT;
    Layer l = mCurrentLayer;
    float x = event.getX() - getViewportX();
    float y = event.getY() - getViewportY();

    if (mMode == MODE_LAYER_DRAG || mMode == MODE_LAYER_PRE_DRAG) {
        icon = PointerIcon.TYPE_GRABBING;
    } else {
        if (l != null) {
            if (inPointTouchRadius(x, y, l.getTopLeft())
                    || inPointTouchRadius(x, y, l.getBottomRight())) {
                icon = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getTopRight())
                    || inPointTouchRadius(x, y, l.getBottomLeft())) {
                icon = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getMidTop())
                    || inPointTouchRadius(x, y, l.getMidBottom())) {
                icon = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
            } else if (inPointTouchRadius(x, y, l.getMidLeft())
                    || inPointTouchRadius(x, y, l.getMidRight())) {
                icon = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
            } else if (l.inBounds(x, y)) {
                switch (event.getActionMasked()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_MOVE:
                        // Only change to hand if this is a primary button click
                        if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) {
                            icon = PointerIcon.TYPE_GRABBING;
                        } else {
                            icon = PointerIcon.TYPE_DEFAULT;
                        }
                        break;
                    case MotionEvent.ACTION_HOVER_MOVE:
                        icon = PointerIcon.TYPE_GRAB;
                        break;
                    case MotionEvent.ACTION_UP:
                    default:
                        if (event.getActionButton() == MotionEvent.BUTTON_PRIMARY) {
                            icon = PointerIcon.TYPE_GRAB;
                        } else {
                            icon = PointerIcon.TYPE_DEFAULT;
                        }
                }
            }
        }
    }
    return PointerIcon.getSystemIcon(getContext(), icon);
}
 
Example #16
Source File: ApiHelperForN.java    From cronet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** See {@link PointerIcon#create(Bitmap, float, float)}. */
public static PointerIcon createPointerIcon(Bitmap bitmap, float width, float height) {
    return PointerIcon.create(bitmap, width, height);
}
 
Example #17
Source File: ApiHelperForN.java    From cronet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** See {@link View#setPointerIcon(PointerIcon)}. */
public static void setPointerIcon(View view, PointerIcon icon) {
    view.setPointerIcon(icon);
}
 
Example #18
Source File: TEditText.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    return super.onResolvePointerIcon(event, pointerIndex);
}
 
Example #19
Source File: DragState.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void overridePointerIconLocked(int touchSource) {
    mTouchSource = touchSource;
    if (isFromSource(InputDevice.SOURCE_MOUSE)) {
        InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_GRABBING);
    }
}
 
Example #20
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private PointerIcon getPointerIcon() {
    return PointerIcon.getDefaultIcon(mContext);
}
 
Example #21
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void setCustomPointerIcon(PointerIcon icon) {
    Preconditions.checkNotNull(icon);
    nativeSetCustomPointerIcon(mPtr, icon);
}
 
Example #22
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 votes vote down vote up
private static native void nativeSetCustomPointerIcon(long ptr, PointerIcon icon);