Skip to content

Commit 24463ec

Browse files
committed
SystemUI: Screenshots: Refactor shutter sound logic
* Commit 2f09bac introduced some duplicated code * Move it to an own method to reduce the footprint in the AOSP code parts and to reduce duplication Change-Id: I57eaaee4db401d16cc6ef65c68604cdb4053ca01
1 parent e281e53 commit 24463ec

1 file changed

Lines changed: 20 additions & 30 deletions

File tree

packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -755,21 +755,7 @@ private void saveScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect scre
755755
private void saveScreenshotAndToast(Consumer<Uri> finisher) {
756756
// Play the shutter sound to notify that we've taken a screenshot
757757
mScreenshotHandler.post(() -> {
758-
switch (mAudioManager.getRingerMode()) {
759-
case AudioManager.RINGER_MODE_SILENT:
760-
// do nothing
761-
break;
762-
case AudioManager.RINGER_MODE_VIBRATE:
763-
if (mVibrator != null && mVibrator.hasVibrator()) {
764-
mVibrator.vibrate(VibrationEffect.createOneShot(50,
765-
VibrationEffect.DEFAULT_AMPLITUDE));
766-
}
767-
break;
768-
case AudioManager.RINGER_MODE_NORMAL:
769-
// Play the shutter sound to notify that we've taken a screenshot
770-
mCameraSound.play(MediaActionSound.SHUTTER_CLICK);
771-
break;
772-
}
758+
playShutterSound();
773759
});
774760

775761
saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() {
@@ -824,21 +810,7 @@ void onActionsReady(SavedImageData imageData) {
824810
}
825811
});
826812

827-
switch (mAudioManager.getRingerMode()) {
828-
case AudioManager.RINGER_MODE_SILENT:
829-
// do nothing
830-
break;
831-
case AudioManager.RINGER_MODE_VIBRATE:
832-
if (mVibrator != null && mVibrator.hasVibrator()) {
833-
mVibrator.vibrate(VibrationEffect.createOneShot(50,
834-
VibrationEffect.DEFAULT_AMPLITUDE));
835-
}
836-
break;
837-
case AudioManager.RINGER_MODE_NORMAL:
838-
// Play the shutter sound to notify that we've taken a screenshot
839-
mCameraSound.play(MediaActionSound.SHUTTER_CLICK);
840-
break;
841-
}
813+
playShutterSound();
842814

843815
mScreenshotPreview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
844816
mScreenshotPreview.buildLayer();
@@ -1281,4 +1253,22 @@ private Drawable createScreenDrawable(Bitmap bitmap, Insets insets) {
12811253
return insetDrawable;
12821254
}
12831255
}
1256+
1257+
private void playShutterSound() {
1258+
switch (mAudioManager.getRingerMode()) {
1259+
case AudioManager.RINGER_MODE_SILENT:
1260+
// do nothing
1261+
break;
1262+
case AudioManager.RINGER_MODE_VIBRATE:
1263+
if (mVibrator != null && mVibrator.hasVibrator()) {
1264+
mVibrator.vibrate(VibrationEffect.createOneShot(50,
1265+
VibrationEffect.DEFAULT_AMPLITUDE));
1266+
}
1267+
break;
1268+
case AudioManager.RINGER_MODE_NORMAL:
1269+
// Play the shutter sound to notify that we've taken a screenshot
1270+
mCameraSound.play(MediaActionSound.SHUTTER_CLICK);
1271+
break;
1272+
}
1273+
}
12841274
}

0 commit comments

Comments
 (0)