当前位置: 首页>>代码示例>>Java>>正文


Java View.FOCUS_DOWN属性代码示例

本文整理汇总了Java中android.view.View.FOCUS_DOWN属性的典型用法代码示例。如果您正苦于以下问题:Java View.FOCUS_DOWN属性的具体用法?Java View.FOCUS_DOWN怎么用?Java View.FOCUS_DOWN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.View的用法示例。


在下文中一共展示了View.FOCUS_DOWN属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRequestFocusInDescendants

/**
 * When looking for focus in children of a scroll view, need to be a little
 * more careful not to give focus to something that is scrolled off screen.
 * <p/>
 * This is more expensive than the default {@link android.view.ViewGroup}
 * implementation, otherwise this behavior might have been made the default.
 */
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    // convert from forward / backward notation to up / down / left / right
    // (ugh).
    if (direction == View.FOCUS_FORWARD) {
        direction = View.FOCUS_DOWN;
    } else if (direction == View.FOCUS_BACKWARD) {
        direction = View.FOCUS_UP;
    }

    final View nextFocus = previouslyFocusedRect == null ?
            FocusFinder.getInstance().findNextFocus(this, null, direction) :
            FocusFinder.getInstance().findNextFocusFromRect(this,
                    previouslyFocusedRect, direction);

    if (nextFocus == null) {
        return false;
    }

    return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:TwoDScrollView.java

示例2: isPreferredNextFocusAbsolute

/**
 * Logic taken from FocusSearch#isCandidate
 */
private boolean isPreferredNextFocusAbsolute(View focused, View next, int direction) {

    int[] location = getLocation(focused);
    int[] location2 = getLocation(next);
    mTempRect.set(location[0], location[1], location[0] + focused.getWidth(), location[1] + focused.getHeight());
    mTempRect2.set(location2[0], location2[1], location2[0] + next.getWidth(), location2[1] + next.getHeight());

    switch (direction) {
        case View.FOCUS_LEFT:
            return mTempRect.left >= mTempRect2.right;
        case View.FOCUS_RIGHT:
            return mTempRect.right <= mTempRect2.left;
        case View.FOCUS_UP:
            return mTempRect.top >= mTempRect2.bottom;
        case View.FOCUS_DOWN:
            return mTempRect.bottom <= mTempRect2.top;
    }
    throw new IllegalArgumentException("direction must be absolute. received:" + direction);
}
 
开发者ID:LikangR,项目名称:TvHelper,代码行数:22,代码来源:FocusBehaviourHandlerView.java

示例3: convertFocusDirectionToLayoutDirectionExpose

/**
 * Converts a focusDirection to orientation.
 *
 * @param focusDirection One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
 *                       {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT},
 *                       {@link View#FOCUS_BACKWARD}, {@link View#FOCUS_FORWARD}
 *                       or 0 for not applicable
 * @return {@link LayoutState#LAYOUT_START} or {@link LayoutState#LAYOUT_END} if focus direction
 * is applicable to current state, {@link LayoutState#INVALID_LAYOUT} otherwise.
 */
