author | Medo <smaxein@googlemail.com> |
Mon, 23 Jul 2012 00:17:06 +0200 | |
changeset 7352 | 641f11cdd319 |
parent 7349 | 12fdfd2038d4 |
child 7355 | 5673e95ef647 |
permissions | -rw-r--r-- |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
package org.hedgewars.hedgeroid.netplay; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
|
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
3 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
import org.hedgewars.hedgeroid.R; |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
5 |
import org.hedgewars.hedgeroid.netplay.NetplayService.NetplayBinder; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
|
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
7 |
import android.content.ComponentName; |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
8 |
import android.content.Context; |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
9 |
import android.content.Intent; |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
10 |
import android.content.ServiceConnection; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
import android.os.Bundle; |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
12 |
import android.os.IBinder; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
import android.support.v4.app.Fragment; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
import android.util.Log; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
import android.view.KeyEvent; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
import android.view.LayoutInflater; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
import android.view.View; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
import android.view.ViewGroup; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
import android.view.inputmethod.EditorInfo; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
import android.widget.EditText; |
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
21 |
import android.widget.ListView; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
import android.widget.TextView; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
import android.widget.TextView.OnEditorActionListener; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
public class LobbyChatFragment extends Fragment { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
private EditText editText; |
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
27 |
private ListView listView; |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
28 |
private ChatlogAdapter adapter; |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
29 |
private Netconn netconn; |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
30 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
private void commitText() { |
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
32 |
String text = editText.getText().toString(); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
33 |
if(netconn != null && netconn.isConnected() && text.length()>0) { |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
34 |
editText.setText(""); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
35 |
netconn.sendChat(text); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
} |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
38 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
@Override |
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
40 |
public void onCreate(Bundle savedInstanceState) { |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
41 |
super.onCreate(savedInstanceState); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
42 |
adapter = new ChatlogAdapter(getActivity()); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
43 |
} |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
44 |
|
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
45 |
@Override |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
public void onStart() { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
super.onStart(); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
getActivity().bindService(new Intent(getActivity(), NetplayService.class), serviceConnection, |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
Context.BIND_AUTO_CREATE); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
} |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
51 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
@Override |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
Bundle savedInstanceState) { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
View view = inflater.inflate(R.layout.lobby_chat_fragment, container, false); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
editText = (EditText) view.findViewById(R.id.lobbyChatInput); |
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
57 |
listView = (ListView) view.findViewById(R.id.lobbyConsole); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
|
7346
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
59 |
listView.setAdapter(adapter); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
60 |
listView.setDivider(null); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
61 |
listView.setDividerHeight(0); |
b0f67c5b4215
Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents:
7332
diff
changeset
|
62 |
listView.setVerticalFadingEdgeEnabled(true); |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
63 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
editText.setOnEditorActionListener(new OnEditorActionListener() { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
boolean handled = false; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
if(actionId == EditorInfo.IME_ACTION_SEND) { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
commitText(); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
handled = true; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
return handled; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
}); |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
74 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
return view; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
} |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
77 |
|
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
78 |
@Override |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
79 |
public void onDestroy() { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
80 |
super.onDestroy(); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
81 |
getActivity().unbindService(serviceConnection); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
82 |
} |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
83 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
private ServiceConnection serviceConnection = new ServiceConnection() { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
public void onServiceConnected(ComponentName className, IBinder binder) { |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
86 |
Log.d("LobbyChatFragment", "netconn received"); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
87 |
netconn = ((NetplayBinder) binder).getNetconn(); |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
88 |
adapter.setLog(netconn.lobbyChatlog.getLog()); |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
89 |
netconn.lobbyChatlog.registerObserver(adapter); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
92 |
public void onServiceDisconnected(ComponentName className) { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
// TODO navigate away |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
94 |
netconn.lobbyChatlog.unregisterObserver(adapter); |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
95 |
netconn = null; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
96 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
}; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
} |