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

The following are Jave code examples for showing how to use isEnabled() 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.
Example 1
Project: recyclerview-android   File: ClickableViewFinder.java   Source Code and License Vote up 7 votes
@Nullable
private View findViewAt(@NonNull final View view, final float x, final float y) {
    if (!view.isShown() || !view.isEnabled() || !isViewAt(view, x, y)) {
        return null;
    }

    if (view instanceof ViewGroup) {
        final float transformedX = x - view.getLeft() - ViewCompat.getTranslationX(view);
        final float transformedY = y - view.getTop() - ViewCompat.getTranslationY(view);

        final ViewGroup viewGroup = (ViewGroup) view;
        final int childCount = viewGroup.getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = viewGroup.getChildAt(i);
            final View foundView = findViewAt(child, transformedX, transformedY);
            if (foundView != null) {
                return foundView;
            }
        }
    }

    return view;
}
 
Example 2
Project: letv   File: AbsHListView.java   Source Code and License Vote up 7 votes
protected void positionSelector(int position, View sel) {
    if (position != -1) {
        this.mSelectorPosition = position;
    }
    Rect selectorRect = this.mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());
    if (sel instanceof SelectionBoundsAdjuster) {
        ((SelectionBoundsAdjuster) sel).adjustListItemSelectionBounds(selectorRect);
    }
    positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom);
    boolean isChildViewEnabled = this.mIsChildViewEnabled;
    if (sel.isEnabled() != isChildViewEnabled) {
        this.mIsChildViewEnabled = !isChildViewEnabled;
        if (getSelectedItemPosition() != -1) {
            refreshDrawableState();
        }
    }
}
 
Example 3
Project: YCUtils   File: MaterialRippleLayout.java   Source Code and License 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 4
Project: exciting-app   File: AbsHListView.java   Source Code and License Vote up 7 votes
protected void positionSelector(int position, View sel) {
	if (position != INVALID_POSITION) {
		mSelectorPosition = position;
	}

	final Rect selectorRect = mSelectorRect;
	selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(),
			sel.getBottom());
	if (sel instanceof SelectionBoundsAdjuster) {
		((SelectionBoundsAdjuster) sel)
				.adjustListItemSelectionBounds(selectorRect);
	}
	positionSelector(selectorRect.left, selectorRect.top,
			selectorRect.right, selectorRect.bottom);

	final boolean isChildViewEnabled = mIsChildViewEnabled;
	if (sel.isEnabled() != isChildViewEnabled) {
		mIsChildViewEnabled = !isChildViewEnabled;
		if (getSelectedItemPosition() != INVALID_POSITION) {
			refreshDrawableState();
		}
	}
}
 
Example 5
Project: QiangHongBao   File: MaterialRippleLayout.java   Source Code and License 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 6
Project: VirtualHook   File: MaterialRippleLayout.java   Source Code and License 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: boohee_v5.6   File: ListViewCompat.java   Source Code and License Vote up 7 votes
protected void positionSelectorCompat(int position, View sel) {
    Rect selectorRect = this.mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());
    selectorRect.left -= this.mSelectionLeftPadding;
    selectorRect.top -= this.mSelectionTopPadding;
    selectorRect.right += this.mSelectionRightPadding;
    selectorRect.bottom += this.mSelectionBottomPadding;
    try {
        boolean isChildViewEnabled = this.mIsChildViewEnabled.getBoolean(this);
        if (sel.isEnabled() != isChildViewEnabled) {
            this.mIsChildViewEnabled.set(this, Boolean.valueOf(!isChildViewEnabled));
            if (position != -1) {
                refreshDrawableState();
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: simple-share-android   File: DirectoryFragment.java   Source Code and License Vote up 6 votes
private void setEnabledRecursive(View v, boolean enabled) {
	if (v == null)
		return;
	if (v.isEnabled() == enabled)
		return;
	v.setEnabled(enabled);

	if (v instanceof ViewGroup) {
		final ViewGroup vg = (ViewGroup) v;
		for (int i = vg.getChildCount() - 1; i >= 0; i--) {
			setEnabledRecursive(vg.getChildAt(i), enabled);
		}
	}
}
 
Example 9
Project: easyfilemanager   File: DirectoryFragment.java   Source Code and License Vote up 6 votes
private void setEnabledRecursive(View v, boolean enabled) {
	if (v == null)
		return;
	if (v.isEnabled() == enabled)
		return;
	v.setEnabled(enabled);

	if (v instanceof ViewGroup) {
		final ViewGroup vg = (ViewGroup) v;
		for (int i = vg.getChildCount() - 1; i >= 0; i--) {
			setEnabledRecursive(vg.getChildAt(i), enabled);
		}
	}
}
 
Example 10
Project: aos-Video   File: FolderPicker.java   Source Code and License Vote up 6 votes
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (!view.isEnabled()) {
        return;
    }
    mSelectedFolder = mListItems.get(position).mUri;
    loadFolder(mSelectedFolder);
}
 
Example 11
Project: Swap   File: PLA_AbsListView.java   Source Code and License Vote up 6 votes
void positionSelector(View sel) {
    final Rect selectorRect = mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());
    positionSelector(selectorRect.left, selectorRect.top, selectorRect.right,
            selectorRect.bottom);

    final boolean isChildViewEnabled = mIsChildViewEnabled;
    if (sel.isEnabled() != isChildViewEnabled) {
        mIsChildViewEnabled = !isChildViewEnabled;
        refreshDrawableState();
    }
}
 
Example 12
Project: boohee_v5.6   File: PLA_AbsListView.java   Source Code and License Vote up 6 votes
void positionSelector(View sel) {
    Rect selectorRect = this.mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());
    positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect
            .bottom);
    boolean isChildViewEnabled = this.mIsChildViewEnabled;
    if (sel.isEnabled() != isChildViewEnabled) {
        this.mIsChildViewEnabled = !isChildViewEnabled;
        refreshDrawableState();
    }
}
 