private int convertFocusDirectionToLayoutDirectionExpose(int focusDirection) {
    int orientation = getOrientation();
    switch (focusDirection) {
        case View.FOCUS_BACKWARD:
            return LayoutState.LAYOUT_START;
        case View.FOCUS_FORWARD:
            return LayoutState.LAYOUT_END;
        case View.FOCUS_UP:
            return orientation == VERTICAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_DOWN:
            return orientation == VERTICAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_LEFT:
            return orientation == HORIZONTAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_RIGHT:
            return orientation == HORIZONTAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        default:
            if (DEBUG) {
                Log.d(TAG, "Unknown focus request:" + focusDirection);
            }
            return LayoutState.INVALID_LAYOUT;
    }

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:ExposeLinearLayoutManagerEx.java

示例4: convertFocusDirectionToLayoutDirection

/**
 * Converts a focusDirection to orientation.
 *
 * @param focusDirection One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
 *                       {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT},
 *                       {@link View#FOCUS_BACKWARD}, {@link View#FOCUS_FORWARD}
 *                       or 0 for not applicable
 * @return {@link LayoutState#LAYOUT_START} or {@link LayoutState#LAYOUT_END} if focus direction
 * is applicable to current state, {@link LayoutState#INVALID_LAYOUT} otherwise.
 */
private int convertFocusDirectionToLayoutDirection(int focusDirection) {
    switch (focusDirection) {
        case View.FOCUS_BACKWARD:
            return LayoutState.LAYOUT_START;
        case View.FOCUS_FORWARD:
            return LayoutState.LAYOUT_END;
        case View.FOCUS_UP:
            return mOrientation == VERTICAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_DOWN:
            return mOrientation == VERTICAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_LEFT:
            return mOrientation == HORIZONTAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_RIGHT:
            return mOrientation == HORIZONTAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        default:
            if (DEBUG) {
                Log.d(TAG, "Unknown focus request:" + focusDirection);
            }
            return LayoutState.INVALID_LAYOUT;
    }

}
 
开发者ID:MLNO,项目名称:airgram,代码行数:36,代码来源:StaggeredGridLayoutManager.java

示例5: convertFocusDirectionToLayoutDirection

/**
 * Converts a focusDirection to orientation.
 *
 * @param focusDirection One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
 *                       {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT},
 *                       {@link View#FOCUS_BACKWARD}, {@link View#FOCUS_FORWARD}
 *                       or 0 for not applicable
 * @return {@link LayoutState#LAYOUT_START} or {@link LayoutState#LAYOUT_END} if focus direction
 * is applicable to current state, {@link LayoutState#INVALID_LAYOUT} otherwise.
 */
int convertFocusDirectionToLayoutDirection(int focusDirection) {
    switch (focusDirection) {
        case View.FOCUS_BACKWARD:
            return LayoutState.LAYOUT_START;
        case View.FOCUS_FORWARD:
            return LayoutState.LAYOUT_END;
        case View.FOCUS_UP:
            return mOrientation == VERTICAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_DOWN:
            return mOrientation == VERTICAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_LEFT:
            return mOrientation == HORIZONTAL ? LayoutState.LAYOUT_START
                    : LayoutState.INVALID_LAYOUT;
        case View.FOCUS_RIGHT:
            return mOrientation == HORIZONTAL ? LayoutState.LAYOUT_END
                    : LayoutState.INVALID_LAYOUT;
        default:
            if (DEBUG) {
                Log.d(TAG, "Unknown focus request:" + focusDirection);
            }
            return LayoutState.INVALID_LAYOUT;
    }

}
 
开发者ID:MLNO,项目名称:airgram,代码行数:36,代码来源:LinearLayoutManager.java

示例6: handleHorizontalFocusWithinListItem

/**
 * To avoid horizontal focus searches changing the selected item, we
 * manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 * 
 * @param direction
 *            one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 */
private boolean handleHorizontalFocusWithinListItem(int direction) {
	// TODO: implement this
	if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) {
		throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}");
	}

	final int numChildren = getChildCount();
	if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
		final View selectedView = getSelectedView();
		if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

			final View currentFocus = selectedView.findFocus();
			final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus,
					direction);
			if (nextFocus != null) {
				// do the math to get interesting rect in next focus'
				// coordinates
				currentFocus.getFocusedRect(mTempRect);
				offsetDescendantRectToMyCoords(currentFocus, mTempRect);
				offsetRectIntoDescendantCoords(nextFocus, mTempRect);
				if (nextFocus.requestFocus(direction, mTempRect)) {
					return true;
				}
			}
			// we are blocking the key from being handled (by returning
			// true)
			// if the global result is going to be some other view within
			// this
			// list. this is to acheive the overall goal of having
			// horizontal d-pad navigation remain in the current item.
			final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
					currentFocus, direction);
			if (globalNextFocus != null) {
				return isViewAncestorOf(globalNextFocus, this);
			}
		}
	}
	return false;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:48,代码来源:HListView.java

示例7: onFocusSearch

