From 7a847cdf413ddbb0fe1cab5d4099e352727fb723 Mon Sep 17 00:00:00 2001 From: RAJESH KUMAR ARUMUGAM Date: Sat, 9 Nov 2019 03:07:36 +0530 Subject: [PATCH] [fenix] Added Vibration Effect On Scanning QR Code (https://github.com/mozilla-mobile/fenix/pull/6129) * Added Vibration Effect On Scanning QR Code Added Vibration Feature for the new feature Request Vibrate phone upon successful pairing https://github.com/mozilla-mobile/fenix/issues/2928 * Added Vibration Effect On Scanning QR Code Added Vibration Feature for the new feature Request Vibrate phone upon successful pairing https://github.com/mozilla-mobile/fenix/issues/2928 * Update PairFragment.kt Removed unwanted blank lines * Update PairFragment.kt Removed the Casting with !! --- app/src/main/AndroidManifest.xml | 1 + .../mozilla/fenix/settings/PairFragment.kt | 29 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 773599dd97..f6c2325e30 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + diff --git a/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt index 5ff6f3655c..665a86aaa5 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt @@ -4,9 +4,13 @@ package org.mozilla.fenix.settings +import android.os.Build import android.os.Bundle +import android.os.VibrationEffect +import android.os.Vibrator import android.view.View import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.getSystemService import androidx.core.text.HtmlCompat import androidx.fragment.app.Fragment import androidx.navigation.fragment.NavHostFragment.findNavController @@ -25,8 +29,10 @@ class PairFragment : Fragment(R.layout.fragment_pair), BackHandler { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - pairInstructions.text = HtmlCompat.fromHtml(getString(R.string.pair_instructions), - HtmlCompat.FROM_HTML_MODE_LEGACY) + pairInstructions.text = HtmlCompat.fromHtml( + getString(R.string.pair_instructions), + HtmlCompat.FROM_HTML_MODE_LEGACY + ) qrFeature.set( QrFeature( @@ -40,8 +46,22 @@ class PairFragment : Fragment(R.layout.fragment_pair), BackHandler { requireContext(), pairingUrl ) - findNavController(this@PairFragment) - .popBackStack(R.id.turnOnSyncFragment, false) + val vibrator = requireContext().getSystemService()!! + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + vibrator.vibrate( + VibrationEffect.createOneShot( + VIBRATE_LENGTH, + VibrationEffect.DEFAULT_AMPLITUDE + ) + ) + } else { + @Suppress("Deprecation") + vibrator.vibrate(VIBRATE_LENGTH) + } + findNavController(this@PairFragment).popBackStack( + R.id.turnOnSyncFragment, + false + ) }), owner = this, view = view @@ -66,6 +86,7 @@ class PairFragment : Fragment(R.layout.fragment_pair), BackHandler { companion object { private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1 + private const val VIBRATE_LENGTH = 200L } override fun onRequestPermissionsResult(