protected override void OnStop () { base.OnStop (); if (_broadcastReceiver == null) { Console.WriteLine ( "Network status monitoring not active."); return; } // Unregister the receiver so we no longer get updates. Application.Context.UnregisterReceiver (_broadcastReceiver); // Set the variable to nil, so that we know the receiver is no longer used. _broadcastReceiver.ConnectionStatusChanged -= _networkmonitor.OnNetworkStatusChanged; _broadcastReceiver = null; }
private View selectedRow; // The row in the listview that is selected #endregion #region Activity events protected override void OnStart() { base.OnStart (); _mainActivity = this; if (_broadcastReceiver == null) { NetworkStatusMonitor.ActivityController = 0; _broadcastReceiver = new NetworkStatusBroadcastReceiver (); _broadcastReceiver.ConnectionStatusChanged += _networkmonitor.OnNetworkStatusChanged; // Register the broadcast receiver Application.Context.RegisterReceiver (_broadcastReceiver, new IntentFilter (ConnectivityManager.ConnectivityAction)); } // Create the instance of the UIManager, the big boss that rules the empire // First check if it has some value or not // If it has then we don't change it -> This the case when another activity just overlappes our one if (this._mainUIManager != null) return; // But if not...!!! this._mainUIManager = LastCustomNonConfigurationInstance as UIManager; // this._mainUIManager = LastNonConfigurationInstance as UIManager; // If we get a value from last configurations, we do it! // This means that the screen has been rotated etc if (this._mainUIManager != null) { _mainUIManager.Restore (this); // Get this damned keystore away Android.Views.InputMethods.InputMethodManager imm = (Android.Views.InputMethods.InputMethodManager)GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(_edSearch.WindowToken, 0); } else { // And set the default tab to Kunden _mainUIManager = new UI.UIManager (this ); _mainUIManager.KundenTabClick (); fragment.SetStateFragement((StateFragmentPersonGeneral)_mainUIManager._currentClassState._fragmentState); // Set a notification if the user is online or offline NotificationManager notificationManager = (NotificationManager) _mainActivity.GetSystemService ( Android.Content.Context.NotificationService); if (_user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected) { Notification.Builder builder = new Notification.Builder(_mainActivity) .SetSmallIcon(UI.Resource.Drawable.ic_action_offline) .SetAutoCancel(false) .SetLights(54, 3000, 5) .SetContentText(Resources.GetString(Resource.String.UserOffline)) .SetContentTitle(Resources.GetString(Resource.String.AppName) + " - " + "Offline") .SetTicker(Resources.GetString(Resource.String.UserOffline)); Notification notification = builder.Build(); notificationManager.Notify(2, notification); } else { Notification.Builder builder = new Notification.Builder(_mainActivity) .SetSmallIcon(UI.Resource.Drawable.ic_action_online) .SetAutoCancel(false) .SetLights(54, 3000, 5) .SetContentText(Resources.GetString(Resource.String.UserOnline)) .SetContentTitle(Resources.GetString(Resource.String.AppName) + " - " + "Online") .SetTicker(Resources.GetString(Resource.String.UserOnline)); Notification notification = builder.Build(); notificationManager.Notify(2, notification); } } // And very important // set a reference to this in the UI.Utility // so that is available for the BusinessLayer and the DAL when the connection to the server has been timed out Utilities.InitializeMainActivity(this); Console.WriteLine ("Find the damned skipped frames"); }
protected override void OnCreate(Bundle savedInstanceState) { // Set the main flag for the activity, so that the blank Launcher knows this activity is running isRunning = true; progress_handler = new ProgressHandler (this); // Create the broadcast receiver and bind the event handler // so that the app gets updates of the network connectivity status _networkmonitor = new NetworkStatusMonitor (this); if (_broadcastReceiver == null) { // Set the ActivityController to 0 -> That has the effect that the sound won't be raised // This is just the first time when the activity starts, after that this counter increments // And doesn't prevent the sound NetworkStatusMonitor.ActivityController = 0; _broadcastReceiver = new NetworkStatusBroadcastReceiver (); _broadcastReceiver.ConnectionStatusChanged += _networkmonitor.OnNetworkStatusChanged; // Register the broadcast receiver Application.Context.RegisterReceiver (_broadcastReceiver, new IntentFilter (ConnectivityManager.ConnectivityAction)); } // Keep the ActivityController to 0 because we want to call the UpdateNetworkStatus on our own // And the sound shouldn't be raised UI.MainActivity._networkstate = _networkmonitor.GetNetworkStatus(); base.OnCreate(savedInstanceState); // The SQLite Utility will be initialized // -> Open Connection -> Create Database -> Create Security and Object tables //DataAccessLayer.SQLiteUtilities.Initialize (); // Set the classname which is by default Kunden _className = "Kunden"; // Set the layout SetContentView(Resource.Layout.ActivityMain); // First run the UtilityClasses BusinessLayer.UtilityClasses.FillUtilityClasses(BaseContext.Resources.Configuration.Locale.Language.ToUpper(), _user); // Run our lovely fragment which is by default the FrgGeneral fragment = new PersonGeneralFragment(Resource.Layout.FrgPersonGeneral,this,null); FragmentManager .BeginTransaction() .Replace(Resource.Id.frameContent, fragment) .Commit(); // Initialize the controls _list = FindViewById<ListView>(Resource.Id.left_pane); _btnSearch = FindViewById<ImageButton> (Resource.Id.btnSearch); _btnNew = FindViewById<ImageButton> (Resource.Id.btnNew); _btnEdit = FindViewById<ImageButton> (Resource.Id.btnEdit); _btnSave = FindViewById<ImageButton> (Resource.Id.btnSave); _btnDelete = FindViewById<ImageButton> (Resource.Id.btnDelete); _leftLayout = FindViewById<LinearLayout> (Resource.Id.leftLayout); _btnOffline = FindViewById<ImageButton> (Resource.Id.btnOffline); _btnUebersicht = FindViewById<Button> (Resource.Id.btnUebersicht); _btnCharts = FindViewById<Button> (Resource.Id.btnCharts); _btnTasks = FindViewById<Button> (Resource.Id.btnTasks); _btnAngebot = FindViewById<Button> (Resource.Id.btnAngebot); _btnAuftrag = FindViewById<Button> (Resource.Id.btnAuftrag); _tvTelefon = FindViewById<TextView>(Resource.Id.tvTelefon); _ImageViewRecord = FindViewById<ImageView>(Resource.Id.ImageViewRecord); _btnAnsprechpartner = FindViewById<Button> (Resource.Id.btnAnsprechpartner); _btnMap = FindViewById<Button> (Resource.Id.btnMap); _edSearch = FindViewById<EditText> (Resource.Id.edSearch); // Set the Buttons // Disable the New - Edit - Save - Delete Button _btnNew.Enabled = false; _btnEdit.Enabled = false; _btnSave.Enabled = false; _btnDelete.Enabled = false; _btnOffline.Enabled = false; // Set the eventhandlers of the controls: // Buttons + listview _list.ItemClick += (sender, args) => { ListItemClickAsync (args); }; // Eventhandler for the Search button on the keyboard _edSearch.EditorAction += (object sender, TextView.EditorActionEventArgs e) => { if (e.ActionId == Android.Views.InputMethods.ImeAction.Search) { BtnSearchAsync(); } }; _btnSearch.Click += (sender, e) => { BtnSearchAsync (); }; _btnNew.Click += (sender, e) => { BtnNewClick (); }; _btnEdit.Click += (sender, e) => { BtnEditClick (); }; // BtnSave Event must be handled here _btnSave.Click += (sender, e) => { BtnSaveClickAsync (); }; _btnDelete.Click += (sender, e) => { BtnDeleteClick (); }; _btnUebersicht.Click += (sender, e) => { BtnUebersichtClick (); }; _btnMap.Click += (sender, e) => { BtnMapClickAsync (); }; _btnAnsprechpartner.Click += (sender, e) => { BtnAnsprechpartnerClickAsync(); }; _btnTasks.Click += (sender, e) => { BtnTasksClickAsync (); }; _btnAngebot.Click += (sender, e) => { BtnAngebotClickAsync(); }; _btnAuftrag.Click += (sender, e) => { BtnAuftragClickAsync(); }; _btnCharts.Click += (sender, e) => { BtnChartsClick(); }; _btnOffline.Click += (sender, e) => { BtnOfflineClickAsync(); }; // set the main tabbar according to the permissions this.setMainTabbar(); // Hide the keyboard except the user clickes on it Console.WriteLine("Window.SetSoftInputMode (SoftInput.StateAlwaysHidden); Hide keyboard"); Window.SetSoftInputMode (SoftInput.StateAlwaysHidden); // Set the MainColor FindViewById<TableLayout>(Resource.Id.AM_ColoredTableLayout).SetBackgroundResource(DataAccessLayer.Utilities.MainColor); }