android.view.View#drawableHotspotChanged ( )源码实例Demo

下面列出了android.view.View#drawableHotspotChanged ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: DropDownListView.java
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();
}
 
源代码2 项目: ticdesign   文件: FocusLayoutHelper.java
private void startPressIfPossible(View view, float x, float y) {
    stopPressConfirm(view);
    if (view != null) {
        view.drawableHotspotChanged(x, y);
        view.setPressed(true);
    }
}
 
源代码3 项目: hipda   文件: RecyclerItemClickListener.java
@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;
}
 
源代码4 项目: KrGallery   文件: ActionBarMenuItem.java
@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);
}
 
源代码5 项目: Telegram-FOSS   文件: ActionBarMenuItem.java
@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);
}
 
源代码6 项目: Telegram   文件: ActionBarMenuItem.java
@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);
}
 
 方法所在类
 同类方法