Android TvSettings Bug: The password box cannot be clicked to invoke the input method

overview

       The Box solution of Android 10 uses TvSettings as the system setting by default. The habit of input operation is to use the mouse, keyboard, and remote control. There is no problem in daily scenes, and the problems mentioned in this article will not appear. When the external USB touch screen is connected , the WIFI password box cannot be clicked to switch out the input method to enter the password.

Problem:
insert image description here
insert image description here
When adding WIFI from Figure 1 and preparing to enter the password, there is no way to click on the external USB touch screen to arouse the input method.

The normal situation should be as shown in the figure below:
insert image description here

process

     In some previous articles, for problems that cannot be clicked or respond to key operations, you can generally check the focus problem first:

View Hierarchy:
      DecorView@661bdd7[WifiConnectionActivity]
        android.widget.LinearLayout{
    
    abf86c4 V.E...... ........ 0,0-1920,1080}
          android.view.ViewStub{
    
    e3449ad G.E...... ......I. 0,0-0,0 #10201a2 android:id/action_mode_bar_stub}
          android.widget.FrameLayout{
    
    38444e2 V.E...... ........ 0,0-1920,1080 #1020002 android:id/content}
            android.widget.FrameLayout{
    
    51a6073 V.E...... ........ 0,0-1920,1080 #7f0a0229 app:id/wifi_container}
              androidx.leanback.app.GuidedStepRootLayout{
    
    1904b30 V.E...... ........ 0,0-1920,1080 #7f0a0105 app:id/guidedstep_root}
                android.widget.FrameLayout{
    
    878d3a9 V.E...... ........ 0,0-1920,1080 #7f0a0104 app:id/guidedstep_background_view_root}
                  androidx.leanback.widget.NonOverlappingView{
    
    9a5cd2e V.ED..... ........ 0,0-1920,1080 #7f0a0103 app:id/guidedstep_background}
                  android.widget.LinearLayout{
    
    fb090cf V.E...... ........ 0,0-1920,1080 #7f0a00a0 app:id/content_frame}
                    androidx.leanback.widget.NonOverlappingFrameLayout{
    
    966ea5c V.E...... ........ 0,0-1231,1080 #7f0a009f app:id/content_fragment}
                      com.android.tv.settings.connectivity.setup.GuidanceRelativeLayout{
    
    b620165 V.E...... ........ 0,0-1231,1080}
                        android.widget.TextView{
    
    e458e3a V.ED..... ........ 168,374-1147,447 #7f0a00f1 app:id/guidance_title}
                        android.widget.TextView{
    
    fcf6aeb V.ED..... ........ 168,474-1147,503 #7f0a00ef app:id/guidance_description}
                    androidx.leanback.widget.NonOverlappingFrameLayout{
    
    aa65048 V.E...... ........ 1231,0-1919,1080 #7f0a0044 app:id/action_fragment_root}
                      androidx.leanback.widget.NonOverlappingView{
    
    4f64ee1 V.ED..... ........ 0,0-688,1080 #7f0a0043 app:id/action_fragment_background}
                      androidx.leanback.widget.NonOverlappingLinearLayout{
    
    bee5406 VFE...... ........ 0,0-688,1080 #7f0a0042 app:id/action_fragment}
                        android.widget.RelativeLayout{
    
    4b7cac7 V.E...... ........ 0,0-688,1080 #7f0a00ff app:id/guidedactions_root}
                          androidx.leanback.widget.NonOverlappingView{
    
    ef428f4 G.ED..... ......ID 0,0-0,0 #7f0a00fd app:id/guidedactions_list_background}
                          androidx.leanback.widget.GuidedActionsRelativeLayout{
    
    327f81d V.E...... ........ 0,0-688,1080 #7f0a00f3 app:id/guidedactions_content}
                            androidx.leanback.widget.VerticalGridView{
    
    90baa92 V.E...... ........ 0,0-348,1080 #7f0a00fb app:id/guidedactions_list}
                              android.widget.LinearLayout{
    
    6dc4c63 VFE...C.. ........ 0,103-348,528}
                                android.widget.FrameLayout{
    
    2a4e060 V.E...... ........ 0,293-348,365 #7f0a020f app:id/text_input_wrapper}
                                  android.widget.EditText{
    
    6d0f919 VFED..... ........ 24,0-324,72 #7f0a00fa app:id/guidedactions_item_title}
                                android.widget.CheckBox{
    
    535ddde VFED..C.. ........ 14,377-146,425 #7f0a01ac app:id/password_checkbox}
                            androidx.leanback.widget.NonOverlappingView{
    
    93d4bbf G.ED..... ......ID 0,0-0,0 #7f0a0102 app:id/guidedactions_sub_list_background}
                            androidx.leanback.widget.VerticalGridView{
    
    e7a28c IFE...... ......I. 0,432-688,432 #7f0a0101 app:id/guidedactions_sub_list}
                        android.widget.RelativeLayout{
    
    a6f0dd5 V.E...... ........ 688,0-688,1080 #7f0a0100 app:id/guidedactions_root2}
                          androidx.leanback.widget.NonOverlappingView{
    
    f3df9ea V.ED..... ......ID 0,0-0,1080 #7f0a00fe app:id/guidedactions_list_background2}
                          androidx.leanback.widget.NonOverlappingFrameLayout{
    
    484e4db V.E...... ......ID 0,0-0,1080 #7f0a00f4 app:id/guidedactions_content2}
                            androidx.leanback.widget.VerticalGridView{
    
    6b25b78 V.E...... ......ID 0,0-0,1080 #7f0a00fc app:id/guidedactions_list2}

Apparently android.widget.EditText{6d0f919 VFED... 24,0-324,72 #7f0a00fa app:id/guidedactions_item_title} is not clickable.

Find the relevant code by ID:

$ grep -r "guidedactions_item_title" packages/apps/TvSettings/Settings
packages/apps/TvSettings/Settings/res/layout/setup_text_input_item.xml:            android:id="@+id/guidedactions_item_title"
packages/apps/TvSettings/Settings/res/layout/setup_password_item.xml:            android:id="@+id/guidedactions_item_title"
packages/apps/TvSettings/Settings/src/com/android/tv/settings/connectivity/util/GuidedActionsAlignUtil.java:                        androidx.leanback.R.id.guidedactions_item_title);
packages/apps/TvSettings/Settings/src/com/android/tv/settings/util/GuidedActionsAlignUtil.java:                        androidx.leanback.R.id.guidedactions_item_title);

packages/apps/TvSettings/Settings/res/layout/setup_password_item.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text_input_wrapper"
        android:layout_width="match_parent"
        android:layout_height="@dimen/setup_list_item_height"
        android:layout_alignParentStart="true"
        android:layout_marginTop="@dimen/setup_action_vertical_offset"
        android:background="@drawable/setup_text_input_background"
        android:elevation="@dimen/setup_elevation"
        android:gravity="start|center_vertical"
        android:paddingEnd="@dimen/setup_list_item_padding"
        android:paddingStart="@dimen/setup_list_item_padding">

        <EditText
            android:id="@+id/guidedactions_item_title"
            style="@style/Setup.Action.TextInput"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
	    	android:focusable="true"
	    	android:gravity="center_vertical"
            android:imeOptions="actionNext|flagNoExtractUi"
            android:inputType="text">
        </EditText>
    </FrameLayout>

    <CheckBox
        android:id="@+id/password_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/setup_obfuscation_margin_start"
        android:layout_marginTop="@dimen/setup_obfuscation_margin_top"
        android:buttonTint="@color/setup_list_item_background_focused"
        android:buttonTintMode="src_in"
        android:text="@string/text_obfuscation_toggle_caption" />
</LinearLayout>

        @Override
        public GuidedActionsStylist onCreateActionsStylist() {
    
    
            return new GuidedActionsStylist() {
    
    
                @Override
                public void onBindViewHolder(ViewHolder vh, GuidedAction action) {
    
    
                    super.onBindViewHolder(vh, action);
                    if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
    
    
                        PasswordViewHolder viewHolder = (PasswordViewHolder) vh;
                        mTextInput = (EditText) viewHolder.getTitleView();
						mTextInput.setClickable(true);
						mTextInput.setFocusableInTouchMode(true);
                        mCheckBox = viewHolder.mCheckbox;
                        mCheckBox.setOnClickListener(view -> {
    
    
                            updatePasswordInputObfuscation();
                            EnterPasswordFragment.this.openInEditMode(action);
                        });
                        mCheckBox.setChecked(mUserChoiceInfo.isPasswordHidden());
                        updatePasswordInputObfuscation();
                        openInEditMode(action);
                    }
                }
             }
			@Override
            public int onProvideItemLayoutId() {
    
    
                return R.layout.setup_password_item;
            }
         }

增加
mTextInput.setClickable(true);
mTextInput.setFocusableInTouchMode(true);

Compile, solve!


Another Attempt
Before this, tried setting in XML:

        <EditText
            android:clickable="true"
			android:focusableInTouchMode="true"
		>

Result: invalid? ?
Repeatedly confirmed the correctness of the layout file to no avail.
It is not realistic to check one by one from the code. As a coincidence, I customized an EditText to replace the default one, and rewritten the setClickable function. From the printed stack of calls, I know that it is indeed called in GuidedActionsStylist.onBindViewHolder .

GuidedActionsStylist is in androidx ,

packages/apps/TvSettings/Settings/Android.mk

LOCAL_PACKAGE_NAME := TvSettings
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_FLAG_FILES := proguard.cfg
LOCAL_PROGUARD_ENABLED := disabled

LOCAL_PRIVILEGED_MODULE := true

LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.recyclerview_recyclerview \
    androidx.preference_preference \
    androidx.appcompat_appcompat \
    androidx.legacy_legacy-preference-v14 \
    androidx.leanback_leanback-preference \
    androidx.leanback_leanback \
    androidx.lifecycle_lifecycle-extensions \
    androidx-constraintlayout_constraintlayout \

Corresponding jar package path:

out/target/common/obj/JAVA_LIBRARIES/androidx.leanback_leanback_intermediates/classes.jar

By the way, look at the source code:

GuidedActionsStylist.java

		public ViewHolder(@NonNull View v, boolean isSubAction) {
    
    
            super(v);

            mContentView = v.findViewById(R.id.guidedactions_item_content);
            mTitleView = (TextView) v.findViewById(R.id.guidedactions_item_title);
            mActivatorView = v.findViewById(R.id.guidedactions_activator_item);
            mDescriptionView = (TextView) v.findViewById(R.id.guidedactions_item_description);
            mIconView = (ImageView) v.findViewById(R.id.guidedactions_item_icon);
            mCheckmarkView = (ImageView) v.findViewById(R.id.guidedactions_item_checkmark);
            mChevronView = (ImageView) v.findViewById(R.id.guidedactions_item_chevron);
            mIsSubAction = isSubAction;

            v.setAccessibilityDelegate(mDelegate);
        }
    /**
     * Binds a {@link ViewHolder} to a particular {@link GuidedAction}.
     * @param vh The view holder to be associated with the given action.
     * @param action The guided action to be displayed by the view holder's view.
     * @return The view to be added to the caller's view hierarchy.
     */
    public void onBindViewHolder(ViewHolder vh, GuidedAction action) {
    
    
        vh.mAction = action;
        if (vh.mTitleView != null) {
    
    
            vh.mTitleView.setInputType(action.getInputType());
            vh.mTitleView.setText(action.getTitle());
            vh.mTitleView.setAlpha(action.isEnabled() ? mEnabledTextAlpha : mDisabledTextAlpha);
            vh.mTitleView.setFocusable(false);
            vh.mTitleView.setClickable(false);
            vh.mTitleView.setLongClickable(false);
            if (BuildCompat.isAtLeastP()) {
    
    
                if (action.isEditable()) {
    
    
                    vh.mTitleView.setAutofillHints(action.getAutofillHints());
                } else {
    
    
                    vh.mTitleView.setAutofillHints((String[]) null);
                }
            } else if (VERSION.SDK_INT >= 26) {
    
    
                // disable autofill below P as dpad/keyboard is not supported
                vh.mTitleView.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
            }
        }
		//....
    }

As can be seen from the above code, after using the GuidedActionsStylist, the control with the ID of guidedactions_item_title will be disabled.
It just happens to be the text input box mentioned earlier, right!

quote

The difference between android:focusable and android:focusableInTouchMode
GuidedActionsStylist
AndroidX GitHub
AOSP AndroidX Contribution Guide

Guess you like

Origin blog.csdn.net/ansondroider/article/details/131718564
Recommended