project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetplayStateFragment.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetplayStateFragment.java Tue Jan 21 22:38:13 2014 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetplayStateFragment.java Tue Jan 21 22:43:06 2014 +0100
@@ -37,7 +37,7 @@
/**
* Fragment for use by an activity that depends on the state of the network
* connection. The activity must implement the NetplayStateListener interface.
- *
+ *
* This fragment manages reacting to changes in the networking state by calling
* a callback method on the activity.
*/
@@ -47,91 +47,91 @@
private LocalBroadcastManager broadcastManager;
private NetplayStateListener listener;
private State knownState;
-
+
interface NetplayStateListener {
- /**
- * This is called while the activity is running, and every time during resume, if
- * a change in the networking state is detected. It is also called once
- * with the initial state (which could be called a change from the "unknown" state).
- */
- void onNetplayStateChanged(State newState);
- }
-
+ /**
+ * This is called while the activity is running, and every time during resume, if
+ * a change in the networking state is detected. It is also called once
+ * with the initial state (which could be called a change from the "unknown" state).
+ */
+ void onNetplayStateChanged(State newState);
+ }
+
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- try {
- listener = (NetplayStateListener) activity;
- } catch(ClassCastException e) {
- throw new ClassCastException("Activity " + activity + " must implement NetplayStateListener to use NetplayStateFragment.");
- }
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- listener = null;
- }
-
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ listener = (NetplayStateListener) activity;
+ } catch(ClassCastException e) {
+ throw new ClassCastException("Activity " + activity + " must implement NetplayStateListener to use NetplayStateFragment.");
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ listener = null;
+ }
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
appContext = getActivity().getApplicationContext();
broadcastManager = LocalBroadcastManager.getInstance(appContext);
netplay = Netplay.getAppInstance(appContext);
- }
+ }
@Override
public void onResume() {
- super.onResume();
- broadcastManager.registerReceiver(disconnectReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
- broadcastManager.registerReceiver(leaveRoomReceiver, new IntentFilter(Netplay.ACTION_LEFT_ROOM));
- broadcastManager.registerReceiver(stateChangeReceiver, new IntentFilter(Netplay.ACTION_STATE_CHANGED));
-
- State newState = netplay.getState();
- if(knownState != newState) {
- listener.onNetplayStateChanged(newState);
- knownState = newState;
- }
+ super.onResume();
+ broadcastManager.registerReceiver(disconnectReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+ broadcastManager.registerReceiver(leaveRoomReceiver, new IntentFilter(Netplay.ACTION_LEFT_ROOM));
+ broadcastManager.registerReceiver(stateChangeReceiver, new IntentFilter(Netplay.ACTION_STATE_CHANGED));
+
+ State newState = netplay.getState();
+ if(knownState != newState) {
+ listener.onNetplayStateChanged(newState);
+ knownState = newState;
+ }
}
-
+
@Override
public void onPause() {
- super.onPause();
- broadcastManager.unregisterReceiver(disconnectReceiver);
- broadcastManager.unregisterReceiver(leaveRoomReceiver);
- broadcastManager.unregisterReceiver(stateChangeReceiver);
+ super.onPause();
+ broadcastManager.unregisterReceiver(disconnectReceiver);
+ broadcastManager.unregisterReceiver(leaveRoomReceiver);
+ broadcastManager.unregisterReceiver(stateChangeReceiver);
}
- private final BroadcastReceiver disconnectReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
- String message = intent.getStringExtra(Netplay.EXTRA_MESSAGE);
- String toastText = getString(R.string.toast_disconnected, message);
- Toast.makeText(appContext, toastText, Toast.LENGTH_LONG).show();
- }
- }
- };
-
- private final BroadcastReceiver leaveRoomReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int reason = intent.getIntExtra(Netplay.EXTRA_REASON, -1);
- if(reason == Frontlib.NETCONN_ROOMLEAVE_ABANDONED) {
- Toast.makeText(appContext, R.string.toast_room_abandoned, Toast.LENGTH_LONG).show();
- } else if(reason == Frontlib.NETCONN_ROOMLEAVE_KICKED) {
- Toast.makeText(appContext, R.string.toast_kicked, Toast.LENGTH_LONG).show();
- }
- }
- };
-
- private final BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- State newState = netplay.getState();
- listener.onNetplayStateChanged(newState);
- knownState = newState;
- }
- };
+ private final BroadcastReceiver disconnectReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
+ String message = intent.getStringExtra(Netplay.EXTRA_MESSAGE);
+ String toastText = getString(R.string.toast_disconnected, message);
+ Toast.makeText(appContext, toastText, Toast.LENGTH_LONG).show();
+ }
+ }
+ };
+
+ private final BroadcastReceiver leaveRoomReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int reason = intent.getIntExtra(Netplay.EXTRA_REASON, -1);
+ if(reason == Frontlib.NETCONN_ROOMLEAVE_ABANDONED) {
+ Toast.makeText(appContext, R.string.toast_room_abandoned, Toast.LENGTH_LONG).show();
+ } else if(reason == Frontlib.NETCONN_ROOMLEAVE_KICKED) {
+ Toast.makeText(appContext, R.string.toast_kicked, Toast.LENGTH_LONG).show();
+ }
+ }
+ };
+
+ private final BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ State newState = netplay.getState();
+ listener.onNetplayStateChanged(newState);
+ knownState = newState;
+ }
+ };
}