Hedgeroid: various improvements:
- Improved main menu dialogs
- Fixed hardware enter button not sending chat messages on Transformer
- Fixed /me messages showing the /me as part of the message
--- a/project_files/Android-build/SDL-android-project/AndroidManifest.xml Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/AndroidManifest.xml Fri Jul 27 01:38:24 2012 +0200
@@ -21,7 +21,7 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
+ android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -70,7 +70,6 @@
android:name=".netplay.LobbyActivity"
android:label="@string/title_activity_lobby"
android:screenOrientation="landscape"
-
android:windowSoftInputMode="adjustResize" >
</activity>
</application>
Binary file project_files/Android-build/SDL-android-project/res/drawable-hdpi/button_local_play.png has changed
Binary file project_files/Android-build/SDL-android-project/res/drawable-hdpi/button_network_play.png has changed
Binary file project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/button_local_play.png has changed
Binary file project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/button_network_play.png has changed
Binary file project_files/Android-build/SDL-android-project/res/drawable-small-hdpi/button_local_play.png has changed
Binary file project_files/Android-build/SDL-android-project/res/drawable-small-hdpi/button_network_play.png has changed
--- a/project_files/Android-build/SDL-android-project/res/layout/main.xml Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/main.xml Fri Jul 27 01:38:24 2012 +0200
@@ -1,31 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <include layout="@layout/background"/>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <Button
- android:id="@+id/downloader"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="downloader"/>
-
- <Button
- android:id="@+id/startGame"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="startgame"/>
-
- <Button
- android:id="@+id/joinLobby"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="join lobby"/>
-
-</LinearLayout>
+ android:layout_height="fill_parent" >
+
+ <include layout="@layout/background" />
+
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <View
+ android:id="@+id/placeholder"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_centerInParent="true" />
+
+ <FrameLayout
+ android:id="@+id/frameLayout1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_toLeftOf="@id/placeholder" >
+
+ <Button
+ android:id="@+id/startGame"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:drawableTop="@drawable/button_local_play"
+ android:text="@string/main_button_localplay" />
+ </FrameLayout>
+
+ <FrameLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_toRightOf="@id/placeholder" >
+
+ <Button
+ android:id="@+id/joinLobby"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:drawableTop="@drawable/button_network_play"
+ android:text="@string/main_button_netplay" />
+ </FrameLayout>
+ </RelativeLayout>
+
</FrameLayout>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/layout/tab_indicator.xml Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/tab_indicator.xml Fri Jul 27 01:38:24 2012 +0200
@@ -1,10 +1,9 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="64dip"
- android:layout_height="0dip"
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
android:layout_weight="1"
- android:layout_marginTop="-3dip"
- android:layout_marginBottom="-3dip"
- android:orientation="vertical">
+ android:orientation="vertical"
+ android:background="@drawable/box">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
@@ -15,6 +14,8 @@
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:scrollHorizontally="false"
+ android:padding="4dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
style="?android:attr/tabWidgetStyle"
--- a/project_files/Android-build/SDL-android-project/res/layout/vertical_tabs.xml Thu Jul 26 11:10:56 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/tabhost"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal" >
-
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="0" />
-
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="0dip"
- android:layout_height="match_parent"
- android:layout_weight="1" />
- </LinearLayout>
-</TabHost>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/menu/lobby_roomlist_options.xml Thu Jul 26 11:10:56 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/roomlist_refresh"
- android:title="@string/lobby_roomlistmenu_refresh"
- android:showAsAction="ifRoom" />
-</menu>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/menu/main_options.xml Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,12 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item
+ android:id="@+id/download"
+ android:title="@string/main_menu_downloader"
+ android:icon="@android:drawable/ic_menu_save"
+ android:showAsAction="ifRoom|withText" />
+ <item
+ android:id="@+id/preferences"
+ android:title="@string/main_menu_preferences"
+ android:icon="@android:drawable/ic_menu_preferences"
+ android:showAsAction="ifRoom|withText" />
+</menu>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/values/strings.xml Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/values/strings.xml Fri Jul 27 01:38:24 2012 +0200
@@ -28,8 +28,13 @@
<string name="download_downloadnow">Download now!</string>
<string name="download_queued">This download has been queued</string>
+ <!-- main activity -->
+ <string name="main_button_localplay">Local Game</string>
+ <string name="main_button_netplay">Network Game</string>
+ <string name="main_menu_downloader">Downloader</string>
+ <string name="main_menu_preferences">Preferences</string>
+
<!-- start game -->
-
<string name="start_gameplay">Style</string>
<string name="start_gamescheme">Game scheme</string>
<string name="start_weapons">Weapons</string>
@@ -97,6 +102,9 @@
<string name="lobby_roomlistmenu_create">Create room</string>
<string name="lobby_roomlistmenu_refresh">Refresh</string>
<string name="lobby_menu_disconnect">Disconnect</string>
+ <string name="lobby_tab_rooms">Rooms</string>
+ <string name="lobby_tab_chat">Chat</string>
+ <string name="lobby_tab_players">Users</string>
<string name="not_implemented_yet">Sorry, not implemented yet. :(</string>
@@ -113,5 +121,5 @@
<string name="dialog_password_title">Password required</string>
<string name="dialog_password_message">The server has requested a password to connect as "%1$s".</string>
<string name="dialog_password_hint">Password</string>
-
+ <string name="dialog_password_remember">remember password</string>
</resources>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectingDialog.java Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,59 @@
+package org.hedgewars.hedgeroid;
+
+import org.hedgewars.hedgeroid.netplay.Netplay;
+import org.hedgewars.hedgeroid.netplay.Netplay.State;
+
+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.os.Bundle;
+import android.support.v4.content.LocalBroadcastManager;
+
+public class ConnectingDialog extends ConnectionDependendDialogFragment {
+ @Override
+ public void onStart() {
+ super.onStart();
+ LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
+
+ if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() != State.CONNECTING) {
+ dismiss();
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(connectedReceiver);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ ProgressDialog dialog = new ProgressDialog(getActivity());
+ dialog.setIndeterminate(true);
+ dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ dialog.setTitle(R.string.dialog_connecting_title);
+ dialog.setMessage(getString(R.string.dialog_connecting_message));
+ return dialog;
+ }
+
+ private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Dialog dialog = getDialog();
+ if(dialog != null) {
+ dialog.dismiss();
+ } else {
+ dismiss();
+ }
+ }
+ };
+
+ public void onCancel(DialogInterface dialog) {
+ super.onCancel(dialog);
+ Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectionDependendDialogFragment.java Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,41 @@
+package org.hedgewars.hedgeroid;
+
+import org.hedgewars.hedgeroid.netplay.Netplay;
+import org.hedgewars.hedgeroid.netplay.Netplay.State;
+
+import android.app.Dialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.content.LocalBroadcastManager;
+
+public class ConnectionDependendDialogFragment extends DialogFragment {
+ @Override
+ public void onStart() {
+ super.onStart();
+ LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(dismissReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+ if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() == State.NOT_CONNECTED) {
+ dismiss();
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(dismissReceiver);
+ }
+
+ private BroadcastReceiver dismissReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Dialog dialog = getDialog();
+ if(dialog != null) {
+ dialog.dismiss();
+ } else {
+ dismiss();
+ }
+ }
+ };
+}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Fri Jul 27 01:38:24 2012 +0200
@@ -34,66 +34,35 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.DialogInterface.OnCancelListener;
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.app.FragmentManager;
import android.support.v4.content.LocalBroadcastManager;
-import android.text.InputType;
-import android.text.method.PasswordTransformationMethod;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
-import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
private static final int DIALOG_NO_SDCARD = 0;
- private static final int DIALOG_START_NETGAME = 1;
- private static final int DIALOG_CONNECTING = 2;
- private static final int DIALOG_PASSWORD = 3;
-
- private static final String PREF_PLAYERNAME = "playerName";
private LocalBroadcastManager broadcastManager;
-
- private Button downloader, startGame;
private ProgressDialog assetsDialog;
- private String passwordedUsername; // TODO ugly - move dialogs to fragments to get rid of e.g. this
public void onCreate(Bundle sis){
super.onCreate(sis);
- if(sis != null) {
- passwordedUsername = sis.getString(PREF_PLAYERNAME);
- }
setContentView(R.layout.main);
broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
- downloader = (Button)findViewById(R.id.downloader);
- startGame = (Button)findViewById(R.id.startGame);
- Button joinLobby = (Button)findViewById(R.id.joinLobby);
+ Button startLocalGame = (Button)findViewById(R.id.startGame);
+ Button startNetGame = (Button)findViewById(R.id.joinLobby);
- downloader.setOnClickListener(downloadClicker);
- startGame.setOnClickListener(startGameClicker);
- joinLobby.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- State state = Netplay.getAppInstance(getApplicationContext()).getState();
- switch(state) {
- case NOT_CONNECTED:
- showDialog(DIALOG_START_NETGAME);
- break;
- case CONNECTING:
- startWaitingForConnection();
- break;
- default:
- startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
- break;
- }
- }
- });
+ startLocalGame.setOnClickListener(startGameListener);
+ startNetGame.setOnClickListener(startNetGameListener);
if(!Utils.isDataPathAvailable()){
showDialog(DIALOG_NO_SDCARD);
@@ -120,15 +89,44 @@
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putString(PREF_PLAYERNAME, passwordedUsername);
+ protected void onResume() {
+ super.onResume();
+ broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
+ broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+ broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED));
}
@Override
- protected void onDestroy() {
- super.onDestroy();
- stopWaitingForConnection();
+ protected void onPause() {
+ super.onPause();
+ broadcastManager.unregisterReceiver(connectedReceiver);
+ broadcastManager.unregisterReceiver(connectionFailedReceiver);
+ broadcastManager.unregisterReceiver(passwordRequestedReceiver);
+ Netplay netplay = Netplay.getAppInstance(getApplicationContext());
+ if(netplay.getState() == State.CONNECTING) {
+ netplay.disconnect();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ getMenuInflater().inflate(R.menu.main_options, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case R.id.download:
+ startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0);
+ return true;
+ case R.id.preferences:
+ Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
}
@Override
@@ -140,23 +138,13 @@
@Override
protected void onStop() {
super.onStop();
- Netplay netplay = Netplay.getAppInstance(getApplicationContext());
- netplay.unrequestFastTicks();
- if(netplay.getState() == State.CONNECTING) {
- netplay.disconnect();
- }
+ Netplay.getAppInstance(getApplicationContext()).unrequestFastTicks();
}
public Dialog onCreateDialog(int id, Bundle args){
switch(id) {
case DIALOG_NO_SDCARD:
return createNoSdcardDialog();
- case DIALOG_START_NETGAME:
- return createStartNetgameDialog();
- case DIALOG_CONNECTING:
- return createConnectingDialog();
- case DIALOG_PASSWORD:
- return createPasswordDialog();
default:
throw new IndexOutOfBoundsException();
}
@@ -174,81 +162,6 @@
return builder.create();
}
-
- private Dialog createStartNetgameDialog() {
- final SharedPreferences prefs = getPreferences(MODE_PRIVATE);
- final String playerName = prefs.getString(PREF_PLAYERNAME, "Player");
- final EditText editText = new EditText(this);
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
-
- editText.setText(playerName);
- editText.setHint(R.string.start_netgame_dialog_playername_hint);
- editText.setId(android.R.id.text1);
-
- builder.setTitle(R.string.start_netgame_dialog_title);
- builder.setMessage(R.string.start_netgame_dialog_message);
- builder.setView(editText);
- builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- editText.setText(playerName);
- }
- });
- builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- String playerName = editText.getText().toString();
- if(playerName.length() > 0) {
- Editor edit = prefs.edit();
- edit.putString(PREF_PLAYERNAME, playerName);
- edit.commit();
-
- startWaitingForConnection();
- Netplay.getAppInstance(getApplicationContext()).connectToDefaultServer(playerName);
- }
- }
- });
-
- return builder.create();
- }
-
- private Dialog createConnectingDialog() {
- ProgressDialog dialog = new ProgressDialog(this);
- dialog.setOnCancelListener(new OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- Netplay.getAppInstance(getApplicationContext()).disconnect();
- }
- });
- dialog.setIndeterminate(true);
- dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- dialog.setTitle(R.string.dialog_connecting_title);
- dialog.setMessage(getString(R.string.dialog_connecting_message));
- return dialog;
- }
-
- private Dialog createPasswordDialog() {
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
- final EditText editText = new EditText(this);
- editText.setHint(R.string.dialog_password_hint);
- editText.setFreezesText(true);
- editText.setId(android.R.id.text1);
- editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
- editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
- builder.setView(editText);
- builder.setTitle(R.string.dialog_password_title);
- builder.setMessage(getString(R.string.dialog_password_message, passwordedUsername));
- builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- String password = editText.getText().toString();
- editText.setText("");
- Netplay.getAppInstance(getApplicationContext()).sendPassword(password);
- }
- });
- builder.setOnCancelListener(new OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- Netplay.getAppInstance(getApplicationContext()).disconnect();
- }
- });
- return builder.create();
- }
public void onAssetsDownloaded(boolean result){
if(!result){
@@ -257,36 +170,34 @@
assetsDialog.dismiss();
}
- private OnClickListener downloadClicker = new OnClickListener(){
- public void onClick(View v){
- startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0);
- }
- };
-
- private OnClickListener startGameClicker = new OnClickListener(){
+ private final OnClickListener startGameListener = new OnClickListener(){
public void onClick(View v){
startActivity(new Intent(getApplicationContext(), StartGameActivity.class));
}
};
- private void startWaitingForConnection() {
- broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
- broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
- broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED));
- showDialog(DIALOG_CONNECTING);
- }
-
- private void stopWaitingForConnection() {
- broadcastManager.unregisterReceiver(connectedReceiver);
- broadcastManager.unregisterReceiver(connectionFailedReceiver);
- broadcastManager.unregisterReceiver(passwordRequestedReceiver);
- }
+ private final OnClickListener startNetGameListener = new OnClickListener() {
+ public void onClick(View v) {
+ State state = Netplay.getAppInstance(getApplicationContext()).getState();
+ switch(state) {
+ case NOT_CONNECTED:
+ FragmentManager fm = getSupportFragmentManager();
+ StartNetgameDialog startNetgameDialog = new StartNetgameDialog();
+ startNetgameDialog.show(fm, "start_netgame_dialog");
+ break;
+ case CONNECTING:
+ onNetConnectingStarted();
+ break;
+ default:
+ startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
+ break;
+ }
+ }
+ };
private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- stopWaitingForConnection();
- dismissDialog(DIALOG_CONNECTING);
startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
}
};
@@ -294,8 +205,6 @@
private BroadcastReceiver connectionFailedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- stopWaitingForConnection();
- dismissDialog(DIALOG_CONNECTING);
if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
Toast.makeText(getApplicationContext(), intent.getStringExtra(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
}
@@ -305,8 +214,15 @@
private BroadcastReceiver passwordRequestedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- passwordedUsername = intent.getStringExtra(Netplay.EXTRA_PLAYERNAME);
- showDialog(DIALOG_PASSWORD);
+ FragmentManager fm = getSupportFragmentManager();
+ PasswordDialog passwordDialog = new PasswordDialog(intent.getStringExtra(Netplay.EXTRA_PLAYERNAME));
+ passwordDialog.show(fm, "fragment_password_dialog");
}
};
+
+ public void onNetConnectingStarted() {
+ FragmentManager fm = getSupportFragmentManager();
+ ConnectingDialog connectingDialog = new ConnectingDialog();
+ connectingDialog.show(fm, "fragment_connecting_dialog");
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/PasswordDialog.java Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,60 @@
+package org.hedgewars.hedgeroid;
+
+import org.hedgewars.hedgeroid.netplay.Netplay;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.text.InputType;
+import android.text.method.PasswordTransformationMethod;
+import android.widget.EditText;
+
+public class PasswordDialog extends ConnectionDependendDialogFragment {
+ String username;
+
+ public PasswordDialog() {
+ }
+
+ public PasswordDialog(String username) {
+ this.username = username;
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle icicle) {
+ super.onSaveInstanceState(icicle);
+ icicle.putString("username", username);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ if(savedInstanceState != null) {
+ username = savedInstanceState.getString("username");
+ }
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final EditText editText = new EditText(getActivity());
+ final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+
+ editText.setHint(R.string.dialog_password_hint);
+ editText.setId(android.R.id.text1);
+ editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
+ builder.setView(editText);
+ builder.setTitle(R.string.dialog_password_title);
+ builder.setMessage(getString(R.string.dialog_password_message, username));
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ String password = editText.getText().toString();
+ editText.setText("");
+ netplay.sendPassword(password);
+ }
+ });
+ return builder.create();
+ }
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ super.onCancel(dialog);
+ Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartNetgameDialog.java Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,76 @@
+package org.hedgewars.hedgeroid;
+
+import org.hedgewars.hedgeroid.netplay.Netplay;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.view.KeyEvent;
+import android.view.inputmethod.EditorInfo;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.TextView.OnEditorActionListener;
+
+public class StartNetgameDialog extends DialogFragment {
+ private static final String PREF_PLAYERNAME = "playerName";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
+ final String playerName = prefs.getString(PREF_PLAYERNAME, "Player");
+ final EditText editText = new EditText(getActivity());
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+
+ editText.setText(playerName);
+ editText.setHint(R.string.start_netgame_dialog_playername_hint);
+ editText.setId(android.R.id.text1);
+ editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
+ editText.setSingleLine();
+
+ builder.setTitle(R.string.start_netgame_dialog_title);
+ builder.setMessage(R.string.start_netgame_dialog_message);
+ builder.setView(editText);
+ builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ editText.setText(playerName);
+ }
+ });
+
+ editText.setOnEditorActionListener(new OnEditorActionListener() {
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ boolean handled = false;
+ if(actionId == EditorInfo.IME_ACTION_DONE) {
+ startConnection(v.getText().toString());
+ handled = true;
+ }
+ return handled;
+ }
+ });
+
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ startConnection(editText.getText().toString());
+ }
+ });
+
+ return builder.create();
+ }
+
+ private void startConnection(String username) {
+ if(username.length() > 0) {
+ SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
+ Editor edit = prefs.edit();
+ edit.putString(PREF_PLAYERNAME, username);
+ edit.commit();
+
+ Netplay.getAppInstance(getActivity().getApplicationContext()).connectToDefaultServer(username);
+ getDialog().dismiss();
+ ((MainActivity)getActivity()).onNetConnectingStarted();
+ }
+ }
+}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java Fri Jul 27 01:38:24 2012 +0200
@@ -48,9 +48,9 @@
tabHost.setup();
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
- tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(createIndicatorView(tabHost, "Rooms", null)).setContent(R.id.roomListFragment));
- tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, "Chat", null)).setContent(R.id.chatFragment));
- tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, "Players", null)).setContent(R.id.playerListFragment));
+ tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_rooms, getResources().getDrawable(R.drawable.roomlist_ingame))).setContent(R.id.roomListFragment));
+ tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_chat, getResources().getDrawable(R.drawable.edit))).setContent(R.id.chatFragment));
+ tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_players, getResources().getDrawable(R.drawable.human))).setContent(R.id.playerListFragment));
if (icicle != null) {
tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
@@ -64,7 +64,7 @@
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(disconnectReceiver);
}
- private View createIndicatorView(TabHost tabHost, CharSequence label, Drawable icon) {
+ private View createIndicatorView(TabHost tabHost, int label, Drawable icon) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tabIndicator = inflater.inflate(R.layout.tab_indicator,
@@ -122,37 +122,6 @@
netconn.disconnect();
super.onBackPressed();
}
-
- /*@Override
- protected void onCreate(Bundle arg0) {
- super.onCreate(arg0);
- setContentView(R.layout.activity_lobby);
- ViewPager pager = (ViewPager)findViewById(R.id.pager);
- if(pager != null) {
- pager.setAdapter(new Adapter(getSupportFragmentManager()));
- }
- }
-
- private static class Adapter extends FragmentPagerAdapter {
- public Adapter(FragmentManager mgr) {
- super(mgr);
- }
-
- @Override
- public int getCount() {
- return 3;
- }
-
- @Override
- public Fragment getItem(int arg0) {
- switch(arg0) {
- case 0: return new RoomlistFragment();
- case 1: return new LobbyChatFragment();
- case 2: return new PlayerlistFragment();
- default: throw new IndexOutOfBoundsException();
- }
- }
- }*/
@Override
protected void onSaveInstanceState(Bundle icicle) {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java Fri Jul 27 01:38:24 2012 +0200
@@ -58,16 +58,12 @@
private final class ChatSendListener implements OnEditorActionListener {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- boolean handled = false;
- if(actionId == EditorInfo.IME_ACTION_SEND) {
- String text = v.getText().toString();
- if(text.length()>0) {
- v.setText("");
- netconn.sendChat(text);
- handled = true;
- }
+ String text = v.getText().toString();
+ if(text.length()>0) {
+ v.setText("");
+ netconn.sendChat(text);
}
- return handled;
+ return true;
}
}
}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java Fri Jul 27 01:38:24 2012 +0200
@@ -95,7 +95,7 @@
void appendChat(String playerName, String msg) {
if(msg.startsWith("/me ")) {
- append(withColor("*"+playerName+" "+msg, MECHAT_COLOR));
+ append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
} else {
Spanned name = bold(playerName+": ");
Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/OpenConnectionService.java Fri Jul 27 01:38:24 2012 +0200
@@ -0,0 +1,13 @@
+package org.hedgewars.hedgeroid.netplay;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+public class OpenConnectionService extends Service {
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistFragment.java Thu Jul 26 11:10:56 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistFragment.java Fri Jul 27 01:38:24 2012 +0200
@@ -6,9 +6,6 @@
import android.os.CountDownTimer;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -37,7 +34,6 @@
adapter = new RoomListAdapter(getActivity());
adapter.setList(netconn.roomList);
setListAdapter(adapter);
- setHasOptionsMenu(true);
}
@Override
@@ -70,23 +66,6 @@
adapter.invalidate();
}
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- inflater.inflate(R.menu.lobby_roomlist_options, menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch(item.getItemId()) {
- case R.id.roomlist_refresh:
- netconn.sendRoomlistRequest();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
}