Przeglądaj źródła

volume,vibrate

losion.liu@sikey.com.cn 1 rok temu
rodzic
commit
21c5488e55

+ 30 - 3
app/src/main/java/com/xplora/xpsettings/Data/DataManager.java

@@ -163,9 +163,9 @@ public class DataManager extends Application {
     }
 
     public static void setRingerMode(int value) {
-//        public static final int RINGER_MODE_SILENT = 0;
-//        public static final int RINGER_MODE_VIBRATE = 1;
-//        public static final int RINGER_MODE_NORMAL = 2;
+//        public static final int RINGER_MODE_SILENT = 0; //无声音、强制不振动
+//        public static final int RINGER_MODE_VIBRATE = 1; //无声音、强制振动
+//        public static final int RINGER_MODE_NORMAL = 2; //有声音、振动可以独立开关
         if (Macros.DEBUG) {
             mRingerMode = value;
         } else {
@@ -208,6 +208,16 @@ public class DataManager extends Application {
         } else {
             AudioManager audioManager = (AudioManager) sContext.getSystemService(Context.AUDIO_SERVICE);
             audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, value, AudioManager.FLAG_PLAY_SOUND);
+
+            if (value <= 0) {
+                if (getIsVibrate() == 1) {
+                    setRingerMode(1);
+                } else {
+                    setRingerMode(0);
+                }
+            } else {
+                setRingerMode(2);
+            }
         }
     }
 
@@ -276,6 +286,23 @@ public class DataManager extends Application {
 
     public static void setIsVibrate(int mIsVibrate) {
         Settings.System.putInt(sContext.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, mIsVibrate);
+
+        Map volume = getSystemVolume();
+        int cur =  (int) volume.get("cur");
+        if (mIsVibrate == 1) {
+            if ( cur <= 0) {
+                //无声音、强制振动
+                setRingerMode(1);
+            } else {
+                setRingerMode(2);
+            }
+        } else {
+            if ( cur <= 0) {
+                setRingerMode(0);
+            } else {
+                setRingerMode(2);
+            }
+        }
     }
 
     @RequiresApi(api = Build.VERSION_CODES.P)