当前位置: 代码迷 >> 综合 >> [RK3288][Android7.1]调试笔记 --- Settings设置WLAN热点支持遥控器弹出软键盘输入法
  详细解决方案

[RK3288][Android7.1]调试笔记 --- Settings设置WLAN热点支持遥控器弹出软键盘输入法

热度:91   发布时间:2023-10-09 13:29:51.0

Platform: RK3288
OS: Android 7.1.2
Kernel: v4.4.143

问题:

使用遥控器点击"设置WLAN热点"后,在这个Dialog上无论用遥控器按哪个按键都无法弹出输入法。

[RK3288][Android7.1]调试笔记 --- Settings设置WLAN热点支持遥控器弹出软键盘输入法

方法: 

先找到这个WifiApDialog:packages/apps/Settings/src/com/android/settings/wifi/WifiApDialog.java

在上面的示意图我们发现这个dialog有两个可输入文本的输入框

private TextView mSsid;
private EditText mPassword;

我们可以设置EditText自动获取焦点且自动弹出软键盘,方法如下;

public void showKeyboard(EditText editText) {if(editText!=null){//设置可获得焦点editText.setFocusable(true);editText.setFocusableInTouchMode(true);//请求获得焦点editText.requestFocus();//调用系统输入法InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);inputManager.showSoftInput(editText, 0);}
}

不可以在OnCreate中直接调用showKeyboard,必须得等View绘制事件完毕之后才能弹出。可以采用Handler新建一个线程做延时弹出键盘;

new Handler().postDelayed(new Runnable(){@Overridepublic void run()  {showKeyboard(mPassword);}},300);

按照以上的方法修改之后,进入设置WLAN热点的dialog后,自动弹出软键盘,且光标在密码输入框的行首;

有两个体验上的问题点:

1、按照正常的流程,应该先设置热点名称,再设置密码;

2、在输入框有默认文本的情况下,光标应该在密码输入框的行尾,这样才能通过删除键删除草稿的内容;

针对问题点1,由于调用showKeyboard需要传一个EdidText,且在源码中ssid被定义为TextView,不可以直接传给showKeyboard,我们尝试将ssid由原来的TextView控件修改为EditText控件。找个这个xml文件,对比ssid和password的xml代码;其实ssid也是一个EditText控件,那么我们是不是可以在代码中定义为EditText呢?

文件:packages/apps/Settings/res/layout/wifi_ap_dialog.xml

[RK3288][Android7.1]调试笔记 --- Settings设置WLAN热点支持遥控器弹出软键盘输入法

针对问题点2,EditText可以设置默认光标显示在行尾;

editText.setSelection(editText.getText().length());

附整体patch:

diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java
old mode 100644
new mode 100755
index 1316a49..0d383c5
--- a/src/com/android/settings/wifi/WifiApDialog.java
+++ b/src/com/android/settings/wifi/WifiApDialog.java
@@ -35,7 +35,8 @@ import android.widget.CheckBox;import android.widget.EditText;import android.widget.Spinner;import android.widget.TextView;
-
+import android.os.Handler;
+import android.view.inputmethod.InputMethodManager;import com.android.settings.R;import java.nio.charset.Charset;
@@ -55,7 +56,7 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,public static final int WPA2_INDEX = 1;private View mView;
-    private TextView mSsid;
+    private EditText mSsid;private int mSecurityTypeIndex = OPEN_INDEX;private EditText mPassword;private int mBandIndex = OPEN_INDEX;
@@ -115,7 +116,16 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,}return null;}
-
+    public void showKeyboard(EditText editText) {
+        if(editText!=null){
+            editText.setFocusable(true);
+            editText.setFocusableInTouchMode(true);
+            editText.requestFocus();
+            editText.setSelection(editText.getText().length());
+            InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+            inputManager.showSoftInput(editText, 0);
+        }
+    }@Overrideprotected void onCreate(Bundle savedInstanceState) {boolean mInit = true;
@@ -130,8 +140,14 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener,setTitle(R.string.wifi_tether_configure_ap_text);mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
-        mSsid = (TextView) mView.findViewById(R.id.ssid);
+        mSsid = (EditText) mView.findViewById(R.id.ssid);mPassword = (EditText) mView.findViewById(R.id.password);
+        new Handler().postDelayed(new Runnable(){
+            @Override
+            public void run()  {
+                showKeyboard(mSsid);
+            }
+        },300);ArrayAdapter <CharSequence> channelAdapter;String countryCode = mWifiManager.getCountryCode();

按照上面的思路解决之后,先打开"设置WLAN热点",自动弹出软键盘且光标在“AndroidAP”的行尾,用户修改ssid名称用遥控器按方向键下键,可以跳到密码输入框,第一次会先跳到密码草稿的行首,再按多次的遥控器下键可以跳到行尾;我们可以再优化下,让默认密码为空;

修改WLAN热点默认密码:frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiApConfigStore.java

diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java
old mode 100644
new mode 100755
index bcd8d03..1452895
--- a/service/java/com/android/server/wifi/WifiApConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiApConfigStore.java
@@ -195,7 +195,8 @@ public class WifiApConfigStore {config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);String randomUUID = UUID.randomUUID().toString();//first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
-        config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
+        //config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
+        config.preSharedKey = "";return config;}}

修改WLAN热点默认名称:frameworks/base/core/res/res/values/strings.xml

diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
old mode 100644
new mode 100755
index 4172864..f77a024
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2980,7 +2980,7 @@<string name="wifi_watchdog_network_disabled_detailed">\u0020has a poor Internet connection.</string><!-- Do not translate. Default access point SSID used for tethering -->
-    <string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>
+    <string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAPAP</string><!-- A notification is shown the first time a connection is attempted on an app owned AP --><!-- title for this message -->

附GIT示意图

[RK3288][Android7.1]调试笔记 --- Settings设置WLAN热点支持遥控器弹出软键盘输入法

  相关解决方案