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;
|
private Toolbar mToolbar;
|
||||||
|
|
||||||
/* Some tracking bits */
|
/* 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;
|
private SharedPreferences mPrefs = null;
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
}
|
}
|
||||||
else if (intent.hasExtra("status"))
|
else if (intent.hasExtra("status"))
|
||||||
{
|
{
|
||||||
torStatus = intent.getIntExtra("status", TorServiceConstants.STATUS_OFF);
|
torStatus = intent.getStringExtra("status");
|
||||||
updateStatus("");
|
updateStatus("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
|
|
||||||
public static boolean ENABLE_DEBUG_LOG = true;
|
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;
|
private final static int CONTROL_SOCKET_TIMEOUT = 0;
|
||||||
|
|
||||||
|
@ -223,14 +223,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTorStatus() {
|
||||||
public int getTorStatus ()
|
|
||||||
{
|
|
||||||
|
|
||||||
return mCurrentStatus;
|
return mCurrentStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearNotifications ()
|
private void clearNotifications ()
|
||||||
{
|
{
|
||||||
if (mNotificationManager != null)
|
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)
|
if (newState == STATUS_ON)
|
||||||
{
|
{
|
||||||
|
@ -2111,17 +2107,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCallbackStatus (int currentStatus)
|
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);
|
||||||
Intent intent = new Intent("status");
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||||
// 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
|
* Another way to do this would be to use the Observer pattern by defining the
|
||||||
|
|
|
@ -66,10 +66,11 @@ public interface TorServiceConstants {
|
||||||
|
|
||||||
//control port
|
//control port
|
||||||
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
|
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
|
||||||
|
|
||||||
public final static int STATUS_OFF = 0;
|
public final static String STATUS_OFF = "OFF";
|
||||||
public final static int STATUS_ON = 1;
|
public final static String STATUS_ON = "ON";
|
||||||
public final static int STATUS_CONNECTING = 2;
|
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 STATUS_MSG = 1;
|
||||||
public static final int ENABLE_TOR_MSG = 2;
|
public static final int ENABLE_TOR_MSG = 2;
|
||||||
|
|
Loading…
Reference in New Issue