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); }
public SchuldeAdapter(Activity context, List <Schudle> schudles) : base() { this.context = context; this.Schudles = schudles; prefs_model = Global.GetAppPreferences(this.context); }
public PartitionAdapter(Activity context, List <Partition> partitions) : base() { this.context = context; this.Partitions = partitions; prefs_model = Global.GetAppPreferences(this.context); }
public override void OnCallStateChanged(CallState state, String incomingNumber) { //Device call state: Ringing. A new call arrived and is ringing or waiting. In the latter case, another call is already active. PreferencesModel prefmodel = Global.GetAppPreferences(context); DAL dal = new DAL(); if (state == CallState.Ringing) { if (prefmodel.Last_Call_State == CallState.Idle && (prefmodel.numbers.Contains(incomingNumber.CleanNumber()))) { var h = new HistoryItem { Time = DateTime.Now, State = Action.ACTION_ID_INCOMING_CALL, PartitionName = "", Detail = "LLAMADA ENTRANTE:" + incomingNumber }; dal.RegiterEvent(h); prefmodel.Ready = !prefmodel.Ready; if (prefmodel.Ready) { prefmodel.Schudled_Call = true; prefmodel.Schudled_Call_Number = incomingNumber; dal.ActivateAllPartitions(); } else { dal.DesactivateAllPartitions(); } SchudlerManager s_mngr = new SchudlerManager(context); s_mngr.RegisterRestartServiceSchudle(); Intent i = new Intent(context, typeof(DetectorService)); if (Binder != null) { var service = Binder.GetService(); service.ForceStop(); } } //if (Binder != null) //{ // var service = Binder.GetService(); // service.Stop(); //} prefmodel.Last_Call_State = state; } //Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting. if (state == CallState.Offhook) { prefmodel.Last_Call_State = state; //if (Binder != null) //{ // var service = Binder.GetService(); // service.Stop(); //} } //Device call state: No activity. if (state == CallState.Idle) { if (prefmodel.Last_Call_State == CallState.Offhook) { //Intent i = new Intent (context, typeof(DetectorService)); //context.StopService (i); //context.StartService(i); //if(Binder!=null){ // var service= Binder.GetService (); // service.Start(); //} } prefmodel.Last_Call_State = state; } }
public override void OnReceive(Context context, Intent intent) { //Toast.MakeText (context, "Received intent!", ToastLength.Short).Show(); lock (Global.Get_Tone_Reciver_Lock()) { ISharedPreferences pref = context.GetSharedPreferences("DroidvigiaCompat.DroidvigiaCompat.DroidvigiaCompat", FileCreationMode.Private); prefmodel = new PreferencesModel(pref); String nums = prefmodel.numbers; bool DoCall = prefmodel.DoCall; bool DoMessage = prefmodel.DoMessage; bool DoMMS = prefmodel.DoMMS; bool DoSilence = prefmodel.DoSilence; string message = intent.GetStringExtra("message"); //if (LicenseUtility.IsValidSerial (prefmodel.Serial, prefmodel.GetInfoForRequest (context))) { if (!DoSilence) { NotificationManager n_mngr = (NotificationManager)context.GetSystemService(Service.NotificationService); Notification n = new Notification(Resource.Drawable.Icon, message, DateTime.UtcNow.Millisecond); Intent notificationIntent = new Intent(context, typeof(MainActivity)); n_mngr.Cancel(ALARM_NOTIFICATION_ID); //PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, 0); n.Defaults |= NotificationDefaults.All; n.Flags |= NotificationFlags.OnlyAlertOnce | NotificationFlags.AutoCancel; n.SetLatestEventInfo(context, "Alarma!", message, null); n_mngr.Notify(ALARM_NOTIFICATION_ID, n); } List <String> l_nums = prefmodel.notificationNumbers; if (l_nums.Count > 0) { string current_number = l_nums [prefmodel.Call_Phone_Index]; if (prefmodel.Call_Phone_Index == l_nums.Count - 1) { prefmodel.Call_Phone_Index = 0; } else { prefmodel.Call_Phone_Index++; } Intent callIntent = new Intent(Intent.ActionCall, Android.Net.Uri.Parse("tel:" + current_number)); callIntent.AddFlags(ActivityFlags.FromBackground); callIntent.AddFlags(ActivityFlags.NewTask); bool call_done = false; //Message Portion if (DoMessage && message != null) { SmsManager sms_mngr = SmsManager.Default; int i = l_nums.Count; for (int j = l_nums.Count - 1; j >= 0; j--) { if (j == 0 && DoCall) { PendingIntent sentIntent = PendingIntent.GetActivity(context, 0, callIntent, PendingIntentFlags.OneShot); sms_mngr.SendTextMessage(l_nums[j], null, message, sentIntent, null); call_done = true; } else { sms_mngr.SendTextMessage(l_nums[j], null, message, null, null); } } } if (DoCall && prefmodel.Last_Call_State == CallState.Idle && !call_done) { context.StartActivity(callIntent); } } //Intent i2 = new Intent (context, typeof(DetectorService)); //context.StopService (i2); //context.StartService(i2); //}/**/ } }
void CreatePrefModel() { prefmodel = Global.GetAppPreferences(this); }