forked from mozilla-mobile/focus-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#7249 Create a search widget
- Loading branch information
1 parent
63c3791
commit ee40969
Showing
14 changed files
with
342 additions
and
12 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/focus-android/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/7474 | ||
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/focus-android/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/7474 | ||
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/focus-android/issues/ | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/7474 | ||
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
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 | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
/* 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.putExtra(SPEECH_PROCESSING, 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
Oops, something went wrong.