|
(为了高效,请按如下格式提问)
硬件主板型号:tinker board 2s
固件名称/系统版本:Android 10
自编的或固件下载地址:自编
Log日志: (可以导出,用TXT附件上传)
问题描述及复现步骤:
添加按钮到相关文件
我添加的按钮是“volume_add2”
- <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
- /** Key code constant: Volume Up key.
- * Adjusts the speaker volume up. */
- public static final int KEYCODE_VOLUME_UP = 24;
- /** Key code constant: Volume Down key.
- * Adjusts the speaker volume down. */
- public static final int KEYCODE_VOLUME_DOWN = 25;
复制代码 在frameworks/base/packages/SystemUI/res/layout/文件下添加volume_add2的xml
- <?xml version="1.0" encoding="utf-8"?>
- <com.android.systemui.statusbar.policy.KeyButtonView
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:systemui="http://schemas.android.com/apk/res-auto"
- android:id="@+id/volume_add2"
- android:layout_width="@dimen/navigation_key_width"
- android:layout_height="match_parent"
- android:layout_weight="0"
- systemui:keyCode="24"//这里就是对应按钮的KEYCODE_VOLUME_UP 表示音量+
- android:scaleType="center"
- android:contentDescription="@string/accessibility_home"
- android:paddingStart="@dimen/navigation_key_padding"
- android:paddingEnd="@dimen/navigation_key_padding
复制代码 音量加按键图像文件路径:
frameworks/base/packages/SystemUI/res/drawable/文件夹下添加
ic_sysbar_volume_add2_button.xml
- <vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?attr/singleToneColor"
- 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"/>
- </vector>
复制代码 最后在NavigationBarFragment.java添加新的按钮属性 ,路径是frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/
- 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
- index 2daf26a3fc..adeb277ffc 100644
- --- 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
- @@ -700,6 +700,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
- }
-
- ButtonDispatcher volumeAddButton=mNavigationBarView.getVolumeAddButton();
- + ButtonDispatcher volumeAdd2Button=mNavigationBarView.getVolumeAdd2Button();
- ButtonDispatcher volumeSubButton=mNavigationBarView.getVolumeSubButton();
- boolean isShowVolumeButton="true".equals(SystemProperties.get("ro.rk.systembar.voiceicon","true"));
- if(isShowVolumeButton){
- 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
- old mode 100644
- new mode 100755
- index 31813bd005..458bd1fd83
- --- 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
- @@ -65,6 +65,7 @@ public class NavigationBarInflaterView extends FrameLayout
- public static final String IME_SWITCHER = "ime_switcher";
- public static final String SCREENSHOT = "screenshot";
- public static final String VOLUME_ADD = "volume_add";
- + public static final String VOLUME_ADD2 = "volume_add2";
- public static final String VOLUME_SUB = "volume_sub";
-
- public static final String GRAVITY_SEPARATOR = ";";
- @@ -414,7 +415,9 @@ public class NavigationBarInflaterView extends FrameLayout
- v = inflater.inflate(R.layout.screenshot, parent, false);
- } else if (VOLUME_ADD.equals(button)) {
- v = inflater.inflate(R.layout.volume_add, parent, false);
- - } else if (VOLUME_SUB.equals(button)) {
- + } else if (VOLUME_ADD2.equals(button)) {
- + v = inflater.inflate(R.layout.volume_add2, parent, false);
- + } else if (VOLUME_SUB.equals(button)) {
- v = inflater.inflate(R.layout.volume_sub, parent, false);
- } else if (button.startsWith(KEY)) {
- String uri = extractImage(button);
- 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
- index 421a58fa74..5c3b078b9c 100644
- --- 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
- @@ -117,6 +117,7 @@ public class NavigationBarView extends FrameLayout implements
- private KeyButtonDrawable mRecentIcon;
- private KeyButtonDrawable mDockedIcon;
- private KeyButtonDrawable mVolumeAddIcon;
- + private KeyButtonDrawable mVolumeAdd2Icon;
- private KeyButtonDrawable mVolumeSubIcon;
- private KeyButtonDrawable mScreenshotIcon;
-
- @@ -315,6 +316,7 @@ public class NavigationBarView extends FrameLayout implements
- mButtonDispatchers.put(R.id.accessibility_button, accessibilityButton);
- mButtonDispatchers.put(R.id.rotate_suggestion, rotateSuggestionButton);
- mButtonDispatchers.put(R.id.menu_container, mContextualButtonGroup);
- + mButtonDispatchers.put(R.id.volume_add2, new ButtonDispatcher(R.id.volume_add2));
- mButtonDispatchers.put(R.id.screenshot, new ButtonDispatcher(R.id.screenshot));
- mButtonDispatchers.put(R.id.volume_add, new ButtonDispatcher(R.id.volume_add));
- mButtonDispatchers.put(R.id.volume_sub, new ButtonDispatcher(R.id.volume_sub));
- @@ -442,6 +444,10 @@ public class NavigationBarView extends FrameLayout implements
- return mButtonDispatchers.get(R.id.volume_add);
- }
-
- + public ButtonDispatcher getVolumeAdd2Button() {
- + return mButtonDispatchers.get(R.id.volume_add2);
- + }
- +
- public ButtonDispatcher getVolumeSubButton() {
- return mButtonDispatchers.get(R.id.volume_sub);
- }
- @@ -492,6 +498,7 @@ public class NavigationBarView extends FrameLayout implements
- }
-
- mVolumeAddIcon = getDrawable(R.drawable.ic_sysbar_volume_add_button);
- + mVolumeAdd2Icon = getDrawable(R.drawable.ic_sysbar_volume_add2_button);
- mVolumeSubIcon = getDrawable(R.drawable.ic_sysbar_volume_sub_button);
- mScreenshotIcon = getDrawable(R.drawable.ic_sysbar_capture_button);
- }
- @@ -636,6 +643,7 @@ public class NavigationBarView extends FrameLayout implements
- getHomeButton().setImageDrawable(homeIcon);
- getBackButton().setImageDrawable(backIcon);
- getVolumeAddButton().setImageDrawable(mVolumeAddIcon);
- + getVolumeAdd2Button().setImageDrawable(mVolumeAdd2Icon);
- getVolumeSubButton().setImageDrawable(mVolumeSubIcon);
- getScreenshotButton().setImageDrawable(mScreenshotIcon);
复制代码
|
|