project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java
changeset 7355 5673e95ef647
parent 7352 641f11cdd319
child 7358 57a508884052
equal deleted inserted replaced
7352:641f11cdd319 7355:5673e95ef647
    24 
    24 
    25 public class LobbyChatFragment extends Fragment {
    25 public class LobbyChatFragment extends Fragment {
    26 	private EditText editText;
    26 	private EditText editText;
    27 	private ListView listView;
    27 	private ListView listView;
    28 	private ChatlogAdapter adapter;
    28 	private ChatlogAdapter adapter;
    29 	private Netconn netconn;
    29 	private NetplayService service;
    30 	
    30 	
    31 	private void commitText() {
    31 	private void commitText() {
    32 		String text = editText.getText().toString();
    32 		String text = editText.getText().toString();
    33 		if(netconn != null && netconn.isConnected() && text.length()>0) {
    33 		if(service != null && service.isConnected() && text.length()>0) {
    34 			editText.setText("");
    34 			editText.setText("");
    35 			netconn.sendChat(text);
    35 			service.sendChat(text);
    36 		}
    36 		}
    37 	}
    37 	}
    38 	
    38 	
    39 	@Override
    39 	@Override
    40 	public void onCreate(Bundle savedInstanceState) {
    40 	public void onCreate(Bundle savedInstanceState) {
    82 	}
    82 	}
    83 
    83 
    84     private ServiceConnection serviceConnection = new ServiceConnection() {
    84     private ServiceConnection serviceConnection = new ServiceConnection() {
    85         public void onServiceConnected(ComponentName className, IBinder binder) {
    85         public void onServiceConnected(ComponentName className, IBinder binder) {
    86         	Log.d("LobbyChatFragment", "netconn received");
    86         	Log.d("LobbyChatFragment", "netconn received");
    87         	netconn = ((NetplayBinder) binder).getNetconn();
    87         	service = ((NetplayBinder) binder).getService();
    88         	adapter.setLog(netconn.lobbyChatlog.getLog());
    88         	adapter.setLog(service.lobbyChatlog.getLog());
    89         	netconn.lobbyChatlog.registerObserver(adapter);
    89         	service.lobbyChatlog.registerObserver(adapter);
    90         }
    90         }
    91 
    91 
    92         public void onServiceDisconnected(ComponentName className) {
    92         public void onServiceDisconnected(ComponentName className) {
    93         	// TODO navigate away
    93         	// TODO navigate away
    94         	netconn.lobbyChatlog.unregisterObserver(adapter);
    94         	service.lobbyChatlog.unregisterObserver(adapter);
    95         	netconn = null;
    95         	service = null;
    96         }
    96         }
    97     };
    97     };
    98 }
    98 }