美文网首页Android TV
Android8.0 焦点处理流程(二)

Android8.0 焦点处理流程(二)

作者: 小的橘子 | 来源:发表于2019-03-05 08:53 被阅读0次

    该篇就看看按键焦点导航,从输入事件流入到ViewRootImpl说起

    按键事件流入

    按键触摸事件都会封装为InputEvent,然后会流转到ViewRootImpl中ViewPostImeInputStage内部类的onProcess方法进行处理,具体的按键事件流程可以参考该篇Android8.0 按键事件处理流程

    frameworks/base/core/java/android/view/ViewRootImpl.java

    final class ViewPostImeInputStage extends InputStage {
        @Override
        protected int onProcess(QueuedInputEvent q) {
            if (q.mEvent instanceof KeyEvent) {
                // 1. 该分支为处理按键事件
                return processKeyEvent(q); 
            } else {
                // else中处理触摸事件
                final int source = q.mEvent.getSource();
                if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) {
                    return processPointerEvent(q); 
                } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) {
                    return processTrackballEvent(q);
                } else {
                    return processGenericMotionEvent(q);
                }
            }
        }
    }
    

    按键焦点导航当然属于按键事件(KeyEvent),那KeyEvent的处理当然是看processKeyEvent(q)方法了

    private int processKeyEvent(QueuedInputEvent q) {
        final KeyEvent event = (KeyEvent)q.mEvent;
    
        // Deliver the key to the view hierarchy.
        // 注释1
        if (mView.dispatchKeyEvent(event)) {
            return FINISH_HANDLED;
        }
    
        ...
        // 只按Tab键则焦点导航方向为向前,如果有KeyEvent.META_SHIFT_ON标识符,则表示按下了shift键,则导航方向为向后
        int groupNavigationDirection = 0;
        if (event.getAction() == KeyEvent.ACTION_DOWN
                && event.getKeyCode() == KeyEvent.KEYCODE_TAB) {
            if (KeyEvent.metaStateHasModifiers(event.getMetaState(), KeyEvent.META_META_ON)) {
                groupNavigationDirection = View.FOCUS_FORWARD;
            } else if (KeyEvent.metaStateHasModifiers(event.getMetaState(),
                    KeyEvent.META_META_ON | KeyEvent.META_SHIFT_ON)) {
                groupNavigationDirection = View.FOCUS_BACKWARD;
            }
        }
        
        // 判断是否作为快捷键
        // If a modifier is held, try to interpret the key as a shortcut.
        if (event.getAction() == KeyEvent.ACTION_DOWN
                && !KeyEvent.metaStateHasNoModifiers(event.getMetaState())
                && event.getRepeatCount() == 0
                && !KeyEvent.isModifierKey(event.getKeyCode())
                && groupNavigationDirection == 0) {
            if (mView.dispatchKeyShortcutEvent(event)) {
                return FINISH_HANDLED;
            }
            if (shouldDropInputEvent(q)) {
                return FINISH_NOT_HANDLED;
            }
        }
    
        ...
        
        // Handle automatic focus changes.
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            if (groupNavigationDirection != 0) {
                if (performKeyboardGroupNavigation(groupNavigationDirection)) {
                    return FINISH_HANDLED;
                }
            } else {
                // 注释2
                if (performFocusNavigation(event)) {
                    return FINISH_HANDLED;
                }
            }
        }
        return FORWARD;
    }
    

    注释1处,由View框架(Activity,ViewGroup&View)进行按键事件处理,关于按键事件派发可参考Android8.0 按键事件处理流程。mView.dispatchKeyEvent, mView具体指的是? 如果当前是Activity和Dialog,mView就是DecorView,是View树的根;如果是Toast,mView是id为com.android.internal.R.id.message,下文只分析Activity。,

    注释2处,如果View框架没有处理按键事件,则继续处理方向键焦点导航处理

    这里我们就分析按方向键进行焦点导航

    方向键焦点导航流程

    private boolean performFocusNavigation(KeyEvent event) {
        int direction = 0;
        // 指定焦点方向,根据按下的是上下左右还是Tab导航键决定方向
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_LEFT;
                }
                break;
            ...
        }
        if (direction != 0) {
            // 注释1
            View focused = mView.findFocus();
            if (focused != null) {
                // 注释2
                View v = focused.focusSearch(direction);
                if (v != null && v != focused) {
                    // do the math the get the interesting rect
                    // of previous focused into the coord system of
                    // newly focused view
                    focused.getFocusedRect(mTempRect);
                    if (mView instanceof ViewGroup) {
                        ((ViewGroup) mView).offsetDescendantRectToMyCoords(
                                focused, mTempRect);
                        ((ViewGroup) mView).offsetRectIntoDescendantCoords(
                                v, mTempRect);
                    }
                    // 注释3
                    if (v.requestFocus(direction, mTempRect)) {
                        playSoundEffect(SoundEffectConstants
                                .getContantForFocusDirection(direction));
                        return true;
                    }
                }
    
                // Give the focused view a last chance to handle the dpad key.
                if (mView.dispatchUnhandledMove(focused, direction)) {
                    return true;
                }
            } else {
                if (mView.restoreDefaultFocus()) {
                    return true;
                }
            }
        }
        return false;
    }
    

    焦点导航整体流程就是注释1,2,3

    1. 找到当前拥有焦点的View
    2. 查找下个应拥有焦点的View
    3. 目标View请求焦点

    下面对1,2展开分析

    1. 找到当前拥有焦点的View-->mView.findFocus()

    mView即DecorView继承自FrameLayout,没复写findFocus方法,所以找到ViewGroup中的findFocus方法。

    ViewGroup

    @Override
    public View findFocus() {
        if (isFocused()) {
            return this;
        }
    
        if (mFocused != null) {
            return mFocused.findFocus();
        }
        return null;
    }
    

    逻辑很简单,如果当前View拥有焦点直接返回自己,否则调用内部间接持有focus的子View即mFocused,遍历查找自己管辖范围内View知道找到拥有焦点的那个View。

    // The view contained within this ViewGroup that has or contains focus.
    private View mFocused;
    

    mFocused指向了拥有或者包含焦点的直接子View。

    View的findFocus()方法

    /**
     * Find the view in the hierarchy rooted at this view that currently has
     * focus.
     *
     * @return The view that currently has focus, or null if no focused view can
     *         be found.
     */
    public View findFocus() {
        return (mPrivateFlags & PFLAG_FOCUSED) != 0 ? this : null;
    }
    /**
     * Returns true if this view has focus itself, or is the ancestor of the
     * view that has focus.
     *
     * @return True if this view has or contains focus, false otherwise.
     */
    @ViewDebug.ExportedProperty(category = "focus")
    public boolean hasFocus() {
        return (mPrivateFlags & PFLAG_FOCUSED) != 0;
    }
    
    /**
     * Returns true if this view has focus
     *
     * @return True if this view has focus, false otherwise.
     */
    @ViewDebug.ExportedProperty(category = "focus")
    public boolean isFocused() {
        return (mPrivateFlags & PFLAG_FOCUSED) != 0;
    }
    

    View的hasFocus()方法和isFocused()方法对比
    Stackoverflow解释来了:

    hasFocus() is different from isFocused(). hasFocus() == true means that the View or one of its descendants is focused. If you look closely, there's a chain of hasFocused Views till you reach the View that isFocused.

    意思就是isFocused返回true表示该View当前focused状态为true,而hasFocus返回true表示的是该View或者层次结构中子view的focused状态为true。focused状态可通过DDMS截取屏幕来查看属性值。

    知道了意思也就知道了findFocus()方法返回的是一个具体的focused状态为true的View

    2. 查找下个要获取焦点的View -->focused.focusSearch(direction)

    focused可能是ViewGroup也可能是View

    ViewGroup.java

    @Override
    public View focusSearch(View focused, int direction) {
        if (isRootNamespace()) {
            // root namespace means we should consider ourselves the top of the
            // tree for focus searching; otherwise we could be focus searching
            // into other tabs.  see LocalActivityManager and TabHost for more info.
            return FocusFinder.getInstance().findNextFocus(this, focused, direction);
        } else if (mParent != null) {
            return mParent.focusSearch(focused, direction);
        }
        return null;
    }
    

    View.java

    public View focusSearch(@FocusRealDirection int direction) {
        if (mParent != null) {
            return mParent.focusSearch(this, direction);
        } else {
            return null;
        }
    }
    

    mParent是什么?mParent指的是View树中父View,对于普通View,mParent就是ViewGroup,这样一级一级网上,最顶级就是DecorView,而DecorView的mParent是ViewRootImpl,具体流程不展开分析,可以自行搜索查看源码。

    因此focusSearch方法最终会调用到ViewGroup中的focusSearch方法中,直至isRootNamespace返回true,也就是当前view为DecorView时,会走FocusFinder.getInstance().findNextFocus(this, focused, direction)。FocusFinder用于从当前拥有焦点的View中找到给定方向上的下一个可获取焦点的View。想想要在所有View树中找到目标View,那肯定是从View树的顶层View去入手,是吧!

    FocusFinder是查找焦点View的核心算法类
    frameworks/base/core/java/android/view/FocusFinder.java

    public final View findNextFocus(ViewGroup root, View focused, int direction) {
        return findNextFocus(root, focused, null, direction);
    }
    private View findNextFocus(ViewGroup root, View focused, Rect focusedRect, int direction) {
        View next = null;
        ViewGroup effectiveRoot = getEffectiveRoot(root, focused);
        if (focused != null) {
            // 注释1
            next = findNextUserSpecifiedFocus(effectiveRoot, focused, direction);
        }
        if (next != null) {
            return next;
        }
        ArrayList<View> focusables = mTempList;
        try {
            focusables.clear();
            // 注释2
            effectiveRoot.addFocusables(focusables, direction);
            if (!focusables.isEmpty()) {
                // 注释3
                next = findNextFocus(effectiveRoot, focused, focusedRect, direction, focusables);
            }
        } finally {
            focusables.clear();
        }
        return next;
    }
    

    注释1是获取开发者指定的下一个获取焦点的View,xml中指定方式例如nextFocusDown="@id/next_id",java代码指定view1.setNextFocusDownId(R.id.next_id);,指定了按下键下个拥有焦点为id为next_id的view1,此时按下"下导航键"view1获取焦点。

    注释2会得到所有可获取焦点View的集合。

    注释3会在可获取焦点View集合中查找下一个该获取焦点的View。

    下面对这三个过程展开分析

    1. 查找开发人员指定的下个获取焦点的View

    private View findNextUserSpecifiedFocus(ViewGroup root, View focused, int direction) {
        // check for user specified next focus
        // 注释1
        View userSetNextFocus = focused.findUserSetNextFocus(root, direction);
        View cycleCheck = userSetNextFocus;
        boolean cycleStep = true; // we want the first toggle to yield false
        // 注释2
        while (userSetNextFocus != null) {
            if (userSetNextFocus.isFocusable()
                    && userSetNextFocus.getVisibility() == View.VISIBLE
                    && (!userSetNextFocus.isInTouchMode()
                            || userSetNextFocus.isFocusableInTouchMode())) {
                return userSetNextFocus;
            }
            userSetNextFocus = userSetNextFocus.findUserSetNextFocus(root, direction);
            if (cycleStep = !cycleStep) {
                cycleCheck = cycleCheck.findUserSetNextFocus(root, direction);
                if (cycleCheck == userSetNextFocus) {
                    // found a cycle, user-specified focus forms a loop and none of the views
                    // are currently focusable.
                    break;
                }
            }
        }
        return null;
    }
    

    注释1处findUserSetNextFocus方法会得到指定的下一个可获取焦点的view

    View findUserSetNextFocus(View root, @FocusDirection int direction) {
        switch (direction) {
            case FOCUS_LEFT:
                // mNextFocusLeftId就是xml中nextFocusDown属性指定的或者通过java代码setNextFocusLeftId()设置的id
                if (mNextFocusLeftId == View.NO_ID) return null;
                return findViewInsideOutShouldExist(root, mNextFocusLeftId);
            ...
            case FOCUS_FORWARD:
                if (mNextFocusForwardId == View.NO_ID) return null;
                return findViewInsideOutShouldExist(root, mNextFocusForwardId);
            case FOCUS_BACKWARD: {
                if (mID == View.NO_ID) return null;
                final int id = mID;
                return root.findViewByPredicateInsideOut(this, new Predicate<View>() {
                    @Override
                    public boolean test(View t) {
                        return t.mNextFocusForwardId == id;
                    }
                });
            }
        }
        return null;
    }
    

    注释2处循环去查找到一个真正下个可以获取焦点的view。因为用户设置的下个获取焦点的View有可能处于不可见或者focusable属性为false,此时其无法获取焦点,故会继续查找下个指定的可获取焦点的view。

    2. 得到所有可获取焦点的View集合

    effectiveRoot.addFocusables(focusables, direction);先会调用到View中两个参数方法,然后再根据多态来调用View或者ViewGroup中的三个参数的addFocusables()方法

    View.java

    public void addFocusables(ArrayList<View> views, @FocusDirection int direction) {    
        // 注释1
        addFocusables(views, direction, isInTouchMode() ? FOCUSABLES_TOUCH_MODE : FOCUSABLES_ALL);
    }
    public void addFocusables(ArrayList<View> views, @FocusDirection int direction,
            @FocusableMode int focusableMode) {
        if (views == null) {
            return;
        }
        if (!isFocusable()) {
            return;
        }
        if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE
                && !isFocusableInTouchMode()) {
            return;
        }
        // 添加自己到可获取焦点的集合中
        views.add(this);
    }
    

    ViewGroup.java

    @Override
    public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
        final int focusableCount = views.size();
    
        final int descendantFocusability = getDescendantFocusability();
        final boolean blockFocusForTouchscreen = shouldBlockFocusForTouchscreen();
        final boolean focusSelf = (isFocusableInTouchMode() || !blockFocusForTouchscreen);
        // 如果是FOCUS_BLOCK_DESCENDANTS,调用View中addFocusables方法将自己添加到可获取焦点的views集合中,然后返回,不再添加view树中该view的子view
        if (descendantFocusability == FOCUS_BLOCK_DESCENDANTS) {
            if (focusSelf) {
                super.addFocusables(views, direction, focusableMode);
            }
            return;
        }
    
        if (blockFocusForTouchscreen) {
            focusableMode |= FOCUSABLES_TOUCH_MODE;
        }
        // 如果是FOCUS_BEFORE_DESCENDANTS,此时先将自己加入views集合中,然后再将view树中子view添加到views中。
        if ((descendantFocusability == FOCUS_BEFORE_DESCENDANTS) && focusSelf) {
            super.addFocusables(views, direction, focusableMode);
        }
    
        int count = 0;
        final View[] children = new View[mChildrenCount];
        for (int i = 0; i < mChildrenCount; ++i) {
            View child = mChildren[i];
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
                children[count++] = child;
            }
        }
        // view树子view进行一个排序
        FocusFinder.sort(children, 0, count, this, isLayoutRtl());
        for (int i = 0; i < count; ++i) {
            children[i].addFocusables(views, direction, focusableMode);
        }
    
        // When set to FOCUS_AFTER_DESCENDANTS, we only add ourselves if
        // there aren't any focusable descendants.  this is
        // to avoid the focus search finding layouts when a more precise search
        // among the focusable children would be more interesting.
        // 如果是FOCUS_AFTER_DESCENDANTS,则最后将自己加入到views中
        if ((descendantFocusability == FOCUS_AFTER_DESCENDANTS) && focusSelf
                && focusableCount == views.size()) {
            super.addFocusables(views, direction, focusableMode);
        }
    }
    
    1. 注释1会判断当前状态是否是触摸模式,如果是TouchMode 则焦点模式为FOCUSABLES_TOUCH_MODE,否则 FOCUSABLES_ALL。这块有必要说明下TouchMode和这两个属性的意思。
      Touch Mode是在手指触摸屏幕后而进入的状态,一旦通过D-pad或者触摸球进行操作后就会退出Touch Mode
      /**
       * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
       * should add all focusable Views regardless if they are focusable in touch mode.
       */
      public static final int FOCUSABLES_ALL = 0x00000000;
      
      /**
       * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
       * should add only Views focusable in touch mode.
       */
      public static final int FOCUSABLES_TOUCH_MODE = 0x00000001;
      
      
      FOCUSABLES_ALL表示的所有可获取焦点的View,FOCUSABLES_TOUCH_MODE表示的是在TouchMode下可获取焦点的View,例如EditText或者某个控件指定了android:focusableInTouchMode="true"
    1. addFocusables()三个参数的方法会根据多态调用

    2. ViewGroup会根据descendantFocusability属性来决定将自己先加入或者后加入或者不加入到可获取焦点的集合中,因为FocusFinder总是去查找集合中首先可以获取焦点的View。

    3. 在可获取焦点的集合中找到目标View

    next = findNextFocus(effectiveRoot, focused, focusedRect, direction, focusables);
    

    FocusFinder

    private View findNextFocus(ViewGroup root, View focused, Rect focusedRect,
                int direction, ArrayList<View> focusables) {
        if (focused != null) {
            if (focusedRect == null) {
                focusedRect = mFocusedRect;
            }
            // fill in interesting rect from focused
            // 取得考虑scroll之后的焦点Rect,该Rect是相对focused视图本身的
            focused.getFocusedRect(focusedRect);
            // 将当前focused视图的坐标系,转换到root的坐标系中,统一坐标,以便进行下一步的计算
            root.offsetDescendantRectToMyCoords(focused, focusedRect);
        } else {
            ...
        }
    
        switch (direction) {
            case View.FOCUS_FORWARD:
            case View.FOCUS_BACKWARD:
                return findNextFocusInRelativeDirection(focusables, root, focused, focusedRect,
                        direction);
            case View.FOCUS_UP:
            case View.FOCUS_DOWN:
            case View.FOCUS_LEFT:
            case View.FOCUS_RIGHT:
                // 注释1
                return findNextFocusInAbsoluteDirection(focusables, root, focused,
                        focusedRect, direction);
            default:
                throw new IllegalArgumentException("Unknown direction: " + direction);
        }
    }
    

    注释1根据导航方向,查找离自己最近的可获取焦点View

    View findNextFocusInAbsoluteDirection(ArrayList<View> focusables, ViewGroup root, View focused,
            Rect focusedRect, int direction) {
        // initialize the best candidate to something impossible
        // (so the first plausible view will become the best choice)
        mBestCandidateRect.set(focusedRect);
        switch(direction) {
            case View.FOCUS_LEFT:
                mBestCandidateRect.offset(focusedRect.width() + 1, 0);
                break;
            case View.FOCUS_RIGHT:
                mBestCandidateRect.offset(-(focusedRect.width() + 1), 0);
                break;
            case View.FOCUS_UP:
                mBestCandidateRect.offset(0, focusedRect.height() + 1);
                break;
            case View.FOCUS_DOWN:
                mBestCandidateRect.offset(0, -(focusedRect.height() + 1));
        }
    
        View closest = null;
    
        int numFocusables = focusables.size();
        // 遍历所有focusable的视图
        for (int i = 0; i < numFocusables; i++) {
            View focusable = focusables.get(i);
    
            // only interested in other non-root views
            if (focusable == focused || focusable == root) continue;
    
            // get focus bounds of other view in same coordinate system
            // 取得focusable的rect
            focusable.getFocusedRect(mOtherRect);
            // 将该rect转化到root的坐标系中
            root.offsetDescendantRectToMyCoords(focusable, mOtherRect);
            // 进行比较,选出离当前view最近的可获取焦点的view
            if (isBetterCandidate(direction, focusedRect, mOtherRect, mBestCandidateRect)) {
                mBestCandidateRect.set(mOtherRect);
                closest = focusable;
            }
        }
        return closest;
    }
    

    具体判断是否符和要求是iCandidate()方法

    boolean isCandidate(Rect srcRect, Rect destRect, int direction) {
        switch (direction) {
            case View.FOCUS_LEFT:
                return (srcRect.right > destRect.right || srcRect.left >= destRect.right) 
                        && srcRect.left > destRect.left;
            case View.FOCUS_RIGHT:
                return (srcRect.left < destRect.left || srcRect.right <= destRect.left)
                        && srcRect.right < destRect.right;
            case View.FOCUS_UP:
                return (srcRect.bottom > destRect.bottom || srcRect.top >= destRect.bottom)
                        && srcRect.top > destRect.top;
            case View.FOCUS_DOWN:
                return (srcRect.top < destRect.top || srcRect.bottom <= destRect.top)
                        && srcRect.bottom < destRect.bottom;
        }
    }
    

    当然这样的焦点查找方式属于普遍的查找理论,但是我们能否指定查找规则或者做一些客制化呢?答案是肯定的,见下文。

    3. 目标View请求焦点-->v.requestFocus()

    v.requestFocus(),调用下个应获取焦点的View的requestFocus()是其获取焦点并让上个获取焦点的View清除焦点,最后回调onFocusChange()方法。

    客制化焦点查找规则

    1. 通过nextFocusDown等属性指定下个获取焦点的View
    2. 重写focusSearch()方法,RecyclerView就重写了该方法
    3. View中处理按键事件,则按键事件不会走到处理焦点流程中。例如onKeyDown()方法中监听导航键来指定焦点查找规则,例如ListView重写了onKeyDown(),并做了焦点查找的客制化。

    总结

    View框架不处理导航键的焦点查找trace

    01-04 00:38:34.282  2077  2077 W System.err: java.lang.Exception: Stack trace
    01-04 00:38:34.283  2077  2077 W System.err:    at java.lang.Thread.dumpStack(Thread.java:1348)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.FocusFinder.findNextFocusInAbsoluteDirection(FocusFinder.java:340)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.FocusFinder.findNextFocus(FocusFinder.java:268)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.FocusFinder.findNextFocus(FocusFinder.java:110)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.FocusFinder.findNextFocus(FocusFinder.java:80)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.support.v7.widget.RecyclerView.focusSearch(RecyclerView.java:2441)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.View.focusSearch(View.java:10194)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$ViewPostImeInputStage.performFocusNavigation(ViewRootImpl.java:4841)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4966)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4782)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4318)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4371)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4337)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4464)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4345)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4521)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4318)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4371)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4337)
    01-04 00:38:34.283  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4345)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4318)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4371)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4337)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4497)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4664)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2435)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1998)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1989)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2412)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
    01-04 00:38:34.284  2077  2077 W System.err:    at android.os.MessageQueue.nativePollOnce(Native Method)
    01-04 00:38:34.286  2077  2077 W System.err:    at android.os.MessageQueue.next(MessageQueue.java:325)
    01-04 00:38:34.286  2077  2077 W System.err:    at android.os.Looper.loop(Looper.java:142)
    01-04 00:38:34.286  2077  2077 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:6523)
    01-04 00:38:34.286  2077  2077 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    01-04 00:38:34.286  2077  2077 W System.err:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    01-04 00:38:34.286  2077  2077 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
    

    导航键焦点处理流程

    参考

    从源码出发浅析 Android TV 的焦点移动原理 (上篇)

    一点见解: 焦点那点事

    相关文章

      网友评论

        本文标题:Android8.0 焦点处理流程(二)

        本文链接:https://www.haomeiwen.com/subject/qnwguqtx.html