本文整理汇总了Java中android.view.FocusFinder类的典型用法代码示例。如果您正苦于以下问题:Java FocusFinder类的具体用法?Java FocusFinder怎么用?Java FocusFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FocusFinder类属于android.view包,在下文中一共展示了FocusFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleHorizontalFocusWithinListItem
import android.view.FocusFinder; //导入依赖的package包/类
private boolean handleHorizontalFocusWithinListItem(int direction) {
if (direction == 33 || direction == 130) {
int numChildren = getChildCount();
if (this.mItemsCanFocus && numChildren > 0 && this.mSelectedPosition != -1) {
View selectedView = getSelectedView();
if (selectedView != null && selectedView.hasFocus() && (selectedView instanceof ViewGroup)) {
View currentFocus = selectedView.findFocus();
View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction);
if (nextFocus != null) {
currentFocus.getFocusedRect(this.mTempRect);
offsetDescendantRectToMyCoords(currentFocus, this.mTempRect);
offsetRectIntoDescendantCoords(nextFocus, this.mTempRect);
if (nextFocus.requestFocus(direction, this.mTempRect)) {
return true;
}
}
View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction);
if (globalNextFocus != null) {
return isViewAncestorOf(globalNextFocus, this);
}
}
}
return false;
}
throw new IllegalArgumentException("direction must be one of {View.FOCUS_UP, View.FOCUS_DOWN}");
}
示例2: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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);
}
示例3: focusSearch
import android.view.FocusFinder; //导入依赖的package包/类
@Override
public View focusSearch(View focused, int direction) {
View result = mLayout.onInterceptFocusSearch(focused, direction);
if (result != null) {
return result;
}
final FocusFinder ff = FocusFinder.getInstance();
result = ff.findNextFocus(this, focused, direction);
if (result == null && mAdapter != null && mLayout != null && !isComputingLayout()
&& !mLayoutFrozen) {
eatRequestLayout();
result = mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState);
resumeRequestLayout(false);
}
return result != null ? result : super.focusSearch(focused, direction);
}
示例4: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
if (direction == 2) {
direction = 130;
} else if (direction == 1) {
direction = 33;
}
View nextFocus = previouslyFocusedRect == null ? FocusFinder.getInstance().findNextFocus(this, null, direction) : FocusFinder.getInstance().findNextFocusFromRect(this, previouslyFocusedRect, direction);
if (nextFocus == null || isOffScreen(nextFocus)) {
return false;
}
return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
示例5: arrowScroll
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 获得滑动的方向
*/
public boolean arrowScroll(int direction) {
View currentFocused = findFocus();
if (currentFocused == this) currentFocused = null;
boolean handled = false;
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
direction);
if (nextFocused != null && nextFocused != currentFocused) {
if (direction == View.FOCUS_LEFT) {
handled = nextFocused.requestFocus();
} else if (direction == View.FOCUS_RIGHT) {
// 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.
if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
handled = pageRight();
} else {
handled = nextFocused.requestFocus();
}
}
} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
// Trying to move left and nothing there; try to page.
handled = pageLeft();
} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
// Trying to move right and nothing there; try to page.
handled = pageRight();
}
if (handled) {
playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
}
return handled;
}
示例6: handleHorizontalFocusWithinListItem
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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;
}
示例7: arrowScroll
import android.view.FocusFinder; //导入依赖的package包/类
public boolean arrowScroll(int direction) {
View currentFocused = findFocus();
if (currentFocused == this) currentFocused = null;
boolean handled = false;
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
direction);
if (nextFocused != null && nextFocused != currentFocused) {
if (direction == View.FOCUS_LEFT) {
handled = nextFocused.requestFocus();
} else if (direction == View.FOCUS_RIGHT) {
// 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.
if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
handled = pageRight();
} else {
handled = nextFocused.requestFocus();
}
}
} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
// Trying to move left and nothing there; try to page.
handled = pageLeft();
} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
// Trying to move right and nothing there; try to page.
handled = pageRight();
}
if (handled) {
playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
}
return handled;
}
示例8: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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);
return nextFocus != null && nextFocus.requestFocus(direction, previouslyFocusedRect);
}
示例9: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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 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;
}
if (isOffScreen(nextFocus)) {
return false;
}
return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
示例10: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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 ViewGroup}
* implementation, otherwise this behavior might have been made the default.
*/
@Override
protected boolean onRequestFocusInDescendants(int direction, @Nullable 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;
}
View nextFocus = (previouslyFocusedRect == null) ? FocusFinder.getInstance().findNextFocus(this, null, direction) : FocusFinder.getInstance().findNextFocusFromRect(this, previouslyFocusedRect, direction);
if (nextFocus == null) {
return false;
}
return !isOffScreen(nextFocus) && nextFocus.requestFocus(direction, previouslyFocusedRect);
}
示例11: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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.
*
* This is more expensive than the default {@link 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);
}
示例12: focusSearch
import android.view.FocusFinder; //导入依赖的package包/类
public View focusSearch(View paramView, int paramInt)
{
View localView1 = this.mLayout.onInterceptFocusSearch(paramView, paramInt);
if (localView1 != null) {
return localView1;
}
View localView2 = FocusFinder.getInstance().findNextFocus(this, paramView, paramInt);
if ((localView2 == null) && (this.mAdapter != null) && (this.mLayout != null) && (!isComputingLayout()) && (!this.mLayoutFrozen))
{
eatRequestLayout();
localView2 = this.mLayout.onFocusSearchFailed$1539f5dc(paramInt, this.mRecycler, this.mState);
resumeRequestLayout(false);
}
if (localView2 != null) {
return localView2;
}
return super.focusSearch(paramView, paramInt);
}
示例13: focusSearch
import android.view.FocusFinder; //导入依赖的package包/类
public View focusSearch(View paramView, int paramInt)
{
View localView = FocusFinder.getInstance().findNextFocus(this, paramView, paramInt);
if ((localView == null) && (this.g != null) && (this.h != null)) {
if (this.r <= 0) {
break label82;
}
}
label82:
for (int i1 = 1;; i1 = 0)
{
if ((i1 == 0) && (!this.n))
{
a();
localView = this.h.c(paramInt, this.b, this.y);
a(false);
}
if (localView == null) {
break;
}
return localView;
}
return super.focusSearch(paramView, paramInt);
}
示例14: onRequestFocusInDescendants
import android.view.FocusFinder; //导入依赖的package包/类
/**
* 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 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;
}
if (isOffScreen(nextFocus)) {
return false;
}
return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
示例15: setUp
import android.view.FocusFinder; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
mFocusFinder = FocusFinder.getInstance();
// inflate the layout
final Context context = getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
mRoot = (ViewGroup) inflater.inflate(R.layout.focus_2, null);
// manually measure it, and lay it out
mRoot.measure(500, 500);
mRoot.layout(0, 0, 500, 500);
mLeftButton = (Button) mRoot.findViewById(R.id.leftButton);
mCenterButton = (Button) mRoot.findViewById(R.id.centerButton);
mRightButton = (Button) mRoot.findViewById(R.id.rightButton);
}