热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

frameworksbaseservicescorejavacomandroidservermediaMediaSessionService.java---amt8788frame



在这里插入图片描述

在这里插入图片描述

在这里插入图片描述在这里插入图片描述

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;


推荐阅读
author-avatar
王婷山东理工_441_796
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有