List of usage examples for android.view View isPressed
@ViewDebug.ExportedProperty public boolean isPressed()
From source file:android.support.v7.widget.DropDownListView.java
private void setPressedItem(View child, int position, float x, float y) { mDrawsInPressedState = true;// www . ja v a 2 s. c o m // Ordering is essential. First, update the container's pressed state. if (Build.VERSION.SDK_INT >= 21) { drawableHotspotChanged(x, y); } if (!isPressed()) { setPressed(true); } // Next, run layout to stabilize child positions. layoutChildren(); // Manage the pressed view based on motion position. This allows us to // play nicely with actual touch and scroll events. if (mMotionPosition != INVALID_POSITION) { final View motionView = getChildAt(mMotionPosition - getFirstVisiblePosition()); 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(); if (Build.VERSION.SDK_INT >= 21) { child.drawableHotspotChanged(childX, childY); } if (!child.isPressed()) { child.setPressed(true); } // Ensure that keyboard focus starts from the last touched position. positionSelectorLikeTouchCompat(position, child, x, y); // This needs some explanation. We need to disable the selector for this next call // due to the way that ListViewCompat works. Otherwise both ListView and ListViewCompat // will draw the selector and bad things happen. setSelectorEnabled(false); // Refresh the drawable state to reflect the new pressed state, // which will also update the selector state. refreshDrawableState(); }
From source file:android.support.car.app.CarFragmentActivity.java
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break;/*from w ww . j av a2s.c o m*/ case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && r != null) { try { String pkgname; switch (id & 0xff000000) { case 0x7f000000: pkgname = "app"; break; case 0x01000000: pkgname = "android"; break; default: pkgname = r.getResourcePackageName(id); break; } String typename = r.getResourceTypeName(id); String entryname = r.getResourceEntryName(id); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
From source file:com.juick.android.MainActivity.java
public static void restyleChildrenOrWidget(View view, boolean dontBackground) { if (view == null) return;// w w w . j a v a 2s .c o m ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(view.getContext()); boolean pressed = view.isPressed(); boolean selected = view.isSelected(); String name = view.getClass().getName(); if (name.contains("$HomeView")) return; if (view instanceof AbsListView) { ((AbsListView) view).setCacheColorHint(colorTheme.getBackground(pressed)); } if (view instanceof EditText) { EditText et = (EditText) view; et.setTextColor(colorTheme.getForeground(pressed)); et.setBackgroundColor(colorTheme.getBackground(pressed)); } else if (view instanceof RadioButton) { RadioButton btn = (RadioButton) view; btn.setTextColor(colorTheme.getForeground(pressed)); btn.setBackgroundColor(colorTheme.getBackground()); } else if (view instanceof Spinner) { View scan = view; boolean shouldRecolor = false; while (scan != null) { if (scan.getClass().getName().toLowerCase().contains("action")) { shouldRecolor = true; break; } if ("shouldRecolor".equals(scan.getTag())) { shouldRecolor = true; break; } try { scan = (View) scan.getParent(); } catch (Exception e) { scan = null; } } if (shouldRecolor) restyleViewGroup((Spinner) view, colorTheme, pressed, selected, dontBackground); } else if (view instanceof Button) { // Button btn = (Button) view; // btn.setTextColor(colorTheme.getForeground(pressed)); // btn.setBackgroundColor(colorTheme.getButtonBackground()); } else if (view instanceof TextView) { TextView text = (TextView) view; final int id = text.getId(); if (id != R.id.old_title /* && id != R.id.gotoMain */) // keep it authentic text.setTextColor(colorTheme.getForeground(pressed)); } else if (view instanceof ViewGroup) { restyleViewGroup((ViewGroup) view, colorTheme, pressed, selected, dontBackground); } }
From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java
private void onTouchUp(MotionEvent ev) { if (isLayoutFrozen() || mTouchFromScrolling) { return;// w ww. j a va 2 s . com } View motionView = mMotionView; int motionPosition = mMotionPosition; if (motionView != null && motionPosition >= 0) { final float x = ev.getX(); final float y = ev.getY(); if (motionView.isPressed() || mPrePressed) { // The button is being released before we actually // showed it as pressed. Make it show the pressed // state now (before scheduling the click) to ensure // the user sees it. final float[] point = mTmpPoint; point[0] = x; point[1] = y; ViewUtils.transformPointToViewLocal(point, EasyRecyclerView.this, motionView); setPressed(motionView, true, point[0], point[1]); setPressed(true); positionSelector(mMotionPosition, motionView); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } DrawableUtils.setHotspot(mSelector, x, y); } if (!mHasPerformedLongPress) { // This is a tap, so remove the longpress check removeLongPressCallback(); // Use a Runnable and post this rather than calling // performClick directly. This lets other visual state // of the view update before click actions start. if (mPerformClick == null) { mPerformClick = new PerformClick(); } mPerformClick.v = motionView; mPerformClick.p = motionPosition; mPerformClick.rememberWindowAttachCount(); if (!post(mPerformClick)) { mPerformClick.run(); } } if (mUnsetPressedState == null) { mUnsetPressedState = new UnsetPressedState(); } mUnsetPressedState.v = motionView; if (mPrePressed) { postDelayed(mUnsetPressedState, ViewConfiguration.getPressedStateDuration()); } else if (!post(mUnsetPressedState)) { // If the post failed, unpress right now mUnsetPressedState.run(); } removeTapCallback(); } updateSelectorState(); // Release mMotionView = null; } }
From source file:com.appunite.list.GridView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly./*from w ww . jav a2s . co m*/ * * @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... LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p == null) { p = (LayoutParams) generateDefaultLayoutParams(); } 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 (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { if (child instanceof Checkable) { ((Checkable) child).setChecked(mCheckStates.get(position)); } else if (getContext() .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { Compat.setActivated(child, mCheckStates.get(position)); } } 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; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & 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); } if (recycled && (((LayoutParams) child.getLayoutParams()).scrappedFromPosition) != position) { Compat.jumpDrawablesToCurrentState(child); } }
From source file:com.lovebridge.library.view.staggeredGridView.ExtendableListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly./*from w ww.j a v a2 s .c o m*/ * * @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); } }
From source file:com.huewu.pla.lib.internal.PLAListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly.//from w ww . j ava2 s .com * * @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(final View child, final int position, final int y, final boolean flowDown, final int childrenLeft, final boolean selected, final 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 PLAAbsListView.LayoutParams p = (PLAAbsListView.LayoutParams) child.getLayoutParams(); if (p == null) { p = new PLAAbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); } p.viewType = mAdapter.getItemViewType(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); } final boolean useActivated = getContext() .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB; if (mChoiceMode == CHOICE_MODE_NONE) { if (child instanceof Checkable) { ((Checkable) child).setChecked(false); } else if (useActivated) { child.setActivated(false); } } if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { if (child instanceof Checkable) { ((Checkable) child).setChecked(mCheckStates.get(position)); } else if (useActivated) { child.setActivated(mCheckStates.get(position)); } } if (needToMeasure) { final int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mListPadding.left + mListPadding.right, p.width); final 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); } }
From source file:com.huewu.pla.lib.internal.PLA_ListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly./*from www. j a v a 2s . c o m*/ * * @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(11) 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 (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) { if (child instanceof Checkable) { ((Checkable) child).setChecked(mCheckStates.get(position)); } else if (getContext() .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { child.setActivated(mCheckStates.get(position)); } } 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); } }
From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly.// w w w . j av a2 s . c o m * * @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); } }
From source file:com.lcr.widget.ExtendableListView.java
/** * Add a view as a child and make sure it is measured (if necessary) and * positioned properly.// w w w . j ava2 s .c o m * * @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.i(TAG, "setupChild attachViewToParent position:" + position); attachViewToParent(child, flowDown ? -1 : 0, layoutParams); } else { if (DBG) Log.i(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.i(TAG, "setupChild onMeasureChild position:" + position); onMeasureChild(child, layoutParams); } else { if (DBG) Log.i(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.i(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); } }