Java Code Examples for android.view.View.isClickable()

The following are Jave code examples for showing how to use isClickable() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: espresso-support   File: AccessibilityViewMatchers.java   View Source Code Vote up 8 votes
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static Matcher<? super View> withUsageHintOnClick(final Matcher<? extends CharSequence> charSequenceMatcher) {
    return new TypeSafeMatcher<View>() {
        @Override
        protected boolean matchesSafely(View view) {
            if (!view.isClickable()) {
                return false;
            }
            AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_CLICK);
            return charSequenceMatcher.matches(clickAction.getLabel());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is clickable and has custom usage hint for ACTION_CLICK: ");
            charSequenceMatcher.describeTo(description);
        }
    };
}
 
Example 2
Project: GitHub   File: BaseViewHolder.java   View Source Code Vote up 7 votes
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnClickListener(@IdRes final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isClickable()) {
            view.setClickable(true);
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
Example 3
Project: GitHub   File: BaseViewHolder.java   View Source Code Vote up 7 votes
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnClickListener(@IdRes final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isClickable()) {
            view.setClickable(true);
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
Example 4
Project: garras   File: BaseViewHolder.java   View Source Code Vote up 7 votes
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnClickListener(@IdRes final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isClickable()) {
            view.setClickable(true);
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
Example 5
Project: JD-Test   File: BaseViewHolder.java   View Source Code Vote up 7 votes
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */

public BaseViewHolder addOnClickListener(final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (!view.isClickable()) {
        view.setClickable(true);
    }
    if (view != null) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
Example 6
Project: YCUtils   File: MaterialRippleLayout.java   View Source Code Vote up 7 votes
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
Example 7
Project: QiangHongBao   File: MaterialRippleLayout.java   View Source Code Vote up 7 votes
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
Example 8
Project: VirtualHook   File: MaterialRippleLayout.java   View Source Code Vote up 7 votes
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
Example 9
Project: boohee_v5.6   File: MaterialRippleLayout.java   View Source Code Vote up 7 votes
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            Rect rect = new Rect();
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != this.childView) {
        return view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode());
    }
    return view.isFocusableInTouchMode();
}
 
Example 10
Project: RLibrary   File: ViewGroupUtils.java   View Source Code Vote up 7 votes
/**
 * 为任意ViewGroup设置OnItemClickListener.
 * 该方法必须在addViews()方法之后调用,否则无效。
 * 因为ItemView 必须被添加在ViewGroup里才能遍历到。
 * 建议直接在addViews()方法里传入OnItemClickListener进行设置,性能更高
 *
 * @param viewGroup
 * @param onItemClickListener
 */
public static void setOnItemClickListener(final ViewGroup viewGroup, final OnItemClickListener onItemClickListener) {
    if (viewGroup == null || onItemClickListener == null) {
        return;
    }
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View itemView = viewGroup.getChildAt(i);
        //itemView之前没有点击事件才会去设置
        if (null != itemView && !itemView.isClickable()) {
            final int finalI = i;
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemClick(viewGroup, itemView, finalI);
                }
            });
        }
    }
}
 
Example 11
Project: ValueAddSubView   File: FocusManager.java   View Source Code Vote up 6 votes
@Override
public boolean onTouch(View v, MotionEvent event) {
    KeyboardUtils.hideSoftInput(mContext);
    View currentFocus = mContext.getCurrentFocus();
    //处理列表中的控件需要点击两次才生效的问题
    if (currentFocus != v && v.isClickable() && event.getAction() == MotionEvent.ACTION_DOWN) {
        v.requestFocus();
        return false;
    }
    
    if (currentFocus instanceof EditText) {
        mRootView.requestFocus();
    }
    return false;
}
 
Example 12
Project: espresso-support   File: AccessibilityViewMatchers.java   View Source Code Vote up 6 votes
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static Matcher<? super View> withUsageHintOnClick(@StringRes final int resourceId) {
    return new TypeSafeMatcher<View>() {

        private String resourceName;
        private String expectedText;

        @Override
        protected boolean matchesSafely(View view) {
            if (!view.isClickable()) {
                return false;
            }

            expectedText = view.getResources().getString(resourceId);
            resourceName = view.getResources().getResourceEntryName(resourceId);

            if (expectedText == null) {
                return false;
            }

            AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_CLICK);
            return expectedText.equals(clickAction.getLabel());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is clickable and has custom usage hint for ACTION_CLICK from resource id: ").appendValue(resourceId);
            appendResourceNameAndExpectedTextToDescription(description, resourceName, expectedText);
        }
    };
}
 
Example 13
Project: UIWidget   File: RadiusViewDelegate.java   View Source Code Vote up 6 votes
public RadiusViewDelegate(View view, Context context, AttributeSet attrs) {
    this.view = view;
    this.mContext = context;
    obtainAttributes(context, attrs);
    view.setSelected(selected);
    if (!(view instanceof CompoundButton) && !view.isClickable()) {
        view.setClickable(isRippleEnable);
    }
}
 