@Override
public View onFocusSearch(View focused, int direction) {
    if (focused != mTitleView && direction == View.FOCUS_UP) {
        return mTitleView;
    }
    final boolean isRtl = ViewCompat.getLayoutDirection(focused) ==
            View.LAYOUT_DIRECTION_RTL;
    //final int forward = isRtl ? View.FOCUS_LEFT : View.FOCUS_RIGHT;
    if (mTitleView.hasFocus() && direction == View.FOCUS_DOWN /*|| direction == forward*/) {
        return mSceneRoot;
    }
    return null;
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:13,代码来源:TitleHelper.java

示例8: calcOffsetToNextView

/**
 * Calculates position offset.
 *
 * @param direction regular {@code View.FOCUS_*}.
 * @return position offset according to {@code direction}.
 */
protected int calcOffsetToNextView(int direction)
{
    int spanCount = getSpanCount();
    int orientation = getOrientation();
    
    if (orientation == VERTICAL)
    {
        switch (direction)
        {
            case View.FOCUS_DOWN:
                return spanCount;
            case View.FOCUS_UP:
                return -spanCount;
            case View.FOCUS_RIGHT:
                return 1;
            case View.FOCUS_LEFT:
                return -1;
        }
    }
    else if (orientation == HORIZONTAL)
    {
        switch (direction)
        {
            case View.FOCUS_DOWN:
                return 1;
            case View.FOCUS_UP:
                return -1;
            case View.FOCUS_RIGHT:
                return spanCount;
            case View.FOCUS_LEFT:
                return -spanCount;
        }
    }
    
    return 0;
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:42,代码来源:FocusGridLayoutManager.java

示例9: getDistance

/**
 * What is the distance between the source and destination rectangles given the direction of
 * focus navigation between them? The direction basically helps figure out more quickly what is
 * self evident by the relationship between the rects...
 *
 * @param source the source rectangle
 * @param dest the destination rectangle
 * @param direction the direction
 * @return the distance between the rectangles
 */
static int getDistance(Rect source, Rect dest, int direction) {
    int sX, sY; // source x, y
    int dX, dY; // dest x, y
    switch (direction) {
        case View.FOCUS_RIGHT:
            sX = source.right;
            sY = source.top + source.height() / 2;
            dX = dest.left;
            dY = dest.top + dest.height() / 2;
            break;
        case View.FOCUS_DOWN:
            sX = source.left + source.width() / 2;
            sY = source.bottom;
            dX = dest.left + dest.width() / 2;
            dY = dest.top;
            break;
        case View.FOCUS_LEFT:
            sX = source.left;
            sY = source.top + source.height() / 2;
            dX = dest.right;
            dY = dest.top + dest.height() / 2;
            break;
        case View.FOCUS_UP:
            sX = source.left + source.width() / 2;
            sY = source.top;
            dX = dest.left + dest.width() / 2;
            dY = dest.bottom;
            break;
        default:
            throw new IllegalArgumentException("direction must be one of "
                    + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    }
    int deltaX = dX - sX;
    int deltaY = dY - sY;
    return deltaY * deltaY + deltaX * deltaX;
}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:46,代码来源:PLA_AbsListView.java

示例10: arrowScroll

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    } else if (currentFocused != null) {
        boolean isChild = false;
        for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
             parent = parent.getParent()) {
            if (parent == this) {
                isChild = true;
                break;
            }
        }
        if (!isChild) {
            // This would cause the focus search down below to fail in fun ways.
            final StringBuilder sb = new StringBuilder();
            sb.append(currentFocused.getClass().getSimpleName());
            for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
                 parent = parent.getParent()) {
                sb.append(" => ").append(parent.getClass().getSimpleName());
            }
            Log.e(TAG, "arrowScroll tried to find focus based on non-child " +
                    "current focused view " + sb.toString());
            currentFocused = null;
        }
    }

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
            direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_UP) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            final int nextTop = getChildRectInPagerCoordinates(mTempRect, nextFocused).top;
            final int currTop = getChildRectInPagerCoordinates(mTempRect, currentFocused).top;
            if (currentFocused != null && nextTop >= currTop) {
                handled = pageUp();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_DOWN) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            final int nextDown = getChildRectInPagerCoordinates(mTempRect, nextFocused).bottom;
            final int currDown = getChildRectInPagerCoordinates(mTempRect, currentFocused).bottom;
            if (currentFocused != null && nextDown <= currDown) {
                handled = pageDown();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_UP || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageUp();
    } else if (direction == FOCUS_DOWN || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageDown();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:65,代码来源:VerticalViewPager.java

示例11: arrowScroll

/**
 * Handle scrolling in response to a left or right arrow click.
 *
 * @param direction The direction corresponding to the arrow key that was pressed. It should be
 *                  either {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT}.
 * @return Whether the scrolling was handled successfully.
 */
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    } else if (currentFocused != null) {
        boolean isChild = false;
        for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
             parent = parent.getParent()) {
            if (parent == this) {
                isChild = true;
                break;
            }
        }
        if (!isChild) {
            // This would cause the focus search down below to fail in fun ways.
            final StringBuilder sb = new StringBuilder();
            sb.append(currentFocused.getClass().getSimpleName());
            for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
                 parent = parent.getParent()) {
                sb.append(" => ").append(parent.getClass().getSimpleName());
            }
            Log.e(TAG, "arrowScroll tried to find focus based on non-child "
                    + "current focused view " + sb.toString());
            currentFocused = null;
        }
    }

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
            direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_UP) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            final int nextTop = getChildRectInPagerCoordinates(mTempRect, nextFocused).top;
            final int currTop = getChildRectInPagerCoordinates(mTempRect, currentFocused).top;
            if (currentFocused != null && nextTop >= currTop) {
                handled = pageUp();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_DOWN) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            final int nextDown = getChildRectInPagerCoordinates(mTempRect, nextFocused).bottom;
            final int currDown = getChildRectInPagerCoordinates(mTempRect, currentFocused).bottom;
            if (currentFocused != null && nextDown <= currDown) {
                handled = pageDown();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_UP || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageUp();
    } else if (direction == FOCUS_DOWN || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageDown();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}
 
