示例#1
0
        /// <summary>
        ///     Disconnect to whatever we are connected to.
        ///     Also forget the previous connection details.
        /// </summary>
        private async void Disconnect()
        {
            SocketWorker.Disconnect();
            await IOWorker.ClearFile(AppFiles.Connection, AppFileExtension.JSON);

            SetConnectionDetails();

            Toast.MakeText(this, Resource.String.toast_disconnected, ToastLength.Long).Show();
        }
示例#2
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            base.SetContentView(Resource.Layout.main);

            //TODO, REMOVE: Debug code.
            await IOWorker.ClearFile(AppFiles.Alarm, AppFileExtension.JSON);

            await IOWorker.ClearFile(AppFiles.LightSocket, AppFileExtension.JSON);

            //await IOWorker.ClearFile(AppFiles.Connection, AppFileExtension.JSON);

            //Fetch the buttons.
            buttonSnoozeAlarms       = FindViewById <Button>(Resource.Id.btn_quick_snooze);
            buttonStopAlarms         = FindViewById <Button>(Resource.Id.btn_quick_stop);
            buttonAlarmActivity      = FindViewById <Button>(Resource.Id.btn_alarm_management);
            buttonConnectionActivity = FindViewById <Button>(Resource.Id.btn_connection_management);
            buttonKakuActivity       = FindViewById <Button>(Resource.Id.btn_light_management);
            buttonTimeActivity       = FindViewById <Button>(Resource.Id.btn_time_management);
            textStatus = FindViewById <TextView>(Resource.Id.text_status);

            //Tell each button to start a different activity.
            buttonAlarmActivity.Click      += (o, s) => StartActivity(typeof(AlarmActivity));
            buttonConnectionActivity.Click += (o, s) => StartActivity(typeof(ConnectionActivity));
            buttonKakuActivity.Click       += (o, s) => StartActivity(typeof(KakuActivity));
            buttonTimeActivity.Click       += (o, s) => StartActivity(typeof(TimeActivity));
            buttonSnoozeAlarms.Click       += (o, s) => SnoozeAlarms();
            buttonStopAlarms.Click         += (o, s) => StopAlarms();

            SetUI(SocketWorker.IsConnected);

            //Check if we previously connected and try those connection details.
            ConnectionData data = await IOWorker.ReadFile <ConnectionData>(AppFiles.Connection);

            //Try to connect to connections details we used earlier.
            if (!data.Equals(default(ConnectionData)))
            {
                if (!SocketWorker.IsConnected)
                {
                    SockErr err = SocketWorker.Connect(data.IP, data.Port);

                    //If we do not have an error, notify the user we connected successfully
                    if (err == SockErr.None)
                    {
                        Toast.MakeText(this, Resource.String.toast_connected, ToastLength.Long).Show();
                        SetUI(SocketWorker.IsConnected);
                    }
                }
            }
        }