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

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

源代码1 项目: HaoReader   文件: AudioBookPlayActivity.java
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_pause:
            if (v.isSelected()) {
                AudioBookPlayService.pause(this);
            } else {
                AudioBookPlayService.resume(this);
            }
            break;
        case R.id.btn_previous:
            AudioBookPlayService.previous(this);
            break;
        case R.id.btn_next:
            AudioBookPlayService.next(this);
            break;

        case R.id.btn_catalog:
            audioChapterPop.showAtLocation(ivBlurCover, Gravity.BOTTOM, 0, 0);
            break;
        case R.id.btn_timer:
            audioTimerPop.showAtLocation(ivBlurCover, Gravity.BOTTOM, 0, 0);
            break;
    }
}
 
源代码2 项目: demo4Fish   文件: HomeViewLayer.java
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        int count = mDotLayout.getChildCount();
        if (0 == count) {
            return;
        }

        LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int position = manager.findFirstCompletelyVisibleItemPosition() % count;
        for (int i = 0; i < count; i++) {
            View view = mDotLayout.getChildAt(i);
            if (i == position) {
                if (!view.isSelected()) {
                    view.setSelected(true);
                }
            } else {
                if (view.isSelected()) {
                    view.setSelected(false);
                }
            }
        }
    }
}
 
public void onOptionClick(View view) {
    if (view.isSelected()) {
        view.setSelected(false);
    } else {
        view.setSelected(true);
    }
}
 
源代码4 项目: FlowHelper   文件: LabelFlowLayout.java
/**
 * 拿到当前选中的view
 * 适合单选的时候
 *
 * @return
 */
public View getSelectedView() {
    for (int i = 0; i < getChildCount(); i++) {
        View view = getChildAt(i);
        if (view.isSelected()) {
            return view;
        }
    }
    return null;
}
 
源代码5 项目: FlowHelper   文件: LabelFlowLayout.java
/**
 * 拿到选中数据
 *
 * @return
 */
public List<Integer> getSelecteds() {
    List<Integer> indexs = new ArrayList<>();
    for (int i = 0; i < getChildCount(); i++) {
        View view = getChildAt(i);
        if (view.isSelected()) {
            indexs.add(i);

        }
    }
    return indexs;
}
 
源代码6 项目: DevUtils   文件: ViewUtils.java
/**
 * 获取 View 是否选中
 * @param view {@link View}
 * @return {@code true} 选中, {@code false} 非选中
 */
public static boolean isSelected(final View view) {
    if (view != null) {
        return view.isSelected();
    }
    return false;
}
 
源代码7 项目: litho   文件: LithoMountData.java
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;
}
 
源代码8 项目: PLDroidShortVideo   文件: BaseRecyclerAdapter.java
@Override
protected void onMultiClick(View view) {
    int position = mViewHolder.getAdapterPosition();
    if (position < 0) {
        return;
    }
    int choiceMode = choiceMode();
    T selectedData = getItem(position);
    if (choiceMode == SINGLE_CHOICE_MODE) {
        mSelectedItems.put(position, selectedData);
        if (isValidPosition(mLastSelected) && mLastSelected != position) {
            mSelectedItems.remove(mLastSelected);
        }
        notifyItemChanged(mLastSelected);
        notifyItemChanged(position);
        mLastSelected = position;
    } else if (choiceMode == MULTI_CHOICE_MODE) {
        boolean isClicked = !view.isSelected();
        if (isClicked) {
            mSelectedItems.put(position, selectedData);
        } else {
            mSelectedItems.remove(position);
        }
        notifyItemChanged(position);
    }

    if (mOnItemClickListener != null) {
        mOnItemClickListener.onItemClick(BaseRecyclerAdapter.this, view, position);
    }
}
 
源代码9 项目: ArcLayout   文件: DemoLikeTumblrActivity.java
private void onFabClick(View v) {
  int x = (v.getLeft() + v.getRight()) / 2;
  int y = (v.getTop() + v.getBottom()) / 2;
  float radiusOfFab = 1f * v.getWidth() / 2f;
  float radiusFromFabToRoot = (float) Math.hypot(
      Math.max(x, rootLayout.getWidth() - x),
      Math.max(y, rootLayout.getHeight() - y));

  if (v.isSelected()) {
    hideMenu(x, y, radiusFromFabToRoot, radiusOfFab);
  } else {
    showMenu(x, y, radiusOfFab, radiusFromFabToRoot);
  }
  v.setSelected(!v.isSelected());
}
 
源代码10 项目: ArcLayout   文件: DemoLikePathActivity.java
private void onFabClick(View v) {
  if (v.isSelected()) {
    hideMenu();
  } else {
    showMenu();
  }
  v.setSelected(!v.isSelected());
}
 
