查看: 1888|回复: 0

tinker board 2s Android10添加导航 按钮(音量键)

[复制链接]

3

主题

10

回帖

93

积分

注册会员

Rank: 2

积分
93
发表于 2023-12-7 19:58:16 | 显示全部楼层 |阅读模式
(为了高效,请按如下格式提问)

硬件主板型号:tinker board 2s
固件名称/系统版本:Android 10
自编的或固件下载地址:自编
Log日志: (可以导出,用TXT附件上传)

问题描述及复现步骤:
添加按钮到相关文件
我添加的按钮是“volume_add2”
  1. <wiz-editor-doc data-source="wiz-editor-doc::eyJibG9ja3MiOlt7ImlkIjoiX2F5VklDcnd4IiwidHlwZSI6InRleHQiLCJ0ZXh0IjpbeyJpbnNlcnQiOiJmcmFtZXdvcmtzL2Jhc2UvcGFja2FnZXMvU3lzdGVtVUkvcmVzL3ZhbHVlcy1zdzQwMGRwL2NvbmZpZy54bWwifV19XSwiY29tbWVudHMiOnt9LCJtZXRhIjp7ImFwcElkIjoiMDliNWY3ZjAtYTJlZS0xMWVkLTkyNjEtNDcwNDhkMzlkNGNhIiwiZG9jSWQiOiI1MWI1ZDg0ZS1kOWRhLTQxOGItOTYxYS0xYmEwMDZlYmQ4MjQiLCJ0aXRsZSI6IlJLMzM5OS1BbmRyb2lkMTDln7rnoYDmm7TmlLnorr7lpIflnovlj7fvvIzor63oqIDvvIzml7bljLrlkozlvIDmnLrlm77moIciLCJmaXJzdEJsb2NrSWQiOiJfYXlWSUNyd3giLCJhcGlTZXJ2ZXIiOiJodHRwczovL3ZpcGtzaHR0cHM4Lndpei5jbi9lZGl0b3IvMDliNWY3ZjAtYTJlZS0xMWVkLTkyNjEtNDcwNDhkMzlkNGNhLzUxYjVkODRlLWQ5ZGEtNDE4Yi05NjFhLTFiYTAwNmViZDgyNCIsInRva2VuIjoiVy55M2kyUzdxa0ZIWmVZc0daTVRjTVFPYmNSMk1lNEw2YklDajhkY0EzZ1BWcy1YM2JfYUl4YlVmamctT25lWHcifSwiY29tbWVudGF0b3JzIjpbXX0::wiz-editor-doc">frameworks/base/packages/SystemUI/res/values-sw400dp/config.xml</wiz-editor-doc>
复制代码


音量按键处理流程

Android系统定义了音量volume_uo和volume_down的值KeyEevent,

frameworks/base/core/java/android/view/KeyEvent.java
  1. /** Key code constant: Volume Up key.
  2.      * Adjusts the speaker volume up. */
  3.     public static final int KEYCODE_VOLUME_UP       = 24;                                                                                         
  4.     /** Key code constant: Volume Down key.
  5.      * Adjusts the speaker volume down. */
  6.     public static final int KEYCODE_VOLUME_DOWN     = 25;
复制代码
在frameworks/base/packages/SystemUI/res/layout/文件下添加volume_add2的xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <com.android.systemui.statusbar.policy.KeyButtonView
  3.         xmlns:android="http://schemas.android.com/apk/res/android"
  4.         xmlns:systemui="http://schemas.android.com/apk/res-auto"
  5.         android:id="@+id/volume_add2"
  6.         android:layout_width="@dimen/navigation_key_width"
  7.         android:layout_height="match_parent"
  8.         android:layout_weight="0"
  9.         systemui:keyCode="24"//这里就是对应按钮的KEYCODE_VOLUME_UP  表示音量+
  10.         android:scaleType="center"
  11.         android:contentDescription="@string/accessibility_home"
  12.         android:paddingStart="@dimen/navigation_key_padding"
  13.         android:paddingEnd="@dimen/navigation_key_padding
复制代码
音量加按键图像文件路径:
frameworks/base/packages/SystemUI/res/drawable/文件夹下添加


ic_sysbar_volume_add2_button.xml
  1. <vector xmlns:android="http://schemas.android.com/apk/res/android"
  2.         android:width="24dp"
  3.         android:height="24dp"
  4.         android:viewportWidth="24.0"
  5.         android:viewportHeight="24.0">
  6.     <path
  7.             android:fillColor="?attr/singleToneColor"
  8.             android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z"/>
  9. </vector>
