Android P 修改音量键控制与方向和UI一致

Android P 修改音量键控制与方向和UI一致,第1张

概述frameworks/base/services/core/java/com/android/server/media/MediaSessionService.java---a/mt8788/frameworks/base/services/core/java/com/android/server/media/MediaSessionService.java+++b/mt8788/frameworks/base/services/core/java/com/android/server/




frameworks/base/services/core/java/com/androID/server/media/MediaSessionService.java

--- a/mt8788/frameworks/base/services/core/java/com/androID/server/media/MediaSessionService.java+++ b/mt8788/frameworks/base/services/core/java/com/androID/server/media/MediaSessionService.java@@ -81,7 +81,7 @@ import androID.util.SparseArray; import androID.util.SparseIntArray; import androID.vIEw.KeyEvent; import androID.vIEw.VIEwConfiguration;-+import androID.vIEw.WindowManager; import com.androID.internal.os.BackgroundThread; import com.androID.internal.util.Dumputils; import com.androID.server.SystemService;@@ -1434,13 +1434,30 @@ public class MediaSessionService extends SystemService implements Monitor {             boolean down = keyEvent.getAction() == KeyEvent.ACTION_DOWN;             boolean up = keyEvent.getAction() == KeyEvent.ACTION_UP;             int direction = 0;+            int rotation = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultdisplay().getRotation();+            int device_ID = keyEvent.getdeviceid();+            Log.d("addlog", "====================rotation = "+ rotation);             boolean isMute = false;             switch (keyEvent.getKeyCode()) {                 case KeyEvent.KEYCODE_VolUME_UP:-                    direction = AudioManager.ADJUST_RAISE;+                    if(device_ID==1){+                        direction = (rotation == 0  || rotation == 1) ? AudioManager.ADJUST_LOWER : AudioManager.ADJUST_RAISE;+                    }else{+                        direction = AudioManager.ADJUST_RAISE;+                    }                     break;                 case KeyEvent.KEYCODE_VolUME_DOWN:-                    direction = AudioManager.ADJUST_LOWER;+                    if(device_ID==1){+                        direction = (rotation == 0  || rotation == 1) ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;+                    }else{+                        direction = AudioManager.ADJUST_LOWER;+                    }                     break;                 case KeyEvent.KEYCODE_VolUME_MUTE:                     isMute = true;

注:AndroID O还需修改如下文件:
frameworks/base/core/java/com/androID/internal/policy/PhoneWindow.java

--- a/mt8167/frameworks/base/core/java/com/androID/internal/policy/PhoneWindow.java+++ b/mt8167/frameworks/base/core/java/com/androID/internal/policy/PhoneWindow.java@@ -1866,6 +1866,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {         //Log.i(TAG, "Key down: repeat=" + event.getRepeatCount()         //        + " flags=0x" + Integer.toHexString(event.getFlags())); +        int rotation = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultdisplay().getRotation();+        int device_ID = event.getdeviceid();         switch (keyCode) {             case KeyEvent.KEYCODE_VolUME_UP:             case KeyEvent.KEYCODE_VolUME_DOWN:@@ -1876,10 +1881,22 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {                     int direction = 0;                     switch (keyCode) {                         case KeyEvent.KEYCODE_VolUME_UP:-                            direction = AudioManager.ADJUST_RAISE;+                            if(device_ID==1){+                                direction = (rotation == 2  || rotation == 1) ? AudioManager.ADJUST_LOWER : AudioManager.ADJUST_RAISE;+                            }else{+                                direction = AudioManager.ADJUST_RAISE;+                            }                             break;                         case KeyEvent.KEYCODE_VolUME_DOWN:-                            direction = AudioManager.ADJUST_LOWER;+                            if(device_ID==1){+                                direction = (rotation == 2  || rotation == 1) ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;+                            }else{+                                direction = AudioManager.ADJUST_LOWER;+                            }                             break;                         case KeyEvent.KEYCODE_VolUME_MUTE:                             direction = AudioManager.ADJUST_TOGGLE_MUTE;
总结

以上是内存溢出为你收集整理的Android P 修改音量控制与方向和UI一致全部内容,希望文章能够帮你解决Android P 修改音量键控制与方向和UI一致所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1112130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存