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

The following examples show how to use android.view.View#isClickable() . 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: RippleLayout.java    From fingerpoetry-android with Apache License 2.0 6 votes vote down vote up
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 2
Source File: BaseViewHolder.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 */
@Deprecated
@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
Source File: MaterialRippleLayout.java    From AdvancedMaterialDrawer with Apache License 2.0 6 votes vote down vote up
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 4
Source File: MaterialPlain.java    From KickAssSlidingMenu with Apache License 2.0 6 votes vote down vote up
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 5
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    int x = (int) event.getRawX();
    int y = (int) event.getRawY();
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        View touchTarget = getTouchTarget(this, x, y);
        if (touchTarget != null && touchTarget.isClickable() && touchTarget.isEnabled()) {
            mTouchTarget = touchTarget;
            initParametersForChild(event, touchTarget);
            postInvalidateDelayed(INVALIDATE_DURATION);
        }
    } else if (action == MotionEvent.ACTION_UP) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
        mDispatchUpTouchEventRunnable.event = event;
        postDelayed(mDispatchUpTouchEventRunnable, 200);
        return true;
    } else if (action == MotionEvent.ACTION_CANCEL) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
    }

    return super.dispatchTouchEvent(event);
}
 
Example 6
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    int x = (int) event.getRawX();
    int y = (int) event.getRawY();
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        View touchTarget = getTouchTarget(this, x, y);
        if (touchTarget != null && touchTarget.isClickable() && touchTarget.isEnabled()) {
            mTouchTarget = touchTarget;
            initParametersForChild(event, touchTarget);
            postInvalidateDelayed(INVALIDATE_DURATION);
        }
    } else if (action == MotionEvent.ACTION_UP) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
        mDispatchUpTouchEventRunnable.event = event;
        postDelayed(mDispatchUpTouchEventRunnable, 200);
        return true;
    } else if (action == MotionEvent.ACTION_CANCEL) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
    }

    return super.dispatchTouchEvent(event);
}
 
Example 7
Source File: MaterialRippleLayout.java    From LoyalNativeSlider with MIT License 6 votes vote down vote up
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
Source File: MaterialRippleLayout.java    From material-ripple with Apache License 2.0 6 votes vote down vote up
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
Source File: MaterialRippleLayout.java    From MDPreference with Apache License 2.0 6 votes vote down vote up
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 10
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    int x = (int) event.getRawX();
    int y = (int) event.getRawY();
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        View touchTarget = getTouchTarget(this, x, y);
        if (touchTarget != null && touchTarget.isClickable() && touchTarget.isEnabled()) {
            mTouchTarget = touchTarget;
            initParametersForChild(event, touchTarget);
            postInvalidateDelayed(INVALIDATE_DURATION);
        }
    } else if (action == MotionEvent.ACTION_UP) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
        mDispatchUpTouchEventRunnable.event = event;
        postDelayed(mDispatchUpTouchEventRunnable, 200);
        return true;
    } else if (action == MotionEvent.ACTION_CANCEL) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
    }

    return super.dispatchTouchEvent(event);
}
 
Example 11
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    int x = (int) event.getRawX();
    int y = (int) event.getRawY();
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        View touchTarget = getTouchTarget(this, x, y);
        if (touchTarget != null && touchTarget.isClickable() && touchTarget.isEnabled()) {
            mTouchTarget = touchTarget;
            initParametersForChild(event, touchTarget);
            postInvalidateDelayed(INVALIDATE_DURATION);
        }
    } else if (action == MotionEvent.ACTION_UP) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
        mDispatchUpTouchEventRunnable.event = event;
        postDelayed(mDispatchUpTouchEventRunnable, 200);
        return true;
    } else if (action == MotionEvent.ACTION_CANCEL) {
        mIsPressed = false;
        postInvalidateDelayed(INVALIDATE_DURATION);
    }

    return super.dispatchTouchEvent(event);
}
 
Example 12
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 5 votes vote down vote up
private boolean isTouchPointInView(View view, int x, int y) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int left = location[0];
    int top = location[1];
    int right = left + view.getMeasuredWidth();
    int bottom = top + view.getMeasuredHeight();
    if (view.isClickable() && y >= top && y <= bottom
            && x >= left && x <= right) {
        return true;
    }
    return false;
}
 
Example 13
Source File: FlipViewPager.java    From Travel-Mate with MIT License 5 votes vote down vote up
private void checkIfChildWasClicked(MotionEvent ev, final View childView) {
    if (childView.isClickable() && isPointInsideView(ev.getRawX(), ev.getRawY(), childView)) {
        childView.performClick();
    } else if (childView instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) childView;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View childChildView = viewGroup.getChildAt(i);
            checkIfChildWasClicked(ev, childChildView);
        }
    }
}
 
Example 14
Source File: LongTouchHandler.java    From ProgressView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (v.isClickable()) {
        /* handle press states */
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            v.setPressed(true);
            timer = new Timer();
            // Initial delay = length of a long press
            timer.schedule(new IncrementTask(0, ViewConfiguration.getLongPressTimeout()), ViewConfiguration.getLongPressTimeout());
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            timer.cancel();
            v.setPressed(false);
        }

        long lengthOfPress = event.getEventTime() - event.getDownTime();
        // If the button has been "tapped" then handle normally
        if (lengthOfPress < ViewConfiguration.getLongPressTimeout()
            && event.getAction() == MotionEvent.ACTION_UP) {
                incrementListener.increment();
        }

        return true;
    } else {
        /* If the view isn't clickable, let the touch be handled by others. */
        return false;
    }
}
 
