summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java33
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");