diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 041b3f39..4ad427d5 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,60 +1,61 @@ + package="com.github.shadowsocks" + android:installLocation="auto" + android:versionCode="21" + android:versionName="1.3.9"> - - - - - + + + + + - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - + - - - - - - + + + + + + + - + diff --git a/pom.xml b/pom.xml index faeb4ee7..e8c05414 100755 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ com.google.android support-v4 - r7 + r12 crouton diff --git a/res/drawable-hdpi/ic_stat_large.png b/res/drawable-hdpi/ic_stat_large.png new file mode 100644 index 00000000..e1985b13 Binary files /dev/null and b/res/drawable-hdpi/ic_stat_large.png differ diff --git a/res/drawable-mdpi/ic_stat_large.png b/res/drawable-mdpi/ic_stat_large.png new file mode 100644 index 00000000..17979ec3 Binary files /dev/null and b/res/drawable-mdpi/ic_stat_large.png differ diff --git a/res/drawable-xhdpi/ic_stat_large.png b/res/drawable-xhdpi/ic_stat_large.png new file mode 100644 index 00000000..3a8afa26 Binary files /dev/null and b/res/drawable-xhdpi/ic_stat_large.png differ diff --git a/res/values/strings.xml b/res/values/strings.xml index cc7ca5fc..cbe836e8 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -50,12 +50,13 @@ Start Shadowsocks at the startup - Shadowsocks started - Running in the background - Shadowsocks failed to start - Shadowsocks stopped - Shadowsocks stopped + Shadowsocks started. + Running in the background. + Shadowsocks failed to start. + Shadowsocks stopped. + Shadowsocks stopped. Please check your network status and try again. + Stop the service OK diff --git a/src/com/github/shadowsocks/ShadowsocksReceiver.java b/src/com/github/shadowsocks/ShadowsocksReceiver.java index 393dfbec..5b7a7db6 100644 --- a/src/com/github/shadowsocks/ShadowsocksReceiver.java +++ b/src/com/github/shadowsocks/ShadowsocksReceiver.java @@ -47,6 +47,8 @@ import android.preference.PreferenceManager; public class ShadowsocksReceiver extends BroadcastReceiver { + public static final String CLOSE_ACTION = "com.github.shadowsocks.ACTION_SHUTDOWN"; + private static final String TAG = "Shadowsocks"; @Override @@ -54,7 +56,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver { if (intent != null) { final String action = intent.getAction(); - if (action.equals(Intent.ACTION_SHUTDOWN)) { + if (action.equals(Intent.ACTION_SHUTDOWN) + || action.equals(CLOSE_ACTION)) { context.stopService(new Intent(context, ShadowsocksService.class)); return; } diff --git a/src/com/github/shadowsocks/ShadowsocksService.java b/src/com/github/shadowsocks/ShadowsocksService.java index 1b964147..50d9675d 100755 --- a/src/com/github/shadowsocks/ShadowsocksService.java +++ b/src/com/github/shadowsocks/ShadowsocksService.java @@ -48,11 +48,14 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.PowerManager; import android.preference.PreferenceManager; +import android.support.v4.app.NotificationCompat; import android.util.Log; import com.google.analytics.tracking.android.EasyTracker; import java.io.BufferedReader; @@ -153,9 +156,7 @@ public class ShadowsocksService extends Service { super.handleMessage(msg); } }; - private Notification notification; private NotificationManager notificationManager; - private PendingIntent pendIntent; private PowerManager.WakeLock mWakeLock; private String appHost; private int remotePort; @@ -403,22 +404,29 @@ public class ShadowsocksService extends Service { } private void notifyAlert(String title, String info) { - notification.icon = R.drawable.ic_stat_shadowsocks; - notification.tickerText = title; - notification.flags = Notification.FLAG_ONGOING_EVENT; - initSoundVibrateLights(notification); - // notification.defaults = Notification.DEFAULT_SOUND; - notification.setLatestEventInfo(this, getString(R.string.app_name), info, pendIntent); - startForegroundCompat(1, notification); - } - private void notifyAlert(String title, String info, int flags) { - notification.icon = R.drawable.ic_stat_shadowsocks; - notification.tickerText = title; - notification.flags = flags; - initSoundVibrateLights(notification); - notification.setLatestEventInfo(this, getString(R.string.app_name), info, pendIntent); - notificationManager.notify(0, notification); + // ContentIntent + Intent openIntent = new Intent(this, Shadowsocks.class); + openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openIntent, 0); + + // ActionIntent + Intent closeIntent = new Intent(ShadowsocksReceiver.CLOSE_ACTION); + PendingIntent actionIntent = PendingIntent.getBroadcast(this, 0, closeIntent, 0); + + //large icon for notification,normally use App icon + final Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_large); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + builder.setSmallIcon(R.drawable.ic_stat_shadowsocks) + .setWhen(0) + .setTicker(title) + .setContentTitle(getString(R.string.app_name)) + .setContentText(info) + .setContentIntent(contentIntent) + .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.stop), actionIntent); + + startForegroundCompat(1, builder.build()); } @Override @@ -435,11 +443,6 @@ public class ShadowsocksService extends Service { settings = PreferenceManager.getDefaultSharedPreferences(this); notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); - Intent intent = new Intent(this, Shadowsocks.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendIntent = PendingIntent.getActivity(this, 0, intent, 0); - notification = new Notification(); - try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); @@ -464,9 +467,6 @@ public class ShadowsocksService extends Service { stopForegroundCompat(1); - notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped), - Notification.FLAG_AUTO_CANCEL); - new Thread() { @Override public void run() {