Example 14
Project: DeviceInfo   File: Methods.java   View Source Code Vote up 6 votes
/***
 * To prevent from double clicking the row item and so prevents overlapping fragment.
 * **/
public static void avoidDoubleClicks(final View view) {
    final long DELAY_IN_MS = 500;
    if (!view.isClickable()) {
        return;
    }
    view.setClickable(false);
    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            view.setClickable(true);
        }
    }, DELAY_IN_MS);
}
 
Example 15
Project: airgram   File: RecyclerListView.java   View Source Code Vote up 5 votes
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {
    int action = event.getActionMasked();
    boolean isScrollIdle = RecyclerListView.this.getScrollState() == RecyclerListView.SCROLL_STATE_IDLE;

    if ((action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) && currentChildView == null && isScrollIdle) {
        currentChildView = view.findChildViewUnder(event.getX(), event.getY());
        if (currentChildView instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) currentChildView;
            float x = event.getX() - currentChildView.getLeft();
            float y = event.getY() - currentChildView.getTop();
            final int count = viewGroup.getChildCount();
            for (int i = count - 1; i >= 0; i--) {
                final View child = viewGroup.getChildAt(i);
                if (x >= child.getLeft() && x <= child.getRight() && y >= child.getTop() && y <= child.getBottom()) {
                    if (child.isClickable()) {
                        currentChildView = null;
                        break;
                    }
                }
            }
        }
        currentChildPosition = -1;
        if (currentChildView != null) {
            currentChildPosition = view.getChildPosition(currentChildView);
            MotionEvent childEvent = MotionEvent.obtain(0, 0, event.getActionMasked(), event.getX() - currentChildView.getLeft(), event.getY() - currentChildView.getTop(), 0);
            if (currentChildView.onTouchEvent(childEvent)) {
                interceptedByChild = true;
            }
            childEvent.recycle();
        }
    }

    if (currentChildView != null && !interceptedByChild) {
        try {
            if (event != null) {
                mGestureDetector.onTouchEvent(event);
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }

    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) {
        if (!interceptedByChild && currentChildView != null) {
            selectChildRunnable = new Runnable() {
                @Override
                public void run() {
                    if (selectChildRunnable != null && currentChildView != null) {
                        currentChildView.setPressed(true);
                        selectChildRunnable = null;
                    }
                }
            };
            AndroidUtilities.runOnUIThread(selectChildRunnable, ViewConfiguration.getTapTimeout());
        }
    } else if (currentChildView != null && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_CANCEL || !isScrollIdle)) {
        if (selectChildRunnable != null) {
            AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
            selectChildRunnable = null;
        }
        currentChildView.setPressed(false);
        currentChildView = null;
        interceptedByChild = false;
    }
    return false;
}
 
Example 16
Project: PlusGram   File: RecyclerListView.java   View Source Code Vote up 5 votes
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {
    int action = event.getActionMasked();
    boolean isScrollIdle = RecyclerListView.this.getScrollState() == RecyclerListView.SCROLL_STATE_IDLE;

    if ((action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) && currentChildView == null && isScrollIdle) {
        currentChildView = view.findChildViewUnder(event.getX(), event.getY());
        if (currentChildView instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) currentChildView;
            float x = event.getX() - currentChildView.getLeft();
            float y = event.getY() - currentChildView.getTop();
            final int count = viewGroup.getChildCount();
            for (int i = count - 1; i >= 0; i--) {
                final View child = viewGroup.getChildAt(i);
                if (x >= child.getLeft() && x <= child.getRight() && y >= child.getTop() && y <= child.getBottom()) {
                    if (child.isClickable()) {
                        currentChildView = null;
                        break;
                    }
                }
            }
        }
        currentChildPosition = -1;
        if (currentChildView != null) {
            currentChildPosition = view.getChildPosition(currentChildView);
            MotionEvent childEvent = MotionEvent.obtain(0, 0, event.getActionMasked(), event.getX() - currentChildView.getLeft(), event.getY() - currentChildView.getTop(), 0);
            if (currentChildView.onTouchEvent(childEvent)) {
                interceptedByChild = true;
            }
            childEvent.recycle();
        }
    }

    if (currentChildView != null && !interceptedByChild) {
        try {
            if (event != null) {
                mGestureDetector.onTouchEvent(event);
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }

    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) {
        if (!interceptedByChild && currentChildView != null) {
            selectChildRunnable = new Runnable() {
                @Override
                public void run() {
                    if (selectChildRunnable != null && currentChildView != null) {
                        currentChildView.setPressed(true);
                        selectChildRunnable = null;
                    }
                }
            };
            AndroidUtilities.runOnUIThread(selectChildRunnable, ViewConfiguration.getTapTimeout());
        }
    } else if (currentChildView != null && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_CANCEL || !isScrollIdle)) {
        if (selectChildRunnable != null) {
            AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
            selectChildRunnable = null;
        }
        currentChildView.setPressed(false);
        currentChildView = null;
        interceptedByChild = false;
    }
    return false;
}