最近处理一个问题,设备有方向键盘,做cit中的按键测试,发现按方向键第一次按键不能触发该键值,而是让屏幕第一个按钮获取焦点,然后再次按键,则其他正常。问题:进入界面第一次按键就要响应对应按键逻辑,不需要焦点。该问题查找了很久,最后找到了答案!

布局中的按键测试布局中按钮是button或imagebutton。这布局进入时,初次会相应方向键(原理未知),解决方案:设置所有按钮clickable=false(防止触屏幕激发),主要的是将所有按钮设置

enable=false(imagebutton在xml中设置无效,需要在代码中设置)

修改如下

Date:   Wed Aug 28 18:38:33 2024 +0800

    处理按键测试按钮获取焦点问题
    
    Change-Id: I6f317fec43c213761573fb793bc057fd14da71ae

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8e8eb03..23abed9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -87,7 +87,7 @@
                 <data
                     android:host="83789"
                     android:scheme="unisoc_secret_code" />
-            </intent-filter>
+            </intent-filter>    
         </receiver>
         <receiver
             android:name="com.sprd.validationtools.PhaseCheckBroadcastReceiver"
diff --git a/res/layout/key_test.xml b/res/layout/key_test.xml
index 53eba2e..16f2164 100644
--- a/res/layout/key_test.xml
+++ b/res/layout/key_test.xml
@@ -3,12 +3,6 @@
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
-     <Button
-        android:id="@+id/focus_button"
-        android:layout_width="0dp"
-        android:layout_height="0dp"
-        android:clickable="false" >
-    </Button>
 
     <LinearLayout
         android:layout_width="fill_parent"
@@ -21,6 +15,7 @@
             android:layout_height="wrap_content"
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
             android:src="@drawable/voice_up" />                                                                    
                                                                                                                    
         <ImageButton                                                                                               
@@ -28,6 +23,7 @@                                                                                                   
             android:layout_width="0dip"                                                                            
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
+            android:enabled="false"                                                                                
             android:clickable="false"                                                                              
             android:src="@drawable/voice_down" />                                                                  
         <ImageButton                                                                                               
@@ -36,6 +32,7 @@                                                                                                   
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
             android:src="@drawable/power_off" />                                                                   
                                                                                                                    
     </LinearLayout>                                                                                                
@@ -69,6 +66,7 @@                                                                                                   
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
             android:gravity="center"                                                                               
             android:text="CALL" />                                                                                 
                                                                                                                    
@@ -78,6 +76,8 @@                                                                                                   
         android:layout_height="wrap_content"                                                                       
         android:layout_weight="1"                                                                                  
         android:gravity="center"                                                                                   
+        android:enabled="false"                                                                                    
+        android:clickable="false"                                                                                  
         android:src="@drawable/menu"                                                                               
         android:visibility="visible" />                                                                            
                                                                                                                    
@@ -87,6 +87,7 @@                                                                                                   
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
             android:src="@drawable/camera" />                                                                      
             <ImageButton                                                                                           
             android:id="@+id/home_button"                                                                          
@@ -95,6 +96,7 @@                                                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
             android:gravity="center"                                                                               
+            android:enabled="false"                                                                                
             android:src="@drawable/home" />                                                                        
                                                                                                                    
     </LinearLayout>                                                                                                
@@ -110,6 +112,9 @@                                                                                                 
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
+                                                                                                                   
+                                                                                                                   
             android:text="PTT" />                                                                                  
                                                                                                                    
         <Button                                                                                                    
@@ -118,6 +123,8 @@                                                                                                 
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+            android:enabled="false"                                                                                
+                                                                                                                   
             android:text="SOS" />                                                                                  
         <ImageButton                                                                                               
                     android:id="@+id/back_button"                                                                  
@@ -125,6 +132,7 @@                                                                                                 
                     android:layout_height="wrap_content"                                                           
                     android:layout_weight="1"                                                                      
                     android:clickable="false"                                                                      
+                    android:enabled="false"                                                                        
                     android:gravity="center"                                                                       
                     android:src="@drawable/back"                                                                   
                     android:visibility="visible" />                                                                
@@ -134,6 +142,7 @@                                                                                                 
                 android:layout_weight="1"                                                                          
                 android:layout_height="wrap_content"                                                               
                 android:clickable="false"                                                                          
+                android:enabled="false"                                                                            
                 android:gravity="center"                                                                           
                 android:text="Fn"                                                                                  
                 android:visibility="visible" />                                                                    
