Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #12565 Implement the common part of search widget in Android Comp…
Browse files Browse the repository at this point in the history
…onents
  • Loading branch information
iorgamgabriel committed Aug 8, 2022
2 parents 9d815ff + 8c3aab7 commit 1c3714e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.toBitmap
import mozilla.components.feature.search.R
import mozilla.components.feature.search.widget.VoiceSearchActivity.Companion.SPEECH_PROCESSING
import mozilla.components.feature.search.widget.BaseVoiceSearchActivity.Companion.SPEECH_PROCESSING
import mozilla.components.support.utils.PendingIntentUtils

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class AppSearchWidgetProvider : AppWidgetProvider() {
/**
* Activity that extends VoiceSearchActivity
*/
abstract fun voiceSearchActivity(): VoiceSearchActivity
abstract fun voiceSearchActivity(): BaseVoiceSearchActivity

/**
* Config that sets the icons and the strings for search widget
Expand Down Expand Up @@ -239,18 +239,17 @@ abstract class AppSearchWidgetProvider : AppWidgetProvider() {
/**
* It updates AppSearchWidgetProvider size and microphone icon visibility
*/
fun updateAllWidgets(context: Context, widgetClassNameApp: AppSearchWidgetProvider) {
fun updateAllWidgets(context: Context, clazz: Class<out AppSearchWidgetProvider>) {
val widgetManager = AppWidgetManager.getInstance(context)
val widgetIds = widgetManager.getAppWidgetIds(
ComponentName(
context,
widgetClassNameApp::class.java
clazz
)
)

if (widgetIds.isNotEmpty()) {
context.sendBroadcast(
Intent(context, widgetClassNameApp::class.java).apply {
Intent(context, clazz).apply {
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.util.Locale
/**
* Launches voice recognition then uses it to start a new web search.
*/
abstract class VoiceSearchActivity : AppCompatActivity() {
abstract class BaseVoiceSearchActivity : AppCompatActivity() {

/**
* Holds the intent that initially started this activity
Expand Down Expand Up @@ -125,7 +125,7 @@ abstract class VoiceSearchActivity : AppCompatActivity() {
const val PREVIOUS_INTENT = "org.mozilla.components.previous_intent"

/**
* In [VoiceSearchActivity] activity, used to store if the speech processing should start.
* In [BaseVoiceSearchActivity] activity, used to store if the speech processing should start.
*/
const val SPEECH_PROCESSING = "speech_processing"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package mozilla.components.feature.search.widget

import java.util.Locale

class VoiceSearchActivityExtendedForTests : VoiceSearchActivity() {
class VoiceSearchActivityExtendedForTests : BaseVoiceSearchActivity() {

override fun getCurrentLocale(): Locale {
return Locale.getDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import android.os.Bundle
import android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH
import android.speech.RecognizerIntent.EXTRA_RESULTS
import androidx.activity.result.ActivityResult
import mozilla.components.feature.search.widget.VoiceSearchActivity.Companion.PREVIOUS_INTENT
import mozilla.components.feature.search.widget.VoiceSearchActivity.Companion.SPEECH_PROCESSING
import mozilla.components.feature.search.widget.BaseVoiceSearchActivity.Companion.PREVIOUS_INTENT
import mozilla.components.feature.search.widget.BaseVoiceSearchActivity.Companion.SPEECH_PROCESSING
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand Down

0 comments on commit 1c3714e

Please sign in to comment.