android.widget.ListAdapter#isEnabled ( )源码实例Demo

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

源代码1 项目: Klyph   文件: AbsHListView.java
/**
 * {@inheritDoc}
 */
@Override
public void addTouchables( ArrayList<View> views ) {
	final int count = getChildCount();
	final int firstPosition = mFirstPosition;
	final ListAdapter adapter = mAdapter;

	if ( adapter == null ) {
		return;
	}

	for ( int i = 0; i < count; i++ ) {
		final View child = getChildAt( i );
		if ( adapter.isEnabled( firstPosition + i ) ) {
			views.add( child );
		}
		child.addTouchables( views );
	}
}
 
源代码2 项目: AndroidStudyDemo   文件: ZrcAbsListView.java
@Override
public void addTouchables(ArrayList<View> views) {
    final int count = getChildCount();
    final int firstPosition = mFirstPosition;
    final ListAdapter adapter = mAdapter;
    if (adapter == null) {
        return;
    }
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (adapter.isEnabled(firstPosition + i)) {
            views.add(child);
        }
        child.addTouchables(views);
    }
}
 
源代码3 项目: recent-images   文件: TwoWayAbsListView.java
/**
 * {@inheritDoc}
 */
@Override
public void addTouchables(ArrayList<View> views) {
	final int count = getChildCount();
	final int firstPosition = mFirstPosition;
	final ListAdapter adapter = mAdapter;

	if (adapter == null) {
		return;
	}

	for (int i = 0; i < count; i++) {
		final View child = getChildAt(i);
		if (adapter.isEnabled(firstPosition + i)) {
			views.add(child);
		}
		child.addTouchables(views);
	}
}
 
源代码4 项目: EverMemo   文件: PLA_ListView.java
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
	boolean populated = super.dispatchPopulateAccessibilityEvent(event);

	// If the item count is less than 15 then subtract disabled items from the count and
	// position. Otherwise ignore disabled items.
	if (!populated) {
		int itemCount = 0;
		int currentItemIndex = getSelectedItemPosition();

		ListAdapter adapter = getAdapter();
		if (adapter != null) {
			final int count = adapter.getCount();
			if (count < 15) {
				for (int i = 0; i < count; i++) {
					if (adapter.isEnabled(i)) {
						itemCount++;
					} else if (i <= currentItemIndex) {
						currentItemIndex--;
					}
				}
			} else {
				itemCount = count;
			}
		}

		event.setItemCount(itemCount);
		event.setCurrentItemIndex(currentItemIndex);
	}

	return populated;
}
 
源代码5 项目: letv   文件: HListView.java
protected int lookForSelectablePosition(int position, boolean lookDown) {
    ListAdapter adapter = this.mAdapter;
    if (adapter == null || isInTouchMode()) {
        return -1;
    }
    int count = adapter.getCount();
    if (!this.mAreAllItemsSelectable) {
        if (lookDown) {
            position = Math.max(0, position);
            while (position < count && !adapter.isEnabled(position)) {
                position++;
            }
        } else {
            position = Math.min(position, count - 1);
            while (position >= 0 && !adapter.isEnabled(position)) {
                position--;
            }
        }
        if (position < 0 || position >= count) {
            return -1;
        }
        return position;
    } else if (position < 0 || position >= count) {
        return -1;
    } else {
        return position;
    }
}
 
源代码6 项目: EverMemo   文件: PLA_ListView.java
/**
 * Find a position that can be selected (i.e., is not a separator).
 *
 * @param position The starting position to look at.
 * @param lookDown Whether to look down for other positions.
 * @return The next selectable position starting at position and then searching either up or
 *         down. Returns {@link #INVALID_POSITION} if nothing can be found.
 */
