From 1a67a3c148165128860cbb3eb4c0cef502fa3e08 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 2 May 2013 11:26:26 +0800 Subject: [PATCH] refine the notification --- AndroidManifest.xml | 99 +++++++++--------- pom.xml | 2 +- res/drawable-hdpi/ic_stat_large.png | Bin 0 -> 1587 bytes res/drawable-mdpi/ic_stat_large.png | Bin 0 -> 1040 bytes res/drawable-xhdpi/ic_stat_large.png | Bin 0 -> 2224 bytes res/values/strings.xml | 11 +- .../shadowsocks/ShadowsocksReceiver.java | 5 +- .../shadowsocks/ShadowsocksService.java | 50 ++++----- 8 files changed, 86 insertions(+), 81 deletions(-) create mode 100644 res/drawable-hdpi/ic_stat_large.png create mode 100644 res/drawable-mdpi/ic_stat_large.png create mode 100644 res/drawable-xhdpi/ic_stat_large.png 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 0000000000000000000000000000000000000000..e1985b132ea9ec65ca2a2ffc762370810fa44005 GIT binary patch literal 1587 zcmV-32F&@1P)p*fnB| zytSf!1mtE+1R;O^DY z(eYRr?2a;nR=E$UHNbKudOgHmEW_0n#2_Wkv(Qd-1jPPndt#7U6%upN`RK`zy0DCt z_gj9(Aa(*c&qIGh2SMzEwkHOuv5;7du8l5%)aV#eEj?q98Unxv(Jcd+*$}&`t%*Tu zCkWh!`m1~!mf@#uOAJyw22wjGNL<=u>Fg_ z_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wgDbkxnoHg>N_Rbu9($tfhu`L{b-)c0X# z>{1_2x)Q0IT{JNOx%^y)F2{yg`&n5$8UqX;9wrC(v|NgbRfU)vh8ssith%i%?Af=R zR3YXTpKRvjeobiwmQ{$ElugcxC6)Q-zy4t>N)$2P4a+CXD9fpLQ8x>damz|9vBpW) zcGJu`bJR-s4M^g002ovPDHLkV1g-K_CEjs literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_stat_large.png b/res/drawable-mdpi/ic_stat_large.png new file mode 100644 index 0000000000000000000000000000000000000000..17979ec30bc615359f5651b2f8487a05423ee690 GIT binary patch literal 1040 zcmV+r1n>KaP);KO_YY!S~(g;>lQwDH!MP4hK~PPj3PMa*1Y8Csh}mSDj0T$_#I!@eSuhmzL(ua^6NH#HkRJvU zz!}73hbxu1&k$moLw*3{IwEorbR=$qAWSBC8642gMWE2}z2`TH*spOB1YsJ9 zheNQ|Mu2}Q{TqP$C3X=zH`23?QkN zZ#e`bEn=oRb<@J|J)oUp`?Tixz%zuH?j*PZ`hfWm>@*YNPv`kGXzLNWoLGInh!#i? zWSz)%9;AYApf@CMT?YI^XqSR67S;vyS@$0LtK3iNTM%Te79A*Lm|_k{t>jbs%)muI5UjzHT`LU?n992Ak>+oVm9pw592|-qrwUL4pAlJ z=kdJ5BIpNwnZ#VPiM7rU$;J_U9JCJjDLxZF8nV0O&{ab(Wtv`M2L6(8dFu&su9qs( z&H=^zamWsmqdn~k(7}^qGh%eUg|#|@NYsl+?ZSxx#VC9gWNXwQkM^o_o*devv{h95 z5=4>&0xtj^nn6uR#bn4dOA@3j$08%iQ`#!xchM5p&Jal!60EJ?X1ep}K(*NoIU-=gr@^4g_g~d<2yHCzym7&Acy*D#$rd zUyx0gbknqwGpYSt6Kx8z0pNA zH8pj;ydB*HJsyJYUO|vy0CL*vtwDD{-$y$_&<`sJf&s{B$B%o_y$vC=AZJ1- zIaN8tAZJT}X()9zg#5$L9uTy+%@YJU8$iM>XrBlfFY@nh5cFr8CJ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5i|;?b5YxslDz#TwNC|S3US&hte)V&I&T#b ztc@V$8d>&8U1_J?d8nxVJe;ASjMpjgaf$s;f(=kw7R1MSyRMo*IkwORpz{*6Y9lPElUlBMh$GWPLDEQXNh~5&V98pmT zWi;(|wA5r$6hV6sp^`JD20kKiqX2iS%NT+NU}HOL*Bg5tKD@vEa`k0VN&>WoVbEc?hXzJosL;2RX<50Vz2vTk61kcWO?xjiD2@Z0!SZIFHaZ*LRhNfpM zPP5zu0YaC!mHFz%m`l7S<%$!0YyYSGr?RSg4^3AfzR!yw=rB5a5_S2~-byP@>ZBYE z9D-@3=BdK{_zJHYM=P;2=mRt^-lcThBEIIqEYnK^itmUlQw6q)gx- zN1M`T(Yc{RvuGkS69fod>V6&7t&X_p>%Nn-g2VTLA{W(#@SvgDk_giIm~M;NNY=I8 z$yvcckS<>>qy5iC0}l0<=MB;&Oj~(Fh4rB=0bD2=+1zOHk`KubqO3*1V5dD()TYf(lau!z&GX_Xjf^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() {