@@ -150,6 +159,9 @@                                                                                                 
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+                android:enabled="false"                                                                            
+                                                                                                                   
+                                                                                                                   
             android:text="VIDEO" />                                                                                
                                                                                                                    
         <Button                                                                                                    
@@ -158,6 +170,8 @@                                                                                                 
             android:layout_height="wrap_content"                                                                   
             android:layout_weight="1"                                                                              
             android:clickable="false"                                                                              
+                android:enabled="false"                                                                            
+                                                                                                                   
             android:text="LIGHT" />                                                                                
                                                                                                                    
     </LinearLayout>                                                                                                
@@ -181,6 +195,9 @@                                                                                                 
                     android:layout_width="wrap_content"                                                            
                     android:layout_height="wrap_content"                                                           
                     android:clickable="false"                                                                      
+                     android:focusable="false"                                                                     
+                     android:enabled="false"                                                                       
+                    android:focusableInTouchMode="false"                                                           
                     android:src="@drawable/up" />                                                                  
                                                                                                                    
                 <LinearLayout                                                                                      
@@ -199,6 +216,9 @@                                                                                                 
                         android:layout_width="wrap_content"                                                        
                         android:layout_height="wrap_content"                                                       
                         android:clickable="false"                                                                  
+                        android:enabled="false"                                                                    
+                         android:focusable="false"                                                                 
+                    android:focusableInTouchMode="false"                                                           
                         android:src="@drawable/left" />                                                            
                                                                                                                    
                     <ImageButton                                                                                   
@@ -206,6 +226,9 @@                                                                                                 
                         android:layout_width="wrap_content"                                                        
                         android:layout_height="wrap_content"                                                       
                         android:clickable="false"                                                                  
+                         android:focusable="false"                                                                 
+                         android:enabled="false"                                                                   
+                         android:focusableInTouchMode="false"                                                      
                         android:src="@drawable/center" />                                                          
                                                                                                                    
                     <ImageButton                                                                                   
@@ -213,6 +236,9 @@                                                                                                 
                         android:layout_width="wrap_content"                                                        
                         android:layout_height="wrap_content"                                                       
                         android:clickable="false"                                                                  
+                        android:focusable="false"                                                                  
+                        android:enabled="false"                                                                    
+                        android:focusableInTouchMode="false"                                                       
                         android:src="@drawable/right" />                                                           
                 </LinearLayout>                                                                                    
                                                                                                                    
@@ -227,6 +253,9 @@                                                                                                 
                         android:layout_width="wrap_content"                                                        
                         android:layout_height="wrap_content"                                                       
                         android:clickable="false"                                                                  
+                         android:focusable="false"                                                                 
+                         android:enabled="false"                                                                   
+                        android:focusableInTouchMode="false"                                                       
                         android:src="@drawable/down" />                                                            
                 </LinearLayout>                                                                                    
         </LinearLayout>                                                                                            
@@ -249,6 +278,7 @@                                                                                                 
                     android:layout_width="180dip"                                                                  
                     android:layout_height="wrap_content"                                                           
                     android:clickable="false"                                                                      
+                android:enabled="false"                                                                            
                     android:text="@string/ai_key_test" />                                                          
         </LinearLayout>                                                                                            
     </LinearLayout>                                                                                                
