project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Mon Jul 23 00:17:06 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Tue Jul 24 16:57:48 2012 +0200
@@ -25,16 +25,21 @@
import org.hedgewars.hedgeroid.Downloader.DownloadAssets;
import org.hedgewars.hedgeroid.Downloader.DownloadListActivity;
import org.hedgewars.hedgeroid.netplay.LobbyActivity;
+import org.hedgewars.hedgeroid.netplay.NetplayService;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
+import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@@ -63,7 +68,11 @@
startGame.setOnClickListener(startGameClicker);
joinLobby.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- showDialog(DIALOG_START_NETGAME);
+ if(!NetplayService.isActive()) {
+ showDialog(DIALOG_START_NETGAME);
+ } else {
+ startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
+ }
}
});
@@ -141,10 +150,11 @@
edit.putString(PREF_PLAYERNAME, playerName);
edit.commit();
- // TODO actually use that name
- Intent netplayIntent = new Intent(getApplicationContext(), LobbyActivity.class);
- netplayIntent.putExtra("playerName", playerName);
- startActivity(netplayIntent);
+ Intent netplayServiceIntent = new Intent(getApplicationContext(), NetplayService.class);
+ netplayServiceIntent.putExtra(NetplayService.EXTRA_PLAYERNAME, playerName);
+ startService(netplayServiceIntent);
+
+ LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(NetplayService.ACTION_CONNECTED));
}
}
});
@@ -170,4 +180,11 @@
startActivity(new Intent(getApplicationContext(), StartGameActivity.class));
}
};
+
+ private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
+ }
+ };
}