mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 23:55:08 +00:00
Extract duplicate code into method
This commit is contained in:
@@ -183,15 +183,7 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case TelephonyManager.CALL_STATE_RINGING:
|
case TelephonyManager.CALL_STATE_RINGING:
|
||||||
if (isMuted) {
|
unmuteRinger();
|
||||||
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;
|
|
||||||
}
|
|
||||||
np.set("event", "ringing");
|
np.set("event", "ringing");
|
||||||
device.sendPacket(np);
|
device.sendPacket(np);
|
||||||
break;
|
break;
|
||||||
@@ -214,15 +206,7 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isMuted) {
|
unmuteRinger();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@@ -245,6 +229,18 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
lastState = state;
|
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() {
|
private void muteRinger() {
|
||||||
if (!isMuted) {
|
if (!isMuted) {
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
Reference in New Issue
Block a user