diff options
author | Ashwin R C <ashwin2001achu@gmail.com> | 2020-05-27 10:26:16 +0000 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-05-06 01:18:25 +0800 |
commit | 1940e0fb878b7c65fd4674cfd09de80bb1a39e43 (patch) | |
tree | fcfb32a884c802e59fb390d8d4df18268dbfecb9 | |
parent | a34b6c8fc6061ea81de86097978ae9889a365b98 (diff) |
SystemUI: Adapt screenshot sound to ringer modes
Co-authored-by: althafvly <althafvly@gmail.com>
Change-Id: I381c351131241e45ddb6049706d6c302c2eee946
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index e4d5efbb97b5..17b00a9e3b5b 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -49,6 +49,7 @@ import android.graphics.Insets; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.display.DisplayManager; +import android.media.AudioManager; import android.media.MediaActionSound; import android.net.Uri; import android.os.Bundle; @@ -57,6 +58,8 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.provider.Settings; import android.util.DisplayMetrics; import android.util.Log; @@ -250,12 +253,14 @@ public class ScreenshotController { private final WindowManager mWindowManager; private final WindowManager.LayoutParams mWindowLayoutParams; private final AccessibilityManager mAccessibilityManager; + private final AudioManager mAudioManager; private final MediaActionSound mCameraSound; private final ScrollCaptureClient mScrollCaptureClient; private final PhoneWindow mWindow; private final DisplayManager mDisplayManager; private final ScrollCaptureController mScrollCaptureController; private final LongScreenshotData mLongScreenshotHolder; + private final Vibrator mVibrator; private final boolean mIsLowRamDevice; private ScreenshotView mScreenshotView; @@ -354,6 +359,10 @@ public class ScreenshotController { // Setup the Camera shutter sound mCameraSound = new MediaActionSound(); mCameraSound.load(MediaActionSound.SHUTTER_CLICK); + + // Grab system services needed for screenshot sound + mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); } void takeScreenshotFullscreen(ComponentName topComponent, Consumer<Uri> finisher, @@ -786,13 +795,30 @@ public class ScreenshotController { } } + private void playShutterSoundIf() { + switch (mAudioManager.getRingerMode()) { + case AudioManager.RINGER_MODE_SILENT: + // do nothing + break; + case AudioManager.RINGER_MODE_VIBRATE: + if (mVibrator != null && mVibrator.hasVibrator()) { + mVibrator.vibrate(VibrationEffect.createOneShot(50, + VibrationEffect.DEFAULT_AMPLITUDE)); + } + break; + case AudioManager.RINGER_MODE_NORMAL: + // Play the shutter sound to notify that we've taken a screenshot + mCameraSound.play(MediaActionSound.SHUTTER_CLICK); + break; + } + } + /** * Save the bitmap but don't show the normal screenshot UI.. just a toast (or notification on * failure). */ private void saveScreenshotAndToast(Consumer<Uri> finisher) { - // Play the shutter sound to notify that we've taken a screenshot - mCameraSound.play(MediaActionSound.SHUTTER_CLICK); + playShutterSoundIf(); saveScreenshotInWorkerThread( /* onComplete */ finisher, @@ -825,8 +851,7 @@ public class ScreenshotController { mScreenshotAnimation = mScreenshotView.createScreenshotDropInAnimation(screenRect, showFlash); - // Play the shutter sound to notify that we've taken a screenshot - mCameraSound.play(MediaActionSound.SHUTTER_CLICK); + playShutterSoundIf(); if (DEBUG_ANIM) { Log.d(TAG, "starting post-screenshot animation"); |