2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Extract duplicate code into method

This commit is contained in:
Nicolas Fella
2018-09-29 19:30:27 +02:00
parent 405792b707
commit 83432ed143

View File

@@ -183,15 +183,7 @@ public class TelephonyPlugin extends Plugin {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (isMuted) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_RING, false);
}
isMuted = false;
}
unmuteRinger();
np.set("event", "ringing");
device.sendPacket(np);
break;
@@ -214,15 +206,7 @@ public class TelephonyPlugin extends Plugin {
timer.schedule(new TimerTask() {
@Override
public void run() {
if (isMuted) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_RING, false);
}
isMuted = false;
}
unmuteRinger();
}
}, 500);
}
@@ -245,6 +229,18 @@ public class TelephonyPlugin extends Plugin {
lastState = state;
}
private void unmuteRinger() {
if (isMuted) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_RING, false);
}
isMuted = false;
}
}
private void muteRinger() {
if (!isMuted) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);