Example 15
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 5 votes vote down vote up
private boolean isTouchPointInView(View view, int x, int y) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int left = location[0];
    int top = location[1];
    int right = left + view.getMeasuredWidth();
    int bottom = top + view.getMeasuredHeight();
    if (view.isClickable() && y >= top && y <= bottom
            && x >= left && x <= right) {
        return true;
    }
    return false;
}
 
Example 16
Source File: RevealLayout.java    From android-art-res with Apache License 2.0 5 votes vote down vote up
private boolean isTouchPointInView(View view, int x, int y) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int left = location[0];
    int top = location[1];
    int right = left + view.getMeasuredWidth();
    int bottom = top + view.getMeasuredHeight();
    if (view.isClickable() && y >= top && y <= bottom
            && x >= left && x <= right) {
        return true;
    }
    return false;
}
 
Example 17
Source File: ViewAccessibilityUtils.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the supplied {@link View} is actionable for accessibility purposes.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is considered actionable for accessibility
 */
public static boolean isActionableForAccessibility(View view) {
  if (view == null) {
    return false;
  }

  return (view.isClickable() || view.isLongClickable() || view.isFocusable());
}
 
Example 18
Source File: Actor.java    From Backboard with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouch(@NonNull final View v, @NonNull final MotionEvent event) {

	final boolean retVal;

	if (!mMotionListenerEnabled || mMotions.isEmpty()) {

		if (mOnTouchListener != null) {
			retVal = mOnTouchListener.onTouch(v, event);
		} else {
			retVal = false;
		}

		return retVal;
	}

	for (Motion motion : mMotions) {
		for (EventImitator imitator : motion.imitators) {
			imitator.imitate(v, event);
		}
	}

	if (mOnTouchListener != null) {
		retVal = mOnTouchListener.onTouch(v, event);
	} else {
		retVal = true;
	}

	if (mRequestDisallowTouchEvent) {
		// prevents parent from scrolling or otherwise stealing touch events
		v.getParent().requestDisallowInterceptTouchEvent(true);
	}

	if (v.isClickable()) {
		if (event.getEventTime() - event.getDownTime()
				> ViewConfiguration.getLongPressTimeout()) {
			v.setPressed(false);

			return true;
		}

		if (event.getHistorySize() > 0) {
			final float deltaX = event.getHistoricalX(event.getHistorySize() - 1) - event.getX();
			final float deltaY = event.getHistoricalY(event.getHistorySize() - 1) - event.getY();

			// if user has moved too far, it is no longer a click
			final boolean removeClickState = Math.pow(deltaX, 2) + Math.pow(deltaY, 2)
					> Math.pow(MAX_CLICK_DISTANCE, 2);

			v.setPressed(!removeClickState);

			return removeClickState;
		} else {
			return false;
		}
	}

	return retVal;
}
 
Example 19
Source File: ViewMatchers.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.isClickable() == isClickable;
}
 
Example 20
Source File: ViewHierarchyElementAndroid.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
Builder(int id, @Nullable ViewHierarchyElementAndroid parent, View fromView) {
  // Bookkeeping
  this.id = id;
  this.parentId = (parent != null) ? parent.getId() : null;

  this.drawingOrder = null;

  // API 16+ properties
  this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

  // API 11+ properties
  this.backgroundDrawableColor =
      (AT_11 && (fromView != null) && (fromView.getBackground() instanceof ColorDrawable))
          ? ((ColorDrawable) fromView.getBackground()).getColor()
          : null;

  // Base properties
  this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
  this.className = fromView.getClass().getName();
  this.accessibilityClassName = null;
  this.packageName = fromView.getContext().getPackageName();
  this.resourceName =
      (fromView.getId() != View.NO_ID)
          ? ViewAccessibilityUtils.getResourceNameForView(fromView)
          : null;
  this.contentDescription = SpannableStringAndroid.valueOf(fromView.getContentDescription());
  this.enabled = fromView.isEnabled();
  if (fromView instanceof TextView) {
    TextView textView = (TextView) fromView;
    // Hint text takes precedence if no text is present.
    CharSequence text = textView.getText();
    if (TextUtils.isEmpty(text)) {
      text = textView.getHint();
    }
    this.text = SpannableStringAndroid.valueOf(text);
    this.textSize = textView.getTextSize();

    this.textColor = textView.getCurrentTextColor();
    this.typefaceStyle =
        (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
  } else {
    this.text = null;
    this.textSize = null;
    this.textColor = null;
    this.typefaceStyle = null;
  }

  this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
  this.clickable = fromView.isClickable();
  this.longClickable = fromView.isLongClickable();
  this.focusable = fromView.isFocusable();
  this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
  this.canScrollForward =
      (ViewCompat.canScrollVertically(fromView, 1)
          || ViewCompat.canScrollHorizontally(fromView, 1));
  this.canScrollBackward =
      (ViewCompat.canScrollVertically(fromView, -1)
          || ViewCompat.canScrollHorizontally(fromView, -1));
  this.checkable = (fromView instanceof Checkable);
  this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
  this.hasTouchDelegate = (fromView.getTouchDelegate() != null);
  this.touchDelegateBounds = ImmutableList.of(); // Unavailable from the View API
  this.boundsInScreen = getBoundsInScreen(fromView);
  this.nonclippedHeight = fromView.getHeight();
  this.nonclippedWidth = fromView.getWidth();
  this.actionList = ImmutableList.of(); // Unavailable from the View API
}