源代码11 项目: Android   文件: PickHorScrollView.java
@Override
public void onClick(View v) {
    String path = (String) v.getTag();
    if (v.isSelected()) {
        v.setSelected(false);
        clickLists.remove(path);
    } else {
        v.setSelected(true);
        clickLists.add(path);
    }
    itemClickListener.itemOnClick(clickLists);
}
 
源代码12 项目: Klyph   文件: HListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and positioned properly.
 * 
 * @param child
 *           The view to add
 * @param position
 *           The position of this child
 * @param x
 *           The x position relative to which this view will be positioned
 * @param flowDown
 *           If true, align left edge to x. If false, align right edge to x.
 * @param childrenTop
 *           Top edge where children should be positioned
 * @param selected
 *           Is this position selected?
 * @param recycled
 *           Has this view been pulled from the recycle bin? If so it does not need to be remeasured.
 */
private void setupChild( View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled ) {
	final boolean isSelected = selected && shouldShowSelector();
	final boolean updateChildSelected = isSelected != child.isSelected();
	final int mode = mTouchMode;
	final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL && mMotionPosition == position;
	final boolean updateChildPressed = isPressed != child.isPressed();
	final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

	// Respect layout params that are already in the view. Otherwise make some up...
	// noinspection unchecked
	AbsHListView.LayoutParams p = (AbsHListView.LayoutParams) child.getLayoutParams();
	if ( p == null ) {
		p = (AbsHListView.LayoutParams) generateDefaultLayoutParams();
	}
	p.viewType = mAdapter.getItemViewType( position );

	if ( ( recycled && !p.forceAdd ) || ( p.recycledHeaderFooter && p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER ) ) {
		attachViewToParent( child, flowDown ? -1 : 0, p );
	} else {
		p.forceAdd = false;
		if ( p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER ) {
			p.recycledHeaderFooter = true;
		}
		addViewInLayout( child, flowDown ? -1 : 0, p, true );
	}

	if ( updateChildSelected ) {
		child.setSelected( isSelected );
	}

	if ( updateChildPressed ) {
		child.setPressed( isPressed );
	}

	if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null ) {
		if ( child instanceof Checkable ) {
			( (Checkable) child ).setChecked( mCheckStates.get( position ) );
		} else if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
			child.setActivated( mCheckStates.get( position ) );
		}
	}

	if ( needToMeasure ) {
		int childHeightSpec = ViewGroup.getChildMeasureSpec( mHeightMeasureSpec, mListPadding.top + mListPadding.bottom, p.height );
		int lpWidth = p.width;
		int childWidthSpec;
		if ( lpWidth > 0 ) {
			childWidthSpec = MeasureSpec.makeMeasureSpec( lpWidth, MeasureSpec.EXACTLY );
		} else {
			childWidthSpec = MeasureSpec.makeMeasureSpec( 0, MeasureSpec.UNSPECIFIED );
		}
		child.measure( childWidthSpec, childHeightSpec );
	} else {
		cleanupLayoutState( child );
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();
	final int childLeft = flowDown ? x : x - w;

	if ( needToMeasure ) {
		final int childBottom = childrenTop + h;
		final int childRight = childLeft + w;
		child.layout( childLeft, childrenTop, childRight, childBottom );
	} else {
		child.offsetLeftAndRight( childLeft - child.getLeft() );
		child.offsetTopAndBottom( childrenTop - child.getTop() );
	}

	if ( mCachingStarted && !child.isDrawingCacheEnabled() ) {
		child.setDrawingCacheEnabled( true );
	}

	if( android.os.Build.VERSION.SDK_INT >= 11 ) {
		if ( recycled && ( ( (AbsHListView.LayoutParams) child.getLayoutParams() ).scrappedFromPosition ) != position ) {
			child.jumpDrawablesToCurrentState();
		}
	}
}
 
源代码13 项目: EasyPhotos   文件: UCropActivity.java
@Override
public void onClick(View v) {
    if (!v.isSelected()) {
        setWidgetState(v.getId());
    }
}
 
源代码14 项目: EasyPhotos   文件: UCropFragment.java
@Override
public void onClick(View v) {
    if (!v.isSelected()) {
        setWidgetState(v.getId());
    }
}
 
