7444
|
1 |
package org.hedgewars.hedgeroid;
|
|
2 |
|
|
3 |
import org.hedgewars.hedgeroid.netplay.Netplay;
|
|
4 |
import org.hedgewars.hedgeroid.netplay.Netplay.State;
|
|
5 |
|
|
6 |
import android.app.Dialog;
|
|
7 |
import android.app.ProgressDialog;
|
|
8 |
import android.content.BroadcastReceiver;
|
|
9 |
import android.content.Context;
|
|
10 |
import android.content.DialogInterface;
|
|
11 |
import android.content.Intent;
|
|
12 |
import android.content.IntentFilter;
|
|
13 |
import android.os.Bundle;
|
|
14 |
import android.support.v4.content.LocalBroadcastManager;
|
|
15 |
|
|
16 |
public class ConnectingDialog extends ConnectionDependendDialogFragment {
|
|
17 |
@Override
|
|
18 |
public void onStart() {
|
|
19 |
super.onStart();
|
|
20 |
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
|
|
21 |
|
|
22 |
if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() != State.CONNECTING) {
|
|
23 |
dismiss();
|
|
24 |
}
|
|
25 |
}
|
|
26 |
|
|
27 |
@Override
|
|
28 |
public void onStop() {
|
|
29 |
super.onStop();
|
|
30 |
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(connectedReceiver);
|
|
31 |
}
|
|
32 |
|
|
33 |
@Override
|
|
34 |
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
35 |
ProgressDialog dialog = new ProgressDialog(getActivity());
|
|
36 |
dialog.setIndeterminate(true);
|
|
37 |
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
38 |
dialog.setTitle(R.string.dialog_connecting_title);
|
|
39 |
dialog.setMessage(getString(R.string.dialog_connecting_message));
|
|
40 |
return dialog;
|
|
41 |
}
|
|
42 |
|
|
43 |
private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
|
|
44 |
@Override
|
|
45 |
public void onReceive(Context context, Intent intent) {
|
|
46 |
Dialog dialog = getDialog();
|
|
47 |
if(dialog != null) {
|
|
48 |
dialog.dismiss();
|
|
49 |
} else {
|
|
50 |
dismiss();
|
|
51 |
}
|
|
52 |
}
|
|
53 |
};
|
|
54 |
|
|
55 |
public void onCancel(DialogInterface dialog) {
|
|
56 |
super.onCancel(dialog);
|
|
57 |
Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
|
|
58 |
};
|
|
59 |
}
|