复制代码
最后在NavigationBarFragment.java添加新的按钮属性 ,路径是frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/
  1. diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
  2. index 2daf26a3fc..adeb277ffc 100644
  3. --- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
  4. +++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
  5. @@ -700,6 +700,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
  6.          }

  7.          ButtonDispatcher volumeAddButton=mNavigationBarView.getVolumeAddButton();
  8. +       ButtonDispatcher volumeAdd2Button=mNavigationBarView.getVolumeAdd2Button();
  9.          ButtonDispatcher volumeSubButton=mNavigationBarView.getVolumeSubButton();
  10.          boolean isShowVolumeButton="true".equals(SystemProperties.get("ro.rk.systembar.voiceicon","true"));
  11.          if(isShowVolumeButton){
  12. diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
  13. old mode 100644
  14. new mode 100755
  15. index 31813bd005..458bd1fd83
  16. --- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
  17. +++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
  18. @@ -65,6 +65,7 @@ public class NavigationBarInflaterView extends FrameLayout
  19.      public static final String IME_SWITCHER = "ime_switcher";
  20.      public static final String SCREENSHOT = "screenshot";
  21.      public static final String VOLUME_ADD = "volume_add";
  22. +    public static final String VOLUME_ADD2 = "volume_add2";
  23.      public static final String VOLUME_SUB = "volume_sub";

  24.      public static final String GRAVITY_SEPARATOR = ";";
  25. @@ -414,7 +415,9 @@ public class NavigationBarInflaterView extends FrameLayout
  26.              v = inflater.inflate(R.layout.screenshot, parent, false);
  27.          } else if (VOLUME_ADD.equals(button)) {
  28.              v = inflater.inflate(R.layout.volume_add, parent, false);
  29. -        } else if (VOLUME_SUB.equals(button)) {
  30. +        } else if (VOLUME_ADD2.equals(button)) {
  31. +               v = inflater.inflate(R.layout.volume_add2, parent, false);
  32. +        } else if (VOLUME_SUB.equals(button)) {
  33.              v = inflater.inflate(R.layout.volume_sub, parent, false);
  34.          } else if (button.startsWith(KEY)) {
  35.              String uri = extractImage(button);
  36. diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
  37. index 421a58fa74..5c3b078b9c 100644
  38. --- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
  39. +++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
  40. @@ -117,6 +117,7 @@ public class NavigationBarView extends FrameLayout implements
  41.      private KeyButtonDrawable mRecentIcon;
  42.      private KeyButtonDrawable mDockedIcon;
  43.      private KeyButtonDrawable mVolumeAddIcon;
  44. +    private KeyButtonDrawable mVolumeAdd2Icon;
  45.      private KeyButtonDrawable mVolumeSubIcon;
  46.      private KeyButtonDrawable mScreenshotIcon;

  47. @@ -315,6 +316,7 @@ public class NavigationBarView extends FrameLayout implements
  48.          mButtonDispatchers.put(R.id.accessibility_button, accessibilityButton);
  49.          mButtonDispatchers.put(R.id.rotate_suggestion, rotateSuggestionButton);
  50.          mButtonDispatchers.put(R.id.menu_container, mContextualButtonGroup);
  51. +       mButtonDispatchers.put(R.id.volume_add2, new ButtonDispatcher(R.id.volume_add2));
  52.          mButtonDispatchers.put(R.id.screenshot, new ButtonDispatcher(R.id.screenshot));
  53.          mButtonDispatchers.put(R.id.volume_add, new ButtonDispatcher(R.id.volume_add));
  54.          mButtonDispatchers.put(R.id.volume_sub, new ButtonDispatcher(R.id.volume_sub));
  55. @@ -442,6 +444,10 @@ public class NavigationBarView extends FrameLayout implements
  56.          return mButtonDispatchers.get(R.id.volume_add);
  57.      }

  58. +    public ButtonDispatcher getVolumeAdd2Button() {
  59. +       return mButtonDispatchers.get(R.id.volume_add2);
  60. +    }
  61. +
  62.      public ButtonDispatcher getVolumeSubButton() {
  63.          return mButtonDispatchers.get(R.id.volume_sub);
  64.      }
  65. @@ -492,6 +498,7 @@ public class NavigationBarView extends FrameLayout implements
  66.          }

  67.          mVolumeAddIcon = getDrawable(R.drawable.ic_sysbar_volume_add_button);
  68. +       mVolumeAdd2Icon = getDrawable(R.drawable.ic_sysbar_volume_add2_button);
  69.          mVolumeSubIcon = getDrawable(R.drawable.ic_sysbar_volume_sub_button);
  70.          mScreenshotIcon = getDrawable(R.drawable.ic_sysbar_capture_button);
  71.      }
  72. @@ -636,6 +643,7 @@ public class NavigationBarView extends FrameLayout implements
  73.          getHomeButton().setImageDrawable(homeIcon);
  74.          getBackButton().setImageDrawable(backIcon);
  75.          getVolumeAddButton().setImageDrawable(mVolumeAddIcon);
  76. +       getVolumeAdd2Button().setImageDrawable(mVolumeAdd2Icon);
  77.          getVolumeSubButton().setImageDrawable(mVolumeSubIcon);
  78.          getScreenshotButton().setImageDrawable(mScreenshotIcon);
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|风火轮WIKI|手机版|小黑屋|深圳风火轮团队 ( 粤ICP备17095099号 )

GMT+8, 2024-11-21 23:54 , Processed in 0.048680 second(s), 20 queries .

快速回复 返回顶部 返回列表
 
【客服1】 商务合作 15289193
【客服2】 业务洽谈 13257599
【客服3】 售前咨询 510313198
【邮箱】
smartfire@smartfire.cn