convert status variable to String for easy sharing in Intents

Instead of making the apps who receive the broadcasts decipher a number
scheme, send the string of the status.  Then it'll be self-documenting.
This commit is contained in:
Hans-Christoph Steiner 2015-06-08 14:54:38 -04:00
parent 356e79a163
commit a336a294fb
3 changed files with 16 additions and 23 deletions

View File

@ -87,7 +87,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
private Toolbar mToolbar;
/* Some tracking bits */
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
private String torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
private SharedPreferences mPrefs = null;
@ -178,7 +178,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
}
else if (intent.hasExtra("status"))
{
torStatus = intent.getIntExtra("status", TorServiceConstants.STATUS_OFF);
torStatus = intent.getStringExtra("status");
updateStatus("");
}

View File

@ -84,7 +84,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public static boolean ENABLE_DEBUG_LOG = true;
private int mCurrentStatus = STATUS_OFF;
private String mCurrentStatus = STATUS_OFF;
private final static int CONTROL_SOCKET_TIMEOUT = 0;
@ -223,14 +223,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
public int getTorStatus ()
{
public String getTorStatus() {
return mCurrentStatus;
}
private void clearNotifications ()
{
if (mNotificationManager != null)
@ -1427,7 +1423,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
public void setTorProfile(int newState) {
public void setTorProfile(String newState) {
if (newState == STATUS_ON)
{
@ -2111,17 +2107,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
private void sendCallbackStatus (int currentStatus)
{
Intent intent = new Intent("status");
// You can also include some extra data.
intent.putExtra("status", currentStatus);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
private void sendCallbackStatus(String currentStatus) {
Intent intent = new Intent("status"); // TODO rename to proper action
// You can also include some extra data.
intent.putExtra("status", currentStatus);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
/*
* Another way to do this would be to use the Observer pattern by defining the

View File

@ -66,10 +66,11 @@ public interface TorServiceConstants {
//control port
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
public final static int STATUS_OFF = 0;
public final static int STATUS_ON = 1;
public final static int STATUS_CONNECTING = 2;
public final static String STATUS_OFF = "OFF";
public final static String STATUS_ON = "ON";
public final static String STATUS_CONNECTING = "CONNECTING";
public final static String STATUS_DISCONNECTING = "DISCONNECTING";
public static final int STATUS_MSG = 1;
public static final int ENABLE_TOR_MSG = 2;