Example 13
Project: microMathematics   File: HorizontalNumberPicker.java   Source Code and License Vote up 6 votes
private void updateViewColor(View v)
{
    final int attrId = v.isEnabled() ? R.attr.colorDialogContent : R.attr.colorDialogDisabledElement;
    if (v instanceof ImageButton)
    {
        ViewUtils.setImageButtonColorAttr(getContext(), (ImageButton) v, attrId);
    }
    else if (v instanceof TextView)
    {
        final TextView b = (TextView) v;
        b.setTextColor(CompatUtils.getThemeColorAttr(getContext(), attrId));
    }
}
 
Example 14
Project: boohee_v5.6   File: ListPopupWindow.java   Source Code and License Vote up 6 votes
private void onLongPress() {
    clearCallbacks();
    View src = this.mSrc;
    if (src.isEnabled() && !src.isLongClickable() && onForwardingStarted()) {
        src.getParent().requestDisallowInterceptTouchEvent(true);
        long now = SystemClock.uptimeMillis();
        MotionEvent e = MotionEvent.obtain(now, now, 3, 0.0f, 0.0f, 0);
        src.onTouchEvent(e);
        e.recycle();
        this.mForwarding = true;
        this.mWasLongPress = true;
    }
}
 
Example 15
Project: GitHub   File: ButterKnifeTest.java   Source Code and License Vote up 5 votes
@Override public Boolean get(View view) {
  return view.isEnabled();
}
 
Example 16
Project: RNLearn_Project1   File: TouchTargetHelper.java   Source Code and License Vote up 5 votes
/**
 * Returns the touch target View of the event given, or null if neither the given View nor any of
 * its descendants are the touch target.
 */
private static @Nullable View findTouchTargetViewWithPointerEvents(
    float eventCoords[], View view) {
  PointerEvents pointerEvents = view instanceof ReactPointerEventsView ?
      ((ReactPointerEventsView) view).getPointerEvents() : PointerEvents.AUTO;

  // Views that are disabled should never be the target of pointer events. However, their children
  // can be because some views (SwipeRefreshLayout) use enabled but still have children that can
  // be valid targets.
  if (!view.isEnabled()) {
    if (pointerEvents == PointerEvents.AUTO) {
      pointerEvents = PointerEvents.BOX_NONE;
    } else if (pointerEvents == PointerEvents.BOX_ONLY) {
      pointerEvents = PointerEvents.NONE;
    }
  }

  if (pointerEvents == PointerEvents.NONE) {
    // This view and its children can't be the target
    return null;

  } else if (pointerEvents == PointerEvents.BOX_ONLY) {
    // This view is the target, its children don't matter
    return view;

  } else if (pointerEvents == PointerEvents.BOX_NONE) {
    // This view can't be the target, but its children might.
    if (view instanceof ViewGroup) {
      View targetView = findTouchTargetView(eventCoords, (ViewGroup) view);
      if (targetView != view) {
        return targetView;
      }

      // PointerEvents.BOX_NONE means that this react element cannot receive pointer events.
      // However, there might be virtual children that can receive pointer events, in which case
      // we still want to return this View and dispatch a pointer event to the virtual element.
      // Note that this currently only applies to Nodes/FlatViewGroup as it's the only class that
      // is both a ViewGroup and ReactCompoundView (ReactTextView is a ReactCompoundView but not a
      // ViewGroup).
      if (view instanceof ReactCompoundView) {
        int reactTag = ((ReactCompoundView)view).reactTagForTouch(eventCoords[0], eventCoords[1]);
        if (reactTag != view.getId()) {
          // make sure we exclude the View itself because of the PointerEvents.BOX_NONE
          return view;
        }
      }
    }
    return null;

  } else if (pointerEvents == PointerEvents.AUTO) {
    // Either this view or one of its children is the target
    if (view instanceof ReactCompoundViewGroup) {
      if (((ReactCompoundViewGroup) view).interceptsTouchEvent(eventCoords[0], eventCoords[1])) {
        return view;
      }
    }
    if (view instanceof ViewGroup) {
      return findTouchTargetView(eventCoords, (ViewGroup) view);
    }
    return view;

  } else {
    throw new JSApplicationIllegalArgumentException(
        "Unknown pointer event type: " + pointerEvents.toString());
  }
}
 
