Commit 1a67a3c1 authored by Max Lv's avatar Max Lv

refine the notification

parent 721e31d8
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks" package="com.github.shadowsocks"
android:installLocation="auto" android:installLocation="auto"
android:versionCode="21" android:versionCode="21"
android:versionName="1.3.9"> android:versionName="1.3.9">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-feature <uses-feature
android:name="android.hardware.touchscreen" android:name="android.hardware.touchscreen"
android:required="false"/> android:required="false"/>
<uses-sdk <uses-sdk
android:minSdkVersion="9" android:minSdkVersion="9"
android:targetSdkVersion="16"/> android:targetSdkVersion="16"/>
<application <application
android:name=".ShadowsocksApplication" android:name=".ShadowsocksApplication"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name"> android:label="@string/app_name">
<activity <activity
android:name=".Shadowsocks" android:name=".Shadowsocks"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Theme.GAEProxy" android:theme="@style/Theme.GAEProxy"
android:launchMode="singleTask"> android:launchMode="singleTask">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".AppManager" android:name=".AppManager"
android:theme="@style/Theme.GAEProxy" android:theme="@style/Theme.GAEProxy"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="com.github.shadowsocks.AppManager" /> <action android:name="com.github.shadowsocks.AppManager"/>
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</activity> </activity>
<service <service
android:name=".ShadowsocksService" android:name=".ShadowsocksService"
android:enabled="true"/> android:enabled="true"/>
<receiver android:name=".ShadowsocksReceiver"> <receiver android:name=".ShadowsocksReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN"/> <action android:name="android.intent.action.ACTION_SHUTDOWN"/>
</intent-filter> <action android:name="com.github.shadowsocks.ACTION_SHUTDOWN"/>
</receiver> </intent-filter>
</receiver>
</application>
</application>
</manifest> </manifest>
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>com.google.android</groupId> <groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId> <artifactId>support-v4</artifactId>
<version>r7</version> <version>r12</version>
</dependency> </dependency>
<dependency> <dependency>
<artifactId>crouton</artifactId> <artifactId>crouton</artifactId>
......
...@@ -50,12 +50,13 @@ ...@@ -50,12 +50,13 @@
<string name="auto_connect_summary">Start Shadowsocks at the startup</string> <string name="auto_connect_summary">Start Shadowsocks at the startup</string>
<!-- notification category --> <!-- notification category -->
<string name="forward_success">Shadowsocks started</string> <string name="forward_success">Shadowsocks started.</string>
<string name="service_running">Running in the background</string> <string name="service_running">Running in the background.</string>
<string name="forward_fail">Shadowsocks failed to start</string> <string name="forward_fail">Shadowsocks failed to start.</string>
<string name="service_stopped">Shadowsocks stopped</string> <string name="service_stopped">Shadowsocks stopped.</string>
<string name="forward_stop">Shadowsocks stopped</string> <string name="forward_stop">Shadowsocks stopped.</string>
<string name="service_failed">Please check your network status and try again.</string> <string name="service_failed">Please check your network status and try again.</string>
<string name="stop">Stop the service</string>
<!-- alert category --> <!-- alert category -->
<string name="ok_iknow">OK</string> <string name="ok_iknow">OK</string>
......
...@@ -47,6 +47,8 @@ import android.preference.PreferenceManager; ...@@ -47,6 +47,8 @@ import android.preference.PreferenceManager;
public class ShadowsocksReceiver extends BroadcastReceiver { public class ShadowsocksReceiver extends BroadcastReceiver {
public static final String CLOSE_ACTION = "com.github.shadowsocks.ACTION_SHUTDOWN";
private static final String TAG = "Shadowsocks"; private static final String TAG = "Shadowsocks";
@Override @Override
...@@ -54,7 +56,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -54,7 +56,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver {
if (intent != null) { if (intent != null) {
final String action = intent.getAction(); 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)); context.stopService(new Intent(context, ShadowsocksService.class));
return; return;
} }
......
...@@ -48,11 +48,14 @@ import android.content.SharedPreferences; ...@@ -48,11 +48,14 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import com.google.analytics.tracking.android.EasyTracker; import com.google.analytics.tracking.android.EasyTracker;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -153,9 +156,7 @@ public class ShadowsocksService extends Service { ...@@ -153,9 +156,7 @@ public class ShadowsocksService extends Service {
super.handleMessage(msg); super.handleMessage(msg);
} }
}; };
private Notification notification;
private NotificationManager notificationManager; private NotificationManager notificationManager;
private PendingIntent pendIntent;
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
private String appHost; private String appHost;
private int remotePort; private int remotePort;
...@@ -403,22 +404,29 @@ public class ShadowsocksService extends Service { ...@@ -403,22 +404,29 @@ public class ShadowsocksService extends Service {
} }
private void notifyAlert(String title, String info) { 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) { // ContentIntent
notification.icon = R.drawable.ic_stat_shadowsocks; Intent openIntent = new Intent(this, Shadowsocks.class);
notification.tickerText = title; openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notification.flags = flags; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openIntent, 0);
initSoundVibrateLights(notification);
notification.setLatestEventInfo(this, getString(R.string.app_name), info, pendIntent); // ActionIntent
notificationManager.notify(0, notification); 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 @Override
...@@ -435,11 +443,6 @@ public class ShadowsocksService extends Service { ...@@ -435,11 +443,6 @@ public class ShadowsocksService extends Service {
settings = PreferenceManager.getDefaultSharedPreferences(this); settings = PreferenceManager.getDefaultSharedPreferences(this);
notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 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 { try {
mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature);
...@@ -464,9 +467,6 @@ public class ShadowsocksService extends Service { ...@@ -464,9 +467,6 @@ public class ShadowsocksService extends Service {
stopForegroundCompat(1); stopForegroundCompat(1);
notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped),
Notification.FLAG_AUTO_CANCEL);
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
......
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