@Override
int lookForSelectablePosition(int position, boolean lookDown) {
	final ListAdapter adapter = mAdapter;
	if (adapter == null || isInTouchMode()) {
		return INVALID_POSITION;
	}

	final int count = adapter.getCount();
	if (!mAreAllItemsSelectable) {
		if (lookDown) {
			position = Math.max(0, position);
			while (position < count && !adapter.isEnabled(position)) {
				position++;
			}
		} else {
			position = Math.min(position, count - 1);
			while (position >= 0 && !adapter.isEnabled(position)) {
				position--;
			}
		}

		if (position < 0 || position >= count) {
			return INVALID_POSITION;
		}
		return position;
	} else {
		if (position < 0 || position >= count) {
			return INVALID_POSITION;
		}
		return position;
	}
}
 
源代码7 项目: Shield   文件: MergeAdapter.java
/**
 * Returns true if the item at the specified position is not a separator.
 *
 * @param position Position of the item whose data we want
 */
@Override
public boolean isEnabled(int position) {
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();

        if (position < size) {
            return (piece.isEnabled(position));
        }

        position -= size;
    }

    return (false);
}
 
源代码8 项目: zen4android   文件: IcsSpinner.java
/**
 * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call.
 * Otherwise, return true.
 */
public boolean isEnabled(int position) {
    final ListAdapter adapter = mListAdapter;
    if (adapter != null) {
        return adapter.isEnabled(position);
    } else {
        return true;
    }
}
 
/**
 * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call.
 * Otherwise, return true.
 */
public boolean isEnabled(int position) {
    final ListAdapter adapter = mListAdapter;
    if (adapter != null) {
        return adapter.isEnabled(position);
    } else {
        return true;
    }
}
 
源代码10 项目: Klyph   文件: HListView.java
/**
 * Find a position that can be selected (i.e., is not a separator).
 * 
 * @param position
 *           The starting position to look at.
 * @param lookDown
 *           Whether to look down for other positions.
 * @return The next selectable position starting at position and then searching either up or down. Returns
 *         {@link #INVALID_POSITION} if nothing can be found.
 */
@Override
protected int lookForSelectablePosition( int position, boolean lookDown ) {
	final ListAdapter adapter = mAdapter;
	if ( adapter == null || isInTouchMode() ) {
		return INVALID_POSITION;
	}

	final int count = adapter.getCount();
	if ( !mAreAllItemsSelectable ) {
		if ( lookDown ) {
			position = Math.max( 0, position );
			while ( position < count && !adapter.isEnabled( position ) ) {
				position++;
			}
		} else {
			position = Math.min( position, count - 1 );
			while ( position >= 0 && !adapter.isEnabled( position ) ) {
				position--;
			}
		}

		if ( position < 0 || position >= count ) {
			return INVALID_POSITION;
		}
		return position;
	} else {
		if ( position < 0 || position >= count ) {
			return INVALID_POSITION;
		}
		return position;
	}
}
 
源代码11 项目: SimplifyReader   文件: PLAListView.java
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = super.dispatchPopulateAccessibilityEvent(event);

    // If the item count is less than 15 then subtract disabled items from the count and
    // position. Otherwise ignore disabled items.
    if (!populated) {
        int itemCount = 0;
        int currentItemIndex = getSelectedItemPosition();

        ListAdapter adapter = getAdapter();
        if (adapter != null) {
            final int count = adapter.getCount();
            if (count < 15) {
                for (int i = 0; i < count; i++) {
                    if (adapter.isEnabled(i)) {
                        itemCount++;
                    } else if (i <= currentItemIndex) {
                        currentItemIndex--;
                    }
                }
            } else {
                itemCount = count;
            }
        }

        event.setItemCount(itemCount);
        event.setCurrentItemIndex(currentItemIndex);
    }

    return populated;
}
 
源代码12 项目: android-apps   文件: IcsSpinner.java
/**
 * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call.
 * Otherwise, return true.
 */
public boolean isEnabled(int position) {
    final ListAdapter adapter = mListAdapter;
    if (adapter != null) {
        return adapter.isEnabled(position);
    } else {
        return true;
    }
}
 
