private void Realese() { TelephonyManager tmgr = (TelephonyManager)this.GetSystemService(Service.TelephonyService); if (phone_state_listener != null) { tmgr.Listen(phone_state_listener, PhoneStateListenerFlags.None); } var shared_prefs = Global.GetSharedPreferences(this); shared_prefs.UnregisterOnSharedPreferenceChangeListener(this); //var audio_mngr = (AudioManager)GetSystemService(Context.AudioService); //AudioFocusRequest result = audio_mngr.AbandonAudioFocus(this); if (notification_timer != null) { notification_timer.Dispose(); notification_timer = null; } NotificationManager n_mngr = (NotificationManager)GetSystemService(Service.NotificationService); n_mngr.CancelAll(); Detecting = false; //if(_jdtmfController!=null) // _jdtmfController.Dispose(); initialized = false; }
protected override void OnPause() { base.OnPause(); ToggleButton bt = FindViewById <ToggleButton> (Resource.Id.toggleButton1); //var service = Binder.GetService(); //service.ToneDetected -= OnToneDetected; //bt.CheckedChange -= OnToggleChecked;] lv_history.ItemClick -= HistoryItemClicked; try{ var service = Binder.GetService(); service.NewHistoryData -= OnNewHistoryData; }catch (Exception) { } ISharedPreferences pref = Global.GetSharedPreferences(this); pref.UnregisterOnSharedPreferenceChangeListener(this); bt.CheckedChange -= OnCheckedChange; UnbindService(connector); }
private void Init() { if (initialized) { Realese(); } tokenParser = new DTMFTokenParser(); ISharedPreferences shared_prefs = Global.GetSharedPreferences(this); shared_prefs.RegisterOnSharedPreferenceChangeListener(this); prefs_model = new PreferencesModel(shared_prefs); var audio_mngr = (AudioManager)GetSystemService(Context.AudioService); AudioFocusRequest result = audio_mngr.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); if (prefs_model.Notificando) { Notificando = true; } //modoComplemento = prefs_model.Modo_Complemento; TelephonyManager tmgr = (TelephonyManager)this.GetSystemService(Service.TelephonyService); if (phone_state_listener == null) { phone_state_listener = new MyPhoneStateListener(this); } tmgr.Listen(phone_state_listener, PhoneStateListenerFlags.CallState); initialized = true; Schudled_CallBack = prefs_model.Schudled_Call; if ((prefs_model.Teclado_Enabled || prefs_model.Ready) && !Detecting) { new System.Threading.Timer((o) => { StartDetect(); }, null, 2000, -1); } }
protected override void OnResume() { base.OnResume(); connector = new DetectorServiceConnection(this); ToggleButton bt = FindViewById <ToggleButton> (Resource.Id.toggleButton1); BindService(new Intent(this.BaseContext, typeof(DetectorService)), connector, Bind.None); connector.BindComplete += OnBindComplete; //bt.Checked = Global.GetAppPreferences(this).Ready; DAL dal = new DAL(); var partitions = dal.GetAllPartitions(); if (partitions.Find((part) => part.Activated) == null) { bt.Checked = false; } else { bt.Checked = true; } bt.CheckedChange += OnCheckedChange; //service.ToneDetected += OnToneDetected; lv_history = FindViewById <ListView> (Resource.Id.lv_history); history_adapter = new HistoryGridAdapter(this, dal.GetTop10Events()); lv_history.Adapter = history_adapter; lv_history.ItemClick += HistoryItemClicked; //bt.CheckedChange += OnToggleChecked; ISharedPreferences pref = Global.GetSharedPreferences(this); prefs_model = new PreferencesModel(pref); pref.RegisterOnSharedPreferenceChangeListener(this); }