Example 17
Project: TestChat   File: BaseItemClickListener.java   Source Code and License Vote up 5 votes
@Override
                public boolean onSingleTapUp(MotionEvent e) {
                        if (mPressedView != null) {
                                if (mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
//                                        正在滚动中,不处理
                                        return false;
                                }
                                LogUtil.e("onSingleTapUp1");
                                BaseWrappedViewHolder baseWrappedViewHolder = (BaseWrappedViewHolder) mRecyclerView.getChildViewHolder(mPressedView);
//                                头部和底部view不处理
                                if (baseWrappedViewHolder != null) {
                                        LogUtil.e("baseWrappedViewHolder");
                                        if (isHeaderViewOrFooterView(baseWrappedViewHolder.getItemViewType())) {
                                                LogUtil.e("isHeaderViewOrFooterView");
                                                return false;
                                        }
//                                        获取设置点击事件的item_view的id;
                                        Set<Integer> ids = baseWrappedViewHolder.getClickableItemIds();
                                        Set<Integer> nestIds = baseWrappedViewHolder.getNestIds();
                                        LogUtil.e("nestIds");
                                        if (ids != null && ids.size() > 0) {
                                                LogUtil.e("ids.size()");
                                                for (Integer id :
                                                        ids) {
                                                        final View childView = mPressedView.findViewById(id);
                                                        if (childView != null&&childView.getVisibility()==View.VISIBLE) {

//                                                                判断点击位置是否在该view上和该view是否可点击
                                                                if (isOnRange(e, childView) && childView.isEnabled()) {
//                                                                        这里要排除掉嵌套的recyclerView的点击事件
                                                                        if (nestIds != null && nestIds.contains(id)) {
                                                                                LogUtil.e("nestIds");
                                                                                return false;
                                                                        }
//                                                                        设置item的热点
                                                                        setChildHotSpot(childView, e);
                                                                        childView.setPressed(true);
//                                                                        点击接口
                                                                        LogUtil.e("触发item_child点击");
                                                                        onItemChildClick(baseWrappedViewHolder, id, childView, baseWrappedViewHolder.getAdapterPosition() - mBaseWrappedAdapter.getHeaderViewCount());
//                                                                        恢复效果,提交,防止堵塞
                                                                        resetView(childView);
                                                                        return true;
                                                                } else {
                                                                        LogUtil.e("isEnabled" + childView.isEnabled());
                                                                }
                                                        }
                                                }
                                        }
                                        //                                        如果执行到这里,证明没有设置点击事件,所以设置itemView的点击事件
                                        setChildHotSpot(mPressedView, e);
                                        mPressedView.setPressed(true);
                                        onItemClick(baseWrappedViewHolder, baseWrappedViewHolder.itemView.getId(), mPressedView, baseWrappedViewHolder.getAdapterPosition() - mBaseWrappedAdapter.getHeaderViewCount());
                                        resetView(mPressedView);
                                }

                        }
                        return false;
                }
 