diff --git a/src/com/sprd/validationtools/itemstest/audio/PhoneLoopBackTest.java b/src/com/sprd/validationtools/itemstest/audio/PhoneLoopBackTest.java                                                                                  
index d45d9b8..7b8696c 100644                                                                                       
--- a/src/com/sprd/validationtools/itemstest/audio/PhoneLoopBackTest.java                                           
+++ b/src/com/sprd/validationtools/itemstest/audio/PhoneLoopBackTest.java                                           
@@ -83,17 +83,21 @@ public class PhoneLoopBackTest extends BaseActivity {                                           
                                                                                                                    
         mRadioSpeaker.setOnClickListener(new View.OnClickListener() {                                              
             public void onClick(View v) {                                                                          
+                Log.d(TAG, "mRadioSpeaker click---");                                                              
+                                                                                                                   
                 switchLoopback(LOOPBACK_SPEAKER);                                                                  
             }                                                                                                      
         });                                                                                                        
         mRadioReceiver.setOnClickListener(new View.OnClickListener() {                                             
             public void onClick(View v) {                                                                          
+                Log.d(TAG, "mRadioReceiver click---");                                                             
                 switchLoopback(LOOPBACK_RECEIVER);                                                                 
             }                                                                                                      
         });                                                                                                        
                                                                                                                    
         mRadioEarpiece.setOnClickListener(new View.OnClickListener() {                                             
             public void onClick(View v) {                                                                          
+                Log.d(TAG, "mRadioEarpiece click---");                                                             
                 switchLoopback(LOOPBACK_MIC_EARPIECE);                                                             
             }                                                                                                      
         });                                                                                                        
diff --git a/src/com/sprd/validationtools/itemstest/keypad/KeyTestActivity.java b/src/com/sprd/validationtools/itemstest/keypad/KeyTestActivity.java                                                                                    
index 0139c4e..06f5bd1 100644                                                                                       
--- a/src/com/sprd/validationtools/itemstest/keypad/KeyTestActivity.java                                            
+++ b/src/com/sprd/validationtools/itemstest/keypad/KeyTestActivity.java                                            
@@ -19,6 +19,7 @@ import android.widget.Button;                                                                     
 import android.widget.GridLayout;                                                                                  
 import android.widget.ImageButton;                                                                                 
 import android.widget.Toast;                                                                                       
+import android.view.WindowManager;                                                                                 
                                                                                                                    
 import com.sprd.validationtools.BaseActivity;                                                                      
 import com.sprd.validationtools.Const;                                                                             
@@ -118,13 +119,20 @@ public class KeyTestActivity extends BaseActivity {                                           
             setContentView(R.layout.key_test);                                                                     
             setTitle(R.string.key_test);                                                                           
             mHomeButton = (ImageButton) findViewById(R.id.home_button);                                            
+            mHomeButton.setEnabled(false);                                                                         
 //            mMenuButton = (ImageButton) findViewById(R.id.menu_button);                                          
             mCallButton = (Button) findViewById(R.id.call_button);                                                 
             mVolumeUpButton = (ImageButton) findViewById(R.id.volume_up_button);                                   
             mVolumeDownButton = (ImageButton) findViewById(R.id.volume_down_button);                               
             mCameraButton = (ImageButton) findViewById(R.id.camera_button);                                        
+            mVolumeUpButton.setEnabled(false);                                                                     
+            mVolumeDownButton.setEnabled(false);                                                                   
+            mCameraButton.setEnabled(false);                                                                       
+                                                                                                                   
                                                                                                                    
             mPowerButton = (ImageButton) findViewById(R.id.power_button);                                          
+            mPowerButton.setEnabled(false);                                                                        
+                                                                                                                   
             mPTTButton = (Button)findViewById(R.id.ptt_button);                                                    
             mSOSButton = (Button)findViewById(R.id.sos_button);                                                    
                                                                                                                    
@@ -154,10 +162,9 @@ public class KeyTestActivity extends BaseActivity {                                            
             mVideoButton.setVisibility(View.GONE);                                                                 
             mCallButton.setVisibility(View.GONE);                                                                  
                                                                                                                    
-            findViewById(R.id.focus_button).requestFocus();                                                        
-                                                                                                                   
             mFnButton = (Button)findViewById(R.id.fn_button);                                                      
             mMenuButton = (ImageButton)findViewById(R.id.menu_button);                                             
+            mMenuButton.setEnabled(false);                                                                         
                                                                                                                    
             mUpButton = (ImageButton)findViewById(R.id.up_button);                                                 
             mDownButton = (ImageButton)findViewById(R.id.down_button);                                             
@@ -165,7 +172,14 @@ public class KeyTestActivity extends BaseActivity {                                            
             mRightButton = (ImageButton)findViewById(R.id.right_button);                                           
             mCenterButton = (ImageButton)findViewById(R.id.center_button);                                         
             mBackButton = (ImageButton)findViewById(R.id.back_button);                                             
-                                                                                                                   
+            mUpButton.setEnabled(false);                                                                           
+            mDownButton.setEnabled(false);                                                                         
+            mLeftButton.setEnabled(false);                                                                         
+            mRightButton.setEnabled(false);                                                                        
+            mCenterButton.setEnabled(false);                                                                       
+            mBackButton.setEnabled(false);                                                                         
+                                                                                                                   
+            // mVolumeUpButton.requestFocus();                                                                     
             initSupport();                                                                                         
         }                                                                                                          
     }  

over~

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部