Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            towerService = new TowerService();

            recyclerView  = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            layoutManager = new LinearLayoutManager(this);
            recyclerView.SetLayoutManager(layoutManager);
            cellAdapter = new CellAdapter(towerService.GetAll());
            recyclerView.SetAdapter(cellAdapter);

            //Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            //SetSupportActionBar(toolbar);
            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click         += FabOnClick;
            cellText           = FindViewById <TextView>(Resource.Id.cell_text);
            telephony          = GetSystemService(TelephonyService) as TelephonyManager;
            phoneStateListener = new CellListener(ref cellText, telephony);
            telephony.Listen(phoneStateListener, PhoneStateListenerFlags.CellLocation);

            (towerService.GetAll() as ObservableCollection <TowerInfo>).CollectionChanged += (s, e) =>
            {
                cellAdapter.NotifyDataSetChanged();
            };
        }
Esempio n. 2
0
        public void StopService()
        {
            _telephonyManager.Dispose();
            _listener.Dispose();

            _telephonyManager = null;
            _listener         = null;
        }
Esempio n. 3
0
        public void StartService()
        {
            _telephonyManager = (TelephonyManager)Application.Context.GetSystemService(Context.TelephonyService);
            _listener         = new CustomPhoneStateListener(this.CallStatedChanged);

            // Note: manifest must have READ_PHONE_STATE permission
            _telephonyManager.Listen(_listener, PhoneStateListenerFlags.CallState);
        }