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

The following examples show how to use android.view.View#isPressed() . 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: ViewClickProbe.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 判断是否触发Click上报
 *
 * @param element          被点击控件
 * @param hasTrackClickAnn 是否有附属注解
 */
private boolean checkTrackClickEnable(Object pageObj, Object element, boolean hasTrackClickAnn) {
    AgentProcess instance = AgentProcess.getInstance();
    if (element instanceof View) {
        View v = (View) element;
        boolean isByUser = v.isPressed();
        if (v instanceof RatingBar || v instanceof CompoundButton) {
            if (!isByUser) {
                return false;
            }
        }
    }

    boolean isInBlack = instance.isThisViewInAutoClickBlackList(element)
            || (element != null && instance.isThisViewTypeInAutoClickBlackList(element.getClass()))
            || (pageObj != null && instance.isThisPageInAutoClickBlackList(pageObj.getClass().getName()));
    if (isInBlack) {
        return false;
    } else if (AgentProcess.getInstance().hasAutoClickWhiteList()) {
        return instance.isThisViewInAutoClickWhiteList(element)
                || (element != null && instance.isThisViewTypeInAutoClickWhiteList(element.getClass()))
                || (pageObj != null && instance.isThisPageInAutoClickWhiteList(pageObj.getClass().getName()));
    }
    return true;
}
 
Example 2
Source File: DropDownListView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setPressedItem(@NonNull View child, int position, float x, float y) {
    mDrawsInPressedState = true;

    // Ordering is essential. First, update the container's pressed state.
    drawableHotspotChanged(x, y);
    if (!isPressed()) {
        setPressed(true);
    }

    // Next, run layout if we need to stabilize child positions.
    if (mDataChanged) {
        layoutChildren();
    }

    // Manage the pressed view based on motion position. This allows us to
    // play nicely with actual touch and scroll events.
    final View motionView = getChildAt(mMotionPosition - mFirstPosition);
    if (motionView != null && motionView != child && motionView.isPressed()) {
        motionView.setPressed(false);
    }
    mMotionPosition = position;

    // Offset for child coordinates.
    final float childX = x - child.getLeft();
    final float childY = y - child.getTop();
    child.drawableHotspotChanged(childX, childY);
    if (!child.isPressed()) {
        child.setPressed(true);
    }

    // Ensure that keyboard focus starts from the last touched position.
    setSelectedPositionInt(position);
    positionSelectorLikeTouch(position, child, x, y);

    // Refresh the drawable state to reflect the new pressed state,
    // which will also update the selector state.
    refreshDrawableState();
}
 
Example 3
Source File: SideBar.java    From FantasySlide with Apache License 2.0 5 votes vote down vote up
void onMotionEventUp() {
    for (int i = 0; opened && i < getChildCount(); i++) {
        View child = getChildAt(i);
        if (child.isPressed()) {
            if (fantasyListener == null || !fantasyListener.onSelect(child, i)) {
                child.performClick();
            }
            return;
        }
    }
    if (fantasyListener != null) {
        fantasyListener.onCancel();
    }
}
 
Example 4
Source File: TestUtilsMatchers.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Returns a matcher that matches {@link View}s that are pressed. */
public static Matcher<View> isPressed() {
  return new TypeSafeMatcher<View>() {
    @Override
    public void describeTo(Description description) {
      description.appendText("is pressed");
    }

    @Override
    public boolean matchesSafely(View view) {
      return view.isPressed();
    }
  };
}
 
Example 5
Source File: ExerciseActivity.java    From Quiz with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns pressed button View
 * 
 * @return pressed button View
 */
private View getPressedButton() {
	for (View v : answerViews.keySet()) {
		if (v.isPressed()) {
			return v;
		}
	}
	return null;
}
 
Example 6
Source File: HListView.java    From letv with Apache License 2.0 4 votes vote down vote up
@TargetApi(11)
private void setupChild(View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled) {
    boolean isSelected = selected && shouldShowSelector();
    boolean updateChildSelected = isSelected != child.isSelected();
    int mode = this.mTouchMode;
    boolean isPressed = mode > 0 && mode < 3 && this.mMotionPosition == position;
    boolean updateChildPressed = isPressed != child.isPressed();
    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    if ((!recycled || p.forceAdd) && !(p.recycledHeaderFooter && p.viewType == -2)) {
        p.forceAdd = false;
        if (p.viewType == -2) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    } else {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    }
    if (updateChildSelected) {
        child.setSelected(isSelected);
    }
    if (updateChildPressed) {
        child.setPressed(isPressed);
    }
    if (!(this.mChoiceMode == 0 || this.mCheckStates == null)) {
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        } else if (VERSION.SDK_INT >= 11) {
            child.setActivated(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        }
    }
    if (needToMeasure) {
        int childWidthSpec;
        int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
        int lpWidth = p.width;
        if (lpWidth > 0) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
        }
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }
    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();
    int childLeft = flowDown ? x : x - w;
    if (needToMeasure) {
        child.layout(childLeft, childrenTop, childLeft + w, childrenTop + h);
    } else {
        child.offsetLeftAndRight(childLeft - child.getLeft());
        child.offsetTopAndBottom(childrenTop - child.getTop());
    }
    if (this.mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
    if (VERSION.SDK_INT >= 11 && recycled && ((LayoutParams) child.getLayoutParams()).scrappedFromPosition != position) {
        child.jumpDrawablesToCurrentState();
    }
}
 
