Ejemplo n.º 1
0
		protected override void OnCreate (Bundle bundle)
		{

			base.OnCreate(bundle);

			connectivityManager = GetSystemService(ConnectivityService) as ConnectivityManager;
			locationManager = GetSystemService(LocationService) as LocationManager;

			var mobileState = connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState();
			provider = LocationManager.NetworkProvider;
			locationManager = (LocationManager)GetSystemService(LocationService);
			if (mobileState == NetworkInfo.State.Disconnected) {
				// We are connected via WiFi
				AlertDialog.Builder wifiError = new AlertDialog.Builder (this);
				AlertDialog wifiAlert = wifiError.Create ();
				wifiAlert.SetTitle ("Error Connection");
				wifiAlert.SetMessage ("There is no wifi connection!Please connect to wifi and try again!App now will close!");
				wifiAlert.SetButton ("Ok", delegate {
					wifiAlert.Dismiss ();
					System.Environment.Exit (0);					
				});
			} 
			else if (!locationManager.IsProviderEnabled (provider)) 
			{
				AlertDialog.Builder gpsError = new AlertDialog.Builder (this);
				AlertDialog gpsAlert = gpsError.Create ();
				gpsAlert.SetTitle ("Error Connection");
				gpsAlert.SetMessage ("There is no wifi connection!Please connect to wifi and try again!App now will close!");
				gpsAlert.SetButton ("Ok", delegate {
					gpsAlert.Dismiss ();
					System.Environment.Exit (0);
				});					
			}
			else 
			{
				ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
				ActionBar.SetDisplayShowHomeEnabled (false);
				ActionBar.SetDisplayShowTitleEnabled (false);
				SetContentView(Resource.Layout.Main);

				locationText = FindViewById<TextView>(Resource.Id.location);
				locationText.Text = "Please wait until we find you with our spy devices :)";
				addressText = String.Empty;
				home = new HomeFragment ();
				search = new SearchFragment ();

				mCurrentFragment = home;
				mStackFragments = new Stack<Fragment>();

				var homeTab = ActionBar.NewTab();
				homeTab.SetText(Resources.GetString(Resource.String.tab1_text));
				homeTab.SetIcon(Resource.Drawable.home_icon);
				homeTab.SetTabListener (this);
				ActionBar.AddTab(homeTab);

				var searchTab = ActionBar.NewTab();
				searchTab.SetText(Resources.GetString(Resource.String.tab2_text));
				searchTab.SetIcon(Resource.Drawable.search_icon);
				searchTab.SetTabListener (this);
				ActionBar.AddTab(searchTab);

				var trans = FragmentManager.BeginTransaction ();
				trans.Add (Resource.Id.fragmentContainer, home, "Home");
				trans.Add (Resource.Id.fragmentContainer, search, "Search");
				trans.Hide (search);
				trans.Commit ();
				InitializeLocationManager ();	
			}
		}