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:
parent
356e79a163
commit
a336a294fb
|
@ -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("");
|
||||
}
|
||||
|
||||
|
|
|
@ -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,12 +223,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
}
|
||||
|
||||
|
||||
public int getTorStatus ()
|
||||
{
|
||||
|
||||
public String getTorStatus() {
|
||||
return mCurrentStatus;
|
||||
|
||||
}
|
||||
|
||||
private void clearNotifications ()
|
||||
|
@ -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,18 +2107,14 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
}
|
||||
|
||||
private void sendCallbackStatus (int currentStatus)
|
||||
{
|
||||
|
||||
|
||||
Intent intent = new Intent("status");
|
||||
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
|
||||
* BroadcastReciever in the Android manifest.
|
||||
|
|
|
@ -67,9 +67,10 @@ 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;
|
||||
|
|
Loading…
Reference in New Issue