This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
43 changed files
with
595 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
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,29 @@ | ||
<?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/. --> | ||
|
||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<shortcut | ||
android:shortcutId="open_new_tab" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_static_shortcut_tab" | ||
android:shortcutShortLabel="@string/home_screen_shortcut_open_new_tab" | ||
android:shortcutLongLabel="@string/home_screen_shortcut_open_new_tab"> | ||
<intent | ||
android:action="org.mozilla.fenix.OPEN_TAB" | ||
android:targetPackage="org.mozilla.fenix.debug" | ||
android:targetClass="org.mozilla.fenix.IntentReceiverActivity" /> | ||
</shortcut> | ||
<shortcut | ||
android:shortcutId="open_new_private_tab" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_static_shortcut_private_tab" | ||
android:shortcutShortLabel="@string/home_screen_shortcut_open_new_private_tab" | ||
android:shortcutLongLabel="@string/home_screen_shortcut_open_new_private_tab"> | ||
<intent | ||
android:action="org.mozilla.fenix.OPEN_PRIVATE_TAB" | ||
android:targetPackage="org.mozilla.fenix.debug" | ||
android:targetClass="org.mozilla.fenix.IntentReceiverActivity" /> | ||
</shortcut> | ||
</shortcuts> |
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.
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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/org/mozilla/fenix/components/PrivateShortcutCreateManager.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,49 @@ | ||
/* 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.components | ||
|
||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.content.pm.ShortcutInfoCompat | ||
import androidx.core.content.pm.ShortcutManagerCompat | ||
import androidx.core.graphics.drawable.IconCompat | ||
import org.mozilla.fenix.HomeActivity | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor | ||
import java.util.UUID | ||
|
||
/** | ||
* Handles the creation of pinned shortcuts. | ||
*/ | ||
object PrivateShortcutCreateManager { | ||
|
||
fun createPrivateShortcut(context: Context) { | ||
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) return | ||
|
||
val icon = IconCompat.createWithResource(context, R.mipmap.ic_launcher_private_round) | ||
val shortcut = ShortcutInfoCompat.Builder(context, UUID.randomUUID().toString()) | ||
.setShortLabel(context.getString(R.string.app_name_private)) | ||
.setLongLabel(context.getString(R.string.app_name_private)) | ||
.setIcon(icon) | ||
.setIntent(Intent(context, HomeActivity::class.java).apply { | ||
action = Intent.ACTION_VIEW | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
putExtra(HomeActivity.PRIVATE_BROWSING_MODE, true) | ||
putExtra( | ||
HomeActivity.OPEN_TO_SEARCH, | ||
StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT | ||
) | ||
}) | ||
.build() | ||
val homeScreenIntent = Intent(Intent.ACTION_MAIN) | ||
.addCategory(Intent.CATEGORY_HOME) | ||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
val intentSender = PendingIntent | ||
.getActivity(context, 0, homeScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT) | ||
.intentSender | ||
ShortcutManagerCompat.requestPinShortcut(context, shortcut, intentSender) | ||
} | ||
} |
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.