diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-06-08 17:32:17 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-06-08 17:32:17 +0200 |
commit | 692875b3b3afa7408714ccb31ef73099757dc1ee (patch) | |
tree | 9ec2f522b58109d8793a9f8ad1ec1bf5420e094a /src | |
parent | 00d4add3e1ff720c33183d6f575d44a655a5bea8 (diff) |
Fix icon displayed in the notification bar. Using a Leveldrawable does not work as expected.
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVPN.java | 24 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVpnService.java | 40 |
2 files changed, 44 insertions, 20 deletions
diff --git a/src/de/blinkt/openvpn/core/OpenVPN.java b/src/de/blinkt/openvpn/core/OpenVPN.java index 982a1e62..450a13ea 100644 --- a/src/de/blinkt/openvpn/core/OpenVPN.java +++ b/src/de/blinkt/openvpn/core/OpenVPN.java @@ -1,16 +1,5 @@ package de.blinkt.openvpn.core; -import java.io.ByteArrayInputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.Locale; -import java.util.Vector; - import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.PackageInfo; @@ -22,6 +11,17 @@ import android.os.Parcel; import android.os.Parcelable; import de.blinkt.openvpn.R; +import java.io.ByteArrayInputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Locale; +import java.util.Vector; + public class OpenVPN { @@ -50,7 +50,7 @@ public class OpenVPN { LEVEL_CONNECTING_NO_SERVER_REPLY_YET (2), LEVEL_CONNECTED (0), UNKNOWN_LEVEL(-1); - public final int level; + private final int level; ConnectionStatus(int level){ this.level = level; diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java index 6563fa0f..853389fd 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnService.java +++ b/src/de/blinkt/openvpn/core/OpenVpnService.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.Vector; +import static de.blinkt.openvpn.core.OpenVPN.ConnectionStatus.*; + public class OpenVpnService extends VpnService implements StateListener, Callback, ByteCountListener { public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE"; public static final String START_SERVICE_STICKY = "de.blinkt.openvpn.START_SERVICE_STICKY"; @@ -115,7 +117,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); - int icon = R.drawable.ic_notification_icon; + int icon = getIconByLevel(level); + android.app.Notification.Builder nbuilder = new Notification.Builder(this); if(mProfile!=null) @@ -127,7 +130,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac nbuilder.setOnlyAlertOnce(true); nbuilder.setOngoing(true); nbuilder.setContentIntent(getLogPendingIntent()); - nbuilder.setSmallIcon(icon,level.level); + nbuilder.setSmallIcon(icon); + if(when !=0) nbuilder.setWhen(when); @@ -145,8 +149,28 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac startForeground(OPENVPN_STATUS, notification); } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + private int getIconByLevel(ConnectionStatus level) { + switch (level) { + case LEVEL_CONNECTED: + case UNKNOWN_LEVEL: + return R.drawable.ic_stat_vpn; + case LEVEL_AUTH_FAILED: + case LEVEL_NONETWORK: + case LEVEL_NOTCONNECTED: + return R.drawable.ic_stat_vpn_offline; + case LEVEL_CONNECTING_NO_SERVER_REPLY_YET: + case LEVEL_WAITING_FOR_USER_INPUT: + return R.drawable.ic_stat_vpn_outline; + case LEVEL_CONNECTING_SERVER_REPLIED: + return R.drawable.ic_stat_vpn_empty_halo; + default: + return R.drawable.ic_stat_vpn; + + } + } + + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void jbNotificationExtras(boolean lowpriority, android.app.Notification.Builder nbuilder) { try { @@ -268,7 +292,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac String startTitle = getString(R.string.start_vpn_title, mProfile.mName); String startTicker = getString(R.string.start_vpn_ticker, mProfile.mName); showNotification(startTitle, startTicker, - false,0,ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET); + false,0, LEVEL_CONNECTING_NO_SERVER_REPLY_YET); // Set a flag that we are starting a new VPN mStarting=true; @@ -542,11 +566,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac // Display byte count only after being connected { - if (level == ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT) { + if (level == LEVEL_WAITING_FOR_USER_INPUT) { // The user is presented a dialog of some kind, no need to inform the user // with a notifcation return; - } else if(level == ConnectionStatus.LEVEL_CONNECTED) { + } else if(level == LEVEL_CONNECTED) { mDisplayBytecount = true; mConnecttime = System.currentTimeMillis(); } else { @@ -580,7 +604,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac humanReadableByteCount(diffout/OpenVPNMangement.mBytecountinterval, true)); boolean lowpriority = !mNotificationalwaysVisible; - showNotification(netstat,null,lowpriority,mConnecttime, ConnectionStatus.LEVEL_CONNECTED); + showNotification(netstat,null,lowpriority,mConnecttime, LEVEL_CONNECTED); } } |