Commit 179e5456 authored by Mygod's avatar Mygod

Refine shortcuts on Android 7.1

parent 30700fac
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#f5f5f5"
android:pathData="M24,24m-22,0a22,22 0,1 1,44 0a22,22 0,1 1,-44 0Z" />
<path
android:fillColor="#546e7a"
android:pathData="M24,21.8 C25.7673,21.8,27.2,23.2327,27.2,25 C27.2,26.7673,25.7673,28.2,24,28.2
C22.2327,28.2,20.8,26.7673,20.8,25 C20.8,23.2327,22.2327,21.8,24,21.8 Z" />
<path
android:fillColor="#546e7a"
android:pathData="M21,15 L19.17,17 L16,17 A2,2,0,0,0,14,19 L14,31 A2,2,0,0,0,16,33 L32,33
A2,2,0,0,0,34,31 L34,19 A2,2,0,0,0,32,17 L28.83,17 L27,15 Z M24,30
A5,5,0,1,1,29,25 A5,5,0,0,1,24,30 Z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#f5f5f5"
android:pathData="M24,24m-22,0a22,22 0,1 1,44 0a22,22 0,1 1,-44 0Z" />
<path
android:fillColor="#546e7a"
android:pathData="M34,14.72 L30.52,30.04 L22.72,27.53 L29.61,19.31 L20.43,27.04 L14,24.62
L34,14.72 Z" />
<path
android:fillColor="#546e7a"
android:pathData="M22.89,29.1 L25.38,29.9 L22.9,33.28 L22.89,29.1 Z" />
</vector>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut android:shortcutId="toggle" <shortcut android:shortcutId="toggle"
android:enabled="true" android:icon="@drawable/ic_qu_shadowsocks_launcher"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/quick_toggle" android:shortcutShortLabel="@string/quick_toggle"
android:shortcutLongLabel="@string/quick_toggle"> android:shortcutLongLabel="@string/quick_toggle">
<intent android:action="android.intent.action.MAIN" <intent android:action="android.intent.action.MAIN"
...@@ -10,12 +9,19 @@ ...@@ -10,12 +9,19 @@
android:targetClass="com.github.shadowsocks.QuickToggleShortcut" /> android:targetClass="com.github.shadowsocks.QuickToggleShortcut" />
</shortcut> </shortcut>
<shortcut android:shortcutId="switch" <shortcut android:shortcutId="switch"
android:enabled="true" android:icon="@drawable/ic_qu_shadowsocks_launcher"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/quick_switch" android:shortcutShortLabel="@string/quick_switch"
android:shortcutLongLabel="@string/quick_switch"> android:shortcutLongLabel="@string/quick_switch">
<intent android:action="android.intent.action.MAIN" <intent android:action="android.intent.action.MAIN"
android:targetPackage="com.github.shadowsocks" android:targetPackage="com.github.shadowsocks"
android:targetClass="com.github.shadowsocks.ShadowsocksQuickSwitchActivity" /> android:targetClass="com.github.shadowsocks.ShadowsocksQuickSwitchActivity" />
</shortcut> </shortcut>
<shortcut android:shortcutId="scan"
android:icon="@drawable/ic_qu_camera_launcher"
android:shortcutShortLabel="@string/add_profile_methods_scan_qr_code"
android:shortcutLongLabel="@string/add_profile_methods_scan_qr_code">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.github.shadowsocks"
android:targetClass="com.github.shadowsocks.ScannerActivity" />
</shortcut>
</shortcuts> </shortcuts>
...@@ -2,7 +2,8 @@ package com.github.shadowsocks ...@@ -2,7 +2,8 @@ package com.github.shadowsocks
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.content.pm.ShortcutManager
import android.os.{Build, Bundle}
import com.github.shadowsocks.utils.{State, Utils} import com.github.shadowsocks.utils.{State, Utils}
/** /**
...@@ -19,7 +20,9 @@ class QuickToggleShortcut extends Activity with ServiceBoundContext { ...@@ -19,7 +20,9 @@ class QuickToggleShortcut extends Activity with ServiceBoundContext {
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher))) Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)))
finish() finish()
case _ => attachService() case _ =>
attachService()
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("toggle")
} }
} }
......
...@@ -2,8 +2,8 @@ package com.github.shadowsocks ...@@ -2,8 +2,8 @@ package com.github.shadowsocks
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.{PackageManager, ShortcutManager}
import android.os.Bundle import android.os.{Build, Bundle}
import android.support.v4.app.ActivityCompat import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
...@@ -42,6 +42,7 @@ class ScannerActivity extends AppCompatActivity with ZXingScannerView.ResultHand ...@@ -42,6 +42,7 @@ class ScannerActivity extends AppCompatActivity with ZXingScannerView.ResultHand
scannerView = new ZXingScannerView(this) scannerView = new ZXingScannerView(this)
val contentFrame = findViewById(R.id.content_frame).asInstanceOf[ViewGroup] val contentFrame = findViewById(R.id.content_frame).asInstanceOf[ViewGroup]
contentFrame.addView(scannerView) contentFrame.addView(scannerView)
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("scan")
} }
override def onResume() { override def onResume() {
...@@ -66,7 +67,7 @@ class ScannerActivity extends AppCompatActivity with ZXingScannerView.ResultHand ...@@ -66,7 +67,7 @@ class ScannerActivity extends AppCompatActivity with ZXingScannerView.ResultHand
val intent = new Intent() val intent = new Intent()
intent.putExtra("uri", rawResult.getText) intent.putExtra("uri", rawResult.getText)
setResult(Activity.RESULT_OK, intent) setResult(Activity.RESULT_OK, intent)
finish() navigateUpTo(getParentActivityIntent)
} }
def setupToolbar() { def setupToolbar() {
......
package com.github.shadowsocks package com.github.shadowsocks
import android.content.pm.ShortcutManager
import android.content.res.Resources import android.content.res.Resources
import android.os.{Build, Bundle} import android.os.{Build, Bundle}
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
...@@ -70,5 +71,6 @@ class ShadowsocksQuickSwitchActivity extends AppCompatActivity { ...@@ -70,5 +71,6 @@ class ShadowsocksQuickSwitchActivity extends AppCompatActivity {
if (app.profileId >= 0) lm.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst { if (app.profileId >= 0) lm.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst {
case (profile, i) if profile.id == app.profileId => i case (profile, i) if profile.id == app.profileId => i
}.getOrElse(0)) }.getOrElse(0))
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("switch")
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment