Java Code Examples for android.view.View#drawableHotspotChanged()
The following examples show how to use
android.view.View#drawableHotspotChanged() .
These examples are extracted from open source projects.
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 Project: android_9.0.0_r45 File: DropDownListView.java License: Apache License 2.0 | 5 votes |
private void setPressedItem(@NonNull View child, int position, float x, float y) { mDrawsInPressedState = true; // Ordering is essential. First, update the container's pressed state. drawableHotspotChanged(x, y); if (!isPressed()) { setPressed(true); } // Next, run layout if we need to stabilize child positions. if (mDataChanged) { layoutChildren(); } // Manage the pressed view based on motion position. This allows us to // play nicely with actual touch and scroll events. final View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null && motionView != child && motionView.isPressed()) { motionView.setPressed(false); } mMotionPosition = position; // Offset for child coordinates. final float childX = x - child.getLeft(); final float childY = y - child.getTop(); child.drawableHotspotChanged(childX, childY); if (!child.isPressed()) { child.setPressed(true); } // Ensure that keyboard focus starts from the last touched position. setSelectedPositionInt(position); positionSelectorLikeTouch(position, child, x, y); // Refresh the drawable state to reflect the new pressed state, // which will also update the selector state. refreshDrawableState(); }
Example 2
Source Project: ticdesign File: FocusLayoutHelper.java License: Apache License 2.0 | 5 votes |
private void startPressIfPossible(View view, float x, float y) { stopPressConfirm(view); if (view != null) { view.drawableHotspotChanged(x, y); view.setPressed(true); } }
Example 3
Source Project: hipda File: RecyclerItemClickListener.java License: GNU General Public License v2.0 | 5 votes |
@Override public boolean onTouch(final View view, MotionEvent event) { mChildView = view; mGestureDetector.onTouchEvent(event); float x = event.getX(); float y = event.getY(); //hack to delay ripple effect, should be replaced by better way if (HiSettingsHelper.getInstance().isClickEffect()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { view.drawableHotspotChanged(x, y); } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: view.setTag(R.id.rippleKey, ""); view.postDelayed(new Runnable() { @Override public void run() { try { if (view.getTag(R.id.rippleKey) != null) view.setPressed(true); } catch (Exception ingored) { } } }, 200); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: view.setTag(R.id.rippleKey, null); view.setPressed(false); break; } } return true; }
Example 4
Source Project: KrGallery File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { showMenuRunnable = new Runnable() { @Override public void run() { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); } }; AndroidUtilities.runOnUIThread(showMenuRunnable, 200); } } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { if (event.getY() > getHeight()) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); return true; } } else if (popupWindow != null && popupWindow.isShowing()) { getLocationOnScreen(location); float x = event.getX() + location[0]; float y = event.getY() + location[1]; popupLayout.getLocationOnScreen(location); x -= location[0]; y -= location[1]; selectedMenuView = null; for (int a = 0; a < popupLayout.getItemsCount(); a++) { View child = popupLayout.getItemAt(a); child.getHitRect(rect); if ((Integer) child.getTag() < 100) { if (!rect.contains((int) x, (int) y)) { child.setPressed(false); child.setSelected(false); if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(false, false); } } else { child.setPressed(true); child.setSelected(true); if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(true, false); } child.drawableHotspotChanged(x, y - child.getTop()); } selectedMenuView = child; } } } } } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) { if (selectedMenuView != null) { selectedMenuView.setSelected(false); if (parentMenu != null) { parentMenu.onItemClick((Integer) selectedMenuView.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) selectedMenuView.getTag()); } popupWindow.dismiss(allowCloseAnimation); } else { popupWindow.dismiss(); } } else { if (selectedMenuView != null) { selectedMenuView.setSelected(false); selectedMenuView = null; } } return super.onTouchEvent(event); }
Example 5
Source Project: Telegram-FOSS File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (longClickEnabled && hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { showMenuRunnable = () -> { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); }; AndroidUtilities.runOnUIThread(showMenuRunnable, 200); } } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { if (event.getY() > getHeight()) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); return true; } } else if (popupWindow != null && popupWindow.isShowing()) { getLocationOnScreen(location); float x = event.getX() + location[0]; float y = event.getY() + location[1]; popupLayout.getLocationOnScreen(location); x -= location[0]; y -= location[1]; selectedMenuView = null; for (int a = 0; a < popupLayout.getItemsCount(); a++) { View child = popupLayout.getItemAt(a); child.getHitRect(rect); if ((Integer) child.getTag() < 100) { if (!rect.contains((int) x, (int) y)) { child.setPressed(false); child.setSelected(false); if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(false, false); } } else { child.setPressed(true); child.setSelected(true); if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(true, false); } child.drawableHotspotChanged(x, y - child.getTop()); } selectedMenuView = child; } } } } } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) { if (selectedMenuView != null) { selectedMenuView.setSelected(false); if (parentMenu != null) { parentMenu.onItemClick((Integer) selectedMenuView.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) selectedMenuView.getTag()); } popupWindow.dismiss(allowCloseAnimation); } else { popupWindow.dismiss(); } } else { if (selectedMenuView != null) { selectedMenuView.setSelected(false); selectedMenuView = null; } } return super.onTouchEvent(event); }
Example 6
Source Project: Telegram File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (longClickEnabled && hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { showMenuRunnable = () -> { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); }; AndroidUtilities.runOnUIThread(showMenuRunnable, 200); } } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) { if (event.getY() > getHeight()) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } toggleSubMenu(); return true; } } else if (popupWindow != null && popupWindow.isShowing()) { getLocationOnScreen(location); float x = event.getX() + location[0]; float y = event.getY() + location[1]; popupLayout.getLocationOnScreen(location); x -= location[0]; y -= location[1]; selectedMenuView = null; for (int a = 0; a < popupLayout.getItemsCount(); a++) { View child = popupLayout.getItemAt(a); child.getHitRect(rect); if ((Integer) child.getTag() < 100) { if (!rect.contains((int) x, (int) y)) { child.setPressed(false); child.setSelected(false); if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(false, false); } } else { child.setPressed(true); child.setSelected(true); if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT == 21) { child.getBackground().setVisible(true, false); } child.drawableHotspotChanged(x, y - child.getTop()); } selectedMenuView = child; } } } } } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) { if (selectedMenuView != null) { selectedMenuView.setSelected(false); if (parentMenu != null) { parentMenu.onItemClick((Integer) selectedMenuView.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) selectedMenuView.getTag()); } popupWindow.dismiss(allowCloseAnimation); } else { popupWindow.dismiss(); } } else { if (selectedMenuView != null) { selectedMenuView.setSelected(false); selectedMenuView = null; } } return super.onTouchEvent(event); }