Merge "[LE Audio] To add the vibrate when the scan is successful"

This commit is contained in:
Betty Chang
2023-01-13 10:34:12 +00:00
committed by Gerrit Code Review

View File

@@ -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));