From ca475a5d3772788aa7133cdd4cbed1a2f2bcf2ea Mon Sep 17 00:00:00 2001 From: changbetty Date: Thu, 12 Jan 2023 14:37:46 +0000 Subject: [PATCH] [LE Audio] To add the vibrate when the scan is successful Bug: 242023882 Test: manual test Change-Id: Iabff5fb81e307222fb33541e4bf0008830321d3e --- .../bluetooth/QrCodeScanModeFragment.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java b/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java index 0253aa6b748..767461bba7e 100644 --- a/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java +++ b/src/com/android/settings/bluetooth/QrCodeScanModeFragment.java @@ -26,6 +26,8 @@ import android.graphics.SurfaceTexture; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.util.Log; import android.util.Size; import android.view.LayoutInflater; @@ -45,6 +47,8 @@ import com.android.settingslib.bluetooth.BluetoothBroadcastUtils; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.qrcode.QrCamera; +import java.time.Duration; + public class QrCodeScanModeFragment extends InstrumentedFragment implements TextureView.SurfaceTextureListener, QrCamera.ScannerCallback { @@ -61,6 +65,8 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements private static final long SHOW_ERROR_MESSAGE_INTERVAL = 10000; private static final long SHOW_SUCCESS_SQUARE_INTERVAL = 1000; + private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3); + private boolean mIsGroupOp; private int mCornerRadius; private BluetoothDevice mSink; @@ -209,16 +215,39 @@ public class QrCodeScanModeFragment extends InstrumentedFragment implements break; case MESSAGE_SCAN_BROADCAST_SUCCESS: + /* TODO(b/265281156) : Move the logic to BluetoothFindBroadcastsFragment. + * We only pass the QR code string to the previous page. + */ mController.addSource(mSink, mBroadcastMetadata, mIsGroupOp); - updateSummary(); - mSummary.sendAccessibilityEvent( - AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); + notifyUserForQrCodeRecognition(); break; default: } } }; + private void notifyUserForQrCodeRecognition() { + if (mCamera != null) { + mCamera.stop(); + } + + mErrorMessage.setVisibility(View.INVISIBLE); + + triggerVibrationForQrCodeRecognition(getContext()); + + getActivity().finish(); + } + + private static void triggerVibrationForQrCodeRecognition(Context context) { + Vibrator vibrator = context.getSystemService(Vibrator.class); + if (vibrator == null) { + return; + } + vibrator.vibrate(VibrationEffect.createOneShot( + VIBRATE_DURATION_QR_CODE_RECOGNITION.toMillis(), + VibrationEffect.DEFAULT_AMPLITUDE)); + } + private void showErrorMessage(@StringRes int messageResId) { final Message message = mHandler.obtainMessage(MESSAGE_SHOW_ERROR_MESSAGE, getString(messageResId));