Example 18
Project: TestChat   File: BaseItemClickListener.java   Source Code and License Vote up 5 votes
@Override
                public void onLongPress(MotionEvent e) {
                        if (mPressedView != null) {
                                if (mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
                                        return;
                                }
                                mPressedView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                                BaseWrappedViewHolder baseWrappedViewHolder = (BaseWrappedViewHolder) mRecyclerView.getChildViewHolder(mPressedView);
                                if (baseWrappedViewHolder != null) {
                                        boolean isLongClickConsume = false;
                                        if (isHeaderViewOrFooterView(baseWrappedViewHolder.getItemViewType())) {
                                                isLongClickConsume = true;
                                        }
                                        Set<Integer> ids = baseWrappedViewHolder.getLongClickableItemIds();
                                        Set<Integer> nestIds = baseWrappedViewHolder.getNestIds();
                                        if (ids != null && ids.size() > 0) {
                                                for (Integer id :
                                                        ids) {
                                                        final View childView = mPressedView.findViewById(id);
                                                        if (childView != null) {
//                                                                判断点击位置是否在该view上和该view是否可点击
                                                                if (isOnRange(e, childView) && childView.isEnabled()) {
//                                                                        这里要排除掉嵌套的recyclerView的点击事件
                                                                        if (nestIds != null && nestIds.contains(id)) {
                                                                                break;
                                                                        }
//                                                                        设置item的热点
                                                                        setChildHotSpot(childView, e);
                                                                        childView.setPressed(true);
//                                                                        点击接口
                                                                        onItemChildLongClick(baseWrappedViewHolder, id, childView, baseWrappedViewHolder.getAdapterPosition() - mBaseWrappedAdapter.getHeaderViewCount());
//                                                                        恢复效果,提交,防止堵塞
                                                                        isLongClickConsume = true;
                                                                        isPressing = true;
                                                                        break;
                                                                }
                                                        }
                                                }
                                        }
                                        if (!isLongClickConsume) {
                                                setChildHotSpot(mPressedView, e);
                                                mPressedView.setPressed(true);
                                                onItemLongClick(baseWrappedViewHolder, mPressedView, baseWrappedViewHolder.getAdapterPosition() - mBaseWrappedAdapter.getHeaderViewCount());
                                                isPressing = true;
                                        }
                                }
                        }
                }
 
Example 19
Project: RNLearn_Project1   File: TouchTargetHelper.java   Source Code and License Vote up 5 votes
/**
 * Returns the touch target View of the event given, or null if neither the given View nor any of
 * its descendants are the touch target.
 */
private static @Nullable View findTouchTargetViewWithPointerEvents(
    float eventCoords[], View view) {
  PointerEvents pointerEvents = view instanceof ReactPointerEventsView ?
      ((ReactPointerEventsView) view).getPointerEvents() : PointerEvents.AUTO;

  // Views that are disabled should never be the target of pointer events. However, their children
  // can be because some views (SwipeRefreshLayout) use enabled but still have children that can
  // be valid targets.
  if (!view.isEnabled()) {
    if (pointerEvents == PointerEvents.AUTO) {
      pointerEvents = PointerEvents.BOX_NONE;
    } else if (pointerEvents == PointerEvents.BOX_ONLY) {
      pointerEvents = PointerEvents.NONE;
    }
  }

  if (pointerEvents == PointerEvents.NONE) {
    // This view and its children can't be the target
    return null;

  } else if (pointerEvents == PointerEvents.BOX_ONLY) {
    // This view is the target, its children don't matter
    return view;

  } else if (pointerEvents == PointerEvents.BOX_NONE) {
    // This view can't be the target, but its children might.
    if (view instanceof ViewGroup) {
      View targetView = findTouchTargetView(eventCoords, (ViewGroup) view);
      if (targetView != view) {
        return targetView;
      }

      // PointerEvents.BOX_NONE means that this react element cannot receive pointer events.
      // However, there might be virtual children that can receive pointer events, in which case
      // we still want to return this View and dispatch a pointer event to the virtual element.
      // Note that this currently only applies to Nodes/FlatViewGroup as it's the only class that
      // is both a ViewGroup and ReactCompoundView (ReactTextView is a ReactCompoundView but not a
      // ViewGroup).
      if (view instanceof ReactCompoundView) {
        int reactTag = ((ReactCompoundView)view).reactTagForTouch(eventCoords[0], eventCoords[1]);
        if (reactTag != view.getId()) {
          // make sure we exclude the View itself because of the PointerEvents.BOX_NONE
          return view;
        }
      }
    }
    return null;

  } else if (pointerEvents == PointerEvents.AUTO) {
    // Either this view or one of its children is the target
    if (view instanceof ReactCompoundViewGroup) {
      if (((ReactCompoundViewGroup) view).interceptsTouchEvent(eventCoords[0], eventCoords[1])) {
        return view;
      }
    }
    if (view instanceof ViewGroup) {
      return findTouchTargetView(eventCoords, (ViewGroup) view);
    }
    return view;

  } else {
    throw new JSApplicationIllegalArgumentException(
        "Unknown pointer event type: " + pointerEvents.toString());
  }
}
 
Example 20
Project: EasyAndroid   File: ViewTool.java   Source Code and License Vote up 3 votes
/**
 * 判断View是不是可用
 *
 * @param v View
 * @return {@code true} enabled
 */
public static boolean isEnabled(View v)
{
    return v.isEnabled();
}