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


Java View.FOCUS_UP属性代码示例

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


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

示例1: amountToScrollToNewFocus

/**
 * Determine how much we need to scroll in order to get newFocus in view.
 * 
 * @param direction
 *            either {@link android.view.View#FOCUS_UP} or
 *            {@link android.view.View#FOCUS_DOWN}.
 * @param newFocus
 *            The view that would take focus.
 * @param positionOfNewFocus
 *            The position of the list item containing newFocus
 * @return The amount to scroll. Note: this is always positive! Direction
 *         needs to be taken into account when actually scrolling.
 */
private int amountToScrollToNewFocus(int direction, View newFocus, int positionOfNewFocus) {
	int amountToScroll = 0;
	newFocus.getDrawingRect(mTempRect);
	offsetDescendantRectToMyCoords(newFocus, mTempRect);
	if (direction == View.FOCUS_UP) {
		if (mTempRect.left < mListPadding.left) {
			amountToScroll = mListPadding.left - mTempRect.left;
			if (positionOfNewFocus > 0) {
				amountToScroll += getArrowScrollPreviewLength();
			}
		}
	} else {
		final int listRight = getWidth() - mListPadding.right;
		if (mTempRect.bottom > listRight) {
			amountToScroll = mTempRect.right - listRight;
			if (positionOfNewFocus < mItemCount - 1) {
				amountToScroll += getArrowScrollPreviewLength();
			}
		}
	}
	return amountToScroll;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:35,代码来源:HListView.java

示例2: 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

示例3: 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

示例4: 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

示例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.
 */
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

示例6: 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

示例7: 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

示例8: scrollAndFocus

/**
 * <p>Scrolls the view to make the area defined by <code>top</code> and
 * <code>bottom</code> visible. This method attempts to give the focus
 * to a component visible in this area. If no component can be focused in
 * the new visible area, the focus is reclaimed by this scrollview.</p>
 *
 * @param direction the scroll direction: {@link android.view.View#FOCUS_UP}
 *                  to go upward
 *                  {@link android.view.View#FOCUS_DOWN} to downward
 * @param top       the top offset of the new area to be made visible
 * @param bottom    the bottom offset of the new area to be made visible
 * @return true if the key event is consumed by this method, false otherwise
 */
private boolean scrollAndFocus(int directionY, int top, int bottom, int directionX, int left, int right) {
    boolean handled = true;
    int height = getHeight();
    int containerTop = getScrollY();
    int containerBottom = containerTop + height;
    boolean up = directionY == View.FOCUS_UP;
    int width = getWidth();
    int containerLeft = getScrollX();
    int containerRight = containerLeft + width;
    boolean leftwards = directionX == View.FOCUS_UP;
    View newFocused = findFocusableViewInBounds(up, top, bottom, leftwards, left, right);
    if (newFocused == null) {
        newFocused = this;
    }
    if ((top >= containerTop && bottom <= containerBottom) || (left >= containerLeft && right <= containerRight)) {
        handled = false;
    } else {
        int deltaY = up ? (top - containerTop) : (bottom - containerBottom);
        int deltaX = leftwards ? (left - containerLeft) : (right - containerRight);
        doScroll(deltaX, deltaY);
    }
    if (newFocused != findFocus() && newFocused.requestFocus(directionY)) {
        mTwoDScrollViewMovedFocus = true;
        mTwoDScrollViewMovedFocus = false;
    }
    return handled;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:TwoDScrollView.java

示例9: 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

示例10: 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

示例11: scrollAndFocus

/**
 * Scrolls the view to make the area defined by <code>top</code> and <code>bottom</code> visible. This method
 * attempts to give the focus to a component visible in this area. If no component can be focused in the new visible
 * area, the focus is reclaimed by this scrollview.
 *
 * @param directionY the scroll direction: {@link android.view.View#FOCUS_UP} to go upward
 *                  {@link android.view.View#FOCUS_DOWN} to downward
 * @param top       the top offset of the new area to be made visible
 * @param bottom    the bottom offset of the new area to be made visible
 * @return true if the key event is consumed by this method, false otherwise
 */
private boolean scrollAndFocus(int directionY, int top, int bottom, int directionX, int left, int right)
{
    boolean handled = true;
    int height = getHeight();
    int containerTop = getScrollY();
    int containerBottom = containerTop + height;
    boolean up = directionY == View.FOCUS_UP;
    int width = getWidth();
    int containerLeft = getScrollX();
    int containerRight = containerLeft + width;
    boolean leftwards = directionX == View.FOCUS_UP;
    View newFocused = findFocusableViewInBounds(up, top, bottom, leftwards, left, right);
    if (newFocused == null)
    {
        newFocused = this;
    }
    if ((top >= containerTop && bottom <= containerBottom) || (left >= containerLeft && right <= containerRight))
    {
        handled = false;
    }
    else
    {
        int deltaY = up ? (top - containerTop) : (bottom - containerBottom);
        int deltaX = leftwards ? (left - containerLeft) : (right - containerRight);
        doScroll(deltaX, deltaY);
    }
    return handled;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:39,代码来源:TwoDScrollView.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
 */
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

示例13: 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

示例14: 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

示例15: handleNewSelectionChange

/**
 * When selection changes, it is possible that the previously selected or
 * the next selected item will change its size. If so, we need to offset
 * some folks, and re-layout the items as appropriate.
 * 
 * @param selectedView
 *            The currently selected view (before changing selection).
 *            should be <code>null</code> if there was no previous
 *            selection.
 * @param direction
 *            Either {@link android.view.View#FOCUS_UP} or
 *            {@link android.view.View#FOCUS_DOWN}.
 * @param newSelectedPosition
 *            The position of the next selection.
 * @param newFocusAssigned
 *            whether new focus was assigned. This matters because when
 *            something has focus, we don't want to show selection (ugh).
 */
private void handleNewSelectionChange(View selectedView, int direction, int newSelectedPosition,
		boolean newFocusAssigned) {
	if (newSelectedPosition == INVALID_POSITION) {
		throw new IllegalArgumentException("newSelectedPosition needs to be valid");
	}

	// whether or not we are moving down or up, we want to preserve the
	// top of whatever view is on top:
	// - moving down: the view that had selection
	// - moving up: the view that is getting selection
	View leftView;
	View rightView;
	int leftViewIndex, rightViewIndex;
	boolean leftSelected = false;
	final int selectedIndex = mSelectedPosition - mFirstPosition;
	final int nextSelectedIndex = newSelectedPosition - mFirstPosition;

	if (direction == View.FOCUS_UP) {
		leftViewIndex = nextSelectedIndex;
		rightViewIndex = selectedIndex;
		leftView = getChildAt(leftViewIndex);
		rightView = selectedView;
		leftSelected = true;
	} else {
		leftViewIndex = selectedIndex;
		rightViewIndex = nextSelectedIndex;
		leftView = selectedView;
		rightView = getChildAt(rightViewIndex);
	}

	final int numChildren = getChildCount();

	// start with top view: is it changing size?
	if (leftView != null) {
		leftView.setSelected(!newFocusAssigned && leftSelected);
		measureAndAdjustRight(leftView, leftViewIndex, numChildren);
	}

	// is the bottom view changing size?
	if (rightView != null) {
		rightView.setSelected(!newFocusAssigned && !leftSelected);
		measureAndAdjustRight(rightView, rightViewIndex, numChildren);
	}
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:62,代码来源:HListView.java


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