本文整理汇总了Java中android.view.View.isFocusable方法的典型用法代码示例。如果您正苦于以下问题:Java View.isFocusable方法的具体用法?Java View.isFocusable怎么用?Java View.isFocusable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.isFocusable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSparseMatrix
import android.view.View; //导入方法依赖的package包/类
/**
* Returns a matrix of size same as the {@link CellLayout} dimension that is initialized with the
* index of the child view.
*/
// TODO: get rid of the dynamic matrix creation
public static int[][] createSparseMatrix(CellLayout layout) {
ShortcutAndWidgetContainer parent = layout.getShortcutsAndWidgets();
final int m = layout.getCountX();
final int n = layout.getCountY();
final boolean invert = parent.invertLayoutHorizontally();
int[][] matrix = createFullMatrix(m, n);
// Iterate thru the children.
for (int i = 0; i < parent.getChildCount(); i++ ) {
View cell = parent.getChildAt(i);
if (!cell.isFocusable()) {
continue;
}
int cx = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellX;
int cy = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellY;
matrix[invert ? (m - cx - 1) : cx][cy] = i;
}
if (DEBUG) {
printMatrix(matrix);
}
return matrix;
}
示例2: handleStateOnResult
import android.view.View; //导入方法依赖的package包/类
protected void handleStateOnResult(LayoutChunkResult result, View view) {
if (view == null) {
return;
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
// Consume the available space if the view is not removed OR changed
if (params.isItemRemoved() || params.isItemChanged()) {
result.mIgnoreConsumed = true;
}
// used when search a focusable view
result.mFocusable = result.mFocusable || view.isFocusable();
}
示例3: handleStateOnResult
import android.view.View; //导入方法依赖的package包/类
/**
* Helper methods to handle focus states for views
* FIXME 可变参数性能不好,会引起一次潜在的数组对象创建,在频繁滑动过程中,容易引起GC,如果只有一个View,建议调用上述方法
* @param result
* @param views
*/
protected void handleStateOnResult(LayoutChunkResult result, View... views) {
if (views == null) return;
for (View view : views) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
// Consume the available space if the view is not removed OR changed
if (params.isItemRemoved() || params.isItemChanged()) {
result.mIgnoreConsumed = true;
}
// used when search a focusable view
result.mFocusable = result.mFocusable || view.isFocusable();
if (result.mFocusable && result.mIgnoreConsumed) {
break;
}
}
}
示例4: focusAndShowKeyboard
import android.view.View; //导入方法依赖的package包/类
/**
* Focus the given view and show the soft keyboard.
* @param activity the current activity
* @param view the view to focus
*/
public static void focusAndShowKeyboard(@Nullable Activity activity, @NonNull View view) {
if (activity == null) return;
if (view.isFocusable()) {
view.requestFocus();
}
if (view instanceof EditText) {
showKeyboard(activity);
}
}
示例5: getFirstFocusableIconInReverseReadingOrder
import android.view.View; //导入方法依赖的package包/类
private static View getFirstFocusableIconInReverseReadingOrder(CellLayout cellLayout,
boolean isRtl) {
View icon;
int countX = cellLayout.getCountX();
for (int y = cellLayout.getCountY() - 1; y >= 0; y--) {
int increment = isRtl ? 1 : -1;
for (int x = isRtl ? 0 : countX - 1; 0 <= x && x < countX; x += increment) {
if ((icon = cellLayout.getChildAt(x, y)) != null && icon.isFocusable()) {
return icon;
}
}
}
return null;
}
示例6: getFirstFocusableIconInReadingOrder
import android.view.View; //导入方法依赖的package包/类
private static View getFirstFocusableIconInReadingOrder(CellLayout cellLayout, boolean isRtl) {
View icon;
int countX = cellLayout.getCountX();
for (int y = 0; y < cellLayout.getCountY(); y++) {
int increment = isRtl ? -1 : 1;
for (int x = isRtl ? countX - 1 : 0; 0 <= x && x < countX; x += increment) {
if ((icon = cellLayout.getChildAt(x, y)) != null && icon.isFocusable()) {
return icon;
}
}
}
return null;
}
示例7: createSparseMatrixWithPivotColumn
import android.view.View; //导入方法依赖的package包/类
/**
* Creates a sparse matrix that merges the icon of previous/next page and last column of
* current page. When left key is triggered on the leftmost column, sparse matrix is created
* that combines previous page matrix and an extra column on the right. Likewise, when right
* key is triggered on the rightmost column, sparse matrix is created that combines this column
* on the 0th column and the next page matrix.
*
* @param pivotX x coordinate of the focused item in the current page
* @param pivotY y coordinate of the focused item in the current page
*/
// TODO: get rid of the dynamic matrix creation
public static int[][] createSparseMatrixWithPivotColumn(CellLayout iconLayout,
int pivotX, int pivotY) {
ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
int[][] matrix = createFullMatrix(iconLayout.getCountX() + 1, iconLayout.getCountY());
// Iterate thru the children of the top parent.
for (int i = 0; i < iconParent.getChildCount(); i++) {
View cell = iconParent.getChildAt(i);
if (!cell.isFocusable()) {
continue;
}
int cx = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellX;
int cy = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellY;
if (pivotX < 0) {
matrix[cx - pivotX][cy] = i;
} else {
matrix[cx][cy] = i;
}
}
if (pivotX < 0) {
matrix[0][pivotY] = PIVOT;
} else {
matrix[pivotX][pivotY] = PIVOT;
}
return matrix;
}
示例8: focusSearch
import android.view.View; //导入方法依赖的package包/类
@Override
public View focusSearch(int direction) {
switch(direction) {
case View.FOCUS_FORWARD:
View v = mDisplay.nextView(this);
while(!v.isFocusable())
v = mDisplay.nextView(v);
return v;
}
return super.focusSearch(direction);
}
示例9: run
import android.view.View; //导入方法依赖的package包/类
@Override
public void run() {
if (tries <= 0) {
return;
}
final View view = viewReferemce.get();
if (view == null) {
// The view is gone. No need to continue.
return;
}
if (!view.isFocusable() || !view.isFocusableInTouchMode()) {
// The view is not focusable - we can't show the keyboard for it.
return;
}
if (!view.requestFocus()) {
// Focus this view first.
post();
return;
}
final Activity activity = (Activity) view.getContext();
if (activity == null) {
return;
}
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) {
return;
}
if (!imm.isActive(view)) {
// This view is not the currently active view for the input method yet.
post();
return;
}
if (!imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)) {
// Showing they keyboard failed. Try again later.
post();
}
}
示例10: onFocusSearchFailed
import android.view.View; //导入方法依赖的package包/类
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
RecyclerView.Recycler recycler, RecyclerView.State state) {
myResolveShouldLayoutReverse();
if (getChildCount() == 0) {
return null;
}
final int layoutDir = convertFocusDirectionToLayoutDirectionExpose(focusDirection);
if (layoutDir == LayoutState.INVALID_LAYOUT) {
return null;
}
View referenceChild = null;
if (layoutDir == LayoutState.LAYOUT_START) {
referenceChild = myFindReferenceChildClosestToStart(state);
} else {
referenceChild = myFindReferenceChildClosestToEnd(state);
}
if (referenceChild == null) {
if (DEBUG) {
Log.d(TAG,
"Cannot find a child with a valid position to be used for focus search.");
}
return null;
}
ensureLayoutStateExpose();
final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace());
updateLayoutStateExpose(layoutDir, maxScroll, false, state);
mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN;
mLayoutState.mRecycle = false;
mLayoutState.mOnRefresLayout = false;
fill(recycler, mLayoutState, state, true);
final View nextFocus;
if (layoutDir == LayoutState.LAYOUT_START) {
nextFocus = getChildClosestToStartExpose();
} else {
nextFocus = getChildClosestToEndExpose();
}
if (nextFocus == referenceChild || !nextFocus.isFocusable()) {
return null;
}
return nextFocus;
}
示例11: layoutChunk
import android.view.View; //导入方法依赖的package包/类
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state,
LayoutState layoutState, LayoutChunkResult result) {
View view = layoutState.next(recycler);
if (view == null) {
if (DEBUG && layoutState.mScrapList == null) {
throw new RuntimeException("received null view when unexpected");
}
// if we are laying out views in scrap, this may return null which means there is
// no more items to layout.
result.mFinished = true;
return;
}
LayoutParams params = (LayoutParams) view.getLayoutParams();
if (layoutState.mScrapList == null) {
if (mShouldReverseLayout == (layoutState.mLayoutDirection
== LayoutState.LAYOUT_START)) {
addView(view);
} else {
addView(view, 0);
}
} else {
if (mShouldReverseLayout == (layoutState.mLayoutDirection
== LayoutState.LAYOUT_START)) {
addDisappearingView(view);
} else {
addDisappearingView(view, 0);
}
}
measureChildWithMargins(view, 0, 0);
result.mConsumed = mOrientationHelper.getDecoratedMeasurement(view);
int left, top, right, bottom;
if (mOrientation == VERTICAL) {
if (isLayoutRTL()) {
right = getWidth() - getPaddingRight();
left = right - mOrientationHelper.getDecoratedMeasurementInOther(view);
} else {
left = getPaddingLeft();
right = left + mOrientationHelper.getDecoratedMeasurementInOther(view);
}
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
bottom = layoutState.mOffset;
top = layoutState.mOffset - result.mConsumed;
} else {
top = layoutState.mOffset;
bottom = layoutState.mOffset + result.mConsumed;
}
} else {
top = getPaddingTop();
bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view);
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
right = layoutState.mOffset;
left = layoutState.mOffset - result.mConsumed;
} else {
left = layoutState.mOffset;
right = layoutState.mOffset + result.mConsumed;
}
}
// We calculate everything with View's bounding box (which includes decor and margins)
// To calculate correct layout position, we subtract margins.
layoutDecorated(view, left + params.leftMargin, top + params.topMargin,
right - params.rightMargin, bottom - params.bottomMargin);
if (DEBUG) {
Log.d(TAG, "laid out child at position " + getPosition(view) + ", with l:"
+ (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:"
+ (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin));
}
// Consume the available space if the view is not removed OR changed
if (params.isItemRemoved() || params.isItemChanged()) {
result.mIgnoreConsumed = true;
}
result.mFocusable = view.isFocusable();
}
示例12: onFocusSearchFailed
import android.view.View; //导入方法依赖的package包/类
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
RecyclerView.Recycler recycler, RecyclerView.State state) {
View prevFocusedChild = findContainingItemView(focused);
if (prevFocusedChild == null) {
return null;
}
StrongGridLayoutManager.LayoutParams lp = (StrongGridLayoutManager.LayoutParams) prevFocusedChild.getLayoutParams();
final int prevSpanStart = lp.mSpanIndex;
final int prevSpanEnd = lp.mSpanIndex + lp.mSpanSize;
View view = super.onFocusSearchFailed(focused, focusDirection, recycler, state);
if (view == null) {
return null;
}
// LinearLayoutManager finds the last child. What we want is the child which has the same
// spanIndex.
final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
final boolean ascend = (layoutDir == LayoutState.LAYOUT_END) != mShouldReverseLayout;
final int start, inc, limit;
if (ascend) {
start = getChildCount() - 1;
inc = -1;
limit = -1;
} else {
start = 0;
inc = 1;
limit = getChildCount();
}
final boolean preferLastSpan = mOrientation == VERTICAL && isLayoutRTL();
View weakCandidate = null; // somewhat matches but not strong
int weakCandidateSpanIndex = -1;
int weakCandidateOverlap = 0; // how many spans overlap
for (int i = start; i != limit; i += inc) {
View candidate = getChildAt(i);
if (candidate == prevFocusedChild) {
break;
}
if (!candidate.isFocusable()) {
continue;
}
final StrongGridLayoutManager.LayoutParams candidateLp = (StrongGridLayoutManager.LayoutParams) candidate.getLayoutParams();
final int candidateStart = candidateLp.mSpanIndex;
final int candidateEnd = candidateLp.mSpanIndex + candidateLp.mSpanSize;
if (candidateStart == prevSpanStart && candidateEnd == prevSpanEnd) {
return candidate; // perfect match
}
boolean assignAsWeek = false;
if (weakCandidate == null) {
assignAsWeek = true;
} else {
int maxStart = Math.max(candidateStart, prevSpanStart);
int minEnd = Math.min(candidateEnd, prevSpanEnd);
int overlap = minEnd - maxStart;
if (overlap > weakCandidateOverlap) {
assignAsWeek = true;
} else if (overlap == weakCandidateOverlap &&
preferLastSpan == (candidateStart > weakCandidateSpanIndex)) {
assignAsWeek = true;
}
}
if (assignAsWeek) {
weakCandidate = candidate;
weakCandidateSpanIndex = candidateLp.mSpanIndex;
weakCandidateOverlap = Math.min(candidateEnd, prevSpanEnd) -
Math.max(candidateStart, prevSpanStart);
}
}
return weakCandidate;
}
示例13: layoutChunk
import android.view.View; //导入方法依赖的package包/类
void layoutChunk(Recycler recycler, State state, LayoutState layoutState, LayoutChunkResult result) {
View view = layoutState.next(recycler);
if (view == null) {
result.mFinished = true;
return;
}
int right;
int left;
int bottom;
int top;
LayoutParams params = (LayoutParams) view.getLayoutParams();
if (layoutState.mScrapList == null) {
if (this.mShouldReverseLayout == (layoutState.mLayoutDirection == -1)) {
addView(view);
} else {
addView(view, 0);
}
} else {
if (this.mShouldReverseLayout == (layoutState.mLayoutDirection == -1)) {
addDisappearingView(view);
} else {
addDisappearingView(view, 0);
}
}
measureChildWithMargins(view, 0, 0);
result.mConsumed = this.mOrientationHelper.getDecoratedMeasurement(view);
if (this.mOrientation == 1) {
if (isLayoutRTL()) {
right = getWidth() - getPaddingRight();
left = right - this.mOrientationHelper.getDecoratedMeasurementInOther(view);
} else {
left = getPaddingLeft();
right = left + this.mOrientationHelper.getDecoratedMeasurementInOther(view);
}
if (layoutState.mLayoutDirection == -1) {
bottom = layoutState.mOffset;
top = layoutState.mOffset - result.mConsumed;
} else {
top = layoutState.mOffset;
bottom = layoutState.mOffset + result.mConsumed;
}
} else {
top = getPaddingTop();
bottom = top + this.mOrientationHelper.getDecoratedMeasurementInOther(view);
if (layoutState.mLayoutDirection == -1) {
right = layoutState.mOffset;
left = layoutState.mOffset - result.mConsumed;
} else {
left = layoutState.mOffset;
right = layoutState.mOffset + result.mConsumed;
}
}
layoutDecorated(view, left + params.leftMargin, top + params.topMargin, right - params.rightMargin, bottom - params.bottomMargin);
if (params.isItemRemoved() || params.isItemChanged()) {
result.mIgnoreConsumed = true;
}
result.mFocusable = view.isFocusable();
}
示例14: onFocusSearchFailed
import android.view.View; //导入方法依赖的package包/类
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
RecyclerView.Recycler recycler, RecyclerView.State state) {
View prevFocusedChild = findContainingItemView(focused);
if (prevFocusedChild == null) {
return null;
}
LayoutParams lp = (LayoutParams) prevFocusedChild.getLayoutParams();
final int prevSpanStart = lp.mSpanIndex;
final int prevSpanEnd = lp.mSpanIndex + lp.mSpanSize;
View view = super.onFocusSearchFailed(focused, focusDirection, recycler, state);
if (view == null) {
return null;
}
// LinearLayoutManager finds the last child. What we want is the child which has the same
// spanIndex.
final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
final boolean ascend = (layoutDir == LayoutState.LAYOUT_END) != mShouldReverseLayout;
final int start, inc, limit;
if (ascend) {
start = getChildCount() - 1;
inc = -1;
limit = -1;
} else {
start = 0;
inc = 1;
limit = getChildCount();
}
final boolean preferLastSpan = mOrientation == VERTICAL && isLayoutRTL();
View weakCandidate = null; // somewhat matches but not strong
int weakCandidateSpanIndex = -1;
int weakCandidateOverlap = 0; // how many spans overlap
for (int i = start; i != limit; i += inc) {
View candidate = getChildAt(i);
if (candidate == prevFocusedChild) {
break;
}
if (!candidate.isFocusable()) {
continue;
}
final LayoutParams candidateLp = (LayoutParams) candidate.getLayoutParams();
final int candidateStart = candidateLp.mSpanIndex;
final int candidateEnd = candidateLp.mSpanIndex + candidateLp.mSpanSize;
if (candidateStart == prevSpanStart && candidateEnd == prevSpanEnd) {
return candidate; // perfect match
}
boolean assignAsWeek = false;
if (weakCandidate == null) {
assignAsWeek = true;
} else {
int maxStart = Math.max(candidateStart, prevSpanStart);
int minEnd = Math.min(candidateEnd, prevSpanEnd);
int overlap = minEnd - maxStart;
if (overlap > weakCandidateOverlap) {
assignAsWeek = true;
} else if (overlap == weakCandidateOverlap &&
preferLastSpan == (candidateStart > weakCandidateSpanIndex)) {
assignAsWeek = true;
}
}
if (assignAsWeek) {
weakCandidate = candidate;
weakCandidateSpanIndex = candidateLp.mSpanIndex;
weakCandidateOverlap = Math.min(candidateEnd, prevSpanEnd) -
Math.max(candidateStart, prevSpanStart);
}
}
return weakCandidate;
}
示例15: onFocusSearchFailed
import android.view.View; //导入方法依赖的package包/类
public View onFocusSearchFailed(View focused, int focusDirection, Recycler recycler, State state) {
View prevFocusedChild = findContainingItemView(focused);
if (prevFocusedChild == null) {
return null;
}
LayoutParams lp = (LayoutParams) prevFocusedChild.getLayoutParams();
int prevSpanStart = lp.mSpanIndex;
int prevSpanEnd = lp.mSpanIndex + lp.mSpanSize;
if (super.onFocusSearchFailed(focused, focusDirection, recycler, state) == null) {
return null;
}
int start;
int inc;
int limit;
if ((convertFocusDirectionToLayoutDirection(focusDirection) == 1) != this.mShouldReverseLayout) {
start = getChildCount() - 1;
inc = -1;
limit = -1;
} else {
start = 0;
inc = 1;
limit = getChildCount();
}
boolean preferLastSpan = this.mOrientation == 1 && isLayoutRTL();
View weakCandidate = null;
int weakCandidateSpanIndex = -1;
int weakCandidateOverlap = 0;
for (int i = start; i != limit; i += inc) {
View candidate = getChildAt(i);
if (candidate == prevFocusedChild) {
break;
}
if (candidate.isFocusable()) {
LayoutParams candidateLp = (LayoutParams) candidate.getLayoutParams();
int candidateStart = candidateLp.mSpanIndex;
int candidateEnd = candidateLp.mSpanIndex + candidateLp.mSpanSize;
if (candidateStart == prevSpanStart && candidateEnd == prevSpanEnd) {
return candidate;
}
boolean assignAsWeek = false;
if (weakCandidate == null) {
assignAsWeek = true;
} else {
int overlap = Math.min(candidateEnd, prevSpanEnd) - Math.max(candidateStart, prevSpanStart);
if (overlap > weakCandidateOverlap) {
assignAsWeek = true;
} else if (overlap == weakCandidateOverlap) {
if (preferLastSpan == (candidateStart > weakCandidateSpanIndex)) {
assignAsWeek = true;
}
}
}
if (assignAsWeek) {
weakCandidate = candidate;
weakCandidateSpanIndex = candidateLp.mSpanIndex;
weakCandidateOverlap = Math.min(candidateEnd, prevSpanEnd) - Math.max(candidateStart, prevSpanStart);
}
}
}
return weakCandidate;
}