下面列出了android.view.View#jumpDrawablesToCurrentState ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Skips any animations on the layout. */
public static ViewAction skipAnimations() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(TextInputLayout.class);
}
@Override
public String getDescription() {
return "Skips any animations.";
}
@Override
public void perform(UiController uiController, View view) {
view.jumpDrawablesToCurrentState();
}
};
}
/**
* Reuses item views when it can
*/
public void updateMenuView(boolean cleared) {
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
if (IS_HONEYCOMB) itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// apply checked state
if (convertView instanceof Checkable){
((Checkable) convertView).setChecked(isItemChecked(position));
if (mNoAnimations){ // suppresses the check animation when filtering
convertView.jumpDrawablesToCurrentState();
}
}
return convertView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// apply checked state
if (convertView instanceof Checkable){
((Checkable) convertView).setChecked(isItemChecked(position));
if (mNoAnimations){ // suppresses the check animation when filtering
convertView.jumpDrawablesToCurrentState();
}
}
return convertView;
}
/**
* Reuses item views when it can
*/
public void updateMenuView(boolean cleared) {
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
if (IS_HONEYCOMB) itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
}
/**
* Reuses item views when it can
*/
public void updateMenuView(boolean cleared) {
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
if (IS_HONEYCOMB) itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
}
/**
* Reuses item views when it can
*/
public void updateMenuView(boolean cleared) {
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
if (IS_HONEYCOMB) itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
}
/**
* Reuses item views when it can
*/
public void updateMenuView(boolean cleared) {
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
if (IS_HONEYCOMB) itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
}
@Override
public void jumpDrawablesToCurrentState(View v) {
v.jumpDrawablesToCurrentState();
}
@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();
}
}
public static void jumpDrawablesToCurrentState(View view) {
view.jumpDrawablesToCurrentState();
}
/**
* 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();
}
}
}
public static void jumpDrawablesToCurrentState(View view) {
view.jumpDrawablesToCurrentState();
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}