forked from WireGuard/wireguard-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.
Merge pull request #1 from gergely-sallai/dynamic-shortcuts
Dynamic shortcuts
- Loading branch information
Showing
18 changed files
with
293 additions
and
6 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
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
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
55 changes: 55 additions & 0 deletions
55
ui/src/main/java/com/wireguard/android/model/ShortcutManager.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,55 @@ | ||
/* | ||
* Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.wireguard.android.model | ||
|
||
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 com.wireguard.android.BuildConfig | ||
import com.wireguard.android.R | ||
import com.wireguard.android.activity.TunnelToggleActivity | ||
|
||
class ShortcutManager(private val context: Context) { | ||
|
||
private fun upIdFor(name: String): String = "$name-UP" | ||
private fun downIdFor(name: String): String = "$name-DOWN" | ||
|
||
private fun createShortcutIntent(action: String, tunnelName: String): Intent = | ||
Intent(context, TunnelToggleActivity::class.java).apply { | ||
setPackage(BuildConfig.APPLICATION_ID) | ||
setAction(action) | ||
putExtra("tunnel", tunnelName) | ||
} | ||
|
||
fun addShortcuts(name: String) { | ||
val upIntent = createShortcutIntent("com.wireguard.android.action.SET_TUNNEL_UP", name) | ||
val shortcutUp = ShortcutInfoCompat.Builder(context, upIdFor(name)) | ||
.setShortLabel(context.getString(R.string.shortcut_label_short_up, name)) | ||
.setLongLabel(context.getString(R.string.shortcut_label_long_up, name)) | ||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_baseline_arrow_circle_up_24)) | ||
.setIntent(upIntent) | ||
.build() | ||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcutUp) | ||
|
||
val downIntent = createShortcutIntent("com.wireguard.android.action.SET_TUNNEL_DOWN", name) | ||
val shortcutDown = ShortcutInfoCompat.Builder(context, downIdFor(name)) | ||
.setShortLabel(context.getString(R.string.shortcut_label_short_down, name)) | ||
.setLongLabel(context.getString(R.string.shortcut_label_long_down, name)) | ||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_baseline_arrow_circle_down_24)) | ||
.setIntent(downIntent) | ||
.build() | ||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcutDown) | ||
} | ||
|
||
fun removeShortcuts(name: String) { | ||
ShortcutManagerCompat.removeDynamicShortcuts(context, listOf(upIdFor(name), downIdFor(name))) | ||
} | ||
|
||
fun hasShortcut(name: String) = | ||
ShortcutManagerCompat.getDynamicShortcuts(context).any { it.id.startsWith(name) } | ||
} |
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,22 @@ | ||
<!-- | ||
~ Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<animated-vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:drawable="@drawable/ic_baseline_star"> | ||
|
||
<target android:name="star"> | ||
<aapt:attr name="android:animation"> | ||
<objectAnimator | ||
android:propertyName="pathData" | ||
android:duration="300" | ||
android:valueFrom="@string/vdpath_star_full" | ||
android:valueTo="@string/vdpath_star_border" | ||
android:valueType="pathType" | ||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"/> | ||
</aapt:attr> | ||
</target> | ||
</animated-vector> |
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,22 @@ | ||
<!-- | ||
~ Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<animated-vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:drawable="@drawable/ic_baseline_star_border"> | ||
|
||
<target android:name="star"> | ||
<aapt:attr name="android:animation"> | ||
<objectAnimator | ||
android:propertyName="pathData" | ||
android:duration="300" | ||
android:valueFrom="@string/vdpath_star_border" | ||
android:valueTo="@string/vdpath_star_full" | ||
android:valueType="pathType" | ||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"/> | ||
</aapt:attr> | ||
</target> | ||
</animated-vector> |
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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:id="@+id/star_full" | ||
android:drawable="@drawable/ic_baseline_star" | ||
android:state_checked="true"/> | ||
<item | ||
android:id="@+id/star_border" | ||
android:drawable="@drawable/ic_baseline_star_border" | ||
android:state_checked="false"/> | ||
|
||
<transition | ||
android:drawable="@drawable/avd_star_to_full" | ||
android:fromId="@id/star_border" | ||
android:toId="@id/star_full"/> | ||
|
||
<transition | ||
android:drawable="@drawable/avd_star_to_border" | ||
android:fromId="@id/star_full" | ||
android:toId="@id/star_border"/> | ||
|
||
</animated-selector> |
5 changes: 5 additions & 0 deletions
5
ui/src/main/res/drawable/ic_baseline_arrow_circle_down_24.xml
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,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M12,4c4.41,0 8,3.59 8,8s-3.59,8 -8,8s-8,-3.59 -8,-8S7.59,4 12,4M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10c5.52,0 10,-4.48 10,-10C22,6.48 17.52,2 12,2L12,2zM13,12l0,-4h-2l0,4H8l4,4l4,-4H13z"/> | ||
</vector> |
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,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20M12,22c5.52,0 10,-4.48 10,-10c0,-5.52 -4.48,-10 -10,-10C6.48,2 2,6.48 2,12C2,17.52 6.48,22 12,22L12,22zM11,12l0,4h2l0,-4h3l-4,-4l-4,4H11z"/> | ||
</vector> |
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,17 @@ | ||
<!-- | ||
~ Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" > | ||
<path | ||
android:name="star" | ||
android:fillColor="@android:color/white" | ||
android:pathData="@string/vdpath_star_full"/> | ||
</vector> |
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,16 @@ | ||
<!-- | ||
~ Copyright © 2017-2022 WireGuard LLC. All Rights Reserved. | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:tint="#000000" > | ||
<path | ||
android:name="star" | ||
android:fillColor="@android:color/white" | ||
android:pathData="@string/vdpath_star_border"/> | ||
</vector> |
Oops, something went wrong.