Example 7
Source File: ZrcListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
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
    ZrcAbsListView.LayoutParams p = (ZrcAbsListView.LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (ZrcAbsListView.LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = mAdapter.getItemViewType(position);

    if ((recycled && !p.forceAdd)
            || (p.recycledHeaderFooter &&
            p.viewType == ZrcAdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    } else {
        p.forceAdd = false;
        if (p.viewType == ZrcAdapterView.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);
        }
        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);
    } else {
        child.offsetLeftAndRight(childrenLeft - child.getLeft());
        child.offsetTopAndBottom(childTop - child.getTop());
    }

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

    if (recycled &&
            (((ZrcAbsListView.LayoutParams) child.getLayoutParams()).scrappedFromPosition) !=
                    position) {
        if (Build.VERSION.SDK_INT >= 11) {
            child.jumpDrawablesToCurrentState();
        }
    }
}
 
Example 8
Source File: TwoWayGridView.java    From recent-images with MIT License 4 votes vote down vote up
/**
 * 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 the view
 * @param y The y position relative to which this view will be positioned
 * @param flow 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.
 * @param where Where to add the item in the list
 *
 */
private void setupChild(View child, int position, int y, boolean flow, int childrenLeft,
		boolean selected, boolean recycled, int where) {
	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();

	boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

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

	if (recycled && !p.forceAdd) {
		attachViewToParent(child, where, p);
	} else {
		p.forceAdd = false;
		addViewInLayout(child, where, p, true);
	}

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

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

	if (needToMeasure) {
		int childHeightSpec = ViewGroup.getChildMeasureSpec(
				MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);

		int childWidthSpec = ViewGroup.getChildMeasureSpec(
				MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width);
		child.measure(childWidthSpec, childHeightSpec);
	} else {
		cleanupLayoutState(child);
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();

	int childLeft;
	final int childTop = flow ? y : y - h;

	switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
	case Gravity.LEFT:
		childLeft = childrenLeft;
		break;
	case Gravity.CENTER_HORIZONTAL:
		childLeft = childrenLeft + ((mColumnWidth - w) / 2);
		break;
	case Gravity.RIGHT:
		childLeft = childrenLeft + mColumnWidth - w;
		break;
	default:
		childLeft = childrenLeft;
		break;
	}

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

	if (mCachingStarted) {
		child.setDrawingCacheEnabled(true);
	}
}
 
Example 9
Source File: TwoWayGridView.java    From recent-images with MIT License 4 votes vote down vote up
/**
 * 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 the view
 * @param x The x position relative to which this view will be positioned
 * @param flow 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.
 * @param where Where to add the item in the list
 *
 */
private void setupChild(View child, int position, int x, boolean flow, int childrenTop,
		boolean selected, boolean recycled, int where) {
	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();

	boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

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

	if (recycled && !p.forceAdd) {
		attachViewToParent(child, where, p);
	} else {
		p.forceAdd = false;
		addViewInLayout(child, where, p, true);
	}

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

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

	if (needToMeasure) {
		int childWidthSpec = ViewGroup.getChildMeasureSpec(
				MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.width);

		int childHeightSpec = ViewGroup.getChildMeasureSpec(
				MeasureSpec.makeMeasureSpec(mRowHeight, MeasureSpec.EXACTLY), 0, p.height);
		child.measure(childWidthSpec, childHeightSpec);
	} else {
		cleanupLayoutState(child);
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();

	final int childLeft = flow ? x : x - w;
	int childTop;

	switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
	case Gravity.TOP:
		childTop = childrenTop;
		break;
	case Gravity.CENTER_HORIZONTAL:
		childTop = childrenTop + ((mRowHeight - h) / 2);
		break;
	case Gravity.RIGHT:
		childTop = childrenTop + mRowHeight - h;
		break;
	default:
		childTop = childrenTop;
		break;
	}

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

	if (mCachingStarted) {
		child.setDrawingCacheEnabled(true);
	}
}
 
Example 10
Source File: PLAListView.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
/**
 * 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 = 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);
    }
}
 
Example 11
Source File: PLAListView.java    From Lay-s with MIT License 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 12
Source File: HListView.java    From Klyph with MIT License 4 votes vote down vote up
/**
 * 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();
		}
	}
}
 
Example 13
Source File: ExtendableListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }

}
 
Example 14
Source File: ZrcListView.java    From ZrcListView with MIT License 4 votes vote down vote up
/**
 * 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.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
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
    ZrcAbsListView.LayoutParams p = (ZrcAbsListView.LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (ZrcAbsListView.LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = mAdapter.getItemViewType(position);

    if ((recycled && !p.forceAdd)
            || (p.recycledHeaderFooter &&
            p.viewType == ZrcAdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    } else {
        p.forceAdd = false;
        if (p.viewType == ZrcAdapterView.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);
        }
        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);
    } else {
        child.offsetLeftAndRight(childrenLeft - child.getLeft());
        child.offsetTopAndBottom(childTop - child.getTop());
    }

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

    if (recycled &&
            (((ZrcAbsListView.LayoutParams) child.getLayoutParams()).scrappedFromPosition) !=
                    position) {
        if (APIUtil.isSupport(11)) {
            child.jumpDrawablesToCurrentState();
        }
    }
}
 
Example 15
Source File: PLA_ListView.java    From EverMemo with MIT License 4 votes vote down vote up
/**
 * 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);
	}
}