project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java
author Medo <smaxein@googlemail.com>
Sat, 21 Jul 2012 14:56:52 +0200
changeset 7349 12fdfd2038d4
parent 7330 867e4fda496e
child 7355 5673e95ef647
permissions -rw-r--r--
Hedgeroid: More work on the lobby activity
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
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
     3
import java.util.ArrayList;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
import org.hedgewars.hedgeroid.R;
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
     7
import android.content.Context;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
import android.os.Bundle;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
     9
import android.support.v4.app.Fragment;
7330
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents: 7328
diff changeset
    10
import android.support.v4.app.FragmentActivity;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    11
import android.support.v4.app.FragmentPagerAdapter;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    12
import android.support.v4.view.ViewPager;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
import android.view.View;
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    14
import android.view.ViewGroup;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    15
import android.widget.TabHost;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    16
import android.widget.TabWidget;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
7330
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents: 7328
diff changeset
    18
public class LobbyActivity extends FragmentActivity {
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    19
    TabHost mTabHost;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    20
    ViewPager  mViewPager;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    21
    TabsAdapter mTabsAdapter;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    23
    @Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    24
    protected void onCreate(Bundle savedInstanceState) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    25
        super.onCreate(savedInstanceState);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    26
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    27
        setContentView(R.layout.activity_lobby);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    28
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    29
        if(mTabHost != null) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    30
	        mTabHost.setup();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    31
	
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    32
	        mViewPager = (ViewPager)findViewById(R.id.pager);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    33
	
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    34
	        mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    36
	        mTabsAdapter.addTab(mTabHost.newTabSpec("roomlist").setIndicator("Rooms"),
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    37
	        		RoomlistFragment.class, null);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    38
	        mTabsAdapter.addTab(mTabHost.newTabSpec("chat").setIndicator("Chat"),
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    39
	        		LobbyChatFragment.class, null);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    40
	        mTabsAdapter.addTab(mTabHost.newTabSpec("players").setIndicator("Players"),
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    41
	        		PlayerlistFragment.class, null);
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    43
	        if (savedInstanceState != null) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    44
	            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
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
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    47
    }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    48
    
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    49
	/*@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    50
	protected void onCreate(Bundle arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    51
		super.onCreate(arg0);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    52
		setContentView(R.layout.activity_lobby);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    53
		ViewPager pager = (ViewPager)findViewById(R.id.pager);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    54
		if(pager != null) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    55
			pager.setAdapter(new Adapter(getSupportFragmentManager()));
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
		}
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	}
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    59
	private static class Adapter extends FragmentPagerAdapter {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    60
		public Adapter(FragmentManager mgr) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    61
			super(mgr);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    62
		}
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    63
		
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    64
		@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    65
		public int getCount() {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    66
			return 3;
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
		}
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    68
		
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    69
		@Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    70
		public Fragment getItem(int arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    71
			switch(arg0) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    72
			case 0: return new RoomlistFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    73
			case 1: return new LobbyChatFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    74
			case 2: return new PlayerlistFragment();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    75
			default: throw new IndexOutOfBoundsException();
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
			}
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    77
		}
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    78
	}*/
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    79
	
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
    @Override
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    81
    protected void onSaveInstanceState(Bundle outState) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    82
        super.onSaveInstanceState(outState);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    83
        if(mTabHost != null) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    84
        	outState.putString("tab", mTabHost.getCurrentTabTag());
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    85
        }
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
    }
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	
7349
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    88
    /**
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    89
     * This is a helper class that implements the management of tabs and all
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    90
     * details of connecting a ViewPager with associated TabHost.  It relies on a
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    91
     * trick.  Normally a tab host has a simple API for supplying a View or
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    92
     * Intent that each tab will show.  This is not sufficient for switching
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    93
     * between pages.  So instead we make the content part of the tab host
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    94
     * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    95
     * view to show as the tab content.  It listens to changes in tabs, and takes
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    96
     * care of switch to the correct paged in the ViewPager whenever the selected
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    97
     * tab changes.
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    98
     */
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    99
    public static class TabsAdapter extends FragmentPagerAdapter
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   100
            implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   101
        private final Context mContext;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   102
        private final TabHost mTabHost;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   103
        private final ViewPager mViewPager;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   104
        private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   105
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   106
        static final class TabInfo {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   107
            private final Class<?> clss;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   108
            private final Bundle args;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   109
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   110
            TabInfo(Class<?> _class, Bundle _args) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   111
                clss = _class;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   112
                args = _args;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   113
            }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   114
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   115
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   116
        static class DummyTabFactory implements TabHost.TabContentFactory {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   117
            private final Context mContext;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   118
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   119
            public DummyTabFactory(Context context) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   120
                mContext = context;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   121
            }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   122
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   123
            public View createTabContent(String tag) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   124
                View v = new View(mContext);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   125
                v.setMinimumWidth(0);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   126
                v.setMinimumHeight(0);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   127
                return v;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   128
            }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   129
        }
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
        public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   132
            super(activity.getSupportFragmentManager());
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   133
            mContext = activity;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   134
            mTabHost = tabHost;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   135
            mViewPager = pager;
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   136
            mTabHost.setOnTabChangedListener(this);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   137
            mViewPager.setAdapter(this);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   138
            mViewPager.setOnPageChangeListener(this);
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
        public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   142
            tabSpec.setContent(new DummyTabFactory(mContext));
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   143
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   144
            TabInfo info = new TabInfo(clss, args);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   145
            mTabs.add(info);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   146
            mTabHost.addTab(tabSpec);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   147
            notifyDataSetChanged();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   148
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   149
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   150
        @Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   151
        public int getCount() {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   152
            return mTabs.size();
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
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   155
        @Override
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   156
        public Fragment getItem(int position) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   157
            TabInfo info = mTabs.get(position);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   158
            return Fragment.instantiate(mContext, info.clss.getName(), info.args);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   159
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   160
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   161
        public void onTabChanged(String tabId) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   162
            int position = mTabHost.getCurrentTab();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   163
            mViewPager.setCurrentItem(position);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   164
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   165
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   166
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   167
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   168
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   169
        public void onPageSelected(int position) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   170
            // Unfortunately when TabHost changes the current tab, it kindly
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   171
            // also takes care of putting focus on it when not in touch mode.
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   172
            // The jerk.
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   173
            // This hack tries to prevent this from pulling focus out of our
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   174
            // ViewPager.
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   175
            TabWidget widget = mTabHost.getTabWidget();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   176
            int oldFocusability = widget.getDescendantFocusability();
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   177
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   178
            mTabHost.setCurrentTab(position);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   179
            widget.setDescendantFocusability(oldFocusability);
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   180
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   181
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   182
        public void onPageScrollStateChanged(int state) {
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   183
        }
12fdfd2038d4 Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
   184
    }
7328
cd919a2ead4e Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff changeset
   185
}