欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android7.1 源码修改之Settings音量调节界面增加通话音量调节

程序员文章站 2022-06-16 16:58:47
前言今天客户提了个需求,因为我们的设备在正常情况下无法调节通话音量,只有在打电话过程中,按物理音量加减键才能出现调节通话音量seekBar,很不方便,于是乎需求就来了。需要优化两个地方1、在正常情况下,按物理音量加减键都显示 通话音量调节seekBar,可方便快速调节通话音量2、在Settings中提示音界面点击设置进入,增加通话音量调节seekBar......

前言

    今天产品要求在Settings中添加调节电话音量的功能,因为我们的设备在正常情况下无法调节通话音量,只有在打电话过程中,按物理音量加减键才能出现调节通话音量seekBar,很不方便,于是乎需求就来了。需要优化一个地方。

     1、在Settings中提示音界面点击设置进入,增加通话音量调节seekBar

实现

     1.修改内容

      

zhoujy@TP:~/data/android/sc826_cn_01_00/msm_8953_git$ git status
On branch sc826_cn_01_00
Your branch is up-to-date with 'origin/sc826_cn_01_00'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   frameworks/base/media/java/android/media/AudioSystem.java
        modified:   packages/apps/Settings/res/values-zh-rCN/strings.xml
        modified:   packages/apps/Settings/res/values-zh-rHK/strings.xml
        modified:   packages/apps/Settings/res/values-zh-rTW/strings.xml
        modified:   packages/apps/Settings/res/values/colors.xml
        modified:   packages/apps/Settings/res/values/strings.xml
        modified:   packages/apps/Settings/res/xml/sound_settings.xml
        modified:   packages/apps/Settings/src/com/android/settings/notification/SoundSettings.java
        modified:   packages/apps/Settings/src/com/android/settings/notification/VolumeSeekBarPreference.java

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        packages/apps/Settings/res/drawable/ic_volume_voice.xml

no changes added to commit (use "git add" and/or "git commit -a")

  2.具体实现

zhoujy@TP:~/data/android/sc826_cn_01_00/msm_8953_git$ git diff ./
diff --git a/frameworks/base/media/java/android/media/AudioSystem.java b/frameworks/base/media/java/android/media/AudioSystem.java
index a930b80..0ee9968 100644
--- a/frameworks/base/media/java/android/media/AudioSystem.java
+++ b/frameworks/base/media/java/android/media/AudioSystem.java
@@ -769,7 +769,7 @@ public class AudioSystem
     }
 
     public static int[] DEFAULT_STREAM_VOLUME = new int[] {
-        4,  // STREAM_VOICE_CALL
+        2,  // STREAM_VOICE_CALL
         4,  // STREAM_SYSTEM
         3,  // STREAM_RING
         5, // STREAM_MUSIC
diff --git a/packages/apps/Settings/res/values-zh-rCN/strings.xml b/packages/apps/Settings/res/values-zh-rCN/strings.xml
index 0c13213..d8f309e 100755
--- a/packages/apps/Settings/res/values-zh-rCN/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rCN/strings.xml
@@ -2628,6 +2628,7 @@
     <string name="media_volume_option_title" msgid="2811531786073003825">"媒体音量"</string>
     <string name="alarm_volume_option_title" msgid="8219324421222242421">"闹钟音量"</string>
     <string name="ring_volume_option_title" msgid="6767101703671248309">"铃声音量"</string>
+    <string name="call_volume_option_title" msgid="6767101703671248329">"电话音量"</string>
     <string name="notification_volume_option_title" msgid="6064656124416882130">"通知音量"</string>
     <string name="ringtone_title" msgid="5379026328015343686">"手机铃声"</string>
     <string name="notification_ringtone_title" msgid="3361201340352664272">"默认通知铃声"</string>
diff --git a/packages/apps/Settings/res/values-zh-rHK/strings.xml b/packages/apps/Settings/res/values-zh-rHK/strings.xml
index 599439f..a4f0069 100644
--- a/packages/apps/Settings/res/values-zh-rHK/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rHK/strings.xml
@@ -2587,6 +2587,7 @@
     <string name="alarm_volume_option_title" msgid="8219324421222242421">"鬧鐘音量"</string>
     <string name="ring_volume_option_title" msgid="6767101703671248309">"鈴聲音量"</string>
     <string name="notification_volume_option_title" msgid="6064656124416882130">"通知音量"</string>
+    <string name="call_volume_option_title" msgid="6767101703671248329">"電話音量"</string>
     <string name="ringtone_title" msgid="5379026328015343686">"電話鈴聲"</string>
     <string name="notification_ringtone_title" msgid="3361201340352664272">"預設通知鈴聲"</string>
     <string name="alarm_ringtone_title" msgid="2015124067611102995">"預設鬧鐘鈴聲"</string>
diff --git a/packages/apps/Settings/res/values-zh-rTW/strings.xml b/packages/apps/Settings/res/values-zh-rTW/strings.xml
index 27fc292..d79680f 100644
--- a/packages/apps/Settings/res/values-zh-rTW/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rTW/strings.xml
@@ -2588,6 +2588,7 @@
     <string name="alarm_volume_option_title" msgid="8219324421222242421">"鬧鐘音量"</string>
     <string name="ring_volume_option_title" msgid="6767101703671248309">"鈴聲音量"</string>
     <string name="notification_volume_option_title" msgid="6064656124416882130">"通知音量"</string>
+    <string name="call_volume_option_title" msgid="6767101703671248329">"電話音量"</string>
     <string name="ringtone_title" msgid="5379026328015343686">"電話鈴聲"</string>
     <string name="notification_ringtone_title" msgid="3361201340352664272">"預設通知鈴聲"</string>
     <string name="alarm_ringtone_title" msgid="2015124067611102995">"預設鬧鐘鈴聲"</string>
diff --git a/packages/apps/Settings/res/values/colors.xml b/packages/apps/Settings/res/values/colors.xml
index c02ac78..fb42e59 100644
--- a/packages/apps/Settings/res/values/colors.xml
+++ b/packages/apps/Settings/res/values/colors.xml
@@ -130,5 +130,5 @@
 
     <!-- Gestures settings -->
     <color name="gestures_setting_background_color">#f5f5f5</color>
-
+    <color name="volume_icon_color">#808080</color>
 </resources>
diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
index 26824a0..252c474 100755
--- a/packages/apps/Settings/res/values/strings.xml
+++ b/packages/apps/Settings/res/values/strings.xml
@@ -6097,6 +6097,7 @@
 
     <!-- Sound: Title for the option managing ring volume. [CHAR LIMIT=30] -->
     <string name="ring_volume_option_title">Ring volume</string>
+    <string name="call_volume_option_title">Call volume</string>
 
     <!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
     <string name="notification_volume_option_title">Notification volume</string>
diff --git a/packages/apps/Settings/res/xml/sound_settings.xml b/packages/apps/Settings/res/xml/sound_settings.xml
index 6ef7a54..c35131a 100644
--- a/packages/apps/Settings/res/xml/sound_settings.xml
+++ b/packages/apps/Settings/res/xml/sound_settings.xml
@@ -37,7 +37,11 @@
                 android:key="ring_volume"
                 android:icon="@*android:drawable/ic_audio_ring_notif"
                 android:title="@string/ring_volume_option_title" />
-
+        <!-- Call volume -->
+       <com.android.settings.notification.VolumeSeekBarPreference
+               android:key="call_volume"
+               android:icon="@drawable/ic_volume_voice"
+               android:title="@string/call_volume_option_title" />   
         <!-- Notification volume -->
         <com.android.settings.notification.VolumeSeekBarPreference
                 android:key="notification_volume"
diff --git a/packages/apps/Settings/src/com/android/settings/notification/SoundSettings.java b/packages/apps/Settings/src/com/android/settings/notification/SoundSettings.java
index 87edd6e..13a8212 100644
--- a/packages/apps/Settings/src/com/android/settings/notification/SoundSettings.java
+++ b/packages/apps/Settings/src/com/android/settings/notification/SoundSettings.java
@@ -76,6 +76,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
     private static final String KEY_MEDIA_VOLUME = "media_volume";
     private static final String KEY_ALARM_VOLUME = "alarm_volume";
     private static final String KEY_RING_VOLUME = "ring_volume";
+    private static final String KEY_CALL_VOLUME = "call_volume";
     private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
     private static final String KEY_PHONE_RINGTONE = "ringtone";
     private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
@@ -146,6 +147,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
                 com.android.internal.R.drawable.ic_audio_media_mute);
         initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM,
                 com.android.internal.R.drawable.ic_audio_alarm_mute);
