Notification compatibility

Refs #243
This commit is contained in:
M66B 2016-01-31 14:07:07 +01:00
parent fff2ba4082
commit 7e1b909be5
2 changed files with 43 additions and 22 deletions

View File

@ -122,16 +122,19 @@ public class Receiver extends BroadcastReceiver {
Util.setTheme(context);
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_security_white_24dp)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.msg_installed, name))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_REMINDER)
.setVisibility(Notification.VISIBILITY_SECRET)
.setColor(tv.data)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_REMINDER)
.setVisibility(Notification.VISIBILITY_SECRET);
}
// Get defaults
SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
@ -147,7 +150,7 @@ public class Receiver extends BroadcastReceiver {
riWifi.putExtra(SinkholeService.EXTRA_BLOCKED, !wifi);
PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT);
notification.addAction(
builder.addAction(
wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
context.getString(wifi ? R.string.title_allow : R.string.title_block),
piWifi
@ -161,7 +164,7 @@ public class Receiver extends BroadcastReceiver {
riOther.putExtra(SinkholeService.EXTRA_PACKAGE, packages[0]);
riOther.putExtra(SinkholeService.EXTRA_BLOCKED, !other);
PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT);
notification.addAction(
builder.addAction(
other ? R.drawable.other_on : R.drawable.other_off,
context.getString(other ? R.string.title_allow : R.string.title_block),
piOther
@ -169,9 +172,9 @@ public class Receiver extends BroadcastReceiver {
// Show notification
if (internet)
NotificationManagerCompat.from(context).notify(uid, notification.build());
NotificationManagerCompat.from(context).notify(uid, builder.build());
else {
NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(notification);
NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
expanded.bigText(context.getString(R.string.msg_installed, name));
expanded.setSummaryText(context.getString(R.string.title_internet));
NotificationManagerCompat.from(context).notify(uid, expanded.build());

View File

@ -630,13 +630,15 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setSmallIcon(R.drawable.ic_equalizer_white_24dp)
.setContent(remoteViews)
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setPriority(Notification.PRIORITY_DEFAULT)
.setColor(tv.data)
.setOngoing(true)
.setAutoCancel(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_PUBLIC);
}
if (state == State.none || state == State.waiting) {
if (state != State.none) {
Log.d(TAG, "Stop foreground state=" + state.toString());
@ -1402,13 +1404,16 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_started))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_MIN)
.setColor(tv.data)
.setOngoing(true)
.setAutoCancel(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_MIN);
}
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_started));
notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
@ -1433,12 +1438,16 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_waiting))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_MIN)
.setColor(tv.data)
.setOngoing(true)
.setAutoCancel(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_MIN);
}
return builder.build();
}
@ -1453,12 +1462,15 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_revoked))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setColor(tv.data)
.setOngoing(false)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET);
}
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_revoked));
@ -1476,12 +1488,15 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_error))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET)
.setColor(tv.data)
.setOngoing(false)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET);
}
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_error));
notification.setSummaryText(reason);
@ -1509,12 +1524,15 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_access, name))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_REMINDER)
.setVisibility(Notification.VISIBILITY_SECRET)
.setColor(colorAccent)
.setOngoing(false)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_REMINDER)
.setVisibility(Notification.VISIBILITY_SECRET);
}
DateFormat df = new SimpleDateFormat("dd HH:mm");
NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);