Java Code Examples for android.view.View.focusSearch()

The following are Jave code examples for showing how to use focusSearch() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: aos-Video   File: TVCardView.java   Source Code and License Vote up 7 votes
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //click mapping
    if(TVUtils.isOKKey(keyCode) &&ocl!=null) {
        this.ocl.onClick(this);
        return true;
    }
    //handle focus on dialog
    else if ((keyCode == KeyEvent.KEYCODE_DPAD_DOWN||keyCode == KeyEvent.KEYCODE_DPAD_UP)&&this.ofol!=null) {
        View v = findFocus().focusSearch(keyCode == KeyEvent.KEYCODE_DPAD_DOWN?FOCUS_DOWN:FOCUS_UP);
        if(v instanceof TVMenuSeparator){
        	v = v.focusSearch(keyCode == KeyEvent.KEYCODE_DPAD_DOWN?FOCUS_DOWN:FOCUS_UP);          	
        }
        if(isViewInCard(v)){
        	v.requestFocus();
        	return true;
        }
        else if(this.ofol!=null)
        	return this.ofol.onFocusOut(keyCode);
    }
    return false;

}
 
Example 2
Project: aos-Video   File: TVCardDialog.java   Source Code and License Vote up 6 votes
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //click mapping
    if (keyCode==KeyEvent.KEYCODE_DPAD_CENTER && ocl != null) {
        this.ocl.onClick(this);

        return true;
    }
    else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BUTTON_B) {
        if(onResult!=null)
            onResult.onResult(DESTROYED);
        exitDialog();
        return true;
    }
    
    //handle focus on dialog
   
    else if (keyCode == KeyEvent.KEYCODE_DPAD_UP||keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            
        View v = findFocus().focusSearch(keyCode == KeyEvent.KEYCODE_DPAD_UP?FOCUS_UP:FOCUS_DOWN);
        if(v instanceof TVMenuSeparator)
        	v=v.focusSearch(keyCode == KeyEvent.KEYCODE_DPAD_UP?FOCUS_UP:FOCUS_DOWN);
        if(isViewInCard(v))
        	v.requestFocus();
        return true;
    }
    return true;

}
 
Example 3
Project: DateTimePicker   File: SimpleMonthView.java   Source Code and License Vote up 5 votes
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}