源代码15 项目: Lay-s   文件: PLAListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 *
 * @param child The view to add
 * @param position The position of this child
 * @param y The y position relative to which this view will be positioned
 * @param flowDown If true, align top edge to y. If false, align bottom
 *        edge to y.
 * @param childrenLeft Left edge where children should be positioned
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *        does not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown, int childrenLeft,
        boolean selected, boolean recycled) {

    final boolean isSelected = selected && shouldShowSelector();
    final boolean updateChildSelected = isSelected != child.isSelected();
    final int mode = mTouchMode;
    final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL &&
            mMotionPosition == position;
    final boolean updateChildPressed = isPressed != child.isPressed();
    final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

    // Respect layout params that are already in the view. Otherwise make some up...
    // noinspection unchecked
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    }
    p.viewType = mAdapter.getItemViewType(position);
    p.scrappedFromPosition = position;

    if ((recycled && !p.forceAdd) || (p.recycledHeaderFooter &&
            p.viewType == PLAAdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    } else {
        p.forceAdd = false;
        if (p.viewType == PLAAdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    }

    if (updateChildSelected) {
        child.setSelected(isSelected);
    }

    if (updateChildPressed) {
        child.setPressed(isPressed);
    }

    if (needToMeasure) {
        int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
                mListPadding.left + mListPadding.right, p.width);
        int lpHeight = p.height;
        int childHeightSpec;
        if (lpHeight > 0) {
            childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        }

        onMeasureChild( child, position, childWidthSpec, childHeightSpec );
        //child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }

    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childTop = flowDown ? y : y - h;

    if (needToMeasure) {
        final int childRight = childrenLeft + w;
        final int childBottom = childTop + h;
        //child.layout(childrenLeft, childTop, childRight, childBottom);
        onLayoutChild(child, position, childrenLeft, childTop, childRight, childBottom);
    } else {
        final int offsetLeft = childrenLeft - child.getLeft();
        final int offsetTop = childTop - child.getTop();
        onOffsetChild(child, position, offsetLeft, offsetTop);
    }

    if (mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
}
 
源代码16 项目: droidddle   文件: ShotFragment.java
private void likeOrUnlike(View view) {
    boolean checked = view.isSelected();
    view.setSelected(!checked);
    likeOrUnlikeShot(!checked);
}
 
源代码17 项目: UltimateAndroid   文件: ExtendableListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 *
 * @param child    The view to add
 * @param position The position of this child
 * @param y        The y position relative to which this view will be positioned
 * @param flowDown If true, align top edge to y. If false, align bottom
 *                 edge to y.
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *                 does not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown,
                        boolean selected, boolean recycled) {
    final boolean isSelected = false; // TODO : selected && shouldShowSelector();
    final boolean updateChildSelected = isSelected != child.isSelected();
    final int mode = mTouchMode;
    final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLLING &&
            mMotionPosition == position;
    final boolean updateChildPressed = isPressed != child.isPressed();
    final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

    int itemViewType = mAdapter.getItemViewType(position);

    LayoutParams layoutParams;
    if (itemViewType == ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
        layoutParams = generateWrapperLayoutParams(child);
    }
    else {
        layoutParams = generateChildLayoutParams(child);
    }

    layoutParams.viewType = itemViewType;
    layoutParams.position = position;

    if (recycled || (layoutParams.recycledHeaderFooter &&
            layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        if (DBG) Log.d(TAG, "setupChild attachViewToParent position:" + position);
        attachViewToParent(child, flowDown ? -1 : 0, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild addViewInLayout position:" + position);
        if (layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
            layoutParams.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, layoutParams, true);
    }

    if (updateChildSelected) {
        child.setSelected(isSelected);
    }

    if (updateChildPressed) {
        child.setPressed(isPressed);
    }

    if (needToMeasure) {
        if (DBG) Log.d(TAG, "setupChild onMeasureChild position:" + position);
        onMeasureChild(child, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild cleanupLayoutState position:" + position);
        cleanupLayoutState(child);
    }

    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childTop = flowDown ? y : y - h;

    if (DBG) {
        Log.d(TAG, "setupChild position:" + position + " h:" + h + " w:" + w);
    }

    final int childrenLeft = getChildLeft(position);

    if (needToMeasure) {
        final int childRight = childrenLeft + w;
        final int childBottom = childTop + h;
        onLayoutChild(child, position, flowDown, childrenLeft, childTop, childRight, childBottom);
    }
    else {
        onOffsetChild(child, position, flowDown, childrenLeft, childTop);
    }

}
 
源代码18 项目: sealtalk-android   文件: SingleCallActivity.java
public void onMuteButtonClick(View view) {
    RongCallClient.getInstance().setEnableLocalAudio(view.isSelected());
    view.setSelected(!view.isSelected());
    muted = view.isSelected();
}
 
源代码19 项目: RichEditor   文件: EditorPanel.java
@Override
public void onClick(View v) {
    v.setSelected(!v.isSelected());
    int i = v.getId();
    BasePanelEvent state = null;
    if (i == R.id.iv_font) {
        if (mFontDatas.size() == 0) {
            PanelFactory.createFontPanel(mFontDatas);
            mPanelDatas.addAll(mFontDatas);
            mPanelAdapter.notifyDataSetChanged();
        }
        mPanel.setVisibility(v.isSelected() ? VISIBLE : GONE);
        state = new FontChangeEvent(v.isSelected());
    } else if (i == R.id.iv_link) {
        String url = "www.baidu.com";
        FontParam param = new FontParam();
        param.url = url;
        param.fontColor = Color.parseColor("#3194D0");
        state = new LinkChangeEvent(v.isSelected(), param, "百度");
    } else if (i == R.id.iv_refer) {
        state = new ParagraphChangeEvent(v.isSelected());
        ((ParagraphChangeEvent)state).pType = Const.PARAGRAPH_REFER;
    } else if (i == R.id.tv_h1) {
        ((TextView)v).setTextColor(v.isSelected()? Color.parseColor("#7dc5eb"):Color.parseColor("#bfbfbf"));
        state = new ParagraphChangeEvent(v.isSelected());
        ((ParagraphChangeEvent)state).pType = Const.PARAGRAPH_T1;
    } else if (i == R.id.tv_h2) {
        ((TextView)v).setTextColor(v.isSelected()? Color.parseColor("#7dc5eb"):Color.parseColor("#bfbfbf"));
        state = new ParagraphChangeEvent(v.isSelected());
        ((ParagraphChangeEvent)state).pType = Const.PARAGRAPH_T2;
    } else if (i == R.id.tv_h3) {
        ((TextView)v).setTextColor(v.isSelected()? Color.parseColor("#7dc5eb"):Color.parseColor("#bfbfbf"));
        state = new ParagraphChangeEvent(v.isSelected());
        ((ParagraphChangeEvent)state).pType = Const.PARAGRAPH_T3;
    } else if (i == R.id.tv_h4) {
        ((TextView)v).setTextColor(v.isSelected()? Color.parseColor("#7dc5eb"):Color.parseColor("#bfbfbf"));
        state = new ParagraphChangeEvent(v.isSelected());
        ((ParagraphChangeEvent)state).pType = Const.PARAGRAPH_T4;
    }
    if (mStateChange != null) {
        mStateChange.onStateChanged(state);
    }
}
 
源代码20 项目: EverMemo   文件: PLA_ListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 *
 * @param child The view to add
 * @param position The position of this child
 * @param y The y position relative to which this view will be positioned
 * @param flowDown If true, align top edge to y. If false, align bottom
 *        edge to y.
 * @param childrenLeft Left edge where children should be positioned
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *        does not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown, int childrenLeft,
		boolean selected, boolean recycled) {

	final boolean isSelected = selected && shouldShowSelector();
	final boolean updateChildSelected = isSelected != child.isSelected();
	final int mode = mTouchMode;
	final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL &&
			mMotionPosition == position;
	final boolean updateChildPressed = isPressed != child.isPressed();
	final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

	// Respect layout params that are already in the view. Otherwise make some up...
	// noinspection unchecked
	PLA_AbsListView.LayoutParams p = (PLA_AbsListView.LayoutParams) child.getLayoutParams();
	if (p == null) {
		p = new PLA_AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT, 0);
	}
	p.viewType = mAdapter.getItemViewType(position);

	if ((recycled && !p.forceAdd) || (p.recycledHeaderFooter &&
			p.viewType == PLA_AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
		attachViewToParent(child, flowDown ? -1 : 0, p);
	} else {
		p.forceAdd = false;
		if (p.viewType == PLA_AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
			p.recycledHeaderFooter = true;
		}
		addViewInLayout(child, flowDown ? -1 : 0, p, true);
	}

	if (updateChildSelected) {
		child.setSelected(isSelected);
	}

	if (updateChildPressed) {
		child.setPressed(isPressed);
	}

	if (needToMeasure) {
		int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
				mListPadding.left + mListPadding.right, p.width);
		int lpHeight = p.height;
		int childHeightSpec;
		if (lpHeight > 0) {
			childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
		} else {
			childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
		}

		onMeasureChild( child, position, childWidthSpec, childHeightSpec );
		//child.measure(childWidthSpec, childHeightSpec);
	} else {
		cleanupLayoutState(child);
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();
	final int childTop = flowDown ? y : y - h;

	if (needToMeasure) {
		final int childRight = childrenLeft + w;
		final int childBottom = childTop + h;
		//child.layout(childrenLeft, childTop, childRight, childBottom);
		onLayoutChild(child, position, childrenLeft, childTop, childRight, childBottom);
	} else {
		final int offsetLeft = childrenLeft - child.getLeft();
		final int offsetTop = childTop - child.getTop();
		onOffsetChild(child, position, offsetLeft, offsetTop);
	}

	if (mCachingStarted && !child.isDrawingCacheEnabled()) {
		child.setDrawingCacheEnabled(true);
	}
}
 
 方法所在类
 同类方法