add new icons showing different status

This commit is contained in:
Nathan Freitas 2014-01-09 22:01:02 -05:00
parent d3c11bed4b
commit 39699e69c6
5 changed files with 48 additions and 50 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

View File

@ -200,14 +200,33 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags) private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags, boolean isOngoing)
{ {
if (mNotifyBuilder == null) if (mNotifyBuilder == null)
startNotification(getString(R.string.status_activated),prefPersistNotifications); {
//Reusable code.
Intent intent = new Intent(TorService.this, Orbot.class);
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotifyBuilder == null)
{
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setContentText( getString(R.string.status_activated))
.setSmallIcon(R.drawable.ic_stat_tor);
mNotifyBuilder.setContentIntent(pendIntent);
}
}
mNotifyBuilder.setContentText(notifyMsg); mNotifyBuilder.setContentText(notifyMsg);
mNotifyBuilder.setSmallIcon(icon); mNotifyBuilder.setSmallIcon(icon);
mNotifyBuilder.setOngoing(isOngoing);
if (notifyId == ERROR_NOTIFY_ID) if (notifyId == ERROR_NOTIFY_ID)
{ {
@ -314,7 +333,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
catch (Exception e) catch (Exception e)
{ {
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
this.showToolbarNotification(getString(R.string.status_disabled), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1); this.showToolbarNotification(getString(R.string.status_disabled), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1, false);
Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e); Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
} }
} }
@ -412,7 +431,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
try { try {
String onionHostname = Utils.readString(new FileInputStream(file)).trim(); String onionHostname = Utils.readString(new FileInputStream(file)).trim();
showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor, Notification.FLAG_ONGOING_EVENT); showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor, Notification.FLAG_ONGOING_EVENT, true);
Editor pEdit = prefs.edit(); Editor pEdit = prefs.edit();
pEdit.putString("pref_hs_hostname",onionHostname); pEdit.putString("pref_hs_hostname",onionHostname);
pEdit.commit(); pEdit.commit();
@ -421,13 +440,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logException("unable to read onion hostname file",e); logException("unable to read onion hostname file",e);
showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1); showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1, false);
return null; return null;
} }
} }
else else
{ {
showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1); showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1, false);
} }
@ -668,13 +687,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if(proxyAll) if(proxyAll)
{ {
showToolbarNotification(getString(R.string.setting_up_full_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.setting_up_full_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
code = mTransProxy.setTransparentProxyingAll(this); code = mTransProxy.setTransparentProxyingAll(this);
} }
else else
{ {
showToolbarNotification(getString(R.string.setting_up_app_based_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.setting_up_app_based_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this, getSharedPrefs(getApplicationContext()))); code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this, getSharedPrefs(getApplicationContext())));
} }
@ -684,11 +703,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (code == 0) if (code == 0)
{ {
showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
if (enableTether) if (enableTether)
{ {
showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
mTransProxy.enableTetheringRules(this); mTransProxy.enableTetheringRules(this);
@ -696,7 +715,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
else else
{ {
showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
} }
@ -1015,33 +1034,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
private void startNotification (String message, boolean persistent)
{
//Reusable code.
Intent intent = new Intent(TorService.this, Orbot.class);
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotifyBuilder == null)
{
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setContentText( getString(R.string.status_activated))
.setSmallIcon(R.drawable.ic_stat_tor);
mNotifyBuilder.setContentIntent(pendIntent);
}
mNotifyBuilder.setOngoing(persistent);
mNotifyBuilder.setContentText(message);
mNotificationManager.notify(
NOTIFY_ID,
mNotifyBuilder.getNotification());
}
public void message(String severity, String msg) { public void message(String severity, String msg) {
@ -1053,8 +1046,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
currentStatus = STATUS_ON; currentStatus = STATUS_ON;
startNotification(getString(R.string.status_activated),prefPersistNotifications); showToolbarNotification(getString(R.string.status_activated), NOTIFY_ID, R.drawable.ic_stat_tor, -1, prefPersistNotifications);
} }
@ -1121,8 +1113,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sb.append(" "); sb.append(" ");
sb.append(getString(R.string.up)); sb.append(getString(R.string.up));
int iconId = R.drawable.ic_stat_tor;
if (read > 0 || written > 0)
iconId = R.drawable.ic_stat_tor_xfer;
if (mConnectivity && prefPersistNotifications) if (mConnectivity && prefPersistNotifications)
startNotification(sb.toString(),prefPersistNotifications); showToolbarNotification(sb.toString(), NOTIFY_ID, iconId, -1, prefPersistNotifications);
mTotalTrafficWritten += written; mTotalTrafficWritten += written;
mTotalTrafficRead += read; mTotalTrafficRead += read;
@ -1578,13 +1575,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (!mConnectivity) if (!mConnectivity)
{ {
logNotice("No network connectivity. Putting Tor to sleep..."); logNotice("No network connectivity. Putting Tor to sleep...");
startNotification(getString(R.string.no_internet_connection_tor),prefPersistNotifications); showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off,-1,prefPersistNotifications);
} }
else else
{ {
logNotice("Network connectivity is good. Waking Tor up..."); logNotice("Network connectivity is good. Waking Tor up...");
startNotification(getString(R.string.status_activated),prefPersistNotifications); showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,-1,prefPersistNotifications);
} }
} catch (RemoteException e) { } catch (RemoteException e) {
logException ("error applying mPrefs",e); logException ("error applying mPrefs",e);
@ -1664,7 +1662,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT); showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT, false);
return false; return false;
} }
@ -1683,7 +1681,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
String msgBridge = getString(R.string.bridge_requires_ip) + String msgBridge = getString(R.string.bridge_requires_ip) +
getString(R.string.send_email_for_bridges); getString(R.string.send_email_for_bridges);
showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
return false; return false;
@ -1698,7 +1696,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
bridgeDelim = ","; bridgeDelim = ",";
} }
showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1); showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false);
boolean obfsBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_OBFUSCATED, false); boolean obfsBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_OBFUSCATED, false);
String bridgeCfgKey = "bridge"; String bridgeCfgKey = "bridge";
@ -1746,7 +1744,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.your_reachableaddresses_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT); showToolbarNotification (getString(R.string.your_reachableaddresses_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT, false);
return false; return false;
} }
@ -1775,7 +1773,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.your_relay_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT); showToolbarNotification (getString(R.string.your_relay_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, Notification.FLAG_ONGOING_EVENT, false);
return false; return false;