开发者ID:simplezhli,项目名称:ChangeTabLayout,代码行数:72,代码来源:VerticalViewPager.java

示例12: getDistance

/**
 * What is the distance between the source and destination rectangles given
 * the direction of focus navigation between them? The direction basically
 * helps figure out more quickly what is self evident by the relationship
 * between the rects...
 * 
 * @param source
 *            the source rectangle
 * @param dest
 *            the destination rectangle
 * @param direction
 *            the direction
 * @return the distance between the rectangles
 */
public static int getDistance(Rect source, Rect dest, int direction) {

	// TODO: implement this

	int sX, sY; // source x, y
	int dX, dY; // dest x, y
	switch (direction) {
	case View.FOCUS_RIGHT:
		sX = source.right;
		sY = source.top + source.height() / 2;
		dX = dest.left;
		dY = dest.top + dest.height() / 2;
		break;
	case View.FOCUS_DOWN:
		sX = source.left + source.width() / 2;
		sY = source.bottom;
		dX = dest.left + dest.width() / 2;
		dY = dest.top;
		break;
	case View.FOCUS_LEFT:
		sX = source.left;
		sY = source.top + source.height() / 2;
		dX = dest.right;
		dY = dest.top + dest.height() / 2;
		break;
	case View.FOCUS_UP:
		sX = source.left + source.width() / 2;
		sY = source.top;
		dX = dest.left + dest.width() / 2;
		dY = dest.bottom;
		break;
	case View.FOCUS_FORWARD:
	case View.FOCUS_BACKWARD:
		sX = source.right + source.width() / 2;
		sY = source.top + source.height() / 2;
		dX = dest.left + dest.width() / 2;
		dY = dest.top + dest.height() / 2;
		break;
	default:
		throw new IllegalArgumentException("direction must be one of "
				+ "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, "
				+ "FOCUS_FORWARD, FOCUS_BACKWARD}.");
	}
	int deltaX = dX - sX;
	int deltaY = dY - sY;
	return deltaY * deltaY + deltaX * deltaX;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:61,代码来源:AbsHListView.java


注:本文中的android.view.View.FOCUS_DOWN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。