Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7e16c22 authored by Betty Chang's avatar Betty Chang Committed by Gerrit Code Review
Browse files

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

parents aef592eb ca475a5d
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -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));