refine the notification
This commit is contained in:
+50
-49
@@ -1,60 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.github.shadowsocks"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="21"
|
||||
android:versionName="1.3.9">
|
||||
package="com.github.shadowsocks"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="21"
|
||||
android:versionName="1.3.9">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.touchscreen"
|
||||
android:required="false"/>
|
||||
<uses-feature
|
||||
android:name="android.hardware.touchscreen"
|
||||
android:required="false"/>
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
android:targetSdkVersion="16"/>
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
android:targetSdkVersion="16"/>
|
||||
|
||||
<application
|
||||
android:name=".ShadowsocksApplication"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".Shadowsocks"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.GAEProxy"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:theme="@style/Theme.GAEProxy"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.AppManager" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<application
|
||||
android:name=".ShadowsocksApplication"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".Shadowsocks"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.GAEProxy"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:theme="@style/Theme.GAEProxy"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.AppManager"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".ShadowsocksService"
|
||||
android:enabled="true"/>
|
||||
<service
|
||||
android:name=".ShadowsocksService"
|
||||
android:enabled="true"/>
|
||||
|
||||
<receiver android:name=".ShadowsocksReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".ShadowsocksReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
|
||||
<action android:name="com.github.shadowsocks.ACTION_SHUTDOWN"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
<version>r7</version>
|
||||
<version>r12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>crouton</artifactId>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -50,12 +50,13 @@
|
||||
<string name="auto_connect_summary">Start Shadowsocks at the startup</string>
|
||||
|
||||
<!-- notification category -->
|
||||
<string name="forward_success">Shadowsocks started</string>
|
||||
<string name="service_running">Running in the background</string>
|
||||
<string name="forward_fail">Shadowsocks failed to start</string>
|
||||
<string name="service_stopped">Shadowsocks stopped</string>
|
||||
<string name="forward_stop">Shadowsocks stopped</string>
|
||||
<string name="forward_success">Shadowsocks started.</string>
|
||||
<string name="service_running">Running in the background.</string>
|
||||
<string name="forward_fail">Shadowsocks failed to start.</string>
|
||||
<string name="service_stopped">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="stop">Stop the service</string>
|
||||
|
||||
<!-- alert category -->
|
||||
<string name="ok_iknow">OK</string>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user