project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java
author Medo <smaxein@googlemail.com>
Tue, 24 Jul 2012 16:57:48 +0200
changeset 7355 5673e95ef647
parent 7349 12fdfd2038d4
child 7358 57a508884052
permissions -rw-r--r--
Hedgeroid: Misguided attempts at getting the connection lifecycle right. Committing this because it basically runs this way, so i might want to revert to it later :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import org.hedgewars.hedgeroid.R;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
     4
import org.hedgewars.hedgeroid.netplay.NetplayService.NetplayBinder;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
     6
import android.content.BroadcastReceiver;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
     7
import android.content.ComponentName;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
     8
import android.content.Context;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
     9
import android.content.Intent;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    10
import android.content.IntentFilter;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    11
import android.content.ServiceConnection;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    12
import android.graphics.drawable.Drawable;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
import android.os.Bundle;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    14
import android.os.IBinder;
7330
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents: 7328
diff changeset
    15
import android.support.v4.app.FragmentActivity;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    16
import android.support.v4.content.LocalBroadcastManager;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    17
import android.view.LayoutInflater;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    18
import android.view.Menu;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    19
import android.view.MenuItem;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
import android.view.View;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    21
import android.widget.ImageView;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    22
import android.widget.LinearLayout;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    23
import android.widget.TabHost;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    24
import android.widget.TextView;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    25
import android.widget.Toast;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
7330
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents: 7328
diff changeset
    27
public class LobbyActivity extends FragmentActivity {
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    28
    private TabHost tabHost;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    29
    private NetplayService service;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    30
    
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    31
    private final BroadcastReceiver disconnectReceiver = new BroadcastReceiver() {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    32
		@Override
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    33
		public void onReceive(Context context, Intent intent) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    34
			String message = intent.getStringExtra(NetplayService.EXTRA_MESSAGE);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    35
			Toast.makeText(getApplicationContext(), "Disconnected: "+message, Toast.LENGTH_LONG).show();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    36
			finish();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    37
		}
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    38
	};
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    39
    
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    40
    @Override
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    41
    protected void onCreate(Bundle icicle) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    42
        super.onCreate(icicle);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    43
        LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(disconnectReceiver, new IntentFilter(NetplayService.ACTION_DISCONNECTED));
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    44
		bindService(new Intent(this, NetplayService.class), serviceConnection, 0);
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    45
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    46
        setContentView(R.layout.activity_lobby);
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    47
        tabHost = (TabHost)findViewById(android.R.id.tabhost);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    48
        if(tabHost != null) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    49
	        tabHost.setup();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    50
	        tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    51
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    52
	        tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(createIndicatorView(tabHost, "Rooms", null)).setContent(R.id.roomListFragment));
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    53
	        tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, "Chat", null)).setContent(R.id.chatFragment));
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    54
	        tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, "Players", null)).setContent(R.id.playerListFragment));
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
	
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    56
	        if (icicle != null) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    57
	            tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    58
	        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    59
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    60
    }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    61
    
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    62
    @Override
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    63
    protected void onDestroy() {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    64
    	super.onDestroy();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    65
    	LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(disconnectReceiver);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    66
    	unbindService(serviceConnection);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    67
    }
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    68
    
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    69
    private View createIndicatorView(TabHost tabHost, CharSequence label, Drawable icon) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    70
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    71
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    72
        View tabIndicator = inflater.inflate(R.layout.tab_indicator,
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    73
                tabHost.getTabWidget(), // tab widget is the parent
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    74
                false); // no inflate params
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    75
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    76
        final TextView tv = (TextView) tabIndicator.findViewById(R.id.title);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    77
        tv.setText(label);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    78
        
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    79
        if(icon != null) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    80
	        final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    81
	        iconView.setImageDrawable(icon);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    82
        }
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    83
        
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    84
        return tabIndicator;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    85
    }
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    86
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    87
    
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    88
	@Override
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    89
	public boolean onCreateOptionsMenu(Menu menu) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    90
		super.onCreateOptionsMenu(menu);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    91
		getMenuInflater().inflate(R.menu.lobby_options, menu);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    92
		return true;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    93
	}
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    94
	
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    95
	@Override
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    96
	public boolean onOptionsItemSelected(MenuItem item) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    97
		switch(item.getItemId()) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    98
		case R.id.room_create:
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
    99
			Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   100
			return true;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   101
		case R.id.disconnect:
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   102
			if(service != null && service.isConnected()) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   103
				service.disconnect();
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   104
			}
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   105
			return true;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   106
		default:
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   107
			return super.onOptionsItemSelected(item);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   108
		}
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   109
	}
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   110
    
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   111
	/*@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   112
	protected void onCreate(Bundle arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   113
		super.onCreate(arg0);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   114
		setContentView(R.layout.activity_lobby);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   115
		ViewPager pager = (ViewPager)findViewById(R.id.pager);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   116
		if(pager != null) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   117
			pager.setAdapter(new Adapter(getSupportFragmentManager()));
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
		}
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
	}
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   121
	private static class Adapter extends FragmentPagerAdapter {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   122
		public Adapter(FragmentManager mgr) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   123
			super(mgr);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   124
		}
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   125
		
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   126
		@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   127
		public int getCount() {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   128
			return 3;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
		}
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   130
		
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   131
		@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   132
		public Fragment getItem(int arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   133
			switch(arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   134
			case 0: return new RoomlistFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   135
			case 1: return new LobbyChatFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   136
			case 2: return new PlayerlistFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   137
			default: throw new IndexOutOfBoundsException();
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
			}
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   139
		}
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   140
	}*/
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   141
	
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
    @Override
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   143
    protected void onSaveInstanceState(Bundle icicle) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   144
        super.onSaveInstanceState(icicle);
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   145
        if(tabHost != null) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   146
        	icicle.putString("currentTab", tabHost.getCurrentTabTag());
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   147
        }
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
    }
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   149
    
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   150
    private ServiceConnection serviceConnection = new ServiceConnection() {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   151
        public void onServiceConnected(ComponentName className, IBinder binder) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   152
        	service = ((NetplayBinder) binder).getService();
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   153
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   154
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   155
        public void onServiceDisconnected(ComponentName className) {
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   156
        	service = null;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   157
        }
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   158
    };
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
}