+       initVolumePreference(KEY_CALL_VOLUME, AudioManager.STREAM_VOICE_CALL,R.drawable.ic_volume_voice);
         if (mVoiceCapable) {
             mRingOrNotificationPreference =
                     initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING,
diff --git a/packages/apps/Settings/src/com/android/settings/notification/VolumeSeekBarPreference.java b/packages/apps/Settings/src/com/android/settings/notification/VolumeSeekBarPreference.java
index 7b02cae..b5443bc 100644
--- a/packages/apps/Settings/src/com/android/settings/notification/VolumeSeekBarPreference.java
+++ b/packages/apps/Settings/src/com/android/settings/notification/VolumeSeekBarPreference.java
@@ -94,7 +94,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
     @Override
     public void onBindViewHolder(PreferenceViewHolder view) {
         super.onBindViewHolder(view);
-        if (mStream == 0) {
+        if (mStream < 0) {
             Log.w(TAG, "No stream found, not binding volumizer");
             return;
         }

3.图标

Settings/res/drawable/ic_volume_voice.xml

<!--
     Copyright (C) 2015 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24.0dp"
    android:viewportHeight="48.0"
    android:viewportWidth="48.0"
    android:width="24.0dp" >

    <path
        android:fillColor="@color/volume_icon_color"
        android:pathData="M13.25,21.59c2.88,5.66 7.51,10.29 13.18,13.17l4.4,-4.41c0.55,-0.55 1.34,-0.71 2.03,-0.49C35.1,30.6 37.51,31.0 40.0,31.0c1.11,0.0 2.0,0.89 2.0,2.0l0.0,7.0c0.0,1.11 -0.89,2.0 -2.0,2.0C21.22,42.0 6.0,26.78 6.0,8.0
c0.0,-1.1 0.9,-2.0 2.0,-2.0l7.0,0.0c1.11,0.0 2.0,0.89 2.0,2.0 0.0,2.4 0.4,4.9 1.14,7.1 0.2,0.6 0.06,1.48 -0.49,2.03l-4.4,4.42z" />

</vector>

参考

https://www.cnblogs.com/cczheng-666/p/10757358.html

 

  

 

本文地址:https://blog.csdn.net/zjy764219923/article/details/109627101