]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Use modern shortcuts on Android 8+
authorTobias Brunner <tobias@strongswan.org>
Tue, 19 Jun 2018 10:32:55 +0000 (12:32 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:37 +0000 (11:31 +0200)
src/frontends/android/app/src/main/AndroidManifest.xml
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileSelectActivity.java
src/frontends/android/app/src/main/res/mipmap-anydpi-v26/ic_shortcut.xml [new file with mode: 0644]
src/frontends/android/app/src/main/res/mipmap-anydpi/ic_shortcut.xml [new file with mode: 0644]
src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_bg.png [new file with mode: 0644]
src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_fg.png [new file with mode: 0644]

index ab3725b56e09fa0d9d312dd4b99107af2b73f1b6..2a75d05abab7bed36800d6dbf533f008b96cedf1 100644 (file)
@@ -80,7 +80,8 @@
         </activity>
         <activity
             android:name=".ui.VpnProfileSelectActivity"
-            android:label="@string/strongswan_shortcut" >
+            android:label="@string/strongswan_shortcut"
+            android:icon="@mipmap/ic_shortcut" >
             <intent-filter>
                 <action android:name="android.intent.action.CREATE_SHORTCUT" />
                 <category android:name="android.intent.category.DEFAULT" />
index 27cecc7e99ba230572343877e1c752af539d1aa6..fe3d01322a661b622e429b655e6a48c2cae51808 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2018 Tobias Brunner
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -17,6 +17,9 @@ package org.strongswan.android.ui;
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.support.v4.content.pm.ShortcutInfoCompat;
+import android.support.v4.content.pm.ShortcutManagerCompat;
+import android.support.v4.graphics.drawable.IconCompat;
 import android.support.v7.app.AppCompatActivity;
 
 import org.strongswan.android.R;
@@ -42,11 +45,11 @@ public class VpnProfileSelectActivity extends AppCompatActivity implements OnVpn
                Intent shortcut = new Intent(VpnProfileControlActivity.START_PROFILE);
                shortcut.putExtra(VpnProfileControlActivity.EXTRA_VPN_PROFILE_ID, profile.getUUID().toString());
 
-               Intent intent = new Intent();
-               intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
-               intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profile.getName());
-               intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
-               setResult(RESULT_OK, intent);
+               ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(this, profile.getUUID().toString());
+               builder.setIntent(shortcut);
+               builder.setShortLabel(profile.getName());
+               builder.setIcon(IconCompat.createWithResource(this, R.mipmap.ic_shortcut));
+               setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, builder.build()));
                finish();
        }
 }
diff --git a/src/frontends/android/app/src/main/res/mipmap-anydpi-v26/ic_shortcut.xml b/src/frontends/android/app/src/main/res/mipmap-anydpi-v26/ic_shortcut.xml
new file mode 100644 (file)
index 0000000..6aea2ff
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2018 Tobias Brunner
+    HSR Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+    <background android:drawable="@mipmap/ic_shortcut_bg" />
+    <foreground android:drawable="@mipmap/ic_shortcut_fg" />
+</adaptive-icon>
diff --git a/src/frontends/android/app/src/main/res/mipmap-anydpi/ic_shortcut.xml b/src/frontends/android/app/src/main/res/mipmap-anydpi/ic_shortcut.xml
new file mode 100644 (file)
index 0000000..653d080
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2018 Tobias Brunner
+    HSR Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+    android:drawable="@drawable/ic_launcher" />
\ No newline at end of file
diff --git a/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_bg.png b/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_bg.png
new file mode 100644 (file)
index 0000000..7653225
Binary files /dev/null and b/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_bg.png differ
diff --git a/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_fg.png b/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_fg.png
new file mode 100644 (file)
index 0000000..6e62e6d
Binary files /dev/null and b/src/frontends/android/app/src/main/res/mipmap-xxxhdpi-v26/ic_shortcut_fg.png differ