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

The following examples show how to use android.view.View#isLongClickable() . 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: BaseViewHolder.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * add long click view id
 *
 * @param viewId
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildLongClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnLongClickListener(@IdRes final int viewId) {
    itemChildLongClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isLongClickable()) {
            view.setLongClickable(true);
        }
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return adapter.getOnItemChildLongClickListener() != null &&
                        adapter.getOnItemChildLongClickListener().onItemChildLongClick(adapter, v, getClickPosition());
            }
        });
    }
    return this;
}
 
Example 2
Source File: MaterialPlain.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 3
Source File: MaterialRippleLayoutNineOld.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: 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 5
Source File: MaterialRippleLayoutNineOld.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 6
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 7
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 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: BaseViewHolder.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
/**
 * add long click view id
 *
 * @param viewId
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildLongClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
public BaseViewHolder addOnLongClickListener(final int viewId) {
    itemChildLongClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (!view.isLongClickable()) {
        view.setLongClickable(true);
    }
    if (view != null) {
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (adapter.getmOnItemChildLongClickListener() != null) {
                    adapter.getmOnItemChildLongClickListener().onItemChildLongClick(adapter, v, getClickPosition());
                }
                return false;
            }
        });
    }

    return this;
}
 
Example 11
Source File: BaseViewHolder.java    From demo4Fish with MIT License 6 votes vote down vote up
/**
 * add long click view id
 *
 * @param viewId
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildLongClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
public BaseViewHolder addOnLongClickListener(final int viewId) {
    itemChildLongClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isLongClickable()) {
            view.setLongClickable(true);
        }
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (adapter.getmOnItemChildLongClickListener() != null) {
                    return adapter.getmOnItemChildLongClickListener().onItemChildLongClick(adapter, v, getClickPosition());
                }
                return false;
            }
        });
    }
    return this;
}
 
Example 12
Source File: ForwardingListener.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void onLongPress() {
    clearCallbacks();

    final View src = mSrc;
    if (!src.isEnabled() || src.isLongClickable()) {
        // Ignore long-press if the view is disabled or has its own
        // handler.
        return;
    }

    if (!onForwardingStarted()) {
        return;
    }

    // Don't let the parent intercept our events.
    src.getParent().requestDisallowInterceptTouchEvent(true);

    // Make sure we cancel any ongoing source event stream.
    final long now = SystemClock.uptimeMillis();
    final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
    src.onTouchEvent(e);
    e.recycle();

    mForwarding = true;
}
 
Example 13
Source File: LinkMovement.java    From RefreashTabView with Apache License 2.0 5 votes vote down vote up
private void checkForLongClick(View target, int delayOffset) {
    if (!target.isLongClickable()) {
        return;
    }
    if (longPress == null) {
        longPress = new CheckForLongPress(target);
    }
    target.postDelayed(longPress, ViewConfiguration.getLongPressTimeout() - delayOffset);
}
 
Example 14
Source File: TouchTracker.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
private void checkForLongClick(View target, int delayOffset) {
    if (target.isLongClickable()) {
        mHasPerformedLongPress = false;

        if (mPendingCheckForLongPress == null) {
            mPendingCheckForLongPress = new CheckForLongPress(target);
        }
        target.postDelayed(mPendingCheckForLongPress,
                ViewConfiguration.getLongPressTimeout() - delayOffset);
    }
}
 
Example 15
Source File: DrawableHotspotTouch.java    From RippleDrawable with MIT License 5 votes vote down vote up
private void checkForLongClick(View target, int delayOffset) {
    if (target.isLongClickable()) {
        mHasPerformedLongPress = false;

        if (mPendingCheckForLongPress == null) {
            mPendingCheckForLongPress = new CheckForLongPress(target);
        }
        target.postDelayed(mPendingCheckForLongPress,
                ViewConfiguration.getLongPressTimeout() - delayOffset);
    }
}
 
Example 16
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 17
Source File: LithoMountData.java    From litho with Apache License 2.0 5 votes vote down vote up
static int getViewAttributeFlags(Object content) {
  int flags = 0;

  if (content instanceof View) {
    final View view = (View) content;

    if (view.isClickable()) {
      flags |= FLAG_VIEW_CLICKABLE;
    }

    if (view.isLongClickable()) {
      flags |= FLAG_VIEW_LONG_CLICKABLE;
    }

    if (view.isFocusable()) {
      flags |= FLAG_VIEW_FOCUSABLE;
    }

    if (view.isEnabled()) {
      flags |= FLAG_VIEW_ENABLED;
    }

    if (view.isSelected()) {
      flags |= FLAG_VIEW_SELECTED;
    }
  }

  return flags;
}
 
Example 18
Source File: TouchTracker.java    From Mover with Apache License 2.0 5 votes vote down vote up
private void checkForLongClick(View target, int delayOffset) {
    if (target.isLongClickable()) {
        mHasPerformedLongPress = false;

        if (mPendingCheckForLongPress == null) {
            mPendingCheckForLongPress = new CheckForLongPress(target);
        }

        target.postDelayed(mPendingCheckForLongPress,
                ViewConfiguration.getLongPressTimeout() - delayOffset);
    }
}
 
Example 19
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 View 是否可以长按
 * @param view {@link View}
 * @return {@code true} 可长按, {@code false} 不可长按
 */
public static boolean isLongClickable(final View view) {
    if (view != null) {
        return view.isLongClickable();
    }
    return false;
}
 
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
}