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

Android P 修改音量键控制与方向和UI一致
Android P 修改音量键控制与方向和UI一致
Android P 修改音量键控制与方向和UI一致Android P 修改音量键控制与方向和UI一致
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;

上一篇:AS3 TransitionManager 自带特效类


下一篇:交替方向乘子法(Alternating Direction Method of Multipliers)