Skip to content

Commit 792fece

Browse files
authored
Duck.ai: Use a shortcut that is added from the widget picker (#6765)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211289267231652?focus=true ### Description Added the ability to create a Duck.ai shortcut on the home screen directly from the widget picker. This implementation includes a new transparent activity `DuckAiPinShortcutActivity` that handles shortcut creation requests and registers the shortcut with the system. ### Steps to test this PR _Duck.ai Shortcut Creation_ - [x] Install from this branch. - [x] Open the widget picker on your Android device (long tap on the app icon). - [x] Find and select the Duck.ai shortcut option. - [x] Verify the shortcut is created on your home screen with the Duck.ai icon. - [x] Tap the shortcut and confirm it opens directly to Duck.ai. ### UI changes Check screenshots attached on task URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211289267231652?focus=true
1 parent 4a20aae commit 792fece

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,19 @@
248248
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize"
249249
android:resizeableActivity="true" />
250250

251+
<activity
252+
android:name="com.duckduckgo.widget.DuckAiPinShortcutActivity"
253+
android:exported="true"
254+
android:launchMode="singleTask"
255+
android:icon="@drawable/duckai_64"
256+
android:label="@string/duckAiOnlyPinShortcutLabel"
257+
android:theme="@style/Theme.AppCompat.Transparent.NoActionBar">
258+
<intent-filter>
259+
<action android:name="android.intent.action.CREATE_SHORTCUT" />
260+
<category android:name="android.intent.category.DEFAULT" />
261+
</intent-filter>
262+
</activity>
263+
251264
<activity
252265
android:name="com.duckduckgo.app.dispatchers.IntentDispatcherActivity"
253266
android:theme="@style/Theme.AppCompat.Transparent.NoActionBar"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.duckduckgo.widget
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import androidx.appcompat.app.AppCompatActivity
7+
import androidx.core.content.pm.ShortcutInfoCompat
8+
import androidx.core.content.pm.ShortcutManagerCompat
9+
import androidx.core.graphics.drawable.IconCompat
10+
import com.duckduckgo.app.browser.BrowserActivity
11+
import com.duckduckgo.app.browser.R
12+
13+
/**
14+
* This activity is capable of handling requests to create a shortcut.
15+
* Exists purely to be able to add the Duck.ai shortcut on the home screen from the widget picker.
16+
*/
17+
class DuckAiPinShortcutActivity : AppCompatActivity() {
18+
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
22+
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
23+
val shortcutInfo = createShortcutInfo(this)
24+
ShortcutManagerCompat.reportShortcutUsed(this, SHORTCUT_ID)
25+
setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcutInfo))
26+
} else {
27+
setResult(RESULT_OK)
28+
}
29+
30+
finish()
31+
}
32+
33+
private fun createShortcutInfo(context: Context): ShortcutInfoCompat {
34+
val shortLabel = getString(R.string.duckAiOnlyPinShortcutLabel)
35+
36+
val shortcutIntent = BrowserActivity.intent(context, openDuckChat = true, duckChatSessionActive = true).apply {
37+
action = Intent.ACTION_VIEW
38+
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
39+
}
40+
41+
return ShortcutInfoCompat.Builder(context, SHORTCUT_ID)
42+
.setShortLabel(shortLabel)
43+
.setIcon(IconCompat.createWithResource(context, R.drawable.duckai_64))
44+
.setIntent(shortcutIntent)
45+
.build()
46+
}
47+
48+
companion object {
49+
private const val SHORTCUT_ID = "duck_ai_from_widget_picker"
50+
}
51+
}

app/src/main/res/values/donottranslate.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@
6868
<string name="searchOnlyWidgetDescription">Quickly launch a private search with DuckDuckGo.</string>
6969
<string name="searchAndFavoritesWidgetDescription">Search or visit your favorite sites privately with one tap. Voice Search and Duck.ai available if enabled.</string>
7070
<string name="searchWidgetDescription">Search privately with DuckDuckGo or ask Duck.ai. Voice Search and Duck.ai available if enabled.</string>
71+
<string name="duckAiOnlyPinShortcutLabel">Duck.ai</string>
7172
</resources>

0 commit comments

Comments
 (0)