author | Medo <smaxein@googlemail.com> |
Tue, 17 Jul 2012 23:06:20 +0200 | |
changeset 7334 | 66a10ae88457 |
parent 7332 | 3f2e130f9715 |
child 7346 | b0f67c5b4215 |
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 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
import java.io.IOException; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
import android.app.Service; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
import android.content.Intent; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
import android.os.Binder; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
import android.os.CountDownTimer; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
import android.os.IBinder; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
public class NetplayService extends Service { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
private final NetplayBinder binder = new NetplayBinder(); |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
13 |
public Netconn netconn; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
private CountDownTimer timer; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
@Override |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
public IBinder onBind(Intent intent) { |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
return binder; |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
@Override |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
public void onCreate() { |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
23 |
if(Flib.INSTANCE.flib_init() != 0) { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
24 |
throw new RuntimeException("Unable to start frontlib"); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
25 |
} |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
26 |
try { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
27 |
netconn = new Netconn(getApplicationContext(), "AndroidTester"); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
28 |
} catch (IOException e) { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
29 |
// TODO better handling |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
throw new RuntimeException("Unable to start frontlib"); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
} |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
32 |
timer = new CountDownTimer(Long.MAX_VALUE, 50) { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
33 |
@Override |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
34 |
public void onTick(long millisUntilFinished) { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
35 |
if(netconn != null) { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
36 |
netconn.tick(); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
37 |
} |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
38 |
} |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
39 |
|
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
40 |
@Override |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
41 |
public void onFinish() { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
42 |
} |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
43 |
}; |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
44 |
timer.start(); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
@Override |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
public void onDestroy() { |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
49 |
netconn.disconnect(); |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
50 |
Flib.INSTANCE.flib_quit(); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
|
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
public class NetplayBinder extends Binder { |
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
54 |
Netconn getNetconn() { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
55 |
return netconn; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
|
7332
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
59 |
public boolean isConnected() { |
3f2e130f9715
Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
60 |
return netconn!=null; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
} |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
} |