|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU General Public License |
|
7 * as published by the Free Software Foundation; either version 2 |
|
8 * of the License, or (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program; if not, write to the Free Software |
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 */ |
|
19 |
1 package org.hedgewars.hedgeroid; |
20 package org.hedgewars.hedgeroid; |
2 |
21 |
3 import org.hedgewars.hedgeroid.R; |
|
4 import org.hedgewars.hedgeroid.NetplayStateFragment.NetplayStateListener; |
22 import org.hedgewars.hedgeroid.NetplayStateFragment.NetplayStateListener; |
5 import org.hedgewars.hedgeroid.netplay.Netplay; |
23 import org.hedgewars.hedgeroid.netplay.Netplay; |
6 import org.hedgewars.hedgeroid.netplay.Netplay.State; |
24 import org.hedgewars.hedgeroid.netplay.Netplay.State; |
7 import org.hedgewars.hedgeroid.util.TextInputDialog; |
25 import org.hedgewars.hedgeroid.util.TextInputDialog; |
8 import org.hedgewars.hedgeroid.util.TextInputDialog.TextInputDialogListener; |
26 import org.hedgewars.hedgeroid.util.TextInputDialog.TextInputDialogListener; |
|
27 import org.hedgewars.hedgeroid.util.UiUtils; |
9 |
28 |
10 import android.content.Context; |
|
11 import android.content.Intent; |
29 import android.content.Intent; |
12 import android.graphics.drawable.Drawable; |
|
13 import android.os.Bundle; |
30 import android.os.Bundle; |
14 import android.support.v4.app.FragmentActivity; |
31 import android.support.v4.app.FragmentActivity; |
15 import android.support.v4.app.FragmentTransaction; |
32 import android.support.v4.app.FragmentTransaction; |
16 import android.view.LayoutInflater; |
|
17 import android.view.Menu; |
33 import android.view.Menu; |
18 import android.view.MenuItem; |
34 import android.view.MenuItem; |
19 import android.view.View; |
|
20 import android.widget.ImageView; |
|
21 import android.widget.LinearLayout; |
35 import android.widget.LinearLayout; |
22 import android.widget.TabHost; |
36 import android.widget.TabHost; |
23 import android.widget.TextView; |
|
24 |
37 |
|
38 /** |
|
39 * Activity for the server lobby of a hedgewars server. Allows you to chat, join |
|
40 * and create rooms and interact with a list of players. |
|
41 * |
|
42 * Most of the functionality is handled by various fragments. |
|
43 */ |
25 public class LobbyActivity extends FragmentActivity implements TextInputDialogListener, NetplayStateListener { |
44 public class LobbyActivity extends FragmentActivity implements TextInputDialogListener, NetplayStateListener { |
26 private static final int DIALOG_CREATE_ROOM = 0; |
45 private static final int DIALOG_CREATE_ROOM = 0; |
27 |
46 |
28 private TabHost tabHost; |
47 private TabHost tabHost; |
29 private Netplay netplay; |
48 private Netplay netplay; |
40 trans.add(new NetplayStateFragment(), "netplayFragment"); |
59 trans.add(new NetplayStateFragment(), "netplayFragment"); |
41 trans.commit(); |
60 trans.commit(); |
42 |
61 |
43 netplay = Netplay.getAppInstance(getApplicationContext()); |
62 netplay = Netplay.getAppInstance(getApplicationContext()); |
44 |
63 |
|
64 // Set up a tabbed UI for medium and small screens |
45 tabHost = (TabHost)findViewById(android.R.id.tabhost); |
65 tabHost = (TabHost)findViewById(android.R.id.tabhost); |
46 if(tabHost != null) { |
66 if(tabHost != null) { |
47 tabHost.setup(); |
67 tabHost.setup(); |
48 tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
68 tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
49 |
69 |
50 tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_rooms, getResources().getDrawable(R.drawable.roomlist_ingame))).setContent(R.id.roomListFragment)); |
70 tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment)); |
51 tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_chat, getResources().getDrawable(R.drawable.edit))).setContent(R.id.chatFragment)); |
71 tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment)); |
52 tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_players, getResources().getDrawable(R.drawable.human))).setContent(R.id.playerListFragment)); |
72 tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment)); |
53 |
73 |
54 if (icicle != null) { |
74 if (icicle != null) { |
55 tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
75 tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
56 } |
76 } |
57 } |
77 } |
58 } |
|
59 |
|
60 private View createIndicatorView(TabHost tabHost, int label, Drawable icon) { |
|
61 LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
62 |
|
63 View tabIndicator = inflater.inflate(R.layout.tab_indicator, |
|
64 tabHost.getTabWidget(), // tab widget is the parent |
|
65 false); // no inflate params |
|
66 |
|
67 final TextView tv = (TextView) tabIndicator.findViewById(R.id.title); |
|
68 tv.setText(label); |
|
69 |
|
70 if(icon != null) { |
|
71 final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon); |
|
72 iconView.setImageDrawable(icon); |
|
73 } |
|
74 |
|
75 return tabIndicator; |
|
76 } |
78 } |
77 |
79 |
78 @Override |
80 @Override |
79 public boolean onCreateOptionsMenu(Menu menu) { |
81 public boolean onCreateOptionsMenu(Menu menu) { |
80 super.onCreateOptionsMenu(menu); |
82 super.onCreateOptionsMenu(menu); |