This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f46d092
commit 429d294
Showing
13 changed files
with
293 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1900,3 +1900,57 @@ metrics: | |
metadata: | ||
tags: | ||
- Performance | ||
search_widget_installed: | ||
type: boolean | ||
lifetime: application | ||
description: | | ||
Whether or not the search widget is installed | ||
send_in_pings: | ||
- metrics | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/fenix/pull/ | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: 119 | ||
metadata: | ||
tags: | ||
- Search | ||
|
||
search_widget: | ||
new_tab_button: | ||
type: event | ||
description: | | ||
A user pressed anywhere from the Focus logo until the start of the | ||
microphone icon, opening a new tab search screen. | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/fenix/pull/ | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: 119 | ||
metadata: | ||
tags: | ||
- Search | ||
voice_button: | ||
type: event | ||
description: | | ||
A user pressed the microphone icon, opening a new voice search screen. | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/fenix/pull/ | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: 119 | ||
metadata: | ||
tags: | ||
- Search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/org/mozilla/focus/searchwidget/SearchWidgetProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* 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.focus.searchwidget | ||
|
||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.annotation.VisibleForTesting | ||
import mozilla.components.feature.search.widget.AppSearchWidgetProvider | ||
import mozilla.components.feature.search.widget.BaseVoiceSearchActivity | ||
import mozilla.components.feature.search.widget.SearchWidgetConfig | ||
import mozilla.components.support.utils.PendingIntentUtils | ||
import org.mozilla.focus.R | ||
import org.mozilla.focus.activity.IntentReceiverActivity | ||
import org.mozilla.focus.ext.components | ||
|
||
class SearchWidgetProvider : AppSearchWidgetProvider() { | ||
|
||
override fun onEnabled(context: Context) { | ||
context.components.settings.addSearchWidgetInstalled(1) | ||
} | ||
|
||
override fun onDeleted(context: Context, appWidgetIds: IntArray) { | ||
context.components.settings.addSearchWidgetInstalled(-appWidgetIds.size) | ||
} | ||
|
||
override val config: SearchWidgetConfig = | ||
SearchWidgetConfig( | ||
searchWidgetIconResource = R.drawable.ic_splash_screen, | ||
searchWidgetMicrophoneResource = R.drawable.mozac_ic_microphone, | ||
appName = R.string.app_name | ||
) | ||
|
||
override fun createTextSearchIntent(context: Context): PendingIntent { | ||
val textSearchIntent = Intent(context, IntentReceiverActivity::class.java) | ||
.apply { | ||
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
this.putExtra(IntentReceiverActivity.SEARCH_WIDGET, true) | ||
} | ||
return PendingIntent.getActivity( | ||
context, | ||
REQUEST_CODE_NEW_TAB, | ||
textSearchIntent, | ||
PendingIntentUtils.defaultFlags or | ||
PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
} | ||
|
||
override fun shouldShowVoiceSearch(context: Context): Boolean { | ||
return true | ||
} | ||
|
||
override fun voiceSearchActivity(): Class<out BaseVoiceSearchActivity> { | ||
return VoiceSearchActivity::class.java | ||
} | ||
|
||
companion object { | ||
@VisibleForTesting | ||
const val REQUEST_CODE_NEW_TAB = 0 | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/mozilla/focus/searchwidget/VoiceSearchActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* 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.focus.searchwidget | ||
|
||
import android.content.Intent | ||
import mozilla.components.feature.search.widget.BaseVoiceSearchActivity | ||
import mozilla.components.support.locale.LocaleManager | ||
import mozilla.components.support.locale.LocaleManager.getCurrentLocale | ||
import mozilla.telemetry.glean.private.NoExtras | ||
import org.mozilla.focus.GleanMetrics.SearchWidget | ||
import org.mozilla.focus.activity.IntentReceiverActivity | ||
import java.util.Locale | ||
|
||
class VoiceSearchActivity : BaseVoiceSearchActivity() { | ||
|
||
override fun getCurrentLocale(): Locale { | ||
return getCurrentLocale(this) | ||
?: LocaleManager.getSystemDefault() | ||
} | ||
|
||
override fun onSpeechRecognitionEnded(spokenText: String) { | ||
val intent = Intent(this, IntentReceiverActivity::class.java) | ||
intent.action = Intent.ACTION_SEND | ||
intent.putExtra(SPEECH_PROCESSING, spokenText) | ||
intent.putExtra(Intent.EXTRA_TEXT, spokenText) | ||
startActivity(intent) | ||
} | ||
|
||
override fun onSpeechRecognitionStarted() { | ||
SearchWidget.voiceButton.record(NoExtras()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- 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/. --> | ||
|
||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:minWidth="320dp" | ||
android:minHeight="40dp" | ||
android:resizeMode="horizontal" | ||
android:minResizeWidth="30dp" | ||
android:previewImage="@drawable/focus_search_widget" | ||
android:updatePeriodMillis="3600000" | ||
android:initialLayout="@layout/mozac_search_widget_large" | ||
android:widgetCategory="home_screen"> | ||
</appwidget-provider> |
70 changes: 70 additions & 0 deletions
70
app/src/test/java/org/mozilla/focus/searchwidget/SearchWidgetProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* 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.focus.searchwidget | ||
|
||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import mozilla.components.support.test.robolectric.testContext | ||
import mozilla.components.support.utils.PendingIntentUtils | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.spy | ||
import org.mozilla.focus.activity.IntentReceiverActivity | ||
import org.mozilla.focus.ext.components | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class SearchWidgetProviderTest { | ||
|
||
private lateinit var searchWidgetProvider: SearchWidgetProvider | ||
|
||
@Before | ||
fun setup() { | ||
searchWidgetProvider = spy(SearchWidgetProvider()) | ||
} | ||
|
||
@Test | ||
fun `GIVEN search widget provider WHEN onEnabled is called THEN searchWidgetInstalled from Settings should return true`() { | ||
searchWidgetProvider.onEnabled(testContext) | ||
|
||
assertEquals(testContext.components.settings.searchWidgetInstalled, true) | ||
} | ||
|
||
@Test | ||
fun `GIVEN search widget provider WHEN onDeleted is called THEN searchWidgetInstalled from Settings should return false`() { | ||
searchWidgetProvider.onDeleted(testContext, intArrayOf(1)) | ||
|
||
assertEquals(testContext.components.settings.searchWidgetInstalled, false) | ||
} | ||
|
||
@Test | ||
fun `GIVEN search widget provider WHEN createTextSearchIntent is called THEN an PendingIntent should be return`() { | ||
val textSearchIntent = Intent(testContext, IntentReceiverActivity::class.java) | ||
.apply { | ||
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
this.putExtra(IntentReceiverActivity.SEARCH_WIDGET, true) | ||
} | ||
val dummyPendingIntent = PendingIntent.getActivity( | ||
testContext, | ||
SearchWidgetProvider.REQUEST_CODE_NEW_TAB, | ||
textSearchIntent, | ||
PendingIntentUtils.defaultFlags or | ||
PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
|
||
assertEquals(searchWidgetProvider.createTextSearchIntent(testContext), dummyPendingIntent) | ||
} | ||
|
||
@Test | ||
fun `GIVEN search widget provider WHEN shouldShowVoiceSearch is called THEN true should be return`() { | ||
assertEquals(searchWidgetProvider.shouldShowVoiceSearch(testContext), true) | ||
} | ||
|
||
@Test | ||
fun `GIVEN search widget provider WHEN voiceSearchActivity is called THEN VoiceSearchActivity should be return`() { | ||
assertEquals(searchWidgetProvider.voiceSearchActivity(), VoiceSearchActivity::class.java) | ||
} | ||
} |