源代码13 项目: Klyph   文件: AbsHListView.java
@Override
public void onInitializeAccessibilityNodeInfo( View host, AccessibilityNodeInfoCompat info ) {
	super.onInitializeAccessibilityNodeInfo( host, info );

	final int position = getPositionForView( host );
	final ListAdapter adapter = getAdapter();

	if ( ( position == INVALID_POSITION ) || ( adapter == null ) ) {
		return;
	}

	if ( !isEnabled() || !adapter.isEnabled( position ) ) {
		return;
	}

	if ( position == getSelectedItemPosition() ) {
		info.setSelected( true );
		info.addAction( AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION );
	} else {
		info.addAction( AccessibilityNodeInfoCompat.ACTION_SELECT );
	}

	if ( isClickable() ) {
		info.addAction( AccessibilityNodeInfoCompat.ACTION_CLICK );
		info.setClickable( true );
	}

	if ( isLongClickable() ) {
		info.addAction( AccessibilityNodeInfoCompat.ACTION_LONG_CLICK );
		info.setLongClickable( true );
	}

}
 
源代码14 项目: Lay-s   文件: PLAListView.java
/**
 * Find a position that can be selected (i.e., is not a separator).
 *
 * @param position The starting position to look at.
 * @param lookDown Whether to look down for other positions.
 * @return The next selectable position starting at position and then searching either up or
 *         down. Returns {@link #INVALID_POSITION} if nothing can be found.
 */
@Override
int lookForSelectablePosition(int position, boolean lookDown) {
    final ListAdapter adapter = mAdapter;
    if (adapter == null || isInTouchMode()) {
        return INVALID_POSITION;
    }

    final int count = adapter.getCount();
    if (!mAreAllItemsSelectable) {
        if (lookDown) {
            position = Math.max(0, position);
            while (position < count && !adapter.isEnabled(position)) {
                position++;
            }
        } else {
            position = Math.min(position, count - 1);
            while (position >= 0 && !adapter.isEnabled(position)) {
                position--;
            }
        }

        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    } else {
        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    }
}
 
源代码15 项目: zhangshangwuda   文件: IcsSpinner.java
/**
 * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call.
 * Otherwise, return true.
 */
public boolean isEnabled(int position) {
    final ListAdapter adapter = mListAdapter;
    if (adapter != null) {
        return adapter.isEnabled(position);
    } else {
        return true;
    }
}
 
源代码16 项目: letv   文件: HListView.java
private int lookForSelectablePositionOnScreen(int direction) {
    int firstPosition = this.mFirstPosition;
    int startPos;
    ListAdapter adapter;
    int pos;
    if (direction == 130) {
        if (this.mSelectedPosition != -1) {
            startPos = this.mSelectedPosition + 1;
        } else {
            startPos = firstPosition;
        }
        if (startPos >= this.mAdapter.getCount()) {
            return -1;
        }
        if (startPos < firstPosition) {
            startPos = firstPosition;
        }
        int lastVisiblePos = getLastVisiblePosition();
        adapter = getAdapter();
        pos = startPos;
        while (pos <= lastVisiblePos) {
            if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == 0) {
                return pos;
            }
            pos++;
        }
    } else {
        int last = (getChildCount() + firstPosition) - 1;
        if (this.mSelectedPosition != -1) {
            startPos = this.mSelectedPosition - 1;
        } else {
            startPos = (getChildCount() + firstPosition) - 1;
        }
        if (startPos < 0 || startPos >= this.mAdapter.getCount()) {
            return -1;
        }
        if (startPos > last) {
            startPos = last;
        }
        adapter = getAdapter();
        pos = startPos;
        while (pos >= firstPosition) {
            if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == 0) {
                return pos;
            }
            pos--;
        }
    }
    return -1;
}
 
源代码17 项目: MDPreference   文件: Spinner.java
/**
 * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call. Otherwise,
 * return true.
 */
public boolean isEnabled(int position) {
    final ListAdapter adapter = mListAdapter;
    return adapter == null || adapter.isEnabled(position);
}
 
源代码18 项目: Klyph   文件: AbsHListView.java
@Override
public boolean performAccessibilityAction( View host, int action, Bundle arguments ) {
	if ( super.performAccessibilityAction( host, action, arguments ) ) {
		return true;
	}

	final int position = getPositionForView( host );
	final ListAdapter adapter = getAdapter();

	if ( ( position == INVALID_POSITION ) || ( adapter == null ) ) {
		// Cannot perform actions on invalid items.
		return false;
	}

	if ( !isEnabled() || !adapter.isEnabled( position ) ) {
		// Cannot perform actions on disabled items.
		return false;
	}

	final long id = getItemIdAtPosition( position );

	switch ( action ) {
		case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION: {
			if ( getSelectedItemPosition() == position ) {
				setSelection( INVALID_POSITION );
				return true;
			}
		}
			return false;
		case AccessibilityNodeInfoCompat.ACTION_SELECT: {
			if ( getSelectedItemPosition() != position ) {
				setSelection( position );
				return true;
			}
		}
			return false;
		case AccessibilityNodeInfoCompat.ACTION_CLICK: {
			if ( isClickable() ) {
				return performItemClick( host, position, id );
			}
		}
			return false;
		case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK: {
			if ( isLongClickable() ) {
				return performLongPress( host, position, id );
			}
		}
			return false;
	}

	return false;
}
 
源代码19 项目: EverMemo   文件: PLA_ListView.java
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
	super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);

	if(DEBUG)
		Log.v("PLA_ListView", "onFocusChanged");

	int closetChildIndex = -1;
	if (gainFocus && previouslyFocusedRect != null) {
		//previouslyFocusedRect.offset(mScrollX, mScrollY);
		previouslyFocusedRect.offset(getScrollX(), getScrollY());

		final ListAdapter adapter = mAdapter;
		// Don't cache the result of getChildCount or mFirstPosition here,
		// it could change in layoutChildren.
		if (adapter.getCount() < getChildCount() + mFirstPosition) {
			mLayoutMode = LAYOUT_NORMAL;
			layoutChildren();
		}

		// figure out which item should be selected based on previously
		// focused rect
		Rect otherRect = mTempRect;
		int minDistance = Integer.MAX_VALUE;
		final int childCount = getChildCount();
		final int firstPosition = mFirstPosition;

		for (int i = 0; i < childCount; i++) {
			// only consider selectable views
			if (!adapter.isEnabled(firstPosition + i)) {
				continue;
			}

			View other = getChildAt(i);
			other.getDrawingRect(otherRect);
			offsetDescendantRectToMyCoords(other, otherRect);
			int distance = getDistance(previouslyFocusedRect, otherRect, direction);

			if (distance < minDistance) {
				minDistance = distance;
				closetChildIndex = i;
			}
		}
	}

	if (closetChildIndex >= 0) {
		setSelection(closetChildIndex + mFirstPosition);
	} else {
		requestLayout();
	}
}
 
源代码20 项目: Lay-s   文件: PLAListView.java
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);

    int closetChildIndex = -1;
    if (gainFocus && previouslyFocusedRect != null) {
        //previouslyFocusedRect.offset(mScrollX, mScrollY);
        previouslyFocusedRect.offset(getScrollX(), getScrollY());

        final ListAdapter adapter = mAdapter;
        // Don't cache the result of getChildCount or mFirstPosition here,
        // it could change in layoutChildren.
        if (adapter.getCount() < getChildCount() + mFirstPosition) {
            mLayoutMode = LAYOUT_NORMAL;
            layoutChildren();
        }

        // figure out which item should be selected based on previously
        // focused rect
        Rect otherRect = mTempRect;
        int minDistance = Integer.MAX_VALUE;
        final int childCount = getChildCount();
        final int firstPosition = mFirstPosition;

        for (int i = 0; i < childCount; i++) {
            // only consider selectable views
            if (!adapter.isEnabled(firstPosition + i)) {
                continue;
            }

            View other = getChildAt(i);
            other.getDrawingRect(otherRect);
            offsetDescendantRectToMyCoords(other, otherRect);
            int distance = getDistance(previouslyFocusedRect, otherRect, direction);

            if (distance < minDistance) {
                minDistance = distance;
                closetChildIndex = i;
            }
        }
    }

    if (closetChildIndex >= 0) {
        setSelection(closetChildIndex + mFirstPosition);
    } else {
        requestLayout();
    }
}