[fenix] For https://github.com/mozilla-mobile/fenix/issues/24461 - Increase touch target for scan, search engine & voice search button

pull/600/head
jknair 3 years ago committed by mergify[bot]
parent a316b42f44
commit abb02bd596

@ -66,10 +66,12 @@ import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.databinding.FragmentSearchDialogBinding
import org.mozilla.fenix.databinding.SearchSuggestionsHintBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.search.awesomebar.AwesomeBarView
import org.mozilla.fenix.search.awesomebar.toSearchProviderState
import org.mozilla.fenix.search.toolbar.IncreasedTapAreaActionDecorator
import org.mozilla.fenix.search.toolbar.ToolbarView
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.widget.VoiceSearchActivity
@ -252,6 +254,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
else -> {}
}
binding.searchEnginesShortcutButton.increaseTapArea(TAP_INCREASE_DPS)
binding.searchEnginesShortcutButton.setOnClickListener {
interactor.onSearchShortcutsButtonClicked()
}
@ -263,6 +266,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
)
binding.qrScanButton.visibility = if (context?.hasCamera() == true) View.VISIBLE else View.GONE
binding.qrScanButton.increaseTapArea(TAP_INCREASE_DPS)
binding.qrScanButton.setOnClickListener {
if (!requireContext().hasCamera()) { return@setOnClickListener }
@ -636,14 +640,16 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
requireContext().settings().shouldShowVoiceSearch
if (isVisible) {
toolbarView.view.addEditActionEnd(
BrowserToolbar.Button(
AppCompatResources.getDrawable(requireContext(), R.drawable.ic_microphone)!!,
requireContext().getString(R.string.voice_search_content_description),
visible = { true },
listener = ::launchVoiceSearch
)
val voiceSearchAction = BrowserToolbar.Button(
AppCompatResources.getDrawable(requireContext(), R.drawable.ic_microphone)!!,
requireContext().getString(R.string.voice_search_content_description),
visible = { true },
listener = ::launchVoiceSearch
)
toolbarView.view.run {
addEditActionEnd(IncreasedTapAreaActionDecorator(voiceSearchAction))
invalidateActions()
}
voiceSearchButtonAlreadyAdded = true
}
}
@ -719,6 +725,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
}
companion object {
private const val TAP_INCREASE_DPS = 8
private const val QR_FRAGMENT_TAG = "MOZAC_QR_FRAGMENT"
private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1
}

@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.search.toolbar
import android.view.View
import androidx.annotation.VisibleForTesting
import mozilla.components.concept.toolbar.Toolbar
import org.mozilla.fenix.ext.increaseTapArea
/**
* A Decorator that accepts a [Toolbar.Action] and increases its tap area.
*/
class IncreasedTapAreaActionDecorator(
private val action: Toolbar.Action
) : Toolbar.Action by action {
override fun bind(view: View) {
action.bind(view)
view.increaseTapArea(TAP_INCREASE_DPS)
}
companion object {
@VisibleForTesting
const val TAP_INCREASE_DPS = 8
}
}

@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.search.toolbar
import android.view.View
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import io.mockk.justRun
import io.mockk.mockkStatic
import io.mockk.verify
import mozilla.components.concept.toolbar.Toolbar
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.ext.increaseTapArea
class IncreasedTapAreaActionDecoratorTest {
@MockK lateinit var action: Toolbar.Action
@MockK lateinit var view: View
private lateinit var increasedTapAreaActionDecorator: IncreasedTapAreaActionDecorator
@Before
fun setUp() {
MockKAnnotations.init(this)
increasedTapAreaActionDecorator = IncreasedTapAreaActionDecorator(action)
justRun { action.bind(view) }
mockkStatic(View::increaseTapArea)
justRun { view.increaseTapArea(IncreasedTapAreaActionDecorator.TAP_INCREASE_DPS) }
}
@Test
fun `increased tap area of view on bind`() {
increasedTapAreaActionDecorator.bind(view)
verify { view.increaseTapArea(IncreasedTapAreaActionDecorator.TAP_INCREASE_DPS) }
}
@Test
fun `should invoke provided action bind`() {
increasedTapAreaActionDecorator.bind(view)
verify { action.bind(view) }
}
}
Loading…
Cancel
Save