Esempio n. 1
0
            public AcceptThread(BluetoothChatService chatService, bool secure)
            {
                this.chatService = chatService;
                BluetoothServerSocket tmp = null;

                mSocketType = secure ? "Secure":"Insecure";

                // Create a new listening server socket
                try
                {
                    if (secure)
                    {
                        tmp = chatService.mAdapter.ListenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
                    }
                    else
                    {
                        tmp = chatService.mAdapter.ListenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
                    }
                }
                catch (IOException e)
                {
                    Log.E(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
Esempio n. 2
0
            public ConnectThread(BluetoothChatService chatService, BluetoothDevice device, bool secure)
            {
                this.chatService = chatService;
                mmDevice         = device;
                BluetoothSocket tmp = null;

                mSocketType = secure ? "Secure" : "Insecure";

                // Get a BluetoothSocket for a connection with the
                // given BluetoothDevice
                try
                {
                    if (secure)
                    {
                        tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID_SECURE);
                    }
                    else
                    {
                        tmp = device.CreateInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
                    }
                }
                catch (IOException e)
                {
                    Log.E(TAG, "Socket Type: " + mSocketType + "create() failed", e);
                }
                mmSocket = tmp;
            }
Esempio n. 3
0
            public AcceptThread(BluetoothChatService service)
            {
                _service = service;
                BluetoothServerSocket tmp = null;

                // Create a new listening server socket
                try {
                    tmp = _service._adapter.ListenUsingRfcommWithServiceRecord(NAME, MY_UUID);
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
        // TODO: Eliminate
        private void SetupChat()
        {
            Log.Debug(TAG, "SetupChat()");

            conversationArrayAdapter = new ArrayAdapter <string>(this, Resource.Layout.message);
            conversationView         = FindViewById <ListView>(Resource.Id.@in);
            conversationView.Adapter = conversationArrayAdapter;

            outEditText = FindViewById <EditText>(Resource.Id.edit_text_out);
            outEditText.EditorAction += delegate(object sender, TextView.EditorActionEventArgs e)
            {
                if (e.ActionId == ImeAction.ImeNull && e.Event.Action == KeyEventActions.Up)
                {
                    Profile profile = new Profile()
                    {
                        ProfileName = "Test Profile"
                    };
                    for (int i = 0; i < 6; i++)
                    {
                        profile.AddPointAt(i, 50 * i, 100 + 25 * i);
                    }
                    profile.MovePoint(5, 0);
                    profile.DeletePointAt(4);

                    var message = new Java.Lang.String(profile.ConvertToJsonString());
                    SendMessage(message);
                }
            };

            sendButton        = FindViewById <Button>(Resource.Id.button_send);
            sendButton.Click += delegate(object sender, EventArgs e)
            {
                Profile profile = new Profile()
                {
                    ProfileName = "Test Profile"
                };
                for (int i = 0; i < 6; i++)
                {
                    profile.AddPointAt(i, 50 * i, 100 + 25 * i);
                }
                profile.MovePoint(5, 0);
                profile.DeletePointAt(4);

                var message = new Java.Lang.String(profile.ConvertToJsonString());
                SendMessage(message);
            };

            chatService     = new BluetoothChatService(this, new MyHandler(this), UUID.FromString(UUIDs.SDP));
            outStringBuffer = new StringBuffer("");
        }
Esempio n. 5
0
            public ConnectThread(BluetoothDevice device, BluetoothChatService service)
            {
                mmDevice = device;
                _service = service;
                BluetoothSocket tmp = null;

                // Get a BluetoothSocket for a connection with the
                // given BluetoothDevice
                try {
                    tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID);
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "create() failed", e);
                }
                mmSocket = tmp;
            }
Esempio n. 6
0
            public ConnectedThread(BluetoothSocket socket, BluetoothChatService service)
            {
                Log.Debug(TAG, "create ConnectedThread: ");
                mmSocket = socket;
                _service = service;
                Stream tmpIn  = null;
                Stream tmpOut = null;

                // Get the BluetoothSocket input and output streams
                try {
                    tmpIn  = socket.InputStream;
                    tmpOut = socket.OutputStream;
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "temp sockets not created", e);
                }

                mmInStream  = tmpIn;
                mmOutStream = tmpOut;
            }
            public ConnectedThread(BluetoothSocket socket, BluetoothChatService service)
            {
                Log.Debug(TAG, "***ConnectedThread constructor called***");
                mmSocket = socket;
                _service = service;
                Stream tmpIn  = null;
                Stream tmpOut = null;

                try
                {
                    tmpIn  = socket.InputStream;
                    tmpOut = socket.OutputStream;
                }
                catch (Java.IO.IOException e)
                {
                    Log.Error(TAG, "temp sockets not created", e);
                }

                mmInStream  = tmpIn;
                mmOutStream = tmpOut;
            }
Esempio n. 8
0
        private void SetupChat()
        {
            Log.D(TAG, "setupChat()");

            // Initialize the array adapter for the conversation thread
            mConversationArrayAdapter = new ArrayAdapter <string>(this, R.Layouts.message);
            mConversationView         = (ListView)FindViewById(R.Ids.@in);
            mConversationView.SetAdapter(mConversationArrayAdapter);

            // Initialize the compose field with a listener for the return key
            mOutEditText = (EditText)FindViewById(R.Ids.edit_text_out);
            mOutEditText.EditorAction += (s, x) => {
                // If the action is a key-up event on the return key, send the message
                if (x.ActionId == EditorInfo.IME_NULL && x.Event.GetAction() == KeyEvent.ACTION_UP)
                {
                    var message = ((TextView)s).GetText().ToString();
                    SendMessage(message);
                }
                if (D)
                {
                    Log.I(TAG, "END onEditorAction");
                }
                x.IsHandled = true;
            };

            // Initialize the send button with a listener that for click events
            mSendButton        = (Button)FindViewById(R.Ids.button_send);
            mSendButton.Click += (s, x) => {
                // Send a message using content of the edit text widget
                var view    = (TextView)FindViewById(R.Ids.edit_text_out);
                var message = view.GetText().ToString();
                SendMessage(message);
            };

            // Initialize the BluetoothChatService to perform bluetooth connections
            mChatService = new BluetoothChatService(this, mHandler);

            // Initialize the buffer for outgoing messages
            mOutStringBuffer = new StringBuilder("");
        }
Esempio n. 9
0
            public ConnectedThread(BluetoothChatService chatService, BluetoothSocket socket, string socketType)
            {
                Log.D(TAG, "create ConnectedThread: " + socketType);
                this.chatService = chatService;
                mmSocket         = socket;
                InputStream  tmpIn  = null;
                OutputStream tmpOut = null;

                // Get the BluetoothSocket input and output streams
                try
                {
                    tmpIn  = socket.GetInputStream();
                    tmpOut = socket.GetOutputStream();
                }
                catch (IOException e)
                {
                    Log.E(TAG, "temp sockets not created", e);
                }

                mmInStream  = tmpIn;
                mmOutStream = tmpOut;
            }
Esempio n. 10
0
        private void SetupChat()
        {
            Log.Debug(TAG, "SetupChat()");

            // Initialize the array adapter for the conversation thread
            conversationArrayAdapter = new ArrayAdapter <string> (this, Resource.Layout.message);
            conversationView         = FindViewById <ListView> (Resource.Id.@in);
            conversationView.Adapter = conversationArrayAdapter;

            // Initialize the compose field with a listener for the return key
            outEditText = FindViewById <EditText> (Resource.Id.edit_text_out);
            // The action listener for the EditText widget, to listen for the return key
            outEditText.EditorAction += delegate(object sender, TextView.EditorActionEventArgs e) {
                // If the action is a key-up event on the return key, send the message
                if (e.ActionId == ImeAction.ImeNull && e.Event.Action == KeyEventActions.Up)
                {
                    var message = new Java.Lang.String(((TextView)sender).Text);
                    SendMessage(message);
                }
            };

            // Initialize the send button with a listener that for click events
            sendButton        = FindViewById <Button> (Resource.Id.button_send);
            sendButton.Click += delegate(object sender, EventArgs e) {
                // Send a message using content of the edit text widget
                var view    = FindViewById <TextView> (Resource.Id.edit_text_out);
                var message = new Java.Lang.String(view.Text);
                SendMessage(message);
            };

            // Initialize the BluetoothChatService to perform bluetooth connections
            chatService = new BluetoothChatService(this, new MyHandler(this));

            // Initialize the buffer for outgoing messages
            outStringBuffer = new StringBuffer("");
        }
			public AcceptThread(BluetoothChatService chatService, bool secure)
			{
			    this.chatService = chatService;
			    BluetoothServerSocket tmp = null;
				mSocketType = secure ? "Secure":"Insecure";

				// Create a new listening server socket
				try
				{
					if (secure)
					{
						tmp = chatService.mAdapter.ListenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
					}
					else
					{
						tmp = chatService.mAdapter.ListenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
					}
				}
				catch (IOException e)
				{
					Log.E(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
				}
				mmServerSocket = tmp;
			}
			public ConnectThread(BluetoothChatService chatService, BluetoothDevice device, bool secure)
			{
			    this.chatService = chatService;
			    mmDevice = device;
				BluetoothSocket tmp = null;
				mSocketType = secure ? "Secure" : "Insecure";

				// Get a BluetoothSocket for a connection with the
				// given BluetoothDevice
				try
				{
					if (secure)
					{
						tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID_SECURE);
					}
					else
					{
						tmp = device.CreateInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
					}
				}
				catch (IOException e)
				{
					Log.E(TAG, "Socket Type: " + mSocketType + "create() failed", e);
				}
				mmSocket = tmp;
			}
Esempio n. 13
0
		private void SetupChat ()
		{
			Log.Debug (TAG, "SetupChat()");
	
			// Initialize the array adapter for the conversation thread
			conversationArrayAdapter = new ArrayAdapter<string> (this, Resource.Layout.message);
			conversationView = FindViewById<ListView> (Resource.Id.@in);
			conversationView.Adapter = conversationArrayAdapter;
	
			// Initialize the compose field with a listener for the return key
			outEditText = FindViewById<EditText> (Resource.Id.edit_text_out);
			// The action listener for the EditText widget, to listen for the return key
			outEditText.EditorAction += delegate(object sender, TextView.EditorActionEventArgs e) {
				// If the action is a key-up event on the return key, send the message
				if (e.ActionId == ImeAction.ImeNull && e.Event.Action == KeyEventActions.Up) {
					var message = new Java.Lang.String (((TextView) sender).Text);
					SendMessage (message);
				}	
			};
			
			// Initialize the send button with a listener that for click events
			sendButton = FindViewById<Button> (Resource.Id.button_send);
			sendButton.Click += delegate(object sender, EventArgs e) {
				// Send a message using content of the edit text widget
				var view = FindViewById<TextView> (Resource.Id.edit_text_out);
				var message = new Java.Lang.String (view.Text);
				SendMessage (message);
			};
			
			// Initialize the BluetoothChatService to perform bluetooth connections
			chatService = new BluetoothChatService (this, new MyHandler (this));
			
			// Initialize the buffer for outgoing messages
			outStringBuffer = new StringBuffer ("");
		}
Esempio n. 14
0
 public Receiver(Activity chat, BluetoothAdapter btAdapter, BluetoothChatService chatService)
 {
     _chat            = chat;
     this.btAdapter   = btAdapter;
     this.chatService = chatService;
 }
Esempio n. 15
0
        private void SetupChat()
        {
            Log.D(TAG, "setupChat()");

            // Initialize the array adapter for the conversation thread
            mConversationArrayAdapter = new ArrayAdapter<string>(this, R.Layout.message);
            mConversationView = (ListView)FindViewById(R.Id.@in);
            mConversationView.SetAdapter(mConversationArrayAdapter);

            // Initialize the compose field with a listener for the return key
            mOutEditText = (EditText)FindViewById(R.Id.edit_text_out);
            mOutEditText.EditorAction += (s, x) => {
                // If the action is a key-up event on the return key, send the message
                if (x.ActionId == EditorInfo.IME_NULL && x.Event.Action == KeyEvent.ACTION_UP)
                {
                    var message = ((TextView)s).GetText().ToString();
                    SendMessage(message);
                }
                if (D)
                    Log.I(TAG, "END onEditorAction");
                x.IsHandled = true;
            };

            // Initialize the send button with a listener that for click events
            mSendButton = (Button)FindViewById(R.Id.button_send);
            mSendButton.Click += (s, x) => {
                // Send a message using content of the edit text widget
                var view = (TextView)FindViewById(R.Id.edit_text_out);
                var message = view.GetText().ToString();
                SendMessage(message);
            };

            // Initialize the BluetoothChatService to perform bluetooth connections
            mChatService = new BluetoothChatService(this, mHandler);

            // Initialize the buffer for outgoing messages
            mOutStringBuffer = new StringBuilder("");
        }
			public ConnectedThread(BluetoothChatService chatService, BluetoothSocket socket, string socketType)
			{
				Log.D(TAG, "create ConnectedThread: " + socketType);
			    this.chatService = chatService;
			    mmSocket = socket;
				InputStream tmpIn = null;
				OutputStream tmpOut = null;

				// Get the BluetoothSocket input and output streams
				try
				{
					tmpIn = socket.GetInputStream();
					tmpOut = socket.GetOutputStream();
				}
				catch (IOException e)
				{
					Log.E(TAG, "temp sockets not created", e);
				}

				mmInStream = tmpIn;
				mmOutStream = tmpOut;
			}
			public ConnectedThread (BluetoothSocket socket, BluetoothChatService service)
			{
				Log.Debug (TAG, "create ConnectedThread: ");
				mmSocket = socket;
				_service = service;
				Stream tmpIn = null;
				Stream tmpOut = null;
	
				// Get the BluetoothSocket input and output streams
				try {
					tmpIn = socket.InputStream;
					tmpOut = socket.OutputStream;
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "temp sockets not created", e);
				}
	
				mmInStream = tmpIn;
				mmOutStream = tmpOut;
			}
			public ConnectThread (BluetoothDevice device, BluetoothChatService service)
			{
				mmDevice = device;
				_service = service;
				BluetoothSocket tmp = null;
				
				// Get a BluetoothSocket for a connection with the
				// given BluetoothDevice
				try {
					tmp = device.CreateRfcommSocketToServiceRecord (MY_UUID);
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "create() failed", e);
				}
				mmSocket = tmp;
			}
            public ConnectThread(BluetoothDevice device, BluetoothChatService service)
            {
                mmDevice = device;
                _service = service;
                BluetoothSocket tmp = null;

                // Get a BluetoothSocket for a connection with the
                // given BluetoothDevice
                try {
                    //tmp = device.CreateRfcommSocketToServiceRecord (MY_UUID);
                    System.IntPtr createRfcommSocket = JNIEnv.GetMethodID(
                        device.Class.Handle,
                        "createRfcommSocket",
                        "(I)Landroid/bluetooth/BluetoothSocket;");
                    System.IntPtr socket = JNIEnv.CallObjectMethod(
                        device.Handle,
                        createRfcommSocket,
                        new JValue (1));
                    tmp = Java.Lang.Object.GetObject<Android.Bluetooth.BluetoothSocket>(socket, JniHandleOwnership.TransferLocalRef);
                    //System.Reflection.MethodInfo m = typeof(BluetoothDevice).GetMethod("CreateRfcommSocket", System.Reflection.BindingFlags.Default);
                    //tmp = (BluetoothSocket) m.Invoke(device, new object[] {1});
                } catch (Java.IO.IOException e) {
                    Log.Error (TAG, "create() failed", e);
                }
                mmSocket = tmp;
            }
			public AcceptThread (BluetoothChatService service)
			{
				_service = service;
				BluetoothServerSocket tmp = null;
	
				// Create a new listening server socket
				try {
					tmp = _service._adapter.ListenUsingRfcommWithServiceRecord (NAME, MY_UUID);
	
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "listen() failed", e);
				}
				mmServerSocket = tmp;
			}
Esempio n. 21
0
        private void SetupChat()
        {
            Log.Debug (TAG, "SetupChat()");

            // Initialize the BluetoothChatService to perform bluetooth connections
            chatService = new BluetoothChatService (this, new MyHandler (this));
        }