Android N: improved notifications

Refs #453
This commit is contained in:
M66B 2016-07-03 16:24:19 +02:00
parent 090f43bf12
commit 7fee9b3868
3 changed files with 36 additions and 17 deletions

View File

@ -127,12 +127,17 @@ public class Receiver extends BroadcastReceiver {
context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
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)
.setColor(tv.data)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setContentTitle(name)
.setContentText(context.getString(R.string.msg_installed_n));
else
builder.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.msg_installed, name));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET);
@ -178,7 +183,10 @@ public class Receiver extends BroadcastReceiver {
NotificationManagerCompat.from(context).notify(uid, builder.build());
else {
NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
expanded.bigText(context.getString(R.string.msg_installed, name));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
expanded.bigText(context.getString(R.string.msg_installed_n));
else
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

@ -2097,13 +2097,18 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_cloud_upload_white_24dp)
.setGroup("AccessAttempt")
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_access, name))
.setContentIntent(pi)
.setColor(colorOff)
.setOngoing(false)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setContentTitle(name)
.setContentText(getString(R.string.msg_access_n));
else
builder.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_access, name));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET);
@ -2112,11 +2117,15 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
DateFormat df = new SimpleDateFormat("dd HH:mm");
NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
String sname = getString(R.string.msg_access, name);
int pos = sname.indexOf(name);
Spannable sp = new SpannableString(sname);
sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
notification.addLine(sp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
notification.addLine(getString(R.string.msg_access_n));
else {
String sname = getString(R.string.msg_access, name);
int pos = sname.indexOf(name);
Spannable sp = new SpannableString(sname);
sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
notification.addLine(sp);
}
Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7);
int colDAddr = cursor.getColumnIndex("daddr");
@ -2136,13 +2145,13 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
int allowed = cursor.getInt(colAllowed);
if (allowed >= 0) {
pos = sb.indexOf(daddr);
sp = new SpannableString(sb);
int pos = sb.indexOf(daddr);
Spannable sp = new SpannableString(sb);
ForegroundColorSpan fgsp = new ForegroundColorSpan(allowed > 0 ? colorOn : colorOff);
sp.setSpan(fgsp, pos, pos + daddr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
notification.addLine(sp);
notification.addLine(sp);
} else
notification.addLine(sb);
}
cursor.close();

View File

@ -146,13 +146,15 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="msg_disabled">NetGuard is disabled, use the switch above to enable NetGuard</string>
<string name="msg_revoked">NetGuard has been disabled, likely by using another VPN based application</string>
<string name="msg_installed">\'%1$s\' installed</string>
<string name="msg_installed_n">Has been installed</string>
<string name="msg_access">%1$s attempted internet access</string>
<string name="msg_access_n">Attempted internet access</string>
<string name="msg_completed">Action completed</string>
<string name="msg_vpn">NetGuard uses a local VPN to filter internet traffic.
For this reason, please allow a VPN connection in the next dialog.
Your internet traffic is not being sent to a remote VPN server.</string>
<string name="msg_autostart">NetGuard could not be started automatically likely due to a bug in your Android version</string>
<string name="msg_error">An unexpected error has occurred: %s</string>
<string name="msg_autostart">NetGuard could not start automatically. This is likely because of a bug in your Android version.</string>
<string name="msg_error">An unexpected error has occurred: \'%s\'</string>
<string name="msg_try">Try NetGuard</string>
<string name="msg_terms">By donating you agree to the <a href="http://www.netguard.me/#terms">terms &amp; conditions</a></string>
<string name="msg_dimming">If you cannot press OK in the next dialog, another (screen dimming) application